diff --git a/x86.h b/x86.h index b9fa8b8..71427b3 100644 --- a/x86.h +++ b/x86.h @@ -90,25 +90,36 @@ readeflags(void) return eflags; } -static inline uint -xchg(volatile uint *addr, uint newval) -{ - uint result; - - // The + in "+m" denotes a read-modify-write operand. - asm volatile("lock; xchgl %0, %1" : - "+m" (*addr), "=a" (result) : - "1" (newval) : - "cc"); - return result; -} - static inline void loadgs(ushort v) { asm volatile("movw %0, %%gs" : : "r" (v)); } +static inline void lebp(uint val) +{ + asm volatile("movl %0,%%ebp" : : "r" (val)); +} + +static inline uint rebp(void) +{ + uint val; + asm volatile("movl %%ebp,%0" : "=r" (val)); + return val; +} + +static inline void lesp(uint val) +{ + asm volatile("movl %0,%%esp" : : "r" (val)); +} + +static inline uint resp(void) +{ + uint val; + asm volatile("movl %%esp,%0" : "=r" (val)); + return val; +} + static inline void cli(void) { @@ -121,6 +132,25 @@ sti(void) asm volatile("sti"); } +static inline void nop_pause(void) +{ + asm volatile("pause" : :); +} + +//PAGEBREAK! +static inline uint +xchg(volatile uint *addr, uint newval) +{ + uint result; + + // The + in "+m" denotes a read-modify-write operand. + asm volatile("lock; xchgl %0, %1" : + "+m" (*addr), "=a" (result) : + "1" (newval) : + "cc"); + return result; +} + static inline void lcr0(uint val) { asm volatile("movl %0,%%cr0" : : "r" (val)); @@ -152,35 +182,6 @@ static inline uint rcr3(void) return val; } -static inline void lebp(uint val) -{ - asm volatile("movl %0,%%ebp" : : "r" (val)); -} - -static inline uint rebp(void) -{ - uint val; - asm volatile("movl %%ebp,%0" : "=r" (val)); - return val; -} - -static inline void lesp(uint val) -{ - asm volatile("movl %0,%%esp" : : "r" (val)); -} - -static inline uint resp(void) -{ - uint val; - asm volatile("movl %%esp,%0" : "=r" (val)); - return val; -} - -static inline void nop_pause(void) -{ - asm volatile("pause" : :); -} - //PAGEBREAK: 36 // Layout of the trap frame built on the stack by the // hardware and by trapasm.S, and passed to trap().