system_32.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  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("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. #ifdef CONFIG_PARAVIRT
  143. #include <asm/paravirt.h>
  144. #else
  145. #define read_cr0() (native_read_cr0())
  146. #define write_cr0(x) (native_write_cr0(x))
  147. #define read_cr2() (native_read_cr2())
  148. #define write_cr2(x) (native_write_cr2(x))
  149. #define read_cr3() (native_read_cr3())
  150. #define write_cr3(x) (native_write_cr3(x))
  151. #define read_cr4() (native_read_cr4())
  152. #define read_cr4_safe() (native_read_cr4_safe())
  153. #define write_cr4(x) (native_write_cr4(x))
  154. #define wbinvd() (native_wbinvd())
  155. /* Clear the 'TS' bit */
  156. #define clts() (native_clts())
  157. #endif/* CONFIG_PARAVIRT */
  158. /* Set the 'TS' bit */
  159. #define stts() write_cr0(8 | read_cr0())
  160. #endif /* __KERNEL__ */
  161. static inline unsigned long get_limit(unsigned long segment)
  162. {
  163. unsigned long __limit;
  164. __asm__("lsll %1,%0"
  165. :"=r" (__limit):"r" (segment));
  166. return __limit+1;
  167. }
  168. #define nop() __asm__ __volatile__ ("nop")
  169. /*
  170. * Force strict CPU ordering.
  171. * And yes, this is required on UP too when we're talking
  172. * to devices.
  173. *
  174. * For now, "wmb()" doesn't actually do anything, as all
  175. * Intel CPU's follow what Intel calls a *Processor Order*,
  176. * in which all writes are seen in the program order even
  177. * outside the CPU.
  178. *
  179. * I expect future Intel CPU's to have a weaker ordering,
  180. * but I'd also expect them to finally get their act together
  181. * and add some real memory barriers if so.
  182. *
  183. * Some non intel clones support out of order store. wmb() ceases to be a
  184. * nop for these.
  185. */
  186. #define mb() alternative("lock; addl $0,0(%%esp)", "mfence", X86_FEATURE_XMM2)
  187. #define rmb() alternative("lock; addl $0,0(%%esp)", "lfence", X86_FEATURE_XMM2)
  188. #define wmb() alternative("lock; addl $0,0(%%esp)", "sfence", X86_FEATURE_XMM)
  189. /**
  190. * read_barrier_depends - Flush all pending reads that subsequents reads
  191. * depend on.
  192. *
  193. * No data-dependent reads from memory-like regions are ever reordered
  194. * over this barrier. All reads preceding this primitive are guaranteed
  195. * to access memory (but not necessarily other CPUs' caches) before any
  196. * reads following this primitive that depend on the data return by
  197. * any of the preceding reads. This primitive is much lighter weight than
  198. * rmb() on most CPUs, and is never heavier weight than is
  199. * rmb().
  200. *
  201. * These ordering constraints are respected by both the local CPU
  202. * and the compiler.
  203. *
  204. * Ordering is not guaranteed by anything other than these primitives,
  205. * not even by data dependencies. See the documentation for
  206. * memory_barrier() for examples and URLs to more information.
  207. *
  208. * For example, the following code would force ordering (the initial
  209. * value of "a" is zero, "b" is one, and "p" is "&a"):
  210. *
  211. * <programlisting>
  212. * CPU 0 CPU 1
  213. *
  214. * b = 2;
  215. * memory_barrier();
  216. * p = &b; q = p;
  217. * read_barrier_depends();
  218. * d = *q;
  219. * </programlisting>
  220. *
  221. * because the read of "*q" depends on the read of "p" and these
  222. * two reads are separated by a read_barrier_depends(). However,
  223. * the following code, with the same initial values for "a" and "b":
  224. *
  225. * <programlisting>
  226. * CPU 0 CPU 1
  227. *
  228. * a = 2;
  229. * memory_barrier();
  230. * b = 3; y = b;
  231. * read_barrier_depends();
  232. * x = a;
  233. * </programlisting>
  234. *
  235. * does not enforce ordering, since there is no data dependency between
  236. * the read of "a" and the read of "b". Therefore, on some CPUs, such
  237. * as Alpha, "y" could be set to 3 and "x" to 0. Use rmb()
  238. * in cases like this where there are no data dependencies.
  239. **/
  240. #define read_barrier_depends() do { } while(0)
  241. #ifdef CONFIG_SMP
  242. #define smp_mb() mb()
  243. #ifdef CONFIG_X86_PPRO_FENCE
  244. # define smp_rmb() rmb()
  245. #else
  246. # define smp_rmb() barrier()
  247. #endif
  248. #ifdef CONFIG_X86_OOSTORE
  249. # define smp_wmb() wmb()
  250. #else
  251. # define smp_wmb() barrier()
  252. #endif
  253. #define smp_read_barrier_depends() read_barrier_depends()
  254. #define set_mb(var, value) do { (void) xchg(&var, value); } while (0)
  255. #else
  256. #define smp_mb() barrier()
  257. #define smp_rmb() barrier()
  258. #define smp_wmb() barrier()
  259. #define smp_read_barrier_depends() do { } while(0)
  260. #define set_mb(var, value) do { var = value; barrier(); } while (0)
  261. #endif
  262. #include <linux/irqflags.h>
  263. /*
  264. * disable hlt during certain critical i/o operations
  265. */
  266. #define HAVE_DISABLE_HLT
  267. void disable_hlt(void);
  268. void enable_hlt(void);
  269. extern int es7000_plat;
  270. void cpu_idle_wait(void);
  271. extern unsigned long arch_align_stack(unsigned long sp);
  272. extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
  273. void default_idle(void);
  274. #endif