Split the two usages of __ROMCC__:
[coreboot.git] / src / arch / i386 / include / arch / cpu.h
1 #ifndef ARCH_CPU_H
2 #define ARCH_CPU_H
3
4 /*
5  * EFLAGS bits
6  */
7 #define X86_EFLAGS_CF   0x00000001 /* Carry Flag */
8 #define X86_EFLAGS_PF   0x00000004 /* Parity Flag */
9 #define X86_EFLAGS_AF   0x00000010 /* Auxillary carry Flag */
10 #define X86_EFLAGS_ZF   0x00000040 /* Zero Flag */
11 #define X86_EFLAGS_SF   0x00000080 /* Sign Flag */
12 #define X86_EFLAGS_TF   0x00000100 /* Trap Flag */
13 #define X86_EFLAGS_IF   0x00000200 /* Interrupt Flag */
14 #define X86_EFLAGS_DF   0x00000400 /* Direction Flag */
15 #define X86_EFLAGS_OF   0x00000800 /* Overflow Flag */
16 #define X86_EFLAGS_IOPL 0x00003000 /* IOPL mask */
17 #define X86_EFLAGS_NT   0x00004000 /* Nested Task */
18 #define X86_EFLAGS_RF   0x00010000 /* Resume Flag */
19 #define X86_EFLAGS_VM   0x00020000 /* Virtual Mode */
20 #define X86_EFLAGS_AC   0x00040000 /* Alignment Check */
21 #define X86_EFLAGS_VIF  0x00080000 /* Virtual Interrupt Flag */
22 #define X86_EFLAGS_VIP  0x00100000 /* Virtual Interrupt Pending */
23 #define X86_EFLAGS_ID   0x00200000 /* CPUID detection flag */
24
25 struct cpuid_result {
26         uint32_t eax;
27         uint32_t ebx;
28         uint32_t ecx;
29         uint32_t edx;
30 };
31 /*
32  * Generic CPUID function
33  */
34 static inline struct cpuid_result cpuid(int op)
35 {
36         struct cpuid_result result;
37         asm volatile(
38                 "cpuid"
39                 : "=a" (result.eax),
40                   "=b" (result.ebx),
41                   "=c" (result.ecx),
42                   "=d" (result.edx)
43                 : "0" (op));
44         return result;
45 }
46
47
48 /*
49  * CPUID functions returning a single datum
50  */
51 static inline unsigned int cpuid_eax(unsigned int op)
52 {
53         unsigned int eax;
54
55         __asm__("cpuid"
56                 : "=a" (eax)
57                 : "0" (op)
58                 : "ebx", "ecx", "edx");
59         return eax;
60 }
61 static inline unsigned int cpuid_ebx(unsigned int op)
62 {
63         unsigned int eax, ebx;
64
65         __asm__("cpuid"
66                 : "=a" (eax), "=b" (ebx)
67                 : "0" (op)
68                 : "ecx", "edx" );
69         return ebx;
70 }
71 static inline unsigned int cpuid_ecx(unsigned int op)
72 {
73         unsigned int eax, ecx;
74
75         __asm__("cpuid"
76                 : "=a" (eax), "=c" (ecx)
77                 : "0" (op)
78                 : "ebx", "edx" );
79         return ecx;
80 }
81 static inline unsigned int cpuid_edx(unsigned int op)
82 {
83         unsigned int eax, edx;
84
85         __asm__("cpuid"
86                 : "=a" (eax), "=d" (edx)
87                 : "0" (op)
88                 : "ebx", "ecx");
89         return edx;
90 }
91
92
93
94 #define X86_VENDOR_INVALID    0
95 #define X86_VENDOR_INTEL      1
96 #define X86_VENDOR_CYRIX      2
97 #define X86_VENDOR_AMD        3
98 #define X86_VENDOR_UMC        4
99 #define X86_VENDOR_NEXGEN     5
100 #define X86_VENDOR_CENTAUR    6
101 #define X86_VENDOR_RISE       7
102 #define X86_VENDOR_TRANSMETA  8
103 #define X86_VENDOR_NSC        9
104 #define X86_VENDOR_SIS       10 
105 #define X86_VENDOR_UNKNOWN 0xff
106
107 #if !defined( __ROMCC__ ) && !defined(__PRE_RAM__) && defined( __GNUC__)
108 #include <device/device.h>
109
110
111 struct cpu_device_id {
112         unsigned vendor;
113         unsigned device;
114 };
115 struct cpu_driver {
116         struct device_operations *ops;
117         struct cpu_device_id *id_table;
118 };
119
120 struct cpu_info {
121         device_t cpu;
122         unsigned long index;
123 };
124
125 static inline struct cpu_info *cpu_info(void)
126 {
127         struct cpu_info *ci;
128         __asm__("andl %%esp,%0; "
129                 "orl  %2, %0 "
130                 :"=r" (ci) 
131                 : "0" (~(CONFIG_STACK_SIZE - 1)), 
132                 "r" (CONFIG_STACK_SIZE - sizeof(struct cpu_info))
133         );
134         return ci;
135 }
136
137 static inline unsigned long cpu_index(void)
138 {
139         struct cpu_info *ci;
140         ci = cpu_info();
141         return ci->index;
142 }
143
144
145 struct cpuinfo_x86 {
146         uint8_t    x86;            /* CPU family */
147         uint8_t    x86_vendor;     /* CPU vendor */
148         uint8_t    x86_model;
149         uint8_t    x86_mask;
150 };
151
152 static void inline get_fms(struct cpuinfo_x86 *c, uint32_t tfms)
153 {
154         c->x86 = (tfms >> 8) & 0xf;
155         c->x86_model = (tfms >> 4) & 0xf;
156         c->x86_mask = tfms & 0xf;
157         if (c->x86 == 0xf)
158                 c->x86 += (tfms >> 20) & 0xff;
159         if (c->x86 >= 0x6)
160                 c->x86_model += ((tfms >> 16) & 0xF) << 4;
161
162 }
163 #endif
164
165 #endif /* ARCH_CPU_H */