diff --git a/.gitignore b/.gitignore index cce325b9..d1f120d3 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,12 @@ *.ini *build*/ .idea/ -roms/ +*.z64 +*.n64 +*.v64 +*.Z64 +*.N64 +*.V64 saves/ *.bin *.sh diff --git a/src/backend/core/JIT.hpp b/src/backend/core/JIT.hpp index 7f612444..7420aafb 100644 --- a/src/backend/core/JIT.hpp +++ b/src/backend/core/JIT.hpp @@ -3,6 +3,7 @@ #include #include #include +#include namespace n64 { struct Core; @@ -35,7 +36,7 @@ struct JIT : BaseCPU { [[nodiscard]] Disassembler::DisassemblyResult Disassemble(u32, u32) const override { return {}; } private: - Xbyak::CodeGenerator code{kCodeCacheSize}; + Xbyak::CodeGenerator code{kCodeCacheAllocSize}; Registers regs; Mem mem; u64 cop2Latch{}; @@ -83,7 +84,7 @@ private: thisPtr += arr[1]; #endif - code.mov(code.rdi, thisPtr); + code.mov(code.ARG1, thisPtr); code.mov(code.rax, functionPtr); code.sub(code.rsp, 8); code.call(code.rax); diff --git a/src/backend/core/jit/helpers.hpp b/src/backend/core/jit/helpers.hpp index 9878313e..352c8621 100644 --- a/src/backend/core/jit/helpers.hpp +++ b/src/backend/core/jit/helpers.hpp @@ -71,4 +71,18 @@ static bool IsBranchLikely(const u32 instr) { return false; } } + +#ifdef _WIN32 +#define ARG1 rcx +#define ARG2 rdx +#define ARG3 r8 +#define ARG4 r9 +#else +#define ARG1 rdi +#define ARG2 rsi +#define ARG3 rdx +#define ARG4 rcx +#define ARG5 r8 +#define ARG6 r9 +#endif } // namespace n64 diff --git a/src/backend/core/jit/instructions.cpp b/src/backend/core/jit/instructions.cpp index 0f3e9c26..6015a347 100644 --- a/src/backend/core/jit/instructions.cpp +++ b/src/backend/core/jit/instructions.cpp @@ -899,8 +899,9 @@ void JIT::lbu(u32 instr) { // regs.cop0.FireException(Cop0::GetTLBExceptionCode(regs.cop0.tlbError, Cop0::LOAD), 0, regs.oldPC); Util::panic("[JIT]: Unhandled TLBL exception in LBU!"); } else { - code.mov(code.rsi, code.ptr[code.rbp + (reinterpret_cast(®s) - reinterpret_cast(this))]); - code.mov(code.edx, paddr); + code.mov(code.ARG2, + code.ptr[code.rbp + (reinterpret_cast(®s) - reinterpret_cast(this))]); + code.mov(code.ARG3, paddr); emitMemberFunctionCall(&Mem::Read, &mem); regs.Write(RT(instr), code.rax); } @@ -917,8 +918,9 @@ void JIT::lb(u32 instr) { // regs.cop0.FireException(Cop0::GetTLBExceptionCode(regs.cop0.tlbError, Cop0::LOAD), 0, regs.oldPC); Util::panic("[JIT]: Unhandled TLBL exception in LB!"); } else { - code.mov(code.rsi, code.ptr[code.rbp + (reinterpret_cast(®s) - reinterpret_cast(this))]); - code.mov(code.edx, paddr); + code.mov(code.ARG2, + code.ptr[code.rbp + (reinterpret_cast(®s) - reinterpret_cast(this))]); + code.mov(code.ARG3, paddr); emitMemberFunctionCall(&Mem::Read, &mem); regs.Write(RT(instr), code.rax); } @@ -943,8 +945,9 @@ void JIT::ld(u32 instr) { // regs.cop0.FireException(Cop0::GetTLBExceptionCode(regs.cop0.tlbError, Cop0::LOAD), 0, regs.oldPC); Util::panic("[JIT]: Unhandled TLBL exception in LD!"); } else { - code.mov(code.rsi, code.ptr[code.rbp + (reinterpret_cast(®s) - reinterpret_cast(this))]); - code.mov(code.edx, paddr); + code.mov(code.ARG2, + code.ptr[code.rbp + (reinterpret_cast(®s) - reinterpret_cast(this))]); + code.mov(code.ARG3, paddr); emitMemberFunctionCall(&Mem::Read, &mem); regs.Write(RT(instr), code.rax); } @@ -1032,8 +1035,8 @@ void JIT::lh(u32 instr) { return; } - code.mov(code.rsi, code.ptr[code.rbp + (reinterpret_cast(®s) - reinterpret_cast(this))]); - code.mov(code.edx, paddr); + code.mov(code.ARG2, code.ptr[code.rbp + (reinterpret_cast(®s) - reinterpret_cast(this))]); + code.mov(code.ARG3, paddr); emitMemberFunctionCall(&Mem::Read, &mem); regs.Write(RT(instr), code.rax); return; @@ -1068,21 +1071,21 @@ void JIT::lw(u32 instr) { return; } - code.mov(code.rsi, code.ptr[code.rbp + (reinterpret_cast(®s) - reinterpret_cast(this))]); - code.mov(code.edx, paddr); + code.mov(code.ARG2, code.ptr[code.rbp + (reinterpret_cast(®s) - reinterpret_cast(this))]); + code.mov(code.ARG3, paddr); emitMemberFunctionCall(&Mem::Read, &mem); regs.Write(RT(instr), code.rax); return; } - code.mov(code.esi, Cop0::LOAD); + code.mov(code.ARG2, Cop0::LOAD); regs.Read(RS(instr), code.rdx); - code.add(code.rdx, offset); - code.mov(code.rcx, reinterpret_cast(&paddr)); + code.add(code.ARG3, offset); + code.mov(code.ARG4, reinterpret_cast(&paddr)); emitMemberFunctionCall(&Cop0::MapVAddr, ®s.cop0); - code.mov(code.rsi, code.ptr[code.rbp + (reinterpret_cast(®s) - reinterpret_cast(this))]); - code.mov(code.edx, paddr); + code.mov(code.ARG2, code.ptr[code.rbp + (reinterpret_cast(®s) - reinterpret_cast(this))]); + code.mov(code.ARG3, paddr); emitMemberFunctionCall(&Mem::Read, &mem); regs.Write(RT(instr), code.rax); } @@ -1305,9 +1308,10 @@ void JIT::sw(const u32 instr) { // regs.cop0.FireException(Cop0::GetTLBExceptionCode(regs.cop0.tlbError, Cop0::STORE), 0, regs.oldPC); Util::panic("[JIT]: Unhandled TLBS exception in SW!"); } else { - code.lea(code.rsi, code.ptr[code.rbp + (reinterpret_cast(®s) - reinterpret_cast(this))]); - code.mov(code.edx, physical); - code.mov(code.rcx, regs.Read(RT(instr))); + code.lea(code.ARG2, + code.ptr[code.rbp + (reinterpret_cast(®s) - reinterpret_cast(this))]); + code.mov(code.ARG3, physical); + code.mov(code.ARG4, regs.Read(RT(instr))); emitMemberFunctionCall(&Mem::WriteJIT, &mem); } @@ -1329,8 +1333,9 @@ void JIT::sw(const u32 instr) { // regs.cop0.FireException(Cop0::GetTLBExceptionCode(regs.cop0.tlbError, Cop0::STORE), 0, regs.oldPC); Util::panic("[JIT]: Unhandled TLBS exception in SW!"); } else { - code.mov(code.rsi, code.ptr[code.rbp + (reinterpret_cast(®s) - reinterpret_cast(this))]); - code.mov(code.edx, physical); + code.mov(code.ARG2, + code.ptr[code.rbp + (reinterpret_cast(®s) - reinterpret_cast(this))]); + code.mov(code.ARG3, physical); regs.Read(RT(instr), code.rcx); emitMemberFunctionCall(&Mem::WriteJIT, &mem); } @@ -1341,16 +1346,16 @@ void JIT::sw(const u32 instr) { if (regs.IsRegConstant(RT(instr))) { const s16 offset = instr; regs.Read(RS(instr), code.rdx); - code.add(code.rdx, offset); + code.add(code.ARG3, offset); - code.mov(code.esi, Cop0::STORE); + code.mov(code.ARG2, Cop0::STORE); - code.mov(code.rcx, reinterpret_cast(&physical)); + code.mov(code.ARG4, reinterpret_cast(&physical)); emitMemberFunctionCall(&Cop0::MapVAddr, ®s.cop0); - code.mov(code.rsi, code.ptr[code.rbp + (reinterpret_cast(®s) - reinterpret_cast(this))]); - code.mov(code.edx, physical); - code.mov(code.rcx, regs.Read(RT(instr))); + code.mov(code.ARG2, code.ptr[code.rbp + (reinterpret_cast(®s) - reinterpret_cast(this))]); + code.mov(code.ARG3, physical); + code.mov(code.ARG4, regs.Read(RT(instr))); emitMemberFunctionCall(&Mem::WriteJIT, &mem); return; @@ -1358,16 +1363,16 @@ void JIT::sw(const u32 instr) { const s16 offset = instr; regs.Read(RS(instr), code.rdx); - code.add(code.rdx, offset); + code.add(code.ARG3, offset); - code.mov(code.esi, Cop0::STORE); + code.mov(code.ARG2, Cop0::STORE); - code.mov(code.rcx, reinterpret_cast(&physical)); + code.mov(code.ARG4, reinterpret_cast(&physical)); emitMemberFunctionCall(&Cop0::MapVAddr, ®s.cop0); - code.mov(code.rsi, code.ptr[code.rbp + (reinterpret_cast(®s) - reinterpret_cast(this))]); - code.mov(code.edx, physical); - regs.Read(RT(instr), code.rcx); + code.mov(code.ARG2, code.ptr[code.rbp + (reinterpret_cast(®s) - reinterpret_cast(this))]); + code.mov(code.ARG3, physical); + regs.Read(RT(instr), code.ARG4); emitMemberFunctionCall(&Mem::WriteJIT, &mem); }