From cb275dd6a3fa34f0026d796d9789503d0344e577 Mon Sep 17 00:00:00 2001 From: OBattler Date: Mon, 29 Jul 2024 04:34:47 +0200 Subject: [PATCH] Fixes the behavior of F(N)INIT and F(N)SAVE on 8087, fixes the only MCPDIAG failure that was actually an 86Box bug, closes #4518. --- src/cpu/x87_ops_misc.h | 8 ++++++++ src/cpu/x87_ops_sf.h | 10 ++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/cpu/x87_ops_misc.h b/src/cpu/x87_ops_misc.h index d40d70140..96750468a 100644 --- a/src/cpu/x87_ops_misc.h +++ b/src/cpu/x87_ops_misc.h @@ -78,7 +78,11 @@ opFINIT(uint32_t fetchdat) cpu_state.npxc = 0x37F; #endif codegen_set_rounding_mode(X87_ROUNDING_NEAREST); +#ifdef FPU_8087 + cpu_state.npxs &= 0x4700; +#else cpu_state.npxs = 0; +#endif p = (uint64_t *) cpu_state.tag; #ifdef USE_NEW_DYNAREC *p = 0; @@ -406,7 +410,11 @@ FSAVE(void) cpu_state.npxc = 0x37F; codegen_set_rounding_mode(X87_ROUNDING_NEAREST); +#ifdef FPU_8087 + cpu_state.npxs &= 0x4700; +#else cpu_state.npxs = 0; +#endif p = (uint64_t *) cpu_state.tag; #ifdef USE_NEW_DYNAREC *p = 0; diff --git a/src/cpu/x87_ops_sf.h b/src/cpu/x87_ops_sf.h index af94897c9..31416447e 100644 --- a/src/cpu/x87_ops_sf.h +++ b/src/cpu/x87_ops_sf.h @@ -431,11 +431,12 @@ sf_FNSAVE_a16(uint32_t fetchdat) } #ifdef FPU_8087 - fpu_state.swd = 0x3FF; + fpu_state.cwd = 0x3FF; + fpu_state.swd &= 0x4700; #else fpu_state.cwd = 0x37F; -#endif fpu_state.swd = 0; +#endif fpu_state.tos = 0; fpu_state.tag = 0xffff; cpu_state.ismmx = 0; @@ -467,7 +468,7 @@ sf_FNSAVE_a32(uint32_t fetchdat) } # ifdef FPU_8087 - fpu_state.swd = 0x3FF; + fpu_state.cwd = 0x3FF; # else fpu_state.cwd = 0x37F; # endif @@ -504,10 +505,11 @@ sf_FNINIT(uint32_t fetchdat) cpu_state.pc++; #ifdef FPU_8087 fpu_state.cwd = 0x3FF; + fpu_state.swd &= 0x4700; #else fpu_state.cwd = 0x37F; -#endif fpu_state.swd = 0; +#endif fpu_state.tos = 0; fpu_state.tag = 0xffff; fpu_state.foo = 0;