system_32.h 8.1 KB

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