From f88b1b4c2e2a3a3db91068c91d101ad7ad5c004c Mon Sep 17 00:00:00 2001 From: MerryMage Date: Sun, 7 Aug 2016 00:40:29 +0100 Subject: [PATCH] FPSCR: Save and restore MSCSR across supervisor call, fix MXCSR exception mask --- src/backend_x64/emit_x64.cpp | 4 ++++ src/backend_x64/jitstate.cpp | 2 +- src/backend_x64/jitstate.h | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/backend_x64/emit_x64.cpp b/src/backend_x64/emit_x64.cpp index ad71baaf..861cde55 100644 --- a/src/backend_x64/emit_x64.cpp +++ b/src/backend_x64/emit_x64.cpp @@ -307,7 +307,11 @@ void EmitX64::EmitCallSupervisor(IR::Block&, IR::Inst* inst) { reg_alloc.HostCall(nullptr, imm32); + code->STMXCSR(MDisp(R15, offsetof(JitState, guest_MXCSR))); + code->LDMXCSR(MDisp(R15, offsetof(JitState, save_host_MXCSR))); code->ABI_CallFunction(reinterpret_cast(cb.CallSVC)); + code->STMXCSR(MDisp(R15, offsetof(JitState, save_host_MXCSR))); + code->LDMXCSR(MDisp(R15, offsetof(JitState, guest_MXCSR))); } void EmitX64::EmitGetCarryFromOp(IR::Block&, IR::Inst*) { diff --git a/src/backend_x64/jitstate.cpp b/src/backend_x64/jitstate.cpp index f7bba4dc..36e90b42 100644 --- a/src/backend_x64/jitstate.cpp +++ b/src/backend_x64/jitstate.cpp @@ -90,7 +90,7 @@ void JitState::SetFpscr(u32 FPSCR) { guest_MXCSR = 0; // Exception masks / enables - guest_MXCSR |= 0b1111110000000; // mask all + guest_MXCSR |= 0x00001f80; // mask all //guest_MXCSR |= (~FPSCR >> 1) & 0b0000010000000; // IM = ~IOE //guest_MXCSR |= (~FPSCR >> 7) & 0b0000100000000; // DM = ~IDE //guest_MXCSR |= (~FPSCR ) & 0b1111000000000; // PM, UM, OM, ZM = ~IXE, ~UFE, ~OFE, ~DZE diff --git a/src/backend_x64/jitstate.h b/src/backend_x64/jitstate.h index 2efb23dd..c4221411 100644 --- a/src/backend_x64/jitstate.h +++ b/src/backend_x64/jitstate.h @@ -25,7 +25,7 @@ struct JitState { std::array Spill{}; // Spill. // For internal use (See: Routines::RunCode) - u32 guest_MXCSR = 0; + u32 guest_MXCSR = 0x00001f80; u32 save_host_MXCSR = 0; u64 save_host_RSP = 0; s64 cycles_remaining = 0;