processor_32.h 7.2 KB

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