1 #ifndef _ASM_X86_SPECIAL_INSNS_H
2 #define _ASM_X86_SPECIAL_INSNS_H
9 static inline void native_clts(void)
15 * Volatile isn't enough to prevent the compiler from reordering the
16 * read/write functions for the control registers and messing everything up.
17 * A memory clobber would solve the problem, but would prevent reordering of
18 * all loads stores around it, which can hurt performance. Solution is to
19 * use a variable and mimic reads and writes to it to enforce serialization
21 extern unsigned long __force_order
;
23 static inline unsigned long native_read_cr0(void)
26 asm volatile("mov %%cr0,%0\n\t" : "=r" (val
), "=m" (__force_order
));
30 static inline void native_write_cr0(unsigned long val
)
32 asm volatile("mov %0,%%cr0": : "r" (val
), "m" (__force_order
));
35 static inline unsigned long native_read_cr2(void)
38 asm volatile("mov %%cr2,%0\n\t" : "=r" (val
), "=m" (__force_order
));
42 static inline void native_write_cr2(unsigned long val
)
44 asm volatile("mov %0,%%cr2": : "r" (val
), "m" (__force_order
));
47 static inline unsigned long native_read_cr3(void)
50 asm volatile("mov %%cr3,%0\n\t" : "=r" (val
), "=m" (__force_order
));
54 static inline void native_write_cr3(unsigned long val
)
56 asm volatile("mov %0,%%cr3": : "r" (val
), "m" (__force_order
));
59 static inline unsigned long native_read_cr4(void)
62 asm volatile("mov %%cr4,%0\n\t" : "=r" (val
), "=m" (__force_order
));
66 static inline unsigned long native_read_cr4_safe(void)
69 /* This could fault if %cr4 does not exist. In x86_64, a cr4 always
70 * exists, so it will never fail. */
72 asm volatile("1: mov %%cr4, %0\n"
75 : "=r" (val
), "=m" (__force_order
) : "0" (0));
77 val
= native_read_cr4();
82 static inline void native_write_cr4(unsigned long val
)
84 asm volatile("mov %0,%%cr4": : "r" (val
), "m" (__force_order
));
88 static inline unsigned long native_read_cr8(void)
91 asm volatile("movq %%cr8,%0" : "=r" (cr8
));
95 static inline void native_write_cr8(unsigned long val
)
97 asm volatile("movq %0,%%cr8" :: "r" (val
) : "memory");
101 static inline void native_wbinvd(void)
103 asm volatile("wbinvd": : :"memory");
106 extern asmlinkage
void native_load_gs_index(unsigned);
108 #ifdef CONFIG_PARAVIRT
109 #include <asm/paravirt.h>
112 static inline unsigned long read_cr0(void)
114 return native_read_cr0();
117 static inline void write_cr0(unsigned long x
)
122 static inline unsigned long read_cr2(void)
124 return native_read_cr2();
127 static inline void write_cr2(unsigned long x
)
132 static inline unsigned long read_cr3(void)
134 return native_read_cr3();
137 static inline void write_cr3(unsigned long x
)
142 static inline unsigned long __read_cr4(void)
144 return native_read_cr4();
147 static inline unsigned long __read_cr4_safe(void)
149 return native_read_cr4_safe();
152 static inline void __write_cr4(unsigned long x
)
157 static inline void wbinvd(void)
164 static inline unsigned long read_cr8(void)
166 return native_read_cr8();
169 static inline void write_cr8(unsigned long x
)
174 static inline void load_gs_index(unsigned selector
)
176 native_load_gs_index(selector
);
181 /* Clear the 'TS' bit */
182 static inline void clts(void)
187 #endif/* CONFIG_PARAVIRT */
189 #define stts() write_cr0(read_cr0() | X86_CR0_TS)
191 static inline void clflush(volatile void *__p
)
193 asm volatile("clflush %0" : "+m" (*(volatile char __force
*)__p
));
196 static inline void clflushopt(volatile void *__p
)
198 alternative_io(".byte " __stringify(NOP_DS_PREFIX
) "; clflush %P0",
199 ".byte 0x66; clflush %P0",
200 X86_FEATURE_CLFLUSHOPT
,
201 "+m" (*(volatile char __force
*)__p
));
204 static inline void clwb(volatile void *__p
)
206 volatile struct { char x
[64]; } *p
= __p
;
208 asm volatile(ALTERNATIVE_2(
209 ".byte " __stringify(NOP_DS_PREFIX
) "; clflush (%[pax])",
210 ".byte 0x66; clflush (%[pax])", /* clflushopt (%%rax) */
211 X86_FEATURE_CLFLUSHOPT
,
212 ".byte 0x66, 0x0f, 0xae, 0x30", /* clwb (%%rax) */
218 static inline void pcommit_sfence(void)
220 alternative(ASM_NOP7
,
221 ".byte 0x66, 0x0f, 0xae, 0xf8\n\t" /* pcommit */
223 X86_FEATURE_PCOMMIT
);
226 #define nop() asm volatile ("nop")
229 #endif /* __KERNEL__ */
231 #endif /* _ASM_X86_SPECIAL_INSNS_H */