processor_32.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401
  1. /*
  2. * Copyright (C) 1994 Linus Torvalds
  3. */
  4. #ifndef __ASM_I386_PROCESSOR_H
  5. #define __ASM_I386_PROCESSOR_H
  6. #include <asm/vm86.h>
  7. #include <asm/math_emu.h>
  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 <asm/msr.h>
  14. #include <asm/system.h>
  15. #include <linux/cache.h>
  16. #include <linux/threads.h>
  17. #include <asm/percpu.h>
  18. #include <linux/cpumask.h>
  19. #include <linux/init.h>
  20. #include <asm/desc_defs.h>
  21. /*
  22. * CPU type and hardware bug flags. Kept separately for each CPU.
  23. * Members of this structure are referenced in head.S, so think twice
  24. * before touching them. [mj]
  25. */
  26. struct cpuinfo_x86 {
  27. __u8 x86; /* CPU family */
  28. __u8 x86_vendor; /* CPU vendor */
  29. __u8 x86_model;
  30. __u8 x86_mask;
  31. char wp_works_ok; /* It doesn't on 386's */
  32. char hlt_works_ok; /* Problems on some 486Dx4's and old 386's */
  33. char hard_math;
  34. char rfu;
  35. int cpuid_level; /* Maximum supported CPUID level, -1=no CPUID */
  36. unsigned long x86_capability[NCAPINTS];
  37. char x86_vendor_id[16];
  38. char x86_model_id[64];
  39. int x86_cache_size; /* in KB - valid for CPUS which support this
  40. call */
  41. int x86_cache_alignment; /* In bytes */
  42. char fdiv_bug;
  43. char f00f_bug;
  44. char coma_bug;
  45. char pad0;
  46. int x86_power;
  47. unsigned long loops_per_jiffy;
  48. #ifdef CONFIG_SMP
  49. cpumask_t llc_shared_map; /* cpus sharing the last level cache */
  50. #endif
  51. unsigned char x86_max_cores; /* cpuid returned max cores value */
  52. unsigned char apicid;
  53. unsigned short x86_clflush_size;
  54. #ifdef CONFIG_SMP
  55. unsigned char booted_cores; /* number of cores as seen by OS */
  56. __u8 phys_proc_id; /* Physical processor id. */
  57. __u8 cpu_core_id; /* Core id */
  58. __u8 cpu_index; /* index into per_cpu list */
  59. #endif
  60. } __attribute__((__aligned__(SMP_CACHE_BYTES)));
  61. #define X86_VENDOR_INTEL 0
  62. #define X86_VENDOR_CYRIX 1
  63. #define X86_VENDOR_AMD 2
  64. #define X86_VENDOR_UMC 3
  65. #define X86_VENDOR_NEXGEN 4
  66. #define X86_VENDOR_CENTAUR 5
  67. #define X86_VENDOR_TRANSMETA 7
  68. #define X86_VENDOR_NSC 8
  69. #define X86_VENDOR_NUM 9
  70. #define X86_VENDOR_UNKNOWN 0xff
  71. /*
  72. * capabilities of CPUs
  73. */
  74. extern struct cpuinfo_x86 boot_cpu_data;
  75. extern struct cpuinfo_x86 new_cpu_data;
  76. extern struct tss_struct doublefault_tss;
  77. #ifdef CONFIG_SMP
  78. DECLARE_PER_CPU(struct cpuinfo_x86, cpu_info);
  79. #define cpu_data(cpu) per_cpu(cpu_info, cpu)
  80. #define current_cpu_data cpu_data(smp_processor_id())
  81. #else
  82. #define cpu_data(cpu) boot_cpu_data
  83. #define current_cpu_data boot_cpu_data
  84. #endif
  85. /*
  86. * the following now lives in the per cpu area:
  87. * extern int cpu_llc_id[NR_CPUS];
  88. */
  89. DECLARE_PER_CPU(u8, cpu_llc_id);
  90. extern char ignore_fpu_irq;
  91. void __init cpu_detect(struct cpuinfo_x86 *c);
  92. extern void identify_boot_cpu(void);
  93. extern void identify_secondary_cpu(struct cpuinfo_x86 *);
  94. #ifdef CONFIG_X86_HT
  95. extern void detect_ht(struct cpuinfo_x86 *c);
  96. #else
  97. static inline void detect_ht(struct cpuinfo_x86 *c) {}
  98. #endif
  99. /* from system description table in BIOS. Mostly for MCA use, but
  100. others may find it useful. */
  101. extern unsigned int machine_id;
  102. extern unsigned int machine_submodel_id;
  103. extern unsigned int BIOS_revision;
  104. extern unsigned int mca_pentium_flag;
  105. /*
  106. * User space process size: 3GB (default).
  107. */
  108. #define TASK_SIZE (PAGE_OFFSET)
  109. struct i387_fsave_struct {
  110. long cwd;
  111. long swd;
  112. long twd;
  113. long fip;
  114. long fcs;
  115. long foo;
  116. long fos;
  117. long st_space[20]; /* 8*10 bytes for each FP-reg = 80 bytes */
  118. long status; /* software status information */
  119. };
  120. struct i387_fxsave_struct {
  121. unsigned short cwd;
  122. unsigned short swd;
  123. unsigned short twd;
  124. unsigned short fop;
  125. long fip;
  126. long fcs;
  127. long foo;
  128. long fos;
  129. long mxcsr;
  130. long mxcsr_mask;
  131. long st_space[32]; /* 8*16 bytes for each FP-reg = 128 bytes */
  132. long xmm_space[32]; /* 8*16 bytes for each XMM-reg = 128 bytes */
  133. long padding[56];
  134. } __attribute__ ((aligned (16)));
  135. struct i387_soft_struct {
  136. long cwd;
  137. long swd;
  138. long twd;
  139. long fip;
  140. long fcs;
  141. long foo;
  142. long fos;
  143. long st_space[20]; /* 8*10 bytes for each FP-reg = 80 bytes */
  144. unsigned char ftop, changed, lookahead, no_update, rm, alimit;
  145. struct info *info;
  146. unsigned long entry_eip;
  147. };
  148. union i387_union {
  149. struct i387_fsave_struct fsave;
  150. struct i387_fxsave_struct fxsave;
  151. struct i387_soft_struct soft;
  152. };
  153. typedef struct {
  154. unsigned long seg;
  155. } mm_segment_t;
  156. #define ARCH_MIN_TASKALIGN 16
  157. struct thread_struct {
  158. /* cached TLS descriptors. */
  159. struct desc_struct tls_array[GDT_ENTRY_TLS_ENTRIES];
  160. unsigned long sp0;
  161. unsigned long sysenter_cs;
  162. unsigned long ip;
  163. unsigned long sp;
  164. unsigned long fs;
  165. unsigned long gs;
  166. /* Hardware debugging registers */
  167. unsigned long debugreg0;
  168. unsigned long debugreg1;
  169. unsigned long debugreg2;
  170. unsigned long debugreg3;
  171. unsigned long debugreg6;
  172. unsigned long debugreg7;
  173. /* fault info */
  174. unsigned long cr2, trap_no, error_code;
  175. /* floating point info */
  176. union i387_union i387;
  177. /* virtual 86 mode info */
  178. struct vm86_struct __user * vm86_info;
  179. unsigned long screen_bitmap;
  180. unsigned long v86flags, v86mask, saved_sp0;
  181. unsigned int saved_fs, saved_gs;
  182. /* IO permissions */
  183. unsigned long *io_bitmap_ptr;
  184. unsigned long iopl;
  185. /* max allowed port in the bitmap, in bytes: */
  186. unsigned long io_bitmap_max;
  187. /* MSR_IA32_DEBUGCTLMSR value to switch in if TIF_DEBUGCTLMSR is set. */
  188. unsigned long debugctlmsr;
  189. /* Debug Store - if not 0 points to a DS Save Area configuration;
  190. * goes into MSR_IA32_DS_AREA */
  191. unsigned long ds_area_msr;
  192. };
  193. #define INIT_THREAD { \
  194. .sp0 = sizeof(init_stack) + (long)&init_stack, \
  195. .vm86_info = NULL, \
  196. .sysenter_cs = __KERNEL_CS, \
  197. .io_bitmap_ptr = NULL, \
  198. .fs = __KERNEL_PERCPU, \
  199. }
  200. /*
  201. * Note that the .io_bitmap member must be extra-big. This is because
  202. * the CPU will access an additional byte beyond the end of the IO
  203. * permission bitmap. The extra byte must be all 1 bits, and must
  204. * be within the limit.
  205. */
  206. #define INIT_TSS { \
  207. .x86_tss = { \
  208. .sp0 = sizeof(init_stack) + (long)&init_stack, \
  209. .ss0 = __KERNEL_DS, \
  210. .ss1 = __KERNEL_CS, \
  211. .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
  212. }, \
  213. .io_bitmap = { [ 0 ... IO_BITMAP_LONGS] = ~0 }, \
  214. }
  215. #define start_thread(regs, new_eip, new_esp) do { \
  216. __asm__("movl %0,%%gs": :"r" (0)); \
  217. regs->fs = 0; \
  218. set_fs(USER_DS); \
  219. regs->ds = __USER_DS; \
  220. regs->es = __USER_DS; \
  221. regs->ss = __USER_DS; \
  222. regs->cs = __USER_CS; \
  223. regs->ip = new_eip; \
  224. regs->sp = new_esp; \
  225. } while (0)
  226. extern unsigned long thread_saved_pc(struct task_struct *tsk);
  227. #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
  228. #define KSTK_TOP(info) \
  229. ({ \
  230. unsigned long *__ptr = (unsigned long *)(info); \
  231. (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
  232. })
  233. /*
  234. * The below -8 is to reserve 8 bytes on top of the ring0 stack.
  235. * This is necessary to guarantee that the entire "struct pt_regs"
  236. * is accessable even if the CPU haven't stored the SS/ESP registers
  237. * on the stack (interrupt gate does not save these registers
  238. * when switching to the same priv ring).
  239. * Therefore beware: accessing the ss/esp fields of the
  240. * "struct pt_regs" is possible, but they may contain the
  241. * completely wrong values.
  242. */
  243. #define task_pt_regs(task) \
  244. ({ \
  245. struct pt_regs *__regs__; \
  246. __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
  247. __regs__ - 1; \
  248. })
  249. #define KSTK_ESP(task) (task_pt_regs(task)->sp)
  250. /* generic versions from gas */
  251. #define GENERIC_NOP1 ".byte 0x90\n"
  252. #define GENERIC_NOP2 ".byte 0x89,0xf6\n"
  253. #define GENERIC_NOP3 ".byte 0x8d,0x76,0x00\n"
  254. #define GENERIC_NOP4 ".byte 0x8d,0x74,0x26,0x00\n"
  255. #define GENERIC_NOP5 GENERIC_NOP1 GENERIC_NOP4
  256. #define GENERIC_NOP6 ".byte 0x8d,0xb6,0x00,0x00,0x00,0x00\n"
  257. #define GENERIC_NOP7 ".byte 0x8d,0xb4,0x26,0x00,0x00,0x00,0x00\n"
  258. #define GENERIC_NOP8 GENERIC_NOP1 GENERIC_NOP7
  259. /* Opteron nops */
  260. #define K8_NOP1 GENERIC_NOP1
  261. #define K8_NOP2 ".byte 0x66,0x90\n"
  262. #define K8_NOP3 ".byte 0x66,0x66,0x90\n"
  263. #define K8_NOP4 ".byte 0x66,0x66,0x66,0x90\n"
  264. #define K8_NOP5 K8_NOP3 K8_NOP2
  265. #define K8_NOP6 K8_NOP3 K8_NOP3
  266. #define K8_NOP7 K8_NOP4 K8_NOP3
  267. #define K8_NOP8 K8_NOP4 K8_NOP4
  268. /* K7 nops */
  269. /* uses eax dependencies (arbitary choice) */
  270. #define K7_NOP1 GENERIC_NOP1
  271. #define K7_NOP2 ".byte 0x8b,0xc0\n"
  272. #define K7_NOP3 ".byte 0x8d,0x04,0x20\n"
  273. #define K7_NOP4 ".byte 0x8d,0x44,0x20,0x00\n"
  274. #define K7_NOP5 K7_NOP4 ASM_NOP1
  275. #define K7_NOP6 ".byte 0x8d,0x80,0,0,0,0\n"
  276. #define K7_NOP7 ".byte 0x8D,0x04,0x05,0,0,0,0\n"
  277. #define K7_NOP8 K7_NOP7 ASM_NOP1
  278. /* P6 nops */
  279. /* uses eax dependencies (Intel-recommended choice) */
  280. #define P6_NOP1 GENERIC_NOP1
  281. #define P6_NOP2 ".byte 0x66,0x90\n"
  282. #define P6_NOP3 ".byte 0x0f,0x1f,0x00\n"
  283. #define P6_NOP4 ".byte 0x0f,0x1f,0x40,0\n"
  284. #define P6_NOP5 ".byte 0x0f,0x1f,0x44,0x00,0\n"
  285. #define P6_NOP6 ".byte 0x66,0x0f,0x1f,0x44,0x00,0\n"
  286. #define P6_NOP7 ".byte 0x0f,0x1f,0x80,0,0,0,0\n"
  287. #define P6_NOP8 ".byte 0x0f,0x1f,0x84,0x00,0,0,0,0\n"
  288. #ifdef CONFIG_MK8
  289. #define ASM_NOP1 K8_NOP1
  290. #define ASM_NOP2 K8_NOP2
  291. #define ASM_NOP3 K8_NOP3
  292. #define ASM_NOP4 K8_NOP4
  293. #define ASM_NOP5 K8_NOP5
  294. #define ASM_NOP6 K8_NOP6
  295. #define ASM_NOP7 K8_NOP7
  296. #define ASM_NOP8 K8_NOP8
  297. #elif defined(CONFIG_MK7)
  298. #define ASM_NOP1 K7_NOP1
  299. #define ASM_NOP2 K7_NOP2
  300. #define ASM_NOP3 K7_NOP3
  301. #define ASM_NOP4 K7_NOP4
  302. #define ASM_NOP5 K7_NOP5
  303. #define ASM_NOP6 K7_NOP6
  304. #define ASM_NOP7 K7_NOP7
  305. #define ASM_NOP8 K7_NOP8
  306. #elif defined(CONFIG_M686) || defined(CONFIG_MPENTIUMII) || \
  307. defined(CONFIG_MPENTIUMIII) || defined(CONFIG_MPENTIUMM) || \
  308. defined(CONFIG_MCORE2) || defined(CONFIG_PENTIUM4)
  309. #define ASM_NOP1 P6_NOP1
  310. #define ASM_NOP2 P6_NOP2
  311. #define ASM_NOP3 P6_NOP3
  312. #define ASM_NOP4 P6_NOP4
  313. #define ASM_NOP5 P6_NOP5
  314. #define ASM_NOP6 P6_NOP6
  315. #define ASM_NOP7 P6_NOP7
  316. #define ASM_NOP8 P6_NOP8
  317. #else
  318. #define ASM_NOP1 GENERIC_NOP1
  319. #define ASM_NOP2 GENERIC_NOP2
  320. #define ASM_NOP3 GENERIC_NOP3
  321. #define ASM_NOP4 GENERIC_NOP4
  322. #define ASM_NOP5 GENERIC_NOP5
  323. #define ASM_NOP6 GENERIC_NOP6
  324. #define ASM_NOP7 GENERIC_NOP7
  325. #define ASM_NOP8 GENERIC_NOP8
  326. #endif
  327. #define ASM_NOP_MAX 8
  328. /* Prefetch instructions for Pentium III and AMD Athlon */
  329. /* It's not worth to care about 3dnow! prefetches for the K6
  330. because they are microcoded there and very slow.
  331. However we don't do prefetches for pre XP Athlons currently
  332. That should be fixed. */
  333. static inline void prefetch(const void *x)
  334. {
  335. alternative_input(ASM_NOP4,
  336. "prefetchnta (%1)",
  337. X86_FEATURE_XMM,
  338. "r" (x));
  339. }
  340. #define ARCH_HAS_PREFETCH
  341. /* 3dnow! prefetch to get an exclusive cache line. Useful for
  342. spinlocks to avoid one state transition in the cache coherency protocol. */
  343. static inline void prefetchw(const void *x)
  344. {
  345. alternative_input(ASM_NOP4,
  346. "prefetchw (%1)",
  347. X86_FEATURE_3DNOW,
  348. "r" (x));
  349. }
  350. extern void enable_sep_cpu(void);
  351. extern int sysenter_setup(void);
  352. /* Defined in head.S */
  353. extern struct desc_ptr early_gdt_descr;
  354. extern void cpu_set_gdt(int);
  355. extern void switch_to_new_gdt(void);
  356. extern void cpu_init(void);
  357. extern void init_gdt(int cpu);
  358. #endif /* __ASM_I386_PROCESSOR_H */