processor_32.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  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/threads.h>
  16. #include <linux/init.h>
  17. #include <asm/desc_defs.h>
  18. /*
  19. * capabilities of CPUs
  20. */
  21. extern struct cpuinfo_x86 new_cpu_data;
  22. extern struct tss_struct doublefault_tss;
  23. /*
  24. * the following now lives in the per cpu area:
  25. * extern int cpu_llc_id[NR_CPUS];
  26. */
  27. DECLARE_PER_CPU(u8, cpu_llc_id);
  28. extern char ignore_fpu_irq;
  29. void __init cpu_detect(struct cpuinfo_x86 *c);
  30. extern void identify_boot_cpu(void);
  31. extern void identify_secondary_cpu(struct cpuinfo_x86 *);
  32. #ifdef CONFIG_X86_HT
  33. extern void detect_ht(struct cpuinfo_x86 *c);
  34. #else
  35. static inline void detect_ht(struct cpuinfo_x86 *c) {}
  36. #endif
  37. /* from system description table in BIOS. Mostly for MCA use, but
  38. others may find it useful. */
  39. extern unsigned int machine_id;
  40. extern unsigned int machine_submodel_id;
  41. extern unsigned int BIOS_revision;
  42. extern unsigned int mca_pentium_flag;
  43. /*
  44. * User space process size: 3GB (default).
  45. */
  46. #define TASK_SIZE (PAGE_OFFSET)
  47. struct i387_fsave_struct {
  48. long cwd;
  49. long swd;
  50. long twd;
  51. long fip;
  52. long fcs;
  53. long foo;
  54. long fos;
  55. long st_space[20]; /* 8*10 bytes for each FP-reg = 80 bytes */
  56. long status; /* software status information */
  57. };
  58. struct i387_fxsave_struct {
  59. unsigned short cwd;
  60. unsigned short swd;
  61. unsigned short twd;
  62. unsigned short fop;
  63. long fip;
  64. long fcs;
  65. long foo;
  66. long fos;
  67. long mxcsr;
  68. long mxcsr_mask;
  69. long st_space[32]; /* 8*16 bytes for each FP-reg = 128 bytes */
  70. long xmm_space[32]; /* 8*16 bytes for each XMM-reg = 128 bytes */
  71. long padding[56];
  72. } __attribute__ ((aligned (16)));
  73. struct i387_soft_struct {
  74. long cwd;
  75. long swd;
  76. long twd;
  77. long fip;
  78. long fcs;
  79. long foo;
  80. long fos;
  81. long st_space[20]; /* 8*10 bytes for each FP-reg = 80 bytes */
  82. unsigned char ftop, changed, lookahead, no_update, rm, alimit;
  83. struct info *info;
  84. unsigned long entry_eip;
  85. };
  86. union i387_union {
  87. struct i387_fsave_struct fsave;
  88. struct i387_fxsave_struct fxsave;
  89. struct i387_soft_struct soft;
  90. };
  91. typedef struct {
  92. unsigned long seg;
  93. } mm_segment_t;
  94. #define INIT_THREAD { \
  95. .sp0 = sizeof(init_stack) + (long)&init_stack, \
  96. .vm86_info = NULL, \
  97. .sysenter_cs = __KERNEL_CS, \
  98. .io_bitmap_ptr = NULL, \
  99. .fs = __KERNEL_PERCPU, \
  100. }
  101. /*
  102. * Note that the .io_bitmap member must be extra-big. This is because
  103. * the CPU will access an additional byte beyond the end of the IO
  104. * permission bitmap. The extra byte must be all 1 bits, and must
  105. * be within the limit.
  106. */
  107. #define INIT_TSS { \
  108. .x86_tss = { \
  109. .sp0 = sizeof(init_stack) + (long)&init_stack, \
  110. .ss0 = __KERNEL_DS, \
  111. .ss1 = __KERNEL_CS, \
  112. .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
  113. }, \
  114. .io_bitmap = { [ 0 ... IO_BITMAP_LONGS] = ~0 }, \
  115. }
  116. #define start_thread(regs, new_eip, new_esp) do { \
  117. __asm__("movl %0,%%gs": :"r" (0)); \
  118. regs->fs = 0; \
  119. set_fs(USER_DS); \
  120. regs->ds = __USER_DS; \
  121. regs->es = __USER_DS; \
  122. regs->ss = __USER_DS; \
  123. regs->cs = __USER_CS; \
  124. regs->ip = new_eip; \
  125. regs->sp = new_esp; \
  126. } while (0)
  127. extern unsigned long thread_saved_pc(struct task_struct *tsk);
  128. #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
  129. #define KSTK_TOP(info) \
  130. ({ \
  131. unsigned long *__ptr = (unsigned long *)(info); \
  132. (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
  133. })
  134. /*
  135. * The below -8 is to reserve 8 bytes on top of the ring0 stack.
  136. * This is necessary to guarantee that the entire "struct pt_regs"
  137. * is accessable even if the CPU haven't stored the SS/ESP registers
  138. * on the stack (interrupt gate does not save these registers
  139. * when switching to the same priv ring).
  140. * Therefore beware: accessing the ss/esp fields of the
  141. * "struct pt_regs" is possible, but they may contain the
  142. * completely wrong values.
  143. */
  144. #define task_pt_regs(task) \
  145. ({ \
  146. struct pt_regs *__regs__; \
  147. __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
  148. __regs__ - 1; \
  149. })
  150. #define KSTK_ESP(task) (task_pt_regs(task)->sp)
  151. /* generic versions from gas */
  152. #define GENERIC_NOP1 ".byte 0x90\n"
  153. #define GENERIC_NOP2 ".byte 0x89,0xf6\n"
  154. #define GENERIC_NOP3 ".byte 0x8d,0x76,0x00\n"
  155. #define GENERIC_NOP4 ".byte 0x8d,0x74,0x26,0x00\n"
  156. #define GENERIC_NOP5 GENERIC_NOP1 GENERIC_NOP4
  157. #define GENERIC_NOP6 ".byte 0x8d,0xb6,0x00,0x00,0x00,0x00\n"
  158. #define GENERIC_NOP7 ".byte 0x8d,0xb4,0x26,0x00,0x00,0x00,0x00\n"
  159. #define GENERIC_NOP8 GENERIC_NOP1 GENERIC_NOP7
  160. /* Opteron nops */
  161. #define K8_NOP1 GENERIC_NOP1
  162. #define K8_NOP2 ".byte 0x66,0x90\n"
  163. #define K8_NOP3 ".byte 0x66,0x66,0x90\n"
  164. #define K8_NOP4 ".byte 0x66,0x66,0x66,0x90\n"
  165. #define K8_NOP5 K8_NOP3 K8_NOP2
  166. #define K8_NOP6 K8_NOP3 K8_NOP3
  167. #define K8_NOP7 K8_NOP4 K8_NOP3
  168. #define K8_NOP8 K8_NOP4 K8_NOP4
  169. /* K7 nops */
  170. /* uses eax dependencies (arbitary choice) */
  171. #define K7_NOP1 GENERIC_NOP1
  172. #define K7_NOP2 ".byte 0x8b,0xc0\n"
  173. #define K7_NOP3 ".byte 0x8d,0x04,0x20\n"
  174. #define K7_NOP4 ".byte 0x8d,0x44,0x20,0x00\n"
  175. #define K7_NOP5 K7_NOP4 ASM_NOP1
  176. #define K7_NOP6 ".byte 0x8d,0x80,0,0,0,0\n"
  177. #define K7_NOP7 ".byte 0x8D,0x04,0x05,0,0,0,0\n"
  178. #define K7_NOP8 K7_NOP7 ASM_NOP1
  179. /* P6 nops */
  180. /* uses eax dependencies (Intel-recommended choice) */
  181. #define P6_NOP1 GENERIC_NOP1
  182. #define P6_NOP2 ".byte 0x66,0x90\n"
  183. #define P6_NOP3 ".byte 0x0f,0x1f,0x00\n"
  184. #define P6_NOP4 ".byte 0x0f,0x1f,0x40,0\n"
  185. #define P6_NOP5 ".byte 0x0f,0x1f,0x44,0x00,0\n"
  186. #define P6_NOP6 ".byte 0x66,0x0f,0x1f,0x44,0x00,0\n"
  187. #define P6_NOP7 ".byte 0x0f,0x1f,0x80,0,0,0,0\n"
  188. #define P6_NOP8 ".byte 0x0f,0x1f,0x84,0x00,0,0,0,0\n"
  189. #ifdef CONFIG_MK8
  190. #define ASM_NOP1 K8_NOP1
  191. #define ASM_NOP2 K8_NOP2
  192. #define ASM_NOP3 K8_NOP3
  193. #define ASM_NOP4 K8_NOP4
  194. #define ASM_NOP5 K8_NOP5
  195. #define ASM_NOP6 K8_NOP6
  196. #define ASM_NOP7 K8_NOP7
  197. #define ASM_NOP8 K8_NOP8
  198. #elif defined(CONFIG_MK7)
  199. #define ASM_NOP1 K7_NOP1
  200. #define ASM_NOP2 K7_NOP2
  201. #define ASM_NOP3 K7_NOP3
  202. #define ASM_NOP4 K7_NOP4
  203. #define ASM_NOP5 K7_NOP5
  204. #define ASM_NOP6 K7_NOP6
  205. #define ASM_NOP7 K7_NOP7
  206. #define ASM_NOP8 K7_NOP8
  207. #elif defined(CONFIG_M686) || defined(CONFIG_MPENTIUMII) || \
  208. defined(CONFIG_MPENTIUMIII) || defined(CONFIG_MPENTIUMM) || \
  209. defined(CONFIG_MCORE2) || defined(CONFIG_PENTIUM4)
  210. #define ASM_NOP1 P6_NOP1
  211. #define ASM_NOP2 P6_NOP2
  212. #define ASM_NOP3 P6_NOP3
  213. #define ASM_NOP4 P6_NOP4
  214. #define ASM_NOP5 P6_NOP5
  215. #define ASM_NOP6 P6_NOP6
  216. #define ASM_NOP7 P6_NOP7
  217. #define ASM_NOP8 P6_NOP8
  218. #else
  219. #define ASM_NOP1 GENERIC_NOP1
  220. #define ASM_NOP2 GENERIC_NOP2
  221. #define ASM_NOP3 GENERIC_NOP3
  222. #define ASM_NOP4 GENERIC_NOP4
  223. #define ASM_NOP5 GENERIC_NOP5
  224. #define ASM_NOP6 GENERIC_NOP6
  225. #define ASM_NOP7 GENERIC_NOP7
  226. #define ASM_NOP8 GENERIC_NOP8
  227. #endif
  228. #define ASM_NOP_MAX 8
  229. /* Prefetch instructions for Pentium III and AMD Athlon */
  230. /* It's not worth to care about 3dnow! prefetches for the K6
  231. because they are microcoded there and very slow.
  232. However we don't do prefetches for pre XP Athlons currently
  233. That should be fixed. */
  234. static inline void prefetch(const void *x)
  235. {
  236. alternative_input(ASM_NOP4,
  237. "prefetchnta (%1)",
  238. X86_FEATURE_XMM,
  239. "r" (x));
  240. }
  241. #define ARCH_HAS_PREFETCH
  242. /* 3dnow! prefetch to get an exclusive cache line. Useful for
  243. spinlocks to avoid one state transition in the cache coherency protocol. */
  244. static inline void prefetchw(const void *x)
  245. {
  246. alternative_input(ASM_NOP4,
  247. "prefetchw (%1)",
  248. X86_FEATURE_3DNOW,
  249. "r" (x));
  250. }
  251. extern void enable_sep_cpu(void);
  252. extern int sysenter_setup(void);
  253. /* Defined in head.S */
  254. extern struct desc_ptr early_gdt_descr;
  255. extern void cpu_set_gdt(int);
  256. extern void switch_to_new_gdt(void);
  257. extern void cpu_init(void);
  258. extern void init_gdt(int cpu);
  259. #endif /* __ASM_I386_PROCESSOR_H */