]> git.buserror.net Git - polintos/scott/priv.git/blob - include/c/lowlevel/arch-x86-common/misc.h
Initial checkin from Perforce.
[polintos/scott/priv.git] / include / c / lowlevel / arch-x86-common / misc.h
1 #ifndef _LL_ARCH_X86C_MISC_H
2 #define _LL_ARCH_X86C_MISC_H
3
4 #include <lowlevel/types.h>
5
6 // Call this inside busy loops to tell the CPU to save power,
7 // use the bus less, or other CPU-specific effects.
8 // This function is not privileged.
9
10 static inline void ll_busywait()
11 {
12         asm volatile("pause" : : : "memory");
13 }
14
15 // The ll_ints functions are normally privileged, but on x86 can
16 // be also be used with IOPL 3.
17
18 static inline void ll_ints_off()
19 {
20         asm volatile("cli" : : : "memory");
21 }
22
23 static inline void ll_ints_on()
24 {
25         asm volatile("sti" : : : "memory");
26 }
27
28 static inline unsigned long ll_ints_save_and_off()
29 {
30         unsigned long ret;
31         asm volatile("pushf; pop %0; cli" : "=r" (ret) : : "memory");
32         return ret;
33 }
34
35 static inline void ll_ints_restore(unsigned long saved)
36 {
37         asm volatile("push %0; popf" : : "r" (saved) : "memory");
38 }
39
40 // Returns true if ints on, false if off.  This function is not privileged.
41
42 static inline int ll_get_int_state()
43 {
44         unsigned long flags;
45         asm volatile("pushf; pop %0" : "=r" (flags));
46         
47         return flags & 0x200;
48 }
49
50 // Invalidates the TLB entry for one page.  This function is privileged,
51 // and requires at least a 486.
52
53 static inline void ll_invalidate_tlb_entry(unsigned long addr)
54 {
55         asm volatile("invlpg %0" : "+m" (*(char *)addr) : : "memory");
56 }
57
58 #endif