From 968fc3fcfee747ff34759c5c47b45df70a26ae76 Mon Sep 17 00:00:00 2001 From: ptitSeb Date: Wed, 22 May 2024 20:25:59 +0200 Subject: [PATCH] [DYNAREC] Fixes to Cosim and to some x87 utility functions --- src/dynarec/dynarec_arm_00.c | 11 +++++------ src/dynarec/dynarec_arm_0f.c | 12 ++++++------ src/dynarec/dynarec_arm_dd.c | 2 +- src/dynarec/dynarec_arm_helper.c | 4 ++-- src/dynarec/dynarec_arm_helper.h | 16 ++++++++++------ src/dynarec/dynarec_arm_pass.c | 4 ++-- 6 files changed, 26 insertions(+), 23 deletions(-) diff --git a/src/dynarec/dynarec_arm_00.c b/src/dynarec/dynarec_arm_00.c index eedb2861..68946e43 100755 --- a/src/dynarec/dynarec_arm_00.c +++ b/src/dynarec/dynarec_arm_00.c @@ -1667,6 +1667,7 @@ uintptr_t dynarec00(dynarec_arm_t* dyn, uintptr_t addr, uintptr_t ip, int ninst, case 0xCC: SETFLAGS(X_ALL, SF_SET_NODF); // Hack, set all flags (to an unknown state...) + NOTEST(x1, x14); if(PK(0)=='S' && PK(1)=='C') { addr+=2; BARRIER(BARRIER_FLOAT); @@ -1674,7 +1675,6 @@ uintptr_t dynarec00(dynarec_arm_t* dyn, uintptr_t addr, uintptr_t ip, int ninst, if((PK(0)==0) && (PK(1)==0) && (PK(2)==0) && (PK(3)==0)) { addr+=4; - SKIPTEST(x14); MESSAGE(LOG_DEBUG, "Exit x86 Emu\n"); MOV32(x14, ip+1+2); SMEND(); @@ -1685,7 +1685,6 @@ uintptr_t dynarec00(dynarec_arm_t* dyn, uintptr_t addr, uintptr_t ip, int ninst, *need_epilog = 1; } else { MESSAGE(LOG_DUMP, "Native Call to %s\n", GetNativeName(GetNativeFnc(ip))); - SKIPTEST(x14); SMEND(); x87_forget(dyn, ninst, x3, x14, 0); if((box86_log<2) && !cycle_log) { // call the wrapper directly @@ -1735,7 +1734,7 @@ uintptr_t dynarec00(dynarec_arm_t* dyn, uintptr_t addr, uintptr_t ip, int ninst, break; case 0xCD: SETFLAGS(X_ALL, SF_SET_NODF); // Hack, set all flags (to an unknown state...) - SKIPTEST(x14); + SKIPTEST(x1, x14); SMEND(); u8 = F8; if(u8==0x80) { @@ -2258,26 +2257,26 @@ uintptr_t dynarec00(dynarec_arm_t* dyn, uintptr_t addr, uintptr_t ip, int ninst, case 1: //SETFLAGS(X_ALL, SF_SET_NODF); // Hack to set flags to "dont'care" state MESSAGE(LOG_DUMP, "Hack for Call 0\n"); - SKIPTEST(x14); + SKIPTEST(x1, x14); MOV32(xEIP, addr); PUSH1(xEIP); break; case 2: //SETFLAGS(X_ALL, SF_SET_NODF); // Hack to set flags to "dont'care" state MESSAGE(LOG_DUMP, "Hack for Call x86.get_pc_thunk.reg\n"); - SKIPTEST(x14); + SKIPTEST(x1, x14); u8 = PK(i32+1); gd = xEAX+((u8&0x38)>>3); MOV32(gd, addr); break; case 3: SETFLAGS(X_ALL, SF_SET_NODF); // Hack to set flags to "dont'care" state + SKIPTEST(x1, x14); BARRIER(BARRIER_FULL); BARRIER_NEXT(BARRIER_FULL); MOV32(x2, addr); PUSH1(x2); MESSAGE(LOG_DUMP, "Native Call to %s (retn=%d)\n", GetNativeName(GetNativeFnc(dyn->insts[ninst].natcall-1)), dyn->insts[ninst].retn); - SKIPTEST(x14); // calling a native function if(isRetX87Wrapper(*(wrapper_t*)(dyn->insts[ninst].natcall+2))) { // return value will be on the stack, so the stack depth needs to be updated diff --git a/src/dynarec/dynarec_arm_0f.c b/src/dynarec/dynarec_arm_0f.c index 3f858d5f..55cbc9d4 100755 --- a/src/dynarec/dynarec_arm_0f.c +++ b/src/dynarec/dynarec_arm_0f.c @@ -95,7 +95,7 @@ uintptr_t dynarec0F(dynarec_arm_t* dyn, uintptr_t addr, uintptr_t ip, int ninst, addr = fakeed(dyn, addr, ninst, nextop); SETFLAGS(X_ALL, SF_SET_NODF); // Hack to set flags in "don't care" state //CALL(arm_ud, -1, 0); - SKIPTEST(x14); + SKIPTEST(x1, x14); UDF(0); break; case 0xE0: @@ -149,7 +149,7 @@ uintptr_t dynarec0F(dynarec_arm_t* dyn, uintptr_t addr, uintptr_t ip, int ninst, INST_NAME("UD2"); SETFLAGS(X_ALL, SF_SET_NODF); // Hack to set flags in "don't care" state //CALL(arm_ud, -1, 0); - SKIPTEST(x14); + SKIPTEST(x1, x14); UDF(0); break; @@ -481,7 +481,7 @@ uintptr_t dynarec0F(dynarec_arm_t* dyn, uintptr_t addr, uintptr_t ip, int ninst, case 0x31: INST_NAME("RDTSC"); MESSAGE(LOG_DUMP, "Need Optimization\n"); - SKIPTEST(x14); + SKIPTEST(x1, x14); CALL(ReadTSC, xEAX, 0); // will return the u64 in x1:xEAX MOV_REG(xEDX, x1); break; @@ -717,7 +717,7 @@ uintptr_t dynarec0F(dynarec_arm_t* dyn, uintptr_t addr, uintptr_t ip, int ninst, break; case 0x51: INST_NAME("SQRTPS Gx, Ex"); - SKIPTEST(x1); + SKIPTEST(x1, x14); nextop = F8; GETEX(q0, 0); gd = (nextop&0x38)>>3; @@ -786,7 +786,7 @@ uintptr_t dynarec0F(dynarec_arm_t* dyn, uintptr_t addr, uintptr_t ip, int ninst, break; case 0x52: INST_NAME("RSQRTPS Gx, Ex"); - SKIPTEST(x1); + SKIPTEST(x1, x14); nextop = F8; GETEX(q0, 0); gd = (nextop&0x38)>>3; @@ -809,7 +809,7 @@ uintptr_t dynarec0F(dynarec_arm_t* dyn, uintptr_t addr, uintptr_t ip, int ninst, break; case 0x53: INST_NAME("RCPPS Gx, Ex"); - SKIPTEST(x1); + SKIPTEST(x1, x14); nextop = F8; GETEX(q0, 0); gd = (nextop&0x38)>>3; diff --git a/src/dynarec/dynarec_arm_dd.c b/src/dynarec/dynarec_arm_dd.c index 958df569..d56fb985 100755 --- a/src/dynarec/dynarec_arm_dd.c +++ b/src/dynarec/dynarec_arm_dd.c @@ -51,7 +51,7 @@ uintptr_t dynarecDD(dynarec_arm_t* dyn, uintptr_t addr, uintptr_t ip, int ninst, MESSAGE(LOG_DUMP, "Hack for FFREE ST0 / FINCSTP\n"); X87_POP_OR_FAIL(dyn, ninst, x1); addr+=2; - SKIPTEST(x1); + SKIPTEST(x1, x14); } else x87_free(dyn, ninst, x1, x2, x3, nextop&7); #else diff --git a/src/dynarec/dynarec_arm_helper.c b/src/dynarec/dynarec_arm_helper.c index fe3beb7b..f8606211 100755 --- a/src/dynarec/dynarec_arm_helper.c +++ b/src/dynarec/dynarec_arm_helper.c @@ -1044,9 +1044,9 @@ static void x87_unreflectcache(dynarec_arm_t* dyn, int ninst, int s1, int s2, in if(a>0) { MOV32(s2, 0xffff); ORR_REG_LSL_IMM5(s1, s1, s2, 16); - MOV_REG_LSR_IMM5(s1, s1, -a*2); + MOV_REG_LSR_IMM5(s1, s1, a*2); } else { - MOV_REG_LSL_IMM5(s1, s1, a*2); + MOV_REG_LSL_IMM5(s1, s1, -a*2); } STRH_IMM8(s1, xEmu, offsetof(x86emu_t, fpu_tags)); // Sub x87stack to top, with and 7 diff --git a/src/dynarec/dynarec_arm_helper.h b/src/dynarec/dynarec_arm_helper.h index 4d07a292..50ee99fb 100755 --- a/src/dynarec/dynarec_arm_helper.h +++ b/src/dynarec/dynarec_arm_helper.h @@ -894,21 +894,25 @@ uintptr_t dynarecF30F(dynarec_arm_t* dyn, uintptr_t addr, uintptr_t ip, int nins #define MAYUSE(A) #endif -#define NOTEST(s1) \ +#define NOTEST(s1, s2) \ if(box86_dynarec_test) { \ MOVW(s1, 0); \ - STR_IMM9(s1, xEmu, offsetof(x86emu_t, test.test)); \ - STR_IMM9(s1, xEmu, offsetof(x86emu_t, test.clean)); \ + MOVW(s2, offsetof(x86emu_t, test.test)); \ + STR_REG_LSL_IMM5(s1, xEmu, s2, 0); \ + ADD_IMM8(s2, s2, offsetof(x86emu_t, test.clean)-offsetof(x86emu_t, test.test));\ + STR_REG_LSL_IMM5(s1, xEmu, s2, 0); \ } -#define SKIPTEST(s1) \ +#define SKIPTEST(s1, s2) \ if(box86_dynarec_test) { \ MOVW(s1, 0); \ - STR_IMM9(s1, xEmu, offsetof(x86emu_t, test.clean)); \ + MOVW(s2, offsetof(x86emu_t, test.clean)); \ + STR_REG_LSL_IMM5(s1, xEmu, s2, 0); \ } #define GOTEST(s1, s2) \ if(box86_dynarec_test) { \ MOVW(s2, 1); \ - STR_IMM9(s2, xEmu, offsetof(x86emu_t, test.test)); \ + MOVW(s1, offsetof(x86emu_t, test.test)); \ + STR_REG_LSL_IMM5(s2, xEmu, s1, 0); \ } #endif //__DYNAREC_ARM_HELPER_H__ \ No newline at end of file diff --git a/src/dynarec/dynarec_arm_pass.c b/src/dynarec/dynarec_arm_pass.c index 2e33dffc..f37d1d5e 100755 --- a/src/dynarec/dynarec_arm_pass.c +++ b/src/dynarec/dynarec_arm_pass.c @@ -307,14 +307,14 @@ uintptr_t arm_pass(dynarec_arm_t* dyn, uintptr_t addr) dyn->insts[ninst].x86.need_after |= X_PEND; #endif ++ninst; - NOTEST(x3); + NOTEST(x1, x3); fpu_purgecache(dyn, ninst, 0, x1, x2, x3); jump_to_next(dyn, addr, 0, ninst); ok=0; need_epilog=0; } } if(need_epilog) { - NOTEST(x3); + NOTEST(x1, x3); fpu_purgecache(dyn, ninst, 0, x1, x2, x3); jump_to_epilog(dyn, ip, 0, ninst); // no linker here, it's an unknow instruction }