system_32.h 8.3 KB

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