Implement fxsave/xsave assembly

This commit is contained in:
Ali Mashtizadeh 2014-07-20 19:33:02 -07:00
parent a71418733a
commit 32d5f6740a

View File

@ -94,6 +94,10 @@ static INLINE uint64_t rdmsr(uint32_t addr)
return edx << 32 | eax;
}
/*
* Control Registers
*/
static INLINE uint64_t read_cr0()
{
uint64_t val;
@ -155,6 +159,10 @@ static INLINE void write_cr4(uint64_t val)
: "r" (val));
}
/*
* Debug Registers
*/
static INLINE uint64_t read_dr0()
{
uint64_t val;
@ -257,6 +265,10 @@ static INLINE void write_dr7(uint64_t val)
: "r" (val));
}
/*
* Segment Registers
*/
static INLINE uint16_t read_ds()
{
uint16_t val;
@ -325,6 +337,64 @@ static INLINE void write_gs(uint16_t val)
: "r" (val));
}
/*
* Floating Point
*/
static INLINE void fxsave(struct XSAVEArea *xsa)
{
asm volatile("fxsave %0"
: "=m" (*xsa)
:
: "memory");
}
// XXX: Need to fix AMD Bug
static INLINE void fxrstor(struct XSAVEArea *xsa)
{
asm volatile("fxrstor %0"
:
: "m" (*xsa)
: "memory");
}
static INLINE void xsave(struct XSAVEArea *xsa, uint64_t mask)
{
uint32_t lo = (uint32_t)mask;
uint32_t hi = (uint32_t)(mask >> 32);
asm volatile("xsave %0"
: "=m" (*xsa)
: "a" (lo), "d" (hi)
: "memory");
}
static INLINE void xsaveopt(struct XSAVEArea *xsa, uint64_t mask)
{
uint32_t lo = (uint32_t)mask;
uint32_t hi = (uint32_t)(mask >> 32);
asm volatile("xsaveopt %0"
: "=m" (*xsa)
: "a" (lo), "d" (hi)
: "memory");
}
static INLINE void xrstor(struct XSAVEArea *xsa, uint64_t mask)
{
uint32_t lo = (uint32_t)mask;
uint32_t hi = (uint32_t)(mask >> 32);
asm volatile("xrstor %0"
:
: "m" (*xsa), "a" (lo), "d" (hi)
: "memory");
}
/*
* Port IO
*/
static INLINE void outb(uint16_t port, uint8_t data)
{
asm volatile("outb %0, %1"