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.esp),"=m" (prev->thread.eip), \
32 "=a" (last),"=S" (esi),"=D" (edi) \
33 :"m" (next->thread.esp),"m" (next->thread.eip), \
34 "2" (prev), "d" (next)); \
37 #define _set_base(addr,base) do { unsigned long __pr; \
38 __asm__ __volatile__ ("movw %%dx,%1\n\t" \
39 "rorl $16,%%edx\n\t" \
49 #define _set_limit(addr,limit) do { unsigned long __lr; \
50 __asm__ __volatile__ ("movw %%dx,%1\n\t" \
51 "rorl $16,%%edx\n\t" \
53 "andb $0xf0,%%dh\n\t" \
62 #define set_base(ldt,base) _set_base( ((char *)&(ldt)) , (base) )
63 #define set_limit(ldt,limit) _set_limit( ((char *)&(ldt)) , ((limit)-1) )
66 * Load a segment. Fall back on loading the zero
67 * segment if something goes wrong..
69 #define loadsegment(seg,value) \
72 "mov %0,%%" #seg "\n" \
74 ".section .fixup,\"ax\"\n" \
77 "popl %%" #seg "\n\t" \
80 ".section __ex_table,\"a\"\n\t" \
87 * Save a segment register away
89 #define savesegment(seg, value) \
90 asm volatile("mov %%" #seg ",%0":"=rm" (value))
93 static inline void native_clts(void)
95 asm volatile ("clts");
98 static inline unsigned long native_read_cr0(void)
101 asm volatile("movl %%cr0,%0\n\t" :"=r" (val));
105 static inline void native_write_cr0(unsigned long val)
107 asm volatile("movl %0,%%cr0": :"r" (val));
110 static inline unsigned long native_read_cr2(void)
113 asm volatile("movl %%cr2,%0\n\t" :"=r" (val));
117 static inline void native_write_cr2(unsigned long val)
119 asm volatile("movl %0,%%cr2": :"r" (val));
122 static inline unsigned long native_read_cr3(void)
125 asm volatile("movl %%cr3,%0\n\t" :"=r" (val));
129 static inline void native_write_cr3(unsigned long val)
131 asm volatile("movl %0,%%cr3": :"r" (val));
134 static inline unsigned long native_read_cr4(void)
137 asm volatile("movl %%cr4,%0\n\t" :"=r" (val));
141 static inline unsigned long native_read_cr4_safe(void)
144 /* This could fault if %cr4 does not exist */
145 asm volatile("1: movl %%cr4, %0 \n"
147 ".section __ex_table,\"a\" \n"
150 : "=r" (val): "0" (0));
154 static inline void native_write_cr4(unsigned long val)
156 asm volatile("movl %0,%%cr4": :"r" (val));
159 static inline void native_wbinvd(void)
161 asm volatile("wbinvd": : :"memory");
164 static inline void clflush(volatile void *__p)
166 asm volatile("clflush %0" : "+m" (*(char __force *)__p));
169 #ifdef CONFIG_PARAVIRT
170 #include <asm/paravirt.h>
172 #define read_cr0() (native_read_cr0())
173 #define write_cr0(x) (native_write_cr0(x))
174 #define read_cr2() (native_read_cr2())
175 #define write_cr2(x) (native_write_cr2(x))
176 #define read_cr3() (native_read_cr3())
177 #define write_cr3(x) (native_write_cr3(x))
178 #define read_cr4() (native_read_cr4())
179 #define read_cr4_safe() (native_read_cr4_safe())
180 #define write_cr4(x) (native_write_cr4(x))
181 #define wbinvd() (native_wbinvd())
183 /* Clear the 'TS' bit */
184 #define clts() (native_clts())
186 #endif/* CONFIG_PARAVIRT */
188 /* Set the 'TS' bit */
189 #define stts() write_cr0(8 | read_cr0())
191 #endif /* __KERNEL__ */
193 static inline unsigned long get_limit(unsigned long segment)
195 unsigned long __limit;
197 :"=r" (__limit):"r" (segment));
201 #define nop() __asm__ __volatile__ ("nop")
204 * Force strict CPU ordering.
205 * And yes, this is required on UP too when we're talking
208 * For now, "wmb()" doesn't actually do anything, as all
209 * Intel CPU's follow what Intel calls a *Processor Order*,
210 * in which all writes are seen in the program order even
213 * I expect future Intel CPU's to have a weaker ordering,
214 * but I'd also expect them to finally get their act together
215 * and add some real memory barriers if so.
217 * Some non intel clones support out of order store. wmb() ceases to be a
222 #define mb() alternative("lock; addl $0,0(%%esp)", "mfence", X86_FEATURE_XMM2)
223 #define rmb() alternative("lock; addl $0,0(%%esp)", "lfence", X86_FEATURE_XMM2)
224 #define wmb() alternative("lock; addl $0,0(%%esp)", "sfence", X86_FEATURE_XMM)
227 * read_barrier_depends - Flush all pending reads that subsequents reads
230 * No data-dependent reads from memory-like regions are ever reordered
231 * over this barrier. All reads preceding this primitive are guaranteed
232 * to access memory (but not necessarily other CPUs' caches) before any
233 * reads following this primitive that depend on the data return by
234 * any of the preceding reads. This primitive is much lighter weight than
235 * rmb() on most CPUs, and is never heavier weight than is
238 * These ordering constraints are respected by both the local CPU
241 * Ordering is not guaranteed by anything other than these primitives,
242 * not even by data dependencies. See the documentation for
243 * memory_barrier() for examples and URLs to more information.
245 * For example, the following code would force ordering (the initial
246 * value of "a" is zero, "b" is one, and "p" is "&a"):
254 * read_barrier_depends();
258 * because the read of "*q" depends on the read of "p" and these
259 * two reads are separated by a read_barrier_depends(). However,
260 * the following code, with the same initial values for "a" and "b":
268 * read_barrier_depends();
272 * does not enforce ordering, since there is no data dependency between
273 * the read of "a" and the read of "b". Therefore, on some CPUs, such
274 * as Alpha, "y" could be set to 3 and "x" to 0. Use rmb()
275 * in cases like this where there are no data dependencies.
278 #define read_barrier_depends() do { } while(0)
281 #define smp_mb() mb()
282 #ifdef CONFIG_X86_PPRO_FENCE
283 # define smp_rmb() rmb()
285 # define smp_rmb() barrier()
287 #ifdef CONFIG_X86_OOSTORE
288 # define smp_wmb() wmb()
290 # define smp_wmb() barrier()
292 #define smp_read_barrier_depends() read_barrier_depends()
293 #define set_mb(var, value) do { (void) xchg(&var, value); } while (0)
295 #define smp_mb() barrier()
296 #define smp_rmb() barrier()
297 #define smp_wmb() barrier()
298 #define smp_read_barrier_depends() do { } while(0)
299 #define set_mb(var, value) do { var = value; barrier(); } while (0)
302 #include <linux/irqflags.h>
305 * disable hlt during certain critical i/o operations
307 #define HAVE_DISABLE_HLT
308 void disable_hlt(void);
309 void enable_hlt(void);
311 extern int es7000_plat;
312 void cpu_idle_wait(void);
314 extern unsigned long arch_align_stack(unsigned long sp);
315 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
317 void default_idle(void);
318 void __show_registers(struct pt_regs *, int all);