1 #ifndef __ASM_X86_PROCESSOR_H
2 #define __ASM_X86_PROCESSOR_H
4 #include <asm/processor-flags.h>
6 /* Forward declaration, a strange C thing */
11 #include <asm/system.h>
14 * Default implementation of macro that returns current
15 * instruction pointer ("program counter").
17 static inline void *current_text_addr(void)
20 asm volatile("mov $1f,%0\n1:":"=r" (pc));
24 static inline void native_cpuid(unsigned int *eax, unsigned int *ebx,
25 unsigned int *ecx, unsigned int *edx)
27 /* ecx is often an input as well as an output. */
33 : "0" (*eax), "2" (*ecx));
36 static inline void load_cr3(pgd_t *pgdir)
38 write_cr3(__pa(pgdir));
42 # include "processor_32.h"
44 # include "processor_64.h"
47 extern void print_cpu_info(struct cpuinfo_x86 *);
48 extern void init_scattered_cpuid_features(struct cpuinfo_x86 *c);
49 extern unsigned int init_intel_cacheinfo(struct cpuinfo_x86 *c);
50 extern unsigned short num_cache_leaves;
52 static inline unsigned long native_get_debugreg(int regno)
54 unsigned long val = 0; /* Damn you, gcc! */
58 asm("mov %%db0, %0" :"=r" (val)); break;
60 asm("mov %%db1, %0" :"=r" (val)); break;
62 asm("mov %%db2, %0" :"=r" (val)); break;
64 asm("mov %%db3, %0" :"=r" (val)); break;
66 asm("mov %%db6, %0" :"=r" (val)); break;
68 asm("mov %%db7, %0" :"=r" (val)); break;
75 static inline void native_set_debugreg(int regno, unsigned long value)
79 asm("mov %0,%%db0" : /* no output */ :"r" (value));
82 asm("mov %0,%%db1" : /* no output */ :"r" (value));
85 asm("mov %0,%%db2" : /* no output */ :"r" (value));
88 asm("mov %0,%%db3" : /* no output */ :"r" (value));
91 asm("mov %0,%%db6" : /* no output */ :"r" (value));
94 asm("mov %0,%%db7" : /* no output */ :"r" (value));
102 * Set IOPL bits in EFLAGS from given mask
104 static inline void native_set_iopl_mask(unsigned mask)
108 __asm__ __volatile__ ("pushfl;"
115 : "i" (~X86_EFLAGS_IOPL), "r" (mask));
120 #ifndef CONFIG_PARAVIRT
121 #define __cpuid native_cpuid
122 #define paravirt_enabled() 0
125 * These special macros can be used to get or set a debugging register
127 #define get_debugreg(var, register) \
128 (var) = native_get_debugreg(register)
129 #define set_debugreg(value, register) \
130 native_set_debugreg(register, value)
132 #define set_iopl_mask native_set_iopl_mask
133 #endif /* CONFIG_PARAVIRT */
136 * Save the cr4 feature set we're using (ie
137 * Pentium 4MB enable and PPro Global page
138 * enable), so that any CPU's that boot up
139 * after us can get the correct flags.
141 extern unsigned long mmu_cr4_features;
143 static inline void set_in_cr4(unsigned long mask)
146 mmu_cr4_features |= mask;
152 static inline void clear_in_cr4(unsigned long mask)
155 mmu_cr4_features &= ~mask;
161 struct microcode_header {
169 unsigned int datasize;
170 unsigned int totalsize;
171 unsigned int reserved[3];
175 struct microcode_header hdr;
176 unsigned int bits[0];
179 typedef struct microcode microcode_t;
180 typedef struct microcode_header microcode_header_t;
182 /* microcode format is extended from prescott processors */
183 struct extended_signature {
189 struct extended_sigtable {
192 unsigned int reserved[3];
193 struct extended_signature sigs[0];
197 * create a kernel thread without removing it from tasklists
199 extern int kernel_thread(int (*fn)(void *), void *arg, unsigned long flags);
201 /* Free all resources held by a thread. */
202 extern void release_thread(struct task_struct *);
204 /* Prepare to copy thread state - unlazy all lazy status */
205 extern void prepare_to_copy(struct task_struct *tsk);
207 unsigned long get_wchan(struct task_struct *p);
210 * Generic CPUID function
211 * clear %ecx since some cpus (Cyrix MII) do not set or clear %ecx
212 * resulting in stale register contents being returned.
214 static inline void cpuid(unsigned int op,
215 unsigned int *eax, unsigned int *ebx,
216 unsigned int *ecx, unsigned int *edx)
220 __cpuid(eax, ebx, ecx, edx);
223 /* Some CPUID calls want 'count' to be placed in ecx */
224 static inline void cpuid_count(unsigned int op, int count,
225 unsigned int *eax, unsigned int *ebx,
226 unsigned int *ecx, unsigned int *edx)
230 __cpuid(eax, ebx, ecx, edx);
234 * CPUID functions returning a single datum
236 static inline unsigned int cpuid_eax(unsigned int op)
238 unsigned int eax, ebx, ecx, edx;
240 cpuid(op, &eax, &ebx, &ecx, &edx);
243 static inline unsigned int cpuid_ebx(unsigned int op)
245 unsigned int eax, ebx, ecx, edx;
247 cpuid(op, &eax, &ebx, &ecx, &edx);
250 static inline unsigned int cpuid_ecx(unsigned int op)
252 unsigned int eax, ebx, ecx, edx;
254 cpuid(op, &eax, &ebx, &ecx, &edx);
257 static inline unsigned int cpuid_edx(unsigned int op)
259 unsigned int eax, ebx, ecx, edx;
261 cpuid(op, &eax, &ebx, &ecx, &edx);
265 /* REP NOP (PAUSE) is a good thing to insert into busy-wait loops. */
266 static inline void rep_nop(void)
268 __asm__ __volatile__("rep;nop": : :"memory");
271 /* Stop speculative execution */
272 static inline void sync_core(void)
275 asm volatile("cpuid" : "=a" (tmp) : "0" (1)
276 : "ebx", "ecx", "edx", "memory");
279 #define cpu_relax() rep_nop()
281 static inline void __monitor(const void *eax, unsigned long ecx,
284 /* "monitor %eax,%ecx,%edx;" */
286 ".byte 0x0f,0x01,0xc8;"
287 : :"a" (eax), "c" (ecx), "d"(edx));
290 static inline void __mwait(unsigned long eax, unsigned long ecx)
292 /* "mwait %eax,%ecx;" */
294 ".byte 0x0f,0x01,0xc9;"
295 : :"a" (eax), "c" (ecx));
298 static inline void __sti_mwait(unsigned long eax, unsigned long ecx)
300 /* "mwait %eax,%ecx;" */
302 "sti; .byte 0x0f,0x01,0xc9;"
303 : :"a" (eax), "c" (ecx));
306 extern void mwait_idle_with_hints(unsigned long eax, unsigned long ecx);
308 extern int force_mwait;
310 extern void select_idle_routine(const struct cpuinfo_x86 *c);
312 extern unsigned long boot_option_idle_override;
314 /* Boot loader type from the setup header */
315 extern int bootloader_type;
316 #define cache_line_size() (boot_cpu_data.x86_cache_alignment)
318 #define HAVE_ARCH_PICK_MMAP_LAYOUT 1
319 #define ARCH_HAS_PREFETCHW
320 #define ARCH_HAS_SPINLOCK_PREFETCH
322 #define spin_lock_prefetch(x) prefetchw(x)
323 /* This decides where the kernel will search for a free chunk of vm
324 * space during mmap's.
326 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
328 #define KSTK_EIP(task) (task_pt_regs(task)->ip)