4 #include <linux/kernel.h>
5 #include <asm/segment.h>
6 #include <asm/cpufeature.h>
7 #include <asm/cmpxchg.h>
10 #define AT_VECTOR_SIZE_ARCH 2 /* entries in ARCH_DLINFO */
12 struct task_struct; /* one of the stranger aspects of C forward declarations.. */
13 extern struct task_struct * FASTCALL(__switch_to(struct task_struct *prev, struct task_struct *next));
16 * Saving eflags is important. It switches not only IOPL between tasks,
17 * it also protects other tasks from NT leaking through sysenter etc.
19 #define switch_to(prev,next,last) do { \
20 unsigned long esi,edi; \
21 asm volatile("pushfl\n\t" /* Save flags */ \
23 "movl %%esp,%0\n\t" /* save ESP */ \
24 "movl %5,%%esp\n\t" /* restore ESP */ \
25 "movl $1f,%1\n\t" /* save EIP */ \
26 "pushl %6\n\t" /* restore EIP */ \
31 :"=m" (prev->thread.sp),"=m" (prev->thread.ip), \
32 "=a" (last),"=S" (esi),"=D" (edi) \
33 :"m" (next->thread.sp),"m" (next->thread.ip), \
34 "2" (prev), "d" (next)); \
37 static inline void native_clts(void)
39 asm volatile ("clts");
42 static inline unsigned long native_read_cr0(void)
45 asm volatile("movl %%cr0,%0\n\t" :"=r" (val));
49 static inline void native_write_cr0(unsigned long val)
51 asm volatile("movl %0,%%cr0": :"r" (val));
54 static inline unsigned long native_read_cr2(void)
57 asm volatile("movl %%cr2,%0\n\t" :"=r" (val));
61 static inline void native_write_cr2(unsigned long val)
63 asm volatile("movl %0,%%cr2": :"r" (val));
66 static inline unsigned long native_read_cr3(void)
69 asm volatile("movl %%cr3,%0\n\t" :"=r" (val));
73 static inline void native_write_cr3(unsigned long val)
75 asm volatile("movl %0,%%cr3": :"r" (val));
78 static inline unsigned long native_read_cr4(void)
81 asm volatile("movl %%cr4,%0\n\t" :"=r" (val));
85 static inline unsigned long native_read_cr4_safe(void)
88 /* This could fault if %cr4 does not exist */
89 asm volatile("1: movl %%cr4, %0 \n"
91 ".section __ex_table,\"a\" \n"
94 : "=r" (val): "0" (0));
98 static inline void native_write_cr4(unsigned long val)
100 asm volatile("movl %0,%%cr4": :"r" (val));
103 static inline void native_wbinvd(void)
105 asm volatile("wbinvd": : :"memory");
108 #ifdef CONFIG_PARAVIRT
109 #include <asm/paravirt.h>
111 #define read_cr0() (native_read_cr0())
112 #define write_cr0(x) (native_write_cr0(x))
113 #define read_cr2() (native_read_cr2())
114 #define write_cr2(x) (native_write_cr2(x))
115 #define read_cr3() (native_read_cr3())
116 #define write_cr3(x) (native_write_cr3(x))
117 #define read_cr4() (native_read_cr4())
118 #define read_cr4_safe() (native_read_cr4_safe())
119 #define write_cr4(x) (native_write_cr4(x))
120 #define wbinvd() (native_wbinvd())
122 /* Clear the 'TS' bit */
123 #define clts() (native_clts())
125 #endif/* CONFIG_PARAVIRT */
127 /* Set the 'TS' bit */
128 #define stts() write_cr0(8 | read_cr0())
130 #endif /* __KERNEL__ */
134 * Force strict CPU ordering.
135 * And yes, this is required on UP too when we're talking
138 * For now, "wmb()" doesn't actually do anything, as all
139 * Intel CPU's follow what Intel calls a *Processor Order*,
140 * in which all writes are seen in the program order even
143 * I expect future Intel CPU's to have a weaker ordering,
144 * but I'd also expect them to finally get their act together
145 * and add some real memory barriers if so.
147 * Some non intel clones support out of order store. wmb() ceases to be a
152 #define mb() alternative("lock; addl $0,0(%%esp)", "mfence", X86_FEATURE_XMM2)
153 #define rmb() alternative("lock; addl $0,0(%%esp)", "lfence", X86_FEATURE_XMM2)
154 #define wmb() alternative("lock; addl $0,0(%%esp)", "sfence", X86_FEATURE_XMM)
157 * read_barrier_depends - Flush all pending reads that subsequents reads
160 * No data-dependent reads from memory-like regions are ever reordered
161 * over this barrier. All reads preceding this primitive are guaranteed
162 * to access memory (but not necessarily other CPUs' caches) before any
163 * reads following this primitive that depend on the data return by
164 * any of the preceding reads. This primitive is much lighter weight than
165 * rmb() on most CPUs, and is never heavier weight than is
168 * These ordering constraints are respected by both the local CPU
171 * Ordering is not guaranteed by anything other than these primitives,
172 * not even by data dependencies. See the documentation for
173 * memory_barrier() for examples and URLs to more information.
175 * For example, the following code would force ordering (the initial
176 * value of "a" is zero, "b" is one, and "p" is "&a"):
184 * read_barrier_depends();
188 * because the read of "*q" depends on the read of "p" and these
189 * two reads are separated by a read_barrier_depends(). However,
190 * the following code, with the same initial values for "a" and "b":
198 * read_barrier_depends();
202 * does not enforce ordering, since there is no data dependency between
203 * the read of "a" and the read of "b". Therefore, on some CPUs, such
204 * as Alpha, "y" could be set to 3 and "x" to 0. Use rmb()
205 * in cases like this where there are no data dependencies.
208 #define read_barrier_depends() do { } while(0)
211 #define smp_mb() mb()
212 #ifdef CONFIG_X86_PPRO_FENCE
213 # define smp_rmb() rmb()
215 # define smp_rmb() barrier()
217 #ifdef CONFIG_X86_OOSTORE
218 # define smp_wmb() wmb()
220 # define smp_wmb() barrier()
222 #define smp_read_barrier_depends() read_barrier_depends()
223 #define set_mb(var, value) do { (void) xchg(&var, value); } while (0)
225 #define smp_mb() barrier()
226 #define smp_rmb() barrier()
227 #define smp_wmb() barrier()
228 #define smp_read_barrier_depends() do { } while(0)
229 #define set_mb(var, value) do { var = value; barrier(); } while (0)
232 #include <linux/irqflags.h>
235 * disable hlt during certain critical i/o operations
237 #define HAVE_DISABLE_HLT