processor_32.h 14 KB

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