nvmm: Implement FPU save/restore.

Otherwise, the host won't be able to modify the guest FPU (and we could
clobber the state, too.)

This doesn't seem to fix the general problems seen so far, however.
This commit is contained in:
Augustin Cavalier
2026-06-08 16:31:21 -04:00
parent e2accec408
commit 4402cb4497
2 changed files with 43 additions and 3 deletions
@@ -68,6 +68,42 @@ haiku_get_xsave_mask()
}
extern "C" void
haiku_save_fpu(void* area, uint64_t xsave_features)
{
switch (xsave_features) {
case IA32_XCR0_X87:
asm volatile("fnsave %0" : "=m" (*(char*)area));
break;
case IA32_XCR0_X87 | IA32_XCR0_SSE:
asm volatile("fxsaveq %0" : "=m" (*(char*)area));
break;
default:
panic("nvmm save_fpu: unimplemented xsave_features state");
}
}
extern "C" void
haiku_restore_fpu(const void* area, uint64_t xsave_features)
{
switch (xsave_features) {
case IA32_XCR0_X87:
asm volatile("frstor %0" :: "m" (*(const char*)area));
break;
case IA32_XCR0_X87 | IA32_XCR0_SSE:
asm volatile("fxrstorq %0" :: "m" (*(const char*)area));
break;
default:
panic("nvmm restore_fpu: unimplemented xsave_features state");
}
}
extern "C" int32
haiku_smp_get_current_cpu()
{
@@ -908,9 +908,13 @@ void x86_curthread_restore_dbregs(uint64_t *drs);
fpurstor((union savefpu *)(a), m); \
})
#elif defined(__HAIKU__)
// Haiku allows floating point in kernel, we don't need to save and restore FPU
#define x86_save_fpu(a, m)
#define x86_restore_fpu(a, m)
#define x86_curthread_save_fpu() // Haiku allows FPU usage in the kernel, thus
#define x86_curthread_restore_fpu() // save/restore of thread FPU state not needed.
void haiku_save_fpu(void* area, uint64_t xsave_features);
void haiku_restore_fpu(const void* area, uint64_t xsave_features);
#define x86_save_fpu haiku_save_fpu
#define x86_restore_fpu haiku_restore_fpu
#endif
/* XCRs. */