processor_64.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. /*
  2. * Copyright (C) 1994 Linus Torvalds
  3. */
  4. #ifndef __ASM_X86_64_PROCESSOR_H
  5. #define __ASM_X86_64_PROCESSOR_H
  6. #include <asm/segment.h>
  7. #include <asm/page.h>
  8. #include <asm/types.h>
  9. #include <asm/sigcontext.h>
  10. #include <asm/cpufeature.h>
  11. #include <linux/threads.h>
  12. #include <asm/msr.h>
  13. #include <asm/current.h>
  14. #include <asm/system.h>
  15. #include <asm/mmsegment.h>
  16. #include <asm/percpu.h>
  17. #include <linux/personality.h>
  18. #include <linux/cpumask.h>
  19. #include <asm/desc_defs.h>
  20. /*
  21. * Default implementation of macro that returns current
  22. * instruction pointer ("program counter").
  23. */
  24. #define current_text_addr() ({ void *pc; asm volatile("leaq 1f(%%rip),%0\n1:":"=r"(pc)); pc; })
  25. /*
  26. * CPU type and hardware bug flags. Kept separately for each CPU.
  27. */
  28. struct cpuinfo_x86 {
  29. __u8 x86; /* CPU family */
  30. __u8 x86_vendor; /* CPU vendor */
  31. __u8 x86_model;
  32. __u8 x86_mask;
  33. int cpuid_level; /* Maximum supported CPUID level, -1=no CPUID */
  34. __u32 x86_capability[NCAPINTS];
  35. char x86_vendor_id[16];
  36. char x86_model_id[64];
  37. int x86_cache_size; /* in KB */
  38. int x86_clflush_size;
  39. int x86_cache_alignment;
  40. int x86_tlbsize; /* number of 4K pages in DTLB/ITLB combined(in pages)*/
  41. __u8 x86_virt_bits, x86_phys_bits;
  42. __u8 x86_max_cores; /* cpuid returned max cores value */
  43. __u8 x86_coreid_bits; /* cpuid returned core id bits */
  44. __u32 x86_power;
  45. __u32 extended_cpuid_level; /* Max extended CPUID function supported */
  46. unsigned long loops_per_jiffy;
  47. #ifdef CONFIG_SMP
  48. cpumask_t llc_shared_map; /* cpus sharing the last level cache */
  49. #endif
  50. __u8 apicid;
  51. #ifdef CONFIG_SMP
  52. __u8 booted_cores; /* number of cores as seen by OS */
  53. __u8 phys_proc_id; /* Physical Processor id. */
  54. __u8 cpu_core_id; /* Core id. */
  55. __u8 cpu_index; /* index into per_cpu list */
  56. #endif
  57. } ____cacheline_aligned;
  58. #define X86_VENDOR_INTEL 0
  59. #define X86_VENDOR_CYRIX 1
  60. #define X86_VENDOR_AMD 2
  61. #define X86_VENDOR_UMC 3
  62. #define X86_VENDOR_NEXGEN 4
  63. #define X86_VENDOR_CENTAUR 5
  64. #define X86_VENDOR_TRANSMETA 7
  65. #define X86_VENDOR_NUM 8
  66. #define X86_VENDOR_UNKNOWN 0xff
  67. #ifdef CONFIG_SMP
  68. DECLARE_PER_CPU(struct cpuinfo_x86, cpu_info);
  69. #define cpu_data(cpu) per_cpu(cpu_info, cpu)
  70. #define current_cpu_data cpu_data(smp_processor_id())
  71. #else
  72. #define cpu_data(cpu) boot_cpu_data
  73. #define current_cpu_data boot_cpu_data
  74. #endif
  75. extern char ignore_irq13;
  76. extern void identify_cpu(struct cpuinfo_x86 *);
  77. /*
  78. * User space process size. 47bits minus one guard page.
  79. */
  80. #define TASK_SIZE64 (0x800000000000UL - 4096)
  81. /* This decides where the kernel will search for a free chunk of vm
  82. * space during mmap's.
  83. */
  84. #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? 0xc0000000 : 0xFFFFe000)
  85. #define TASK_SIZE (test_thread_flag(TIF_IA32) ? IA32_PAGE_OFFSET : TASK_SIZE64)
  86. #define TASK_SIZE_OF(child) ((test_tsk_thread_flag(child, TIF_IA32)) ? IA32_PAGE_OFFSET : TASK_SIZE64)
  87. /*
  88. * Size of io_bitmap.
  89. */
  90. #define IO_BITMAP_BITS 65536
  91. #define IO_BITMAP_BYTES (IO_BITMAP_BITS/8)
  92. #define IO_BITMAP_LONGS (IO_BITMAP_BYTES/sizeof(long))
  93. #define IO_BITMAP_OFFSET offsetof(struct tss_struct,io_bitmap)
  94. #define INVALID_IO_BITMAP_OFFSET 0x8000
  95. struct i387_fxsave_struct {
  96. u16 cwd;
  97. u16 swd;
  98. u16 twd;
  99. u16 fop;
  100. u64 rip;
  101. u64 rdp;
  102. u32 mxcsr;
  103. u32 mxcsr_mask;
  104. u32 st_space[32]; /* 8*16 bytes for each FP-reg = 128 bytes */
  105. u32 xmm_space[64]; /* 16*16 bytes for each XMM-reg = 256 bytes */
  106. u32 padding[24];
  107. } __attribute__ ((aligned (16)));
  108. union i387_union {
  109. struct i387_fxsave_struct fxsave;
  110. };
  111. struct tss_struct {
  112. u32 reserved1;
  113. u64 sp0;
  114. u64 sp1;
  115. u64 sp2;
  116. u64 reserved2;
  117. u64 ist[7];
  118. u32 reserved3;
  119. u32 reserved4;
  120. u16 reserved5;
  121. u16 io_bitmap_base;
  122. /*
  123. * The extra 1 is there because the CPU will access an
  124. * additional byte beyond the end of the IO permission
  125. * bitmap. The extra byte must be all 1 bits, and must
  126. * be within the limit. Thus we have:
  127. *
  128. * 128 bytes, the bitmap itself, for ports 0..0x3ff
  129. * 8 bytes, for an extra "long" of ~0UL
  130. */
  131. unsigned long io_bitmap[IO_BITMAP_LONGS + 1];
  132. } __attribute__((packed)) ____cacheline_aligned;
  133. extern struct cpuinfo_x86 boot_cpu_data;
  134. DECLARE_PER_CPU(struct tss_struct,init_tss);
  135. /* Save the original ist values for checking stack pointers during debugging */
  136. struct orig_ist {
  137. unsigned long ist[7];
  138. };
  139. DECLARE_PER_CPU(struct orig_ist, orig_ist);
  140. #ifdef CONFIG_X86_VSMP
  141. #define ARCH_MIN_TASKALIGN (1 << INTERNODE_CACHE_SHIFT)
  142. #define ARCH_MIN_MMSTRUCT_ALIGN (1 << INTERNODE_CACHE_SHIFT)
  143. #else
  144. #define ARCH_MIN_TASKALIGN 16
  145. #define ARCH_MIN_MMSTRUCT_ALIGN 0
  146. #endif
  147. struct thread_struct {
  148. unsigned long sp0;
  149. unsigned long sp;
  150. unsigned long usersp; /* Copy from PDA */
  151. unsigned long fs;
  152. unsigned long gs;
  153. unsigned short es, ds, fsindex, gsindex;
  154. /* Hardware debugging registers */
  155. unsigned long debugreg0;
  156. unsigned long debugreg1;
  157. unsigned long debugreg2;
  158. unsigned long debugreg3;
  159. unsigned long debugreg6;
  160. unsigned long debugreg7;
  161. /* fault info */
  162. unsigned long cr2, trap_no, error_code;
  163. /* floating point info */
  164. union i387_union i387 __attribute__((aligned(16)));
  165. /* IO permissions. the bitmap could be moved into the GDT, that would make
  166. switch faster for a limited number of ioperm using tasks. -AK */
  167. int ioperm;
  168. unsigned long *io_bitmap_ptr;
  169. unsigned io_bitmap_max;
  170. /* MSR_IA32_DEBUGCTLMSR value to switch in if TIF_DEBUGCTLMSR is set. */
  171. unsigned long debugctlmsr;
  172. /* Debug Store - if not 0 points to a DS Save Area configuration;
  173. * goes into MSR_IA32_DS_AREA */
  174. unsigned long ds_area_msr;
  175. /* cached TLS descriptors. */
  176. struct desc_struct tls_array[GDT_ENTRY_TLS_ENTRIES];
  177. } __attribute__((aligned(16)));
  178. #define INIT_THREAD { \
  179. .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
  180. }
  181. #define INIT_TSS { \
  182. .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
  183. }
  184. #define INIT_MMAP \
  185. { &init_mm, 0, 0, NULL, PAGE_SHARED, VM_READ | VM_WRITE | VM_EXEC, 1, NULL, NULL }
  186. #define start_thread(regs,new_rip,new_rsp) do { \
  187. asm volatile("movl %0,%%fs; movl %0,%%es; movl %0,%%ds": :"r" (0)); \
  188. load_gs_index(0); \
  189. (regs)->ip = (new_rip); \
  190. (regs)->sp = (new_rsp); \
  191. write_pda(oldrsp, (new_rsp)); \
  192. (regs)->cs = __USER_CS; \
  193. (regs)->ss = __USER_DS; \
  194. (regs)->flags = 0x200; \
  195. set_fs(USER_DS); \
  196. } while(0)
  197. /*
  198. * Return saved PC of a blocked thread.
  199. * What is this good for? it will be always the scheduler or ret_from_fork.
  200. */
  201. #define thread_saved_pc(t) (*(unsigned long *)((t)->thread.sp - 8))
  202. #define task_pt_regs(tsk) ((struct pt_regs *)(tsk)->thread.sp0 - 1)
  203. #define KSTK_ESP(tsk) -1 /* sorry. doesn't work for syscall. */
  204. #if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2)
  205. #define ASM_NOP1 P6_NOP1
  206. #define ASM_NOP2 P6_NOP2
  207. #define ASM_NOP3 P6_NOP3
  208. #define ASM_NOP4 P6_NOP4
  209. #define ASM_NOP5 P6_NOP5
  210. #define ASM_NOP6 P6_NOP6
  211. #define ASM_NOP7 P6_NOP7
  212. #define ASM_NOP8 P6_NOP8
  213. #else
  214. #define ASM_NOP1 K8_NOP1
  215. #define ASM_NOP2 K8_NOP2
  216. #define ASM_NOP3 K8_NOP3
  217. #define ASM_NOP4 K8_NOP4
  218. #define ASM_NOP5 K8_NOP5
  219. #define ASM_NOP6 K8_NOP6
  220. #define ASM_NOP7 K8_NOP7
  221. #define ASM_NOP8 K8_NOP8
  222. #endif
  223. /* Opteron nops */
  224. #define K8_NOP1 ".byte 0x90\n"
  225. #define K8_NOP2 ".byte 0x66,0x90\n"
  226. #define K8_NOP3 ".byte 0x66,0x66,0x90\n"
  227. #define K8_NOP4 ".byte 0x66,0x66,0x66,0x90\n"
  228. #define K8_NOP5 K8_NOP3 K8_NOP2
  229. #define K8_NOP6 K8_NOP3 K8_NOP3
  230. #define K8_NOP7 K8_NOP4 K8_NOP3
  231. #define K8_NOP8 K8_NOP4 K8_NOP4
  232. /* P6 nops */
  233. /* uses eax dependencies (Intel-recommended choice) */
  234. #define P6_NOP1 ".byte 0x90\n"
  235. #define P6_NOP2 ".byte 0x66,0x90\n"
  236. #define P6_NOP3 ".byte 0x0f,0x1f,0x00\n"
  237. #define P6_NOP4 ".byte 0x0f,0x1f,0x40,0\n"
  238. #define P6_NOP5 ".byte 0x0f,0x1f,0x44,0x00,0\n"
  239. #define P6_NOP6 ".byte 0x66,0x0f,0x1f,0x44,0x00,0\n"
  240. #define P6_NOP7 ".byte 0x0f,0x1f,0x80,0,0,0,0\n"
  241. #define P6_NOP8 ".byte 0x0f,0x1f,0x84,0x00,0,0,0,0\n"
  242. #define ASM_NOP_MAX 8
  243. static inline void prefetchw(void *x)
  244. {
  245. alternative_input("prefetcht0 (%1)",
  246. "prefetchw (%1)",
  247. X86_FEATURE_3DNOW,
  248. "r" (x));
  249. }
  250. #define stack_current() \
  251. ({ \
  252. struct thread_info *ti; \
  253. asm("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
  254. ti->task; \
  255. })
  256. #endif /* __ASM_X86_64_PROCESSOR_H */