Submit #3264 » 1-introduce-npx_xcr0_mask.diff
| sys/cpu/x86_64/include/cpufunc.h | ||
|---|---|---|
|
}
|
||
|
static __inline void
|
||
|
xsetbv(u_int ecx, u_int eax, u_int edx)
|
||
|
xsetbv(u_int xcr, u_int64_t newval)
|
||
|
{
|
||
|
uint32_t low, high;
|
||
|
low = newval;
|
||
|
high = newval >> 32;
|
||
|
__asm __volatile(".byte 0x0f,0x01,0xd1"
|
||
|
:
|
||
|
: "a" (eax), "c" (ecx), "d" (edx)
|
||
|
: "a" (low), "d" (high), "c" (xcr)
|
||
|
: "memory");
|
||
|
}
|
||
| sys/cpu/x86_64/include/npx.h | ||
|---|---|---|
|
struct trapframe;
|
||
|
extern uint32_t npx_mxcsr_mask;
|
||
|
extern uint64_t npx_xcr0_mask;
|
||
|
void npxprobemask (void);
|
||
|
void npxexit (void);
|
||
| sys/platform/pc64/x86_64/initcpu.c | ||
|---|---|---|
|
load_cr4(rcr4() | CR4_XSAVE);
|
||
|
/* Adjust size of savefpu in npx.h before adding to mask.*/
|
||
|
xsetbv(0, CPU_XFEATURE_X87 | CPU_XFEATURE_SSE | CPU_XFEATURE_YMM, 0);
|
||
|
npx_xcr0_mask = CPU_XFEATURE_X87 | CPU_XFEATURE_SSE |
|
||
|
CPU_XFEATURE_YMM;
|
||
|
xsetbv(0, npx_xcr0_mask);
|
||
|
cpu_xsave = 1;
|
||
|
}
|
||
|
#endif
|
||
| sys/platform/pc64/x86_64/npx.c | ||
|---|---|---|
|
#define fxrstor(addr) __asm("fxrstor %0" : : "m" (*(addr)))
|
||
|
#define fxsave(addr) __asm __volatile("fxsave %0" : "=m" (*(addr)))
|
||
|
#ifndef CPU_DISABLE_AVX
|
||
|
#define xrstor(eax,edx,addr) __asm __volatile(".byte 0x0f,0xae,0x2f" : : "D" (addr), "a" (eax), "d" (edx))
|
||
|
#define xsave(eax,edx,addr) __asm __volatile(".byte 0x0f,0xae,0x27" : : "D" (addr), "a" (eax), "d" (edx) : "memory")
|
||
|
static inline void
|
||
|
xrstor(const void *addr, uint64_t mask)
|
||
|
{
|
||
|
uint32_t low, high;
|
||
|
low = mask;
|
||
|
high = mask >> 32;
|
||
|
__asm __volatile(".byte 0x0f,0xae,0x2f" : : "D" (addr), "a" (low), "d" (high));
|
||
|
}
|
||
|
static inline void
|
||
|
xsave(void *addr, uint64_t mask)
|
||
|
{
|
||
|
uint32_t low, high;
|
||
|
low = mask;
|
||
|
high = mask >> 32;
|
||
|
__asm __volatile(".byte 0x0f,0xae,0x27" : : "D" (addr), "a" (low), "d" (high) : "memory");
|
||
|
}
|
||
|
#endif
|
||
|
#define start_emulating() __asm("smsw %%ax; orb %0,%%al; lmsw %%ax" \
|
||
|
: : "n" (CR0_TS) : "ax")
|
||
| ... | ... | |
|
static void fpurstor (union savefpu *);
|
||
|
__read_mostly uint32_t npx_mxcsr_mask = 0xFFBF; /* this is the default */
|
||
|
__read_mostly uint64_t npx_xcr0_mask = 0;
|
||
|
/*
|
||
|
* Probe the npx_mxcsr_mask as described in the intel document
|
||
| ... | ... | |
|
{
|
||
|
#ifndef CPU_DISABLE_AVX
|
||
|
if (cpu_xsave)
|
||
|
xsave(CPU_XFEATURE_X87 | CPU_XFEATURE_SSE | CPU_XFEATURE_YMM, 0, addr);
|
||
|
xsave(addr, npx_xcr0_mask);
|
||
|
else
|
||
|
#endif
|
||
|
if (cpu_fxsr)
|
||
| ... | ... | |
|
{
|
||
|
#ifndef CPU_DISABLE_AVX
|
||
|
if (cpu_xsave)
|
||
|
xrstor(CPU_XFEATURE_X87 | CPU_XFEATURE_SSE | CPU_XFEATURE_YMM, 0, addr);
|
||
|
xrstor(addr, npx_xcr0_mask);
|
||
|
else
|
||
|
#endif
|
||
|
if (cpu_fxsr) {
|
||