]> err.no Git - linux-2.6/blob - include/asm-x86/processor_64.h
x86: prepare kprobes code for x86 unification
[linux-2.6] / include / asm-x86 / processor_64.h
1 /*
2  * Copyright (C) 1994 Linus Torvalds
3  */
4
5 #ifndef __ASM_X86_64_PROCESSOR_H
6 #define __ASM_X86_64_PROCESSOR_H
7
8 #include <asm/segment.h>
9 #include <asm/page.h>
10 #include <asm/types.h>
11 #include <asm/sigcontext.h>
12 #include <asm/cpufeature.h>
13 #include <linux/threads.h>
14 #include <asm/msr.h>
15 #include <asm/current.h>
16 #include <asm/system.h>
17 #include <asm/mmsegment.h>
18 #include <asm/percpu.h>
19 #include <linux/personality.h>
20 #include <linux/cpumask.h>
21 #include <asm/processor-flags.h>
22 #include <asm/desc_defs.h>
23
24 #define TF_MASK         0x00000100
25 #define IF_MASK         0x00000200
26 #define IOPL_MASK       0x00003000
27 #define NT_MASK         0x00004000
28 #define VM_MASK         0x00020000
29 #define AC_MASK         0x00040000
30 #define VIF_MASK        0x00080000      /* virtual interrupt flag */
31 #define VIP_MASK        0x00100000      /* virtual interrupt pending */
32 #define ID_MASK         0x00200000
33
34 static inline int desc_empty(const void *ptr)
35 {
36         const u32 *desc = ptr;
37         return !(desc[0] | desc[1]);
38 }
39
40 /*
41  * Default implementation of macro that returns current
42  * instruction pointer ("program counter").
43  */
44 #define current_text_addr() ({ void *pc; asm volatile("leaq 1f(%%rip),%0\n1:":"=r"(pc)); pc; })
45
46 /*
47  *  CPU type and hardware bug flags. Kept separately for each CPU.
48  */
49
50 struct cpuinfo_x86 {
51         __u8    x86;            /* CPU family */
52         __u8    x86_vendor;     /* CPU vendor */
53         __u8    x86_model;
54         __u8    x86_mask;
55         int     cpuid_level;    /* Maximum supported CPUID level, -1=no CPUID */
56         __u32   x86_capability[NCAPINTS];
57         char    x86_vendor_id[16];
58         char    x86_model_id[64];
59         int     x86_cache_size;  /* in KB */
60         int     x86_clflush_size;
61         int     x86_cache_alignment;
62         int     x86_tlbsize;    /* number of 4K pages in DTLB/ITLB combined(in pages)*/
63         __u8    x86_virt_bits, x86_phys_bits;
64         __u8    x86_max_cores;  /* cpuid returned max cores value */
65         __u8    x86_coreid_bits; /* cpuid returned core id bits */
66         __u32   x86_power;      
67         __u32   extended_cpuid_level;   /* Max extended CPUID function supported */
68         unsigned long loops_per_jiffy;
69 #ifdef CONFIG_SMP
70         cpumask_t llc_shared_map;       /* cpus sharing the last level cache */
71 #endif
72         __u8    apicid;
73 #ifdef CONFIG_SMP
74         __u8    booted_cores;   /* number of cores as seen by OS */
75         __u8    phys_proc_id;   /* Physical Processor id. */
76         __u8    cpu_core_id;    /* Core id. */
77         __u8    cpu_index;      /* index into per_cpu list */
78 #endif
79 } ____cacheline_aligned;
80
81 #define X86_VENDOR_INTEL 0
82 #define X86_VENDOR_CYRIX 1
83 #define X86_VENDOR_AMD 2
84 #define X86_VENDOR_UMC 3
85 #define X86_VENDOR_NEXGEN 4
86 #define X86_VENDOR_CENTAUR 5
87 #define X86_VENDOR_TRANSMETA 7
88 #define X86_VENDOR_NUM 8
89 #define X86_VENDOR_UNKNOWN 0xff
90
91 #ifdef CONFIG_SMP
92 DECLARE_PER_CPU(struct cpuinfo_x86, cpu_info);
93 #define cpu_data(cpu)           per_cpu(cpu_info, cpu)
94 #define current_cpu_data        cpu_data(smp_processor_id())
95 #else
96 #define cpu_data(cpu)           boot_cpu_data
97 #define current_cpu_data        boot_cpu_data
98 #endif
99
100 extern char ignore_irq13;
101
102 extern void identify_cpu(struct cpuinfo_x86 *);
103 extern void print_cpu_info(struct cpuinfo_x86 *);
104 extern void init_scattered_cpuid_features(struct cpuinfo_x86 *c);
105 extern unsigned int init_intel_cacheinfo(struct cpuinfo_x86 *c);
106 extern unsigned short num_cache_leaves;
107
108 /*
109  * Save the cr4 feature set we're using (ie
110  * Pentium 4MB enable and PPro Global page
111  * enable), so that any CPU's that boot up
112  * after us can get the correct flags.
113  */
114 extern unsigned long mmu_cr4_features;
115
116 static inline void set_in_cr4 (unsigned long mask)
117 {
118         mmu_cr4_features |= mask;
119         __asm__("movq %%cr4,%%rax\n\t"
120                 "orq %0,%%rax\n\t"
121                 "movq %%rax,%%cr4\n"
122                 : : "irg" (mask)
123                 :"ax");
124 }
125
126 static inline void clear_in_cr4 (unsigned long mask)
127 {
128         mmu_cr4_features &= ~mask;
129         __asm__("movq %%cr4,%%rax\n\t"
130                 "andq %0,%%rax\n\t"
131                 "movq %%rax,%%cr4\n"
132                 : : "irg" (~mask)
133                 :"ax");
134 }
135
136
137 /*
138  * User space process size. 47bits minus one guard page.
139  */
140 #define TASK_SIZE64     (0x800000000000UL - 4096)
141
142 /* This decides where the kernel will search for a free chunk of vm
143  * space during mmap's.
144  */
145 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? 0xc0000000 : 0xFFFFe000)
146
147 #define TASK_SIZE               (test_thread_flag(TIF_IA32) ? IA32_PAGE_OFFSET : TASK_SIZE64)
148 #define TASK_SIZE_OF(child)     ((test_tsk_thread_flag(child, TIF_IA32)) ? IA32_PAGE_OFFSET : TASK_SIZE64)
149
150 #define TASK_UNMAPPED_BASE      PAGE_ALIGN(TASK_SIZE/3)
151
152 /*
153  * Size of io_bitmap.
154  */
155 #define IO_BITMAP_BITS  65536
156 #define IO_BITMAP_BYTES (IO_BITMAP_BITS/8)
157 #define IO_BITMAP_LONGS (IO_BITMAP_BYTES/sizeof(long))
158 #define IO_BITMAP_OFFSET offsetof(struct tss_struct,io_bitmap)
159 #define INVALID_IO_BITMAP_OFFSET 0x8000
160
161 struct i387_fxsave_struct {
162         u16     cwd;
163         u16     swd;
164         u16     twd;
165         u16     fop;
166         u64     rip;
167         u64     rdp; 
168         u32     mxcsr;
169         u32     mxcsr_mask;
170         u32     st_space[32];   /* 8*16 bytes for each FP-reg = 128 bytes */
171         u32     xmm_space[64];  /* 16*16 bytes for each XMM-reg = 256 bytes */
172         u32     padding[24];
173 } __attribute__ ((aligned (16)));
174
175 union i387_union {
176         struct i387_fxsave_struct       fxsave;
177 };
178
179 struct tss_struct {
180         u32 reserved1;
181         u64 sp0;
182         u64 sp1;
183         u64 sp2;
184         u64 reserved2;
185         u64 ist[7];
186         u32 reserved3;
187         u32 reserved4;
188         u16 reserved5;
189         u16 io_bitmap_base;
190         /*
191          * The extra 1 is there because the CPU will access an
192          * additional byte beyond the end of the IO permission
193          * bitmap. The extra byte must be all 1 bits, and must
194          * be within the limit. Thus we have:
195          *
196          * 128 bytes, the bitmap itself, for ports 0..0x3ff
197          * 8 bytes, for an extra "long" of ~0UL
198          */
199         unsigned long io_bitmap[IO_BITMAP_LONGS + 1];
200 } __attribute__((packed)) ____cacheline_aligned;
201
202
203 extern struct cpuinfo_x86 boot_cpu_data;
204 DECLARE_PER_CPU(struct tss_struct,init_tss);
205 /* Save the original ist values for checking stack pointers during debugging */
206 struct orig_ist {
207         unsigned long ist[7];
208 };
209 DECLARE_PER_CPU(struct orig_ist, orig_ist);
210
211 #ifdef CONFIG_X86_VSMP
212 #define ARCH_MIN_TASKALIGN      (1 << INTERNODE_CACHE_SHIFT)
213 #define ARCH_MIN_MMSTRUCT_ALIGN (1 << INTERNODE_CACHE_SHIFT)
214 #else
215 #define ARCH_MIN_TASKALIGN      16
216 #define ARCH_MIN_MMSTRUCT_ALIGN 0
217 #endif
218
219 struct thread_struct {
220         unsigned long   sp0;
221         unsigned long   sp;
222         unsigned long   usersp; /* Copy from PDA */
223         unsigned long   fs;
224         unsigned long   gs;
225         unsigned short  es, ds, fsindex, gsindex;       
226 /* Hardware debugging registers */
227         unsigned long   debugreg0;  
228         unsigned long   debugreg1;  
229         unsigned long   debugreg2;  
230         unsigned long   debugreg3;  
231         unsigned long   debugreg6;  
232         unsigned long   debugreg7;  
233 /* fault info */
234         unsigned long   cr2, trap_no, error_code;
235 /* floating point info */
236         union i387_union        i387  __attribute__((aligned(16)));
237 /* IO permissions. the bitmap could be moved into the GDT, that would make
238    switch faster for a limited number of ioperm using tasks. -AK */
239         int             ioperm;
240         unsigned long   *io_bitmap_ptr;
241         unsigned io_bitmap_max;
242 /* MSR_IA32_DEBUGCTLMSR value to switch in if TIF_DEBUGCTLMSR is set.  */
243         unsigned long   debugctlmsr;
244 /* Debug Store - if not 0 points to a DS Save Area configuration;
245  *               goes into MSR_IA32_DS_AREA */
246         unsigned long   ds_area_msr;
247 /* cached TLS descriptors. */
248         struct desc_struct tls_array[GDT_ENTRY_TLS_ENTRIES];
249 } __attribute__((aligned(16)));
250
251 #define INIT_THREAD  { \
252         .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
253 }
254
255 #define INIT_TSS  { \
256         .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
257 }
258
259 #define INIT_MMAP \
260 { &init_mm, 0, 0, NULL, PAGE_SHARED, VM_READ | VM_WRITE | VM_EXEC, 1, NULL, NULL }
261
262 #define start_thread(regs,new_rip,new_rsp) do { \
263         asm volatile("movl %0,%%fs; movl %0,%%es; movl %0,%%ds": :"r" (0));      \
264         load_gs_index(0);                                                       \
265         (regs)->ip = (new_rip);                                          \
266         (regs)->sp = (new_rsp);                                          \
267         write_pda(oldrsp, (new_rsp));                                            \
268         (regs)->cs = __USER_CS;                                                  \
269         (regs)->ss = __USER_DS;                                                  \
270         (regs)->flags = 0x200;                                                   \
271         set_fs(USER_DS);                                                         \
272 } while(0) 
273
274 #define get_debugreg(var, register)                             \
275                 __asm__("movq %%db" #register ", %0"            \
276                         :"=r" (var))
277 #define set_debugreg(value, register)                   \
278                 __asm__("movq %0,%%db" #register                \
279                         : /* no output */                       \
280                         :"r" (value))
281
282 struct task_struct;
283 struct mm_struct;
284
285 /* Free all resources held by a thread. */
286 extern void release_thread(struct task_struct *);
287
288 /* Prepare to copy thread state - unlazy all lazy status */
289 extern void prepare_to_copy(struct task_struct *tsk);
290
291 /*
292  * create a kernel thread without removing it from tasklists
293  */
294 extern long kernel_thread(int (*fn)(void *), void * arg, unsigned long flags);
295
296 /*
297  * Return saved PC of a blocked thread.
298  * What is this good for? it will be always the scheduler or ret_from_fork.
299  */
300 #define thread_saved_pc(t) (*(unsigned long *)((t)->thread.sp - 8))
301
302 extern unsigned long get_wchan(struct task_struct *p);
303 #define task_pt_regs(tsk) ((struct pt_regs *)(tsk)->thread.sp0 - 1)
304 #define KSTK_EIP(tsk) (task_pt_regs(tsk)->ip)
305 #define KSTK_ESP(tsk) -1 /* sorry. doesn't work for syscall. */
306
307
308 struct microcode_header {
309         unsigned int hdrver;
310         unsigned int rev;
311         unsigned int date;
312         unsigned int sig;
313         unsigned int cksum;
314         unsigned int ldrver;
315         unsigned int pf;
316         unsigned int datasize;
317         unsigned int totalsize;
318         unsigned int reserved[3];
319 };
320
321 struct microcode {
322         struct microcode_header hdr;
323         unsigned int bits[0];
324 };
325
326 typedef struct microcode microcode_t;
327 typedef struct microcode_header microcode_header_t;
328
329 /* microcode format is extended from prescott processors */
330 struct extended_signature {
331         unsigned int sig;
332         unsigned int pf;
333         unsigned int cksum;
334 };
335
336 struct extended_sigtable {
337         unsigned int count;
338         unsigned int cksum;
339         unsigned int reserved[3];
340         struct extended_signature sigs[0];
341 };
342
343
344 #if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2)
345 #define ASM_NOP1 P6_NOP1
346 #define ASM_NOP2 P6_NOP2
347 #define ASM_NOP3 P6_NOP3
348 #define ASM_NOP4 P6_NOP4
349 #define ASM_NOP5 P6_NOP5
350 #define ASM_NOP6 P6_NOP6
351 #define ASM_NOP7 P6_NOP7
352 #define ASM_NOP8 P6_NOP8
353 #else
354 #define ASM_NOP1 K8_NOP1
355 #define ASM_NOP2 K8_NOP2
356 #define ASM_NOP3 K8_NOP3
357 #define ASM_NOP4 K8_NOP4
358 #define ASM_NOP5 K8_NOP5
359 #define ASM_NOP6 K8_NOP6
360 #define ASM_NOP7 K8_NOP7
361 #define ASM_NOP8 K8_NOP8
362 #endif
363
364 /* Opteron nops */
365 #define K8_NOP1 ".byte 0x90\n"
366 #define K8_NOP2 ".byte 0x66,0x90\n" 
367 #define K8_NOP3 ".byte 0x66,0x66,0x90\n" 
368 #define K8_NOP4 ".byte 0x66,0x66,0x66,0x90\n" 
369 #define K8_NOP5 K8_NOP3 K8_NOP2 
370 #define K8_NOP6 K8_NOP3 K8_NOP3
371 #define K8_NOP7 K8_NOP4 K8_NOP3
372 #define K8_NOP8 K8_NOP4 K8_NOP4
373
374 /* P6 nops */
375 /* uses eax dependencies (Intel-recommended choice) */
376 #define P6_NOP1 ".byte 0x90\n"
377 #define P6_NOP2 ".byte 0x66,0x90\n"
378 #define P6_NOP3 ".byte 0x0f,0x1f,0x00\n"
379 #define P6_NOP4 ".byte 0x0f,0x1f,0x40,0\n"
380 #define P6_NOP5 ".byte 0x0f,0x1f,0x44,0x00,0\n"
381 #define P6_NOP6 ".byte 0x66,0x0f,0x1f,0x44,0x00,0\n"
382 #define P6_NOP7 ".byte 0x0f,0x1f,0x80,0,0,0,0\n"
383 #define P6_NOP8 ".byte 0x0f,0x1f,0x84,0x00,0,0,0,0\n"
384
385 #define ASM_NOP_MAX 8
386
387 /* REP NOP (PAUSE) is a good thing to insert into busy-wait loops. */
388 static inline void rep_nop(void)
389 {
390         __asm__ __volatile__("rep;nop": : :"memory");
391 }
392
393 /* Stop speculative execution */
394 static inline void sync_core(void)
395
396         int tmp;
397         asm volatile("cpuid" : "=a" (tmp) : "0" (1) : "ebx","ecx","edx","memory");
398
399
400 #define ARCH_HAS_PREFETCHW 1
401 static inline void prefetchw(void *x) 
402
403         alternative_input("prefetcht0 (%1)",
404                           "prefetchw (%1)",
405                           X86_FEATURE_3DNOW,
406                           "r" (x));
407
408
409 #define ARCH_HAS_SPINLOCK_PREFETCH 1
410
411 #define spin_lock_prefetch(x)  prefetchw(x)
412
413 #define cpu_relax()   rep_nop()
414
415 static inline void __monitor(const void *eax, unsigned long ecx,
416                 unsigned long edx)
417 {
418         /* "monitor %eax,%ecx,%edx;" */
419         asm volatile(
420                 ".byte 0x0f,0x01,0xc8;"
421                 : :"a" (eax), "c" (ecx), "d"(edx));
422 }
423
424 static inline void __mwait(unsigned long eax, unsigned long ecx)
425 {
426         /* "mwait %eax,%ecx;" */
427         asm volatile(
428                 ".byte 0x0f,0x01,0xc9;"
429                 : :"a" (eax), "c" (ecx));
430 }
431
432 static inline void __sti_mwait(unsigned long eax, unsigned long ecx)
433 {
434         /* "mwait %eax,%ecx;" */
435         asm volatile(
436                 "sti; .byte 0x0f,0x01,0xc9;"
437                 : :"a" (eax), "c" (ecx));
438 }
439
440 extern void mwait_idle_with_hints(unsigned long eax, unsigned long ecx);
441
442 extern int force_mwait;
443
444 extern void select_idle_routine(const struct cpuinfo_x86 *c);
445
446 #define stack_current() \
447 ({                                                              \
448         struct thread_info *ti;                                 \
449         asm("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK));  \
450         ti->task;                                       \
451 })
452
453 #define cache_line_size() (boot_cpu_data.x86_cache_alignment)
454
455 extern unsigned long boot_option_idle_override;
456 /* Boot loader type from the setup header */
457 extern int bootloader_type;
458
459 #define HAVE_ARCH_PICK_MMAP_LAYOUT 1
460
461 #endif /* __ASM_X86_64_PROCESSOR_H */