Disintegrate asm/system.h for X86
[linux-2.6.git] / arch / x86 / include / asm / special_insns.h
blob41fc93a2e225d1793465e1ccf5e5ebc0e354d8a5
1 #ifndef _ASM_X86_SPECIAL_INSNS_H
2 #define _ASM_X86_SPECIAL_INSNS_H
5 #ifdef __KERNEL__
7 static inline void native_clts(void)
9 asm volatile("clts");
13 * Volatile isn't enough to prevent the compiler from reordering the
14 * read/write functions for the control registers and messing everything up.
15 * A memory clobber would solve the problem, but would prevent reordering of
16 * all loads stores around it, which can hurt performance. Solution is to
17 * use a variable and mimic reads and writes to it to enforce serialization
19 static unsigned long __force_order;
21 static inline unsigned long native_read_cr0(void)
23 unsigned long val;
24 asm volatile("mov %%cr0,%0\n\t" : "=r" (val), "=m" (__force_order));
25 return val;
28 static inline void native_write_cr0(unsigned long val)
30 asm volatile("mov %0,%%cr0": : "r" (val), "m" (__force_order));
33 static inline unsigned long native_read_cr2(void)
35 unsigned long val;
36 asm volatile("mov %%cr2,%0\n\t" : "=r" (val), "=m" (__force_order));
37 return val;
40 static inline void native_write_cr2(unsigned long val)
42 asm volatile("mov %0,%%cr2": : "r" (val), "m" (__force_order));
45 static inline unsigned long native_read_cr3(void)
47 unsigned long val;
48 asm volatile("mov %%cr3,%0\n\t" : "=r" (val), "=m" (__force_order));
49 return val;
52 static inline void native_write_cr3(unsigned long val)
54 asm volatile("mov %0,%%cr3": : "r" (val), "m" (__force_order));
57 static inline unsigned long native_read_cr4(void)
59 unsigned long val;
60 asm volatile("mov %%cr4,%0\n\t" : "=r" (val), "=m" (__force_order));
61 return val;
64 static inline unsigned long native_read_cr4_safe(void)
66 unsigned long val;
67 /* This could fault if %cr4 does not exist. In x86_64, a cr4 always
68 * exists, so it will never fail. */
69 #ifdef CONFIG_X86_32
70 asm volatile("1: mov %%cr4, %0\n"
71 "2:\n"
72 _ASM_EXTABLE(1b, 2b)
73 : "=r" (val), "=m" (__force_order) : "0" (0));
74 #else
75 val = native_read_cr4();
76 #endif
77 return val;
80 static inline void native_write_cr4(unsigned long val)
82 asm volatile("mov %0,%%cr4": : "r" (val), "m" (__force_order));
85 #ifdef CONFIG_X86_64
86 static inline unsigned long native_read_cr8(void)
88 unsigned long cr8;
89 asm volatile("movq %%cr8,%0" : "=r" (cr8));
90 return cr8;
93 static inline void native_write_cr8(unsigned long val)
95 asm volatile("movq %0,%%cr8" :: "r" (val) : "memory");
97 #endif
99 static inline void native_wbinvd(void)
101 asm volatile("wbinvd": : :"memory");
104 extern void native_load_gs_index(unsigned);
106 #ifdef CONFIG_PARAVIRT
107 #include <asm/paravirt.h>
108 #else
110 static inline unsigned long read_cr0(void)
112 return native_read_cr0();
115 static inline void write_cr0(unsigned long x)
117 native_write_cr0(x);
120 static inline unsigned long read_cr2(void)
122 return native_read_cr2();
125 static inline void write_cr2(unsigned long x)
127 native_write_cr2(x);
130 static inline unsigned long read_cr3(void)
132 return native_read_cr3();
135 static inline void write_cr3(unsigned long x)
137 native_write_cr3(x);
140 static inline unsigned long read_cr4(void)
142 return native_read_cr4();
145 static inline unsigned long read_cr4_safe(void)
147 return native_read_cr4_safe();
150 static inline void write_cr4(unsigned long x)
152 native_write_cr4(x);
155 static inline void wbinvd(void)
157 native_wbinvd();
160 #ifdef CONFIG_X86_64
162 static inline unsigned long read_cr8(void)
164 return native_read_cr8();
167 static inline void write_cr8(unsigned long x)
169 native_write_cr8(x);
172 static inline void load_gs_index(unsigned selector)
174 native_load_gs_index(selector);
177 #endif
179 /* Clear the 'TS' bit */
180 static inline void clts(void)
182 native_clts();
185 #endif/* CONFIG_PARAVIRT */
187 #define stts() write_cr0(read_cr0() | X86_CR0_TS)
189 static inline void clflush(volatile void *__p)
191 asm volatile("clflush %0" : "+m" (*(volatile char __force *)__p));
194 #define nop() asm volatile ("nop")
197 #endif /* __KERNEL__ */
199 #endif /* _ASM_X86_SPECIAL_INSNS_H */