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)); \
38 * Load a segment. Fall back on loading the zero
39 * segment if something goes wrong..
41 #define loadsegment(seg,value) \
44 "mov %0,%%" #seg "\n" \
46 ".section .fixup,\"ax\"\n" \
49 "popl %%" #seg "\n\t" \
52 ".section __ex_table,\"a\"\n\t" \
59 static inline void native_clts(void)
61 asm volatile ("clts");
64 static inline unsigned long native_read_cr0(void)
67 asm volatile("movl %%cr0,%0\n\t" :"=r" (val
));
71 static inline void native_write_cr0(unsigned long val
)
73 asm volatile("movl %0,%%cr0": :"r" (val
));
76 static inline unsigned long native_read_cr2(void)
79 asm volatile("movl %%cr2,%0\n\t" :"=r" (val
));
83 static inline void native_write_cr2(unsigned long val
)
85 asm volatile("movl %0,%%cr2": :"r" (val
));
88 static inline unsigned long native_read_cr3(void)
91 asm volatile("movl %%cr3,%0\n\t" :"=r" (val
));
95 static inline void native_write_cr3(unsigned long val
)
97 asm volatile("movl %0,%%cr3": :"r" (val
));
100 static inline unsigned long native_read_cr4(void)
103 asm volatile("movl %%cr4,%0\n\t" :"=r" (val
));
107 static inline unsigned long native_read_cr4_safe(void)
110 /* This could fault if %cr4 does not exist */
111 asm volatile("1: movl %%cr4, %0 \n"
113 ".section __ex_table,\"a\" \n"
116 : "=r" (val
): "0" (0));
120 static inline void native_write_cr4(unsigned long val
)
122 asm volatile("movl %0,%%cr4": :"r" (val
));
125 static inline void native_wbinvd(void)
127 asm volatile("wbinvd": : :"memory");
130 #ifdef CONFIG_PARAVIRT
131 #include <asm/paravirt.h>
133 #define read_cr0() (native_read_cr0())
134 #define write_cr0(x) (native_write_cr0(x))
135 #define read_cr2() (native_read_cr2())
136 #define write_cr2(x) (native_write_cr2(x))
137 #define read_cr3() (native_read_cr3())
138 #define write_cr3(x) (native_write_cr3(x))
139 #define read_cr4() (native_read_cr4())
140 #define read_cr4_safe() (native_read_cr4_safe())
141 #define write_cr4(x) (native_write_cr4(x))
142 #define wbinvd() (native_wbinvd())
144 /* Clear the 'TS' bit */
145 #define clts() (native_clts())
147 #endif/* CONFIG_PARAVIRT */
149 /* Set the 'TS' bit */
150 #define stts() write_cr0(8 | read_cr0())
152 #endif /* __KERNEL__ */
156 * Force strict CPU ordering.
157 * And yes, this is required on UP too when we're talking
160 * For now, "wmb()" doesn't actually do anything, as all
161 * Intel CPU's follow what Intel calls a *Processor Order*,
162 * in which all writes are seen in the program order even
165 * I expect future Intel CPU's to have a weaker ordering,
166 * but I'd also expect them to finally get their act together
167 * and add some real memory barriers if so.
169 * Some non intel clones support out of order store. wmb() ceases to be a
174 #define mb() alternative("lock; addl $0,0(%%esp)", "mfence", X86_FEATURE_XMM2)
175 #define rmb() alternative("lock; addl $0,0(%%esp)", "lfence", X86_FEATURE_XMM2)
176 #define wmb() alternative("lock; addl $0,0(%%esp)", "sfence", X86_FEATURE_XMM)
179 * read_barrier_depends - Flush all pending reads that subsequents reads
182 * No data-dependent reads from memory-like regions are ever reordered
183 * over this barrier. All reads preceding this primitive are guaranteed
184 * to access memory (but not necessarily other CPUs' caches) before any
185 * reads following this primitive that depend on the data return by
186 * any of the preceding reads. This primitive is much lighter weight than
187 * rmb() on most CPUs, and is never heavier weight than is
190 * These ordering constraints are respected by both the local CPU
193 * Ordering is not guaranteed by anything other than these primitives,
194 * not even by data dependencies. See the documentation for
195 * memory_barrier() for examples and URLs to more information.
197 * For example, the following code would force ordering (the initial
198 * value of "a" is zero, "b" is one, and "p" is "&a"):
206 * read_barrier_depends();
210 * because the read of "*q" depends on the read of "p" and these
211 * two reads are separated by a read_barrier_depends(). However,
212 * the following code, with the same initial values for "a" and "b":
220 * read_barrier_depends();
224 * does not enforce ordering, since there is no data dependency between
225 * the read of "a" and the read of "b". Therefore, on some CPUs, such
226 * as Alpha, "y" could be set to 3 and "x" to 0. Use rmb()
227 * in cases like this where there are no data dependencies.
230 #define read_barrier_depends() do { } while(0)
233 #define smp_mb() mb()
234 #ifdef CONFIG_X86_PPRO_FENCE
235 # define smp_rmb() rmb()
237 # define smp_rmb() barrier()
239 #ifdef CONFIG_X86_OOSTORE
240 # define smp_wmb() wmb()
242 # define smp_wmb() barrier()
244 #define smp_read_barrier_depends() read_barrier_depends()
245 #define set_mb(var, value) do { (void) xchg(&var, value); } while (0)
247 #define smp_mb() barrier()
248 #define smp_rmb() barrier()
249 #define smp_wmb() barrier()
250 #define smp_read_barrier_depends() do { } while(0)
251 #define set_mb(var, value) do { var = value; barrier(); } while (0)
254 #include <linux/irqflags.h>
257 * disable hlt during certain critical i/o operations
259 #define HAVE_DISABLE_HLT