diff --git a/src/386_dynarec.c b/src/386_dynarec.c index 3f905bd..91a2b55 100644 --- a/src/386_dynarec.c +++ b/src/386_dynarec.c @@ -663,7 +663,7 @@ void exec386_dynarec(int cycs) valid_block = 0; } } - if (valid_block && block->was_recompiled && (block->flags & CODEBLOCK_STATIC_TOP) && block->TOP != cpu_state.TOP) + if (valid_block && block->was_recompiled && (block->flags & CODEBLOCK_STATIC_TOP) && block->TOP != (cpu_state.TOP & 7)) { /*FPU top-of-stack does not match the value this block was compiled with, re-compile using dynamic top-of-stack*/ diff --git a/src/codegen_backend.c b/src/codegen_backend.c index 58c092e..7d96ec3 100644 --- a/src/codegen_backend.c +++ b/src/codegen_backend.c @@ -303,7 +303,7 @@ void codegen_block_start_recompile(codeblock_t *block) cpu_state.seg_ds.checked = cpu_state.seg_es.checked = cpu_state.seg_fs.checked = cpu_state.seg_gs.checked = (cr0 & 1) ? 0 : 1; - block->TOP = cpu_state.TOP; + block->TOP = cpu_state.TOP & 7; block->was_recompiled = 1; codegen_flat_ds = !(cpu_cur_status & CPU_STATUS_NOTFLATDS); diff --git a/src/x87_ops_misc.h b/src/x87_ops_misc.h index 5ca534c..eb9fffb 100644 --- a/src/x87_ops_misc.h +++ b/src/x87_ops_misc.h @@ -144,7 +144,7 @@ static int FSAVE() { FP_ENTER(); if (fplog) pclog("FSAVE %08X:%08X %i\n", easeg, cpu_state.eaaddr, cpu_state.ismmx); - cpu_state.npxs = (cpu_state.npxs & ~(7 << 11)) | (cpu_state.TOP << 11); + cpu_state.npxs = (cpu_state.npxs & ~(7 << 11)) | ((cpu_state.TOP & 7) << 11); switch ((cr0 & 1) | (cpu_state.op32 & 0x100)) { @@ -308,7 +308,7 @@ static int opFSTSW_a16(uint32_t fetchdat) fetch_ea_16(fetchdat); SEG_CHECK_WRITE(cpu_state.ea_seg); if (fplog) pclog("FSTSW %08X:%08X\n", easeg, cpu_state.eaaddr); - seteaw((cpu_state.npxs & 0xC7FF) | (cpu_state.TOP << 11)); + seteaw((cpu_state.npxs & 0xC7FF) | ((cpu_state.TOP & 7) << 11)); CLOCK_CYCLES(3); return cpu_state.abrt; } @@ -318,7 +318,7 @@ static int opFSTSW_a32(uint32_t fetchdat) fetch_ea_32(fetchdat); SEG_CHECK_WRITE(cpu_state.ea_seg); if (fplog) pclog("FSTSW %08X:%08X\n", easeg, cpu_state.eaaddr); - seteaw((cpu_state.npxs & 0xC7FF) | (cpu_state.TOP << 11)); + seteaw((cpu_state.npxs & 0xC7FF) | ((cpu_state.TOP & 7) << 11)); CLOCK_CYCLES(3); return cpu_state.abrt; }