6 static __inline
void breakpoint(void) __attribute__((always_inline
));
7 static __inline
uint8_t inb(int port
) __attribute__((always_inline
));
8 static __inline
void insb(int port
, void *addr
, int cnt
) __attribute__((always_inline
));
9 static __inline
uint16_t inw(int port
) __attribute__((always_inline
));
10 static __inline
void insw(int port
, void *addr
, int cnt
) __attribute__((always_inline
));
11 static __inline
uint32_t inl(int port
) __attribute__((always_inline
));
12 static __inline
void insl(int port
, void *addr
, int cnt
) __attribute__((always_inline
));
13 static __inline
void outb(int port
, uint8_t data
) __attribute__((always_inline
));
14 static __inline
void outsb(int port
, const void *addr
, int cnt
) __attribute__((always_inline
));
15 static __inline
void outw(int port
, uint16_t data
) __attribute__((always_inline
));
16 static __inline
void outsw(int port
, const void *addr
, int cnt
) __attribute__((always_inline
));
17 static __inline
void outsl(int port
, const void *addr
, int cnt
) __attribute__((always_inline
));
18 static __inline
void outl(int port
, uint32_t data
) __attribute__((always_inline
));
19 static __inline
void invlpg(void *addr
) __attribute__((always_inline
));
20 static __inline
void lidt(void *p
) __attribute__((always_inline
));
21 static __inline
void lldt(uint16_t sel
) __attribute__((always_inline
));
22 static __inline
void ltr(uint16_t sel
) __attribute__((always_inline
));
23 static __inline
void lcr0(uint32_t val
) __attribute__((always_inline
));
24 static __inline
uint32_t rcr0(void) __attribute__((always_inline
));
25 static __inline
uint32_t rcr2(void) __attribute__((always_inline
));
26 static __inline
void lcr3(uint32_t val
) __attribute__((always_inline
));
27 static __inline
uint32_t rcr3(void) __attribute__((always_inline
));
28 static __inline
void lcr4(uint32_t val
) __attribute__((always_inline
));
29 static __inline
uint32_t rcr4(void) __attribute__((always_inline
));
30 static __inline
void tlbflush(void) __attribute__((always_inline
));
31 static __inline
uint32_t read_eflags(void) __attribute__((always_inline
));
32 static __inline
void write_eflags(uint32_t eflags
) __attribute__((always_inline
));
33 static __inline
uint32_t read_ebp(void) __attribute__((always_inline
));
34 static __inline
uint32_t read_esp(void) __attribute__((always_inline
));
35 static __inline
void cpuid(uint32_t info
, uint32_t *eaxp
, uint32_t *ebxp
, uint32_t *ecxp
, uint32_t *edxp
);
36 static __inline
uint64_t read_tsc(void) __attribute__((always_inline
));
41 __asm
__volatile("int3");
44 static __inline
uint8_t
48 __asm
__volatile("inb %w1,%0" : "=a" (data
) : "d" (port
));
53 insb(int port
, void *addr
, int cnt
)
55 __asm
__volatile("cld\n\trepne\n\tinsb" :
56 "=D" (addr
), "=c" (cnt
) :
57 "d" (port
), "0" (addr
), "1" (cnt
) :
61 static __inline
uint16_t
65 __asm
__volatile("inw %w1,%0" : "=a" (data
) : "d" (port
));
70 insw(int port
, void *addr
, int cnt
)
72 __asm
__volatile("cld\n\trepne\n\tinsw" :
73 "=D" (addr
), "=c" (cnt
) :
74 "d" (port
), "0" (addr
), "1" (cnt
) :
78 static __inline
uint32_t
82 __asm
__volatile("inl %w1,%0" : "=a" (data
) : "d" (port
));
87 insl(int port
, void *addr
, int cnt
)
89 __asm
__volatile("cld\n\trepne\n\tinsl" :
90 "=D" (addr
), "=c" (cnt
) :
91 "d" (port
), "0" (addr
), "1" (cnt
) :
96 outb(int port
, uint8_t data
)
98 __asm
__volatile("outb %0,%w1" : : "a" (data
), "d" (port
));
102 outsb(int port
, const void *addr
, int cnt
)
104 __asm
__volatile("cld\n\trepne\n\toutsb" :
105 "=S" (addr
), "=c" (cnt
) :
106 "d" (port
), "0" (addr
), "1" (cnt
) :
111 outw(int port
, uint16_t data
)
113 __asm
__volatile("outw %0,%w1" : : "a" (data
), "d" (port
));
117 outsw(int port
, const void *addr
, int cnt
)
119 __asm
__volatile("cld\n\trepne\n\toutsw" :
120 "=S" (addr
), "=c" (cnt
) :
121 "d" (port
), "0" (addr
), "1" (cnt
) :
126 outsl(int port
, const void *addr
, int cnt
)
128 __asm
__volatile("cld\n\trepne\n\toutsl" :
129 "=S" (addr
), "=c" (cnt
) :
130 "d" (port
), "0" (addr
), "1" (cnt
) :
135 outl(int port
, uint32_t data
)
137 __asm
__volatile("outl %0,%w1" : : "a" (data
), "d" (port
));
143 __asm
__volatile("invlpg (%0)" : : "r" (addr
) : "memory");
149 __asm
__volatile("lidt (%0)" : : "r" (p
));
155 __asm
__volatile("lldt %0" : : "r" (sel
));
161 __asm
__volatile("ltr %0" : : "r" (sel
));
167 __asm
__volatile("movl %0,%%cr0" : : "r" (val
));
170 static __inline
uint32_t
174 __asm
__volatile("movl %%cr0,%0" : "=r" (val
));
178 static __inline
uint32_t
182 __asm
__volatile("movl %%cr2,%0" : "=r" (val
));
189 __asm
__volatile("movl %0,%%cr3" : : "r" (val
));
192 static __inline
uint32_t
196 __asm
__volatile("movl %%cr3,%0" : "=r" (val
));
203 __asm
__volatile("movl %0,%%cr4" : : "r" (val
));
206 static __inline
uint32_t
210 __asm
__volatile("movl %%cr4,%0" : "=r" (cr4
));
218 __asm
__volatile("movl %%cr3,%0" : "=r" (cr3
));
219 __asm
__volatile("movl %0,%%cr3" : : "r" (cr3
));
222 static __inline
uint32_t
226 __asm
__volatile("pushfl; popl %0" : "=r" (eflags
));
231 write_eflags(uint32_t eflags
)
233 __asm
__volatile("pushl %0; popfl" : : "r" (eflags
));
236 static __inline
uint32_t
240 __asm
__volatile("movl %%ebp,%0" : "=r" (ebp
));
244 static __inline
uint32_t
248 __asm
__volatile("movl %%esp,%0" : "=r" (esp
));
253 cpuid(uint32_t info
, uint32_t *eaxp
, uint32_t *ebxp
, uint32_t *ecxp
, uint32_t *edxp
)
255 uint32_t eax
, ebx
, ecx
, edx
;
257 : "=a" (eax
), "=b" (ebx
), "=c" (ecx
), "=d" (edx
)
269 static __inline
uint64_t
273 __asm
__volatile("rdtsc" : "=A" (tsc
));
277 #endif /* !JOS_INC_X86_H */