system_32.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. #ifndef __ASM_SYSTEM_H
  2. #define __ASM_SYSTEM_H
  3. #include <linux/kernel.h>
  4. #include <asm/segment.h>
  5. #include <asm/cpufeature.h>
  6. #include <asm/cmpxchg.h>
  7. #ifdef __KERNEL__
  8. #define AT_VECTOR_SIZE_ARCH 2 /* entries in ARCH_DLINFO */
  9. struct task_struct; /* one of the stranger aspects of C forward declarations.. */
  10. extern struct task_struct * FASTCALL(__switch_to(struct task_struct *prev, struct task_struct *next));
  11. /*
  12. * Saving eflags is important. It switches not only IOPL between tasks,
  13. * it also protects other tasks from NT leaking through sysenter etc.
  14. */
  15. #define switch_to(prev,next,last) do { \
  16. unsigned long esi,edi; \
  17. asm volatile("pushfl\n\t" /* Save flags */ \
  18. "pushl %%ebp\n\t" \
  19. "movl %%esp,%0\n\t" /* save ESP */ \
  20. "movl %5,%%esp\n\t" /* restore ESP */ \
  21. "movl $1f,%1\n\t" /* save EIP */ \
  22. "pushl %6\n\t" /* restore EIP */ \
  23. "jmp __switch_to\n" \
  24. "1:\t" \
  25. "popl %%ebp\n\t" \
  26. "popfl" \
  27. :"=m" (prev->thread.sp),"=m" (prev->thread.ip), \
  28. "=a" (last),"=S" (esi),"=D" (edi) \
  29. :"m" (next->thread.sp),"m" (next->thread.ip), \
  30. "2" (prev), "d" (next)); \
  31. } while (0)
  32. static inline void native_clts(void)
  33. {
  34. asm volatile ("clts");
  35. }
  36. static inline unsigned long native_read_cr0(void)
  37. {
  38. unsigned long val;
  39. asm volatile("movl %%cr0,%0\n\t" :"=r" (val));
  40. return val;
  41. }
  42. static inline void native_write_cr0(unsigned long val)
  43. {
  44. asm volatile("movl %0,%%cr0": :"r" (val));
  45. }
  46. static inline unsigned long native_read_cr2(void)
  47. {
  48. unsigned long val;
  49. asm volatile("movl %%cr2,%0\n\t" :"=r" (val));
  50. return val;
  51. }
  52. static inline void native_write_cr2(unsigned long val)
  53. {
  54. asm volatile("movl %0,%%cr2": :"r" (val));
  55. }
  56. static inline unsigned long native_read_cr3(void)
  57. {
  58. unsigned long val;
  59. asm volatile("movl %%cr3,%0\n\t" :"=r" (val));
  60. return val;
  61. }
  62. static inline void native_write_cr3(unsigned long val)
  63. {
  64. asm volatile("movl %0,%%cr3": :"r" (val));
  65. }
  66. static inline unsigned long native_read_cr4(void)
  67. {
  68. unsigned long val;
  69. asm volatile("movl %%cr4,%0\n\t" :"=r" (val));
  70. return val;
  71. }
  72. static inline unsigned long native_read_cr4_safe(void)
  73. {
  74. unsigned long val;
  75. /* This could fault if %cr4 does not exist */
  76. asm volatile("1: movl %%cr4, %0 \n"
  77. "2: \n"
  78. ".section __ex_table,\"a\" \n"
  79. ".long 1b,2b \n"
  80. ".previous \n"
  81. : "=r" (val): "0" (0));
  82. return val;
  83. }
  84. static inline void native_write_cr4(unsigned long val)
  85. {
  86. asm volatile("movl %0,%%cr4": :"r" (val));
  87. }
  88. static inline void native_wbinvd(void)
  89. {
  90. asm volatile("wbinvd": : :"memory");
  91. }
  92. #ifdef CONFIG_PARAVIRT
  93. #include <asm/paravirt.h>
  94. #else
  95. #define read_cr0() (native_read_cr0())
  96. #define write_cr0(x) (native_write_cr0(x))
  97. #define read_cr2() (native_read_cr2())
  98. #define write_cr2(x) (native_write_cr2(x))
  99. #define read_cr3() (native_read_cr3())
  100. #define write_cr3(x) (native_write_cr3(x))
  101. #define read_cr4() (native_read_cr4())
  102. #define read_cr4_safe() (native_read_cr4_safe())
  103. #define write_cr4(x) (native_write_cr4(x))
  104. #define wbinvd() (native_wbinvd())
  105. /* Clear the 'TS' bit */
  106. #define clts() (native_clts())
  107. #endif/* CONFIG_PARAVIRT */
  108. /* Set the 'TS' bit */
  109. #define stts() write_cr0(8 | read_cr0())
  110. #endif /* __KERNEL__ */
  111. /*
  112. * Force strict CPU ordering.
  113. * And yes, this is required on UP too when we're talking
  114. * to devices.
  115. *
  116. * For now, "wmb()" doesn't actually do anything, as all
  117. * Intel CPU's follow what Intel calls a *Processor Order*,
  118. * in which all writes are seen in the program order even
  119. * outside the CPU.
  120. *
  121. * I expect future Intel CPU's to have a weaker ordering,
  122. * but I'd also expect them to finally get their act together
  123. * and add some real memory barriers if so.
  124. *
  125. * Some non intel clones support out of order store. wmb() ceases to be a
  126. * nop for these.
  127. */
  128. #define mb() alternative("lock; addl $0,0(%%esp)", "mfence", X86_FEATURE_XMM2)
  129. #define rmb() alternative("lock; addl $0,0(%%esp)", "lfence", X86_FEATURE_XMM2)
  130. #define wmb() alternative("lock; addl $0,0(%%esp)", "sfence", X86_FEATURE_XMM)
  131. /**
  132. * read_barrier_depends - Flush all pending reads that subsequents reads
  133. * depend on.
  134. *
  135. * No data-dependent reads from memory-like regions are ever reordered
  136. * over this barrier. All reads preceding this primitive are guaranteed
  137. * to access memory (but not necessarily other CPUs' caches) before any
  138. * reads following this primitive that depend on the data return by
  139. * any of the preceding reads. This primitive is much lighter weight than
  140. * rmb() on most CPUs, and is never heavier weight than is
  141. * rmb().
  142. *
  143. * These ordering constraints are respected by both the local CPU
  144. * and the compiler.
  145. *
  146. * Ordering is not guaranteed by anything other than these primitives,
  147. * not even by data dependencies. See the documentation for
  148. * memory_barrier() for examples and URLs to more information.
  149. *
  150. * For example, the following code would force ordering (the initial
  151. * value of "a" is zero, "b" is one, and "p" is "&a"):
  152. *
  153. * <programlisting>
  154. * CPU 0 CPU 1
  155. *
  156. * b = 2;
  157. * memory_barrier();
  158. * p = &b; q = p;
  159. * read_barrier_depends();
  160. * d = *q;
  161. * </programlisting>
  162. *
  163. * because the read of "*q" depends on the read of "p" and these
  164. * two reads are separated by a read_barrier_depends(). However,
  165. * the following code, with the same initial values for "a" and "b":
  166. *
  167. * <programlisting>
  168. * CPU 0 CPU 1
  169. *
  170. * a = 2;
  171. * memory_barrier();
  172. * b = 3; y = b;
  173. * read_barrier_depends();
  174. * x = a;
  175. * </programlisting>
  176. *
  177. * does not enforce ordering, since there is no data dependency between
  178. * the read of "a" and the read of "b". Therefore, on some CPUs, such
  179. * as Alpha, "y" could be set to 3 and "x" to 0. Use rmb()
  180. * in cases like this where there are no data dependencies.
  181. **/
  182. #define read_barrier_depends() do { } while(0)
  183. #ifdef CONFIG_SMP
  184. #define smp_mb() mb()
  185. #ifdef CONFIG_X86_PPRO_FENCE
  186. # define smp_rmb() rmb()
  187. #else
  188. # define smp_rmb() barrier()
  189. #endif
  190. #ifdef CONFIG_X86_OOSTORE
  191. # define smp_wmb() wmb()
  192. #else
  193. # define smp_wmb() barrier()
  194. #endif
  195. #define smp_read_barrier_depends() read_barrier_depends()
  196. #define set_mb(var, value) do { (void) xchg(&var, value); } while (0)
  197. #else
  198. #define smp_mb() barrier()
  199. #define smp_rmb() barrier()
  200. #define smp_wmb() barrier()
  201. #define smp_read_barrier_depends() do { } while(0)
  202. #define set_mb(var, value) do { var = value; barrier(); } while (0)
  203. #endif
  204. #include <linux/irqflags.h>
  205. /*
  206. * disable hlt during certain critical i/o operations
  207. */
  208. #define HAVE_DISABLE_HLT
  209. #endif