From 53e2dc0f85563a0ec4b316521d20248f840ac05d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Duval?= Date: Tue, 31 Oct 2023 18:30:18 +0100 Subject: [PATCH] kernel/x86_64: clear any pending exceptions on #MF * also on x86 for simplicity. * fixes #18624 * also makes x87 FPU data registers available for x87 floating instructions. EMMS is cheap. see https://github.com/cloudius-systems/osv/commit/25209d81f7b872111beb02ab9758f0d86898ec6b Change-Id: I5c1b399377102f3eb10bc6d7f7247afbaf6d8483 Reviewed-on: https://review.haiku-os.org/c/haiku/+/7089 Reviewed-by: waddlesplash Reviewed-by: Adrien Destugues --- headers/private/kernel/arch/x86/64/cpu.h | 2 ++ src/system/kernel/arch/x86/arch_int.cpp | 3 +++ 2 files changed, 5 insertions(+) diff --git a/headers/private/kernel/arch/x86/64/cpu.h b/headers/private/kernel/arch/x86/64/cpu.h index 02860371b8..e6c15951c6 100644 --- a/headers/private/kernel/arch/x86/64/cpu.h +++ b/headers/private/kernel/arch/x86/64/cpu.h @@ -48,6 +48,8 @@ x86_context_switch(arch_thread* oldState, arch_thread* newState) "r14", "r15", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", "xmm7", "xmm8", "xmm9", "xmm10", "xmm11", "xmm12", "xmm13", "xmm14", "xmm15", "memory"); + // so that x87 FPU floating-point instructions can be executed + asm volatile("emms"); asm volatile("ldmxcsr %0" : : "m" (sseControl)); asm volatile("fldcw %0" : : "m" (fpuControl)); } diff --git a/src/system/kernel/arch/x86/arch_int.cpp b/src/system/kernel/arch/x86/arch_int.cpp index 9281a5e71a..05eff26306 100644 --- a/src/system/kernel/arch/x86/arch_int.cpp +++ b/src/system/kernel/arch/x86/arch_int.cpp @@ -161,6 +161,9 @@ x86_unexpected_exception(iframe* frame) // TODO: Determine the correct cause via the FPU status // register! signalAddress = frame->ip; + // clear any pending exceptions, otherwise loading a new control word + // could raise exceptions. + asm volatile("fnclex"); break; case 17: // Alignment Check Exception (#AC)