1 #ifndef _ASM_X86_SYSTEM_H_
2 #define _ASM_X86_SYSTEM_H_
6 #include <linux/kernel.h>
9 # include "system_32.h"
11 # include "system_64.h"
15 #define _set_base(addr, base) do { unsigned long __pr; \
16 __asm__ __volatile__ ("movw %%dx,%1\n\t" \
17 "rorl $16,%%edx\n\t" \
27 #define _set_limit(addr, limit) do { unsigned long __lr; \
28 __asm__ __volatile__ ("movw %%dx,%1\n\t" \
29 "rorl $16,%%edx\n\t" \
31 "andb $0xf0,%%dh\n\t" \
40 #define set_base(ldt, base) _set_base(((char *)&(ldt)) , (base))
41 #define set_limit(ldt, limit) _set_limit(((char *)&(ldt)) , ((limit)-1))
43 extern void load_gs_index(unsigned);
46 * Load a segment. Fall back on loading the zero
47 * segment if something goes wrong..
49 #define loadsegment(seg, value) \
52 "movl %k0,%%" #seg "\n" \
54 ".section .fixup,\"ax\"\n" \
56 "movl %k1, %%" #seg "\n\t" \
59 ".section __ex_table,\"a\"\n\t" \
63 : :"r" (value), "r" (0))
67 * Save a segment register away
69 #define savesegment(seg, value) \
70 asm volatile("mov %%" #seg ",%0":"=rm" (value))
72 static inline unsigned long get_limit(unsigned long segment)
74 unsigned long __limit;
76 :"=r" (__limit):"r" (segment));
80 static inline void native_clts(void)
82 asm volatile ("clts");
86 * Volatile isn't enough to prevent the compiler from reordering the
87 * read/write functions for the control registers and messing everything up.
88 * A memory clobber would solve the problem, but would prevent reordering of
89 * all loads stores around it, which can hurt performance. Solution is to
90 * use a variable and mimic reads and writes to it to enforce serialization
92 static unsigned long __force_order;
94 static inline unsigned long native_read_cr0(void)
97 asm volatile("mov %%cr0,%0\n\t" :"=r" (val), "=m" (__force_order));
101 static inline void native_write_cr0(unsigned long val)
103 asm volatile("mov %0,%%cr0": :"r" (val), "m" (__force_order));
106 static inline unsigned long native_read_cr2(void)
109 asm volatile("mov %%cr2,%0\n\t" :"=r" (val), "=m" (__force_order));
113 static inline void native_write_cr2(unsigned long val)
115 asm volatile("mov %0,%%cr2": :"r" (val), "m" (__force_order));
118 static inline unsigned long native_read_cr3(void)
121 asm volatile("mov %%cr3,%0\n\t" :"=r" (val), "=m" (__force_order));
125 static inline void native_write_cr3(unsigned long val)
127 asm volatile("mov %0,%%cr3": :"r" (val), "m" (__force_order));
130 static inline unsigned long native_read_cr4(void)
133 asm volatile("mov %%cr4,%0\n\t" :"=r" (val), "=m" (__force_order));
137 static inline unsigned long native_read_cr4_safe(void)
140 /* This could fault if %cr4 does not exist. In x86_64, a cr4 always
141 * exists, so it will never fail. */
143 asm volatile("1: mov %%cr4, %0 \n"
145 ".section __ex_table,\"a\" \n"
148 : "=r" (val), "=m" (__force_order) : "0" (0));
150 val = native_read_cr4();
155 static inline void native_write_cr4(unsigned long val)
157 asm volatile("mov %0,%%cr4": :"r" (val), "m" (__force_order));
160 static inline void native_wbinvd(void)
162 asm volatile("wbinvd": : :"memory");
164 #ifdef CONFIG_PARAVIRT
165 #include <asm/paravirt.h>
167 #define read_cr0() (native_read_cr0())
168 #define write_cr0(x) (native_write_cr0(x))
169 #define read_cr2() (native_read_cr2())
170 #define write_cr2(x) (native_write_cr2(x))
171 #define read_cr3() (native_read_cr3())
172 #define write_cr3(x) (native_write_cr3(x))
173 #define read_cr4() (native_read_cr4())
174 #define read_cr4_safe() (native_read_cr4_safe())
175 #define write_cr4(x) (native_write_cr4(x))
176 #define wbinvd() (native_wbinvd())
178 /* Clear the 'TS' bit */
179 #define clts() (native_clts())
181 #endif/* CONFIG_PARAVIRT */
183 #define stts() write_cr0(8 | read_cr0())
185 #endif /* __KERNEL__ */
187 static inline void clflush(void *__p)
189 asm volatile("clflush %0" : "+m" (*(char __force *)__p));
192 #define nop() __asm__ __volatile__ ("nop")
194 void disable_hlt(void);
195 void enable_hlt(void);
197 extern int es7000_plat;
198 void cpu_idle_wait(void);
200 extern unsigned long arch_align_stack(unsigned long sp);
201 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
203 void default_idle(void);