8000 [RV64_DYNAREC] New register mapping by ksco · Pull Request #2139 · ptitSeb/box64 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[RV64_DYNAREC] New register mapping #2139

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/dynarec/rv64/dynarec_rv64_00_0.c
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ uintptr_t dynarec64_00_0(dynarec_rv64_t* dyn, uintptr_t addr, uintptr_t ip, int
nextop = F8;
GETEB(x1, 0);
GETGB(x2);
emit_cmp8(dyn, ninst, x1, x2, x9, x4, x5, x6);
emit_cmp8(dyn, ninst, x1, x2, x7, x4, x5, x6);
break;
case 0x39:
INST_NAME("CMP Ed, Gd");
Expand All @@ -557,7 +557,7 @@ uintptr_t dynarec64_00_0(dynarec_rv64_t* dyn, uintptr_t addr, uintptr_t ip, int
nextop = F8;
GETEB(x1, 0);
GETGB(x2);
emit_cmp8(dyn, ninst, x2, x1, x9, x4, x5, x6);
emit_cmp8(dyn, ninst, x2, x1, x7, x4, x5, x6);
break;
case 0x3B:
INST_NAME("CMP Gd, Ed");
Expand Down
4 changes: 2 additions & 2 deletions src/dynarec/rv64/dynarec_rv64_00_1.c
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ uintptr_t dynarec64_00_1(dynarec_rv64_t* dyn, uintptr_t addr, uintptr_t ip, int
SETFLAGS(X_ALL, SF_SET_NODF, NAT_FLAGS_NOFUSION); // Hack to set flags in "don't care" state
GETIP(ip);
STORE_XEMU_CALL(x3);
CALL(native_priv, -1);
CALL(native_priv, -1, 0, 0);
LOAD_XEMU_CALL();
jump_to_epilog(dyn, 0, xRIP, ninst);
*need_epilog = 0;
Expand All @@ -300,7 +300,7 @@ uintptr_t dynarec64_00_1(dynarec_rv64_t* dyn, uintptr_t addr, uintptr_t ip, int
SETFLAGS(X_ALL, SF_SET_NODF, NAT_FLAGS_NOFUSION); // Hack to set flags in "don't care" state
GETIP(ip);
STORE_XEMU_CALL(x3);
CALL(native_priv, -1);
CALL(native_priv, -1, 0, 0);
LOAD_XEMU_CALL();
jump_to_epilog(dyn, 0, xRIP, ninst);
*need_epilog = 0;
Expand Down
8 changes: 4 additions & 4 deletions src/dynarec/rv64/dynarec_rv64_00_2.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ uintptr_t dynarec64_00_2(dynarec_rv64_t* dyn, uintptr_t addr, uintptr_t ip, int
u8 = F8;
if (u8) {
ADDI(x2, xZR, u8);
emit_cmp8(dyn, ninst, x1, x2, x9, x4, x5, x6);
emit_cmp8(dyn, ninst, x1, x2, x7, x4, x5, x6);
} else {
emit_cmp8_0(dyn, ninst, x1, x3, x4);
}
Expand Down Expand Up @@ -175,7 +175,7 @@ uintptr_t dynarec64_00_2(dynarec_rv64_t* dyn, uintptr_t addr, uintptr_t ip, int
else
i64 = F8S;
MOV64xw(x5, i64);
emit_adc32(dyn, ninst, rex, ed, x5, x3, x4, x6, x9);
emit_adc32(dyn, ninst, rex, ed, x5, x3, x4, x6, x7);
WBACK;
break;
case 3: // SBB
Expand Down Expand Up @@ -308,13 +308,13 @@ uintptr_t dynarec64_00_2(dynarec_rv64_t* dyn, uintptr_t addr, uintptr_t ip, int
ADDI(x4, xZR, 0xff);
SLL(x4, x4, x1);
NOT(x4, x4);
SLL(x9, gd, x1);
SLL(x7, gd, x1);

// do aligned ll/sc sequence, reusing x2 (ed might be x2 but is no longer needed)
MARKLOCK;
LR_W(x2, x6, 1, 1);
AND(x5, x2, x4);
OR(x5, x5, x9);
OR(x5, x5, x7);
SC_W(x5, x5, x6, 1, 1);
BNEZ_MARKLOCK(x5);

Expand Down
68 changes: 33 additions & 35 deletions src/dynarec/rv64/dynarec_rv64_00_3.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ uintptr_t dynarec64_00_3(dynarec_rv64_t* dyn, uintptr_t addr, uintptr_t ip, int
GETEB(x1, 1);
u8 = F8;
MOV32w(x2, u8);
CALL_(rol8, ed, x3);
CALL_(rol8, ed, x3, x1, x2);
EBBACK(x5, 0);
break;
case 1:
Expand All @@ -73,7 +73,7 @@ uintptr_t dynarec64_00_3(dynarec_rv64_t* dyn, uintptr_t addr, uintptr_t ip, int
GETEB(x1, 1);
u8 = F8;
MOV32w(x2, u8);
CALL_(ror8, ed, x3);
CALL_(ror8, ed, x3, x1, x2);
EBBACK(x5, 0);
break;
case 2:
Expand All @@ -84,7 +84,7 @@ uintptr_t dynarec64_00_3(dynarec_rv64_t* dyn, uintptr_t addr, uintptr_t ip, int
GETEB(x1, 1);
u8 = F8;
MOV32w(x2, u8);
CALL_(rcl8, ed, x3);
CALL_(rcl8, ed, x3, x1, x2);
EBBACK(x5, 0);
break;
case 3:
Expand All @@ -95,7 +95,7 @@ uintptr_t dynarec64_00_3(dynarec_rv64_t* dyn, uintptr_t addr, uintptr_t ip, int
GETEB(x1, 1);
u8 = F8;
MOV32w(x2, u8);
CALL_(rcr8, ed, x3);
CALL_(rcr8, ed, x3, x1, x2);
EBBACK(x5, 0);
break;
case 4:
Expand Down Expand Up @@ -196,7 +196,7 @@ uintptr_t dynarec64_00_3(dynarec_rv64_t* dyn, uintptr_t addr, uintptr_t ip, int
u8 = (F8) & (rex.w ? 0x3f : 0x1f);
MOV32w(x2, u8);
GETEDW(x4, x1, 0);
CALL_(rex.w ? ((void*)rcl64) : ((void*)rcl32), ed, x4);
CALL_(rex.w ? ((void*)rcl64) : ((void*)rcl32), ed, x4, x1, x2);
WBACK;
if (!wback && !rex.w) ZEROUP(ed);
break;
Expand All @@ -208,7 +208,7 @@ uintptr_t dynarec64_00_3(dynarec_rv64_t* dyn, uintptr_t addr, uintptr_t ip, int
u8 = (F8) & (rex.w ? 0x3f : 0x1f);
MOV32w(x2, u8);
GETEDW(x4, x1, 0);
CALL_(rex.w ? ((void*)rcr64) : ((void*)rcr32), ed, x4);
CALL_(rex.w ? ((void*)rcr64) : ((void*)rcr32), ed, x4, x1, x2);
WBACK;
B41A if (!wback && !rex.w) ZEROUP(ed);
break;
Expand Down Expand Up @@ -446,7 +446,7 @@ uintptr_t dynarec64_00_3(dynarec_rv64_t* dyn, uintptr_t addr, uintptr_t ip, int
GETIP(ip + 1); // read the 0xCC
STORE_XEMU_CALL(x3);
ADDI(x1, xEmu, (uint32_t)offsetof(x64emu_t, ip)); // setup addr as &emu->ip
CALL_S(x64Int3, -1);
CALL_S(x64Int3, -1, x1);
LOAD_XEMU_CALL();
addr += 8 + 8;
TABLE64(x3, addr); // expected return address
Expand All @@ -468,7 +468,7 @@ uintptr_t dynarec64_00_3(dynarec_rv64_t* dyn, uintptr_t addr, uintptr_t ip, int
BEQZ_MARK(x3);
GETIP(addr);
STORE_XEMU_CALL(x3);
CALL(native_int3, -1);
CALL(native_int3, -1, 0, 0);
LOAD_XEMU_CALL();
MARK;
jump_to_epilog(dyn, addr, 0, ninst);
Expand All @@ -487,15 +487,15 @@ uintptr_t dynarec64_00_3(dynarec_rv64_t* dyn, uintptr_t addr, uintptr_t ip, int
GETIP(ip); // priviledged instruction, IP not updated
STORE_XEMU_CALL(x3);
MOV32w(x1, u8);
CALL(native_int, -1);
CALL(native_int, -1, x1, 0);
LOAD_XEMU_CALL();
} else if (u8 == 0x80) {
INST_NAME("32bits SYSCALL");
NOTEST(x1);
SMEND();
GETIP(addr);
STORE_XEMU_CALL(x3);
CALL_S(x86Syscall, -1);
CALL_S(x86Syscall, -1, 0);
LOAD_XEMU_CALL();
TABLE64(x3, addr); // expected return address
BNE_MARK(xRIP, x3);
Expand All @@ -509,7 +509,7 @@ uintptr_t dynarec64_00_3(dynarec_rv64_t* dyn, uintptr_t addr, uintptr_t ip, int
SETFLAGS(X_ALL, SF_SET_NODF, NAT_FLAGS_NOFUSION); // Hack to set flags in "don't care" state
GETIP(addr);
STORE_XEMU_CALL(x3);
CALL(native_int3, -1);
CALL(native_int3, -1, 0, 0);
LOAD_XEMU_CALL();
jump_to_epilog(dyn, 0, xRIP, ninst);
*need_epilog = 0;
Expand All @@ -519,7 +519,7 @@ uintptr_t dynarec64_00_3(dynarec_rv64_t* dyn, uintptr_t addr, uintptr_t ip, int
SETFLAGS(X_ALL, SF_SET_NODF, NAT_FLAGS_NOFUSION); // Hack to set flags in "don't care" state
GETIP(ip); // priviledged instruction, IP not updated
STORE_XEMU_CALL(x3);
CALL(native_priv, -1);
CALL(native_priv, -1, 0, 0);
LOAD_XEMU_CALL();
jump_to_epilog(dyn, 0, xRIP, ninst);
*need_epilog = 0;
Expand Down Expand Up @@ -550,7 +550,7 @@ uintptr_t dynarec64_00_3(dynarec_rv64_t* dyn, uintptr_t addr, uintptr_t ip, int
}
MESSAGE(LOG_DUMP, "Need Optimization\n");
SETFLAGS(X_OF | X_CF, SF_SET_DF, NAT_FLAGS_NOFUSION);
CALL_(rol8, ed, x3);
CALL_(rol8, ed, x3, x1, x2);
EBBACK(x5, 0);
break;
case 1:
Expand All @@ -565,7 +565,7 @@ uintptr_t dynarec64_00_3(dynarec_rv64_t* dyn, uintptr_t addr, uintptr_t ip, int
}
MESSAGE(LOG_DUMP, "Need Optimization\n");
SETFLAGS(X_OF | X_CF, SF_SET_DF, NAT_FLAGS_NOFUSION);
CALL_(ror8, ed, x3);
CALL_(ror8, ed, x3, x1, x2);
EBBACK(x5, 0);
break;
case 2:
Expand All @@ -581,7 +581,7 @@ uintptr_t dynarec64_00_3(dynarec_rv64_t* dyn, uintptr_t addr, uintptr_t ip, int
MESSAGE(LOG_DUMP, "Need Optimization\n");
READFLAGS(X_CF);
SETFLAGS(X_OF | X_CF, SF_SET_DF, NAT_FLAGS_NOFUSION);
CALL_(rcl8, ed, x3);
CALL_(rcl8, ed, x3, x1, x2);
EBBACK(x5, 0);
break;
case 3:
Expand All @@ -597,7 +597,7 @@ uintptr_t dynarec64_00_3(dynarec_rv64_t* dyn, uintptr_t addr, uintptr_t ip, int
MESSAGE(LOG_DUMP, "Need Optimization\n");
READFLAGS(X_CF);
SETFLAGS(X_OF | X_CF, SF_SET_DF, NAT_FLAGS_NOFUSION);
CALL_(rcr8, ed, x3);
CALL_(rcr8, ed, x3, x1, x2);
EBBACK(x5, 0);
break;
case 4:
Expand Down Expand Up @@ -682,7 +682,7 @@ uintptr_t dynarec64_00_3(dynarec_rv64_t* dyn, uintptr_t addr, uintptr_t ip, int
SETFLAGS(X_OF | X_CF, SF_SET_DF, NAT_FLAGS_NOFUSION);
MOV32w(x2, 1);
GETEDW(x4, x1, 0);
CALL_(rex.w ? ((void*)rcl64) : ((void*)rcl32), ed, x4);
CALL_(rex.w ? ((void*)rcl64) : ((void*)rcl32), ed, x4, x1, x2);
WBACK;
if (!wback && !rex.w) ZEROUP(ed);
break;
Expand All @@ -693,7 +693,7 @@ uintptr_t dynarec64_00_3(dynarec_rv64_t* dyn, uintptr_t addr, uintptr_t ip, int
SETFLAGS(X_OF | X_CF, SF_SET_DF, NAT_FLAGS_NOFUSION);
MOV32w(x2, 1);
GETEDW(x4, x1, 0);
CALL_(rex.w ? ((void*)rcr64) : ((void*)rcr32), ed, x4);
CALL_(rex.w ? ((void*)rcr64) : ((void*)rcr32), ed, x4, x1, x2);
WBACK;
if (!wback && !rex.w) ZEROUP(ed);
break;
Expand Down Expand Up @@ -752,7 +752,7 @@ uintptr_t dynarec64_00_3(dynarec_rv64_t* dyn, uintptr_t addr, uintptr_t ip, int
SETFLAGS(X_OF | X_CF, SF_SET_DF, NAT_FLAGS_NOFUSION);
ANDI(x2, xRCX, rex.w ? 0x3f : 0x1f);
GETEDW(x4, x1, 0);
CALL_(rex.w ? ((void*)rcl64) : ((void*)rcl32), ed, x4);
CALL_(rex.w ? ((void*)rcl64) : ((void*)rcl32), ed, x4, x1, x2);
WBACK;
if (!wback && !rex.w) ZEROUP(ed);
break;
Expand All @@ -763,7 +763,7 @@ uintptr_t dynarec64_00_3(dynarec_rv64_t* dyn, uintptr_t addr, uintptr_t ip, int
SETFLAGS(X_OF | X_CF, SF_SET_DF, NAT_FLAGS_NOFUSION);
ANDI(x2, xRCX, rex.w ? 0x3f : 0x1f);
GETEDW(x4, x1, 0);
CALL_(rex.w ? ((void*)rcr64) : ((void*)rcr32), ed, x4);
CALL_(rex.w ? ((void*)rcr64) : ((void*)rcr32), ed, x4, x1, x2);
WBACK;
if (!wback && !rex.w) ZEROUP(ed);
break;
Expand Down Expand Up @@ -946,7 +946,7 @@ uintptr_t dynarec64_00_3(dynarec_rv64_t* dyn, uintptr_t addr, uintptr_t ip, int
GETIP_(dyn->insts[ninst].natcall); // read the 0xCC already
STORE_XEMU_CALL(x3);
ADDI(x1, xEmu, (uint32_t)offsetof(x64emu_t, ip)); // setup addr as &emu->ip
CALL_S(x64Int3, -1);
CALL_S(x64Int3, -1, x1);
LOAD_XEMU_CALL();
TABLE64(x3, dyn->insts[ninst].natcall);
ADDI(x3, x3, 2 + 8 + 8);
Expand Down Expand Up @@ -1074,7 +1074,7 @@ uintptr_t dynarec64_00_3(dynarec_rv64_t* dyn, uintptr_t addr, uintptr_t ip, int
SETFLAGS(X_ALL, SF_SET_NODF, NAT_FLAGS_NOFUSION); // Hack to set flags in "don't care" state
GETIP(ip);
STORE_XEMU_CALL(xRIP);
CALL(native_priv, -1);
CALL(native_priv, -1, 0, 0);
LOAD_XEMU_CALL();
jump_to_epilog(dyn, 0, xRIP, ninst);
*need_epilog = 0;
Expand Down Expand Up @@ -1146,15 +1146,15 @@ uintptr_t dynarec64_00_3(dynarec_rv64_t* dyn, uintptr_t addr, uintptr_t ip, int
MESSAGE(LOG_DUMP, "Need Optimization\n");
SETFLAGS(X_ALL, SF_SET_DF, NAT_FLAGS_NOFUSION);
GETEB(x1, 0);
CALL(div8, -1);
CALL(div8, -1, x1, 0);
break;
case 7:
INST_NAME("IDIV Eb");
SKIPTEST(x1);
MESSAGE(LOG_DUMP, "Need Optimization\n");
SETFLAGS(X_ALL, SF_SET_DF, NAT_FLAGS_NOFUSION);
GETEB(x1, 0);
CALL(idiv8, -1);
CALL(idiv8, -1, x1, 0);
break;
}
break;
Expand Down Expand Up @@ -1268,14 +1268,14 @@ uintptr_t dynarec64_00_3(dynarec_rv64_t* dyn, uintptr_t addr, uintptr_t ip, int
MESSAGE(LOG_INFO, "Divide by 0 hack\n");
GETIP(ip);
STORE_XEMU_CALL(x3);
CALL(native_div0, -1);
CALL(native_div0, -1, 0, 0);
LOAD_XEMU_CALL();
} else {
if (box64_dynarec_div0) {
BNE_MARK3(ed, xZR);
GETIP_(ip);
STORE_XEMU_CALL(x3);
CALL(native_div0, -1);
CALL(native_div0, -1, 0, 0);
CLEARIP();
LOAD_XEMU_CALL();
jump_to_epilog(dyn, 0, xRIP, ninst);
Expand Down Expand Up @@ -1303,7 +1303,7 @@ uintptr_t dynarec64_00_3(dynarec_rv64_t* dyn, uintptr_t addr, uintptr_t ip, int
BNE_MARK3(ed, xZR);
GETIP_(ip);
STORE_XEMU_CALL(x3);
CALL(native_div0, -1);
CALL(native_div0, -1, 0, 0);
CLEARIP();
LOAD_XEMU_CALL();
jump_to_epilog(dyn, 0, xRIP, ninst);
Expand All @@ -1318,15 +1318,14 @@ uintptr_t dynarec64_00_3(dynarec_rv64_t* dyn, uintptr_t addr, uintptr_t ip, int
BNE_MARK3(ed, xZR);
GETIP_(ip);
STORE_XEMU_CALL(x3);
CALL(native_div0, -1);
CALL(native_div0, -1, 0, 0);
CLEARIP();
LOAD_XEMU_CALL();
jump_to_epilog(dyn, 0, xRIP, ninst);
MARK3;
}
BEQ_MARK(xRDX, xZR);
if (ed != x1) { MV(x1, ed); }
CALL(div64, -1);
CALL(div64, -1, ed, 0);
B_NEXT_nocond;
MARK;
DIVU(x2, xRAX, ed);
Expand All @@ -1346,7 +1345,7 @@ uintptr_t dynarec64_00_3(dynarec_rv64_t* dyn, uintptr_t addr, uintptr_t ip, int
BNE_MARK3(ed, xZR);
GETIP_(ip);
STORE_XEMU_CALL(x3);
CALL(native_div0, -1);
CALL(native_div0, -1, 0, 0);
CLEARIP();
LOAD_XEMU_CALL();
jump_to_epilog(dyn, 0, xRIP, ninst);
Expand All @@ -1369,7 +1368,7 @@ uintptr_t dynarec64_00_3(dynarec_rv64_t* dyn, uintptr_t addr, uintptr_t ip, int
BNE_MARK3(ed, xZR);
GETIP_(ip);
STORE_XEMU_CALL(x3);
CALL(native_div0, -1);
CALL(native_div0, -1, 0, 0);
CLEARIP();
LOAD_XEMU_CALL();
jump_to_epilog(dyn, 0, xRIP, ninst);
Expand All @@ -1384,7 +1383,7 @@ uintptr_t dynarec64_00_3(dynarec_rv64_t* dyn, uintptr_t addr, uintptr_t ip, int
BNE_MARK3(ed, xZR);
GETIP_(ip);
STORE_XEMU_CALL(x3);
CALL(native_div0, -1);
CALL(native_div0, -1, 0, 0);
CLEARIP();
LOAD_XEMU_CALL();
jump_to_epilog(dyn, 0, xRIP, ninst);
Expand All @@ -1399,8 +1398,7 @@ uintptr_t dynarec64_00_3(dynarec_rv64_t* dyn, uintptr_t addr, uintptr_t ip, int
BNE_MARK3(x2, xZR);
BLT_MARK(xRAX, xZR);
MARK3;
if (ed != x1) MV(x1, ed);
CALL((void*)idiv64, -1);
CALL((void*)idiv64, -1, ed, 0);
B_NEXT_nocond;
MARK;
DIV(x2, xRAX, ed);
Expand Down
Loading
Loading
0