From 444e2f56a3845cd0e812ad30804f8d5975f726df Mon Sep 17 00:00:00 2001 From: irisz64 Date: Fri, 4 Jul 2025 17:07:54 +0200 Subject: [PATCH] Some JIT fixes --- src/backend/Core.cpp | 1 - src/backend/core/JIT.cpp | 12 ++++++------ src/backend/core/jit/instructions.cpp | 27 ++++++++++++++------------- src/frontend/KaizenGui.cpp | 9 +++++++-- src/frontend/KaizenGui.hpp | 1 + src/utils/log.hpp | 8 ++++---- 6 files changed, 32 insertions(+), 26 deletions(-) diff --git a/src/backend/Core.cpp b/src/backend/Core.cpp index f8ae99dd..d7497c50 100644 --- a/src/backend/Core.cpp +++ b/src/backend/Core.cpp @@ -22,7 +22,6 @@ bool Core::LoadTAS(const fs::path &path) const { return cpu->GetMem().mmio.si.pi void Core::LoadROM(const std::string &rom_) { Stop(); rom = rom_; - cpu->Reset(); std::string archive_types[] = {".zip", ".7z", ".rar", ".tar"}; diff --git a/src/backend/core/JIT.cpp b/src/backend/core/JIT.cpp index 056c29a5..62fcf11e 100644 --- a/src/backend/core/JIT.cpp +++ b/src/backend/core/JIT.cpp @@ -65,7 +65,7 @@ int JIT::Step() { } Util::trace("[JIT]: Compiling block @ 0x{:016X}:", blockPC); - // const auto blockInfo = code.getCurr(); + const auto blockInfo = code.getCurr(); const auto block = code.getCurr(); blockCache[upperIndex][lowerIndex] = block; @@ -82,7 +82,7 @@ int JIT::Step() { code.push(code.rbp); code.mov(code.rbp, reinterpret_cast(this)); // Load context pointer - // cs_insn *insn; + cs_insn *insn; Util::trace("\tMIPS code (guest PC = 0x{:016X}):", blockPC); while (!instrInDelaySlot) { // CheckCompareInterrupt(); @@ -106,7 +106,7 @@ int JIT::Step() { const u32 instruction = mem.Read(regs, paddr); - /*u32 bswapped = bswap(instruction); + u32 bswapped = bswap(instruction); auto count = cs_disasm(disassemblerMips, reinterpret_cast(&bswapped), 4, blockPC, 0, &insn); if (count > 0) { @@ -116,7 +116,7 @@ int JIT::Step() { Util::trace("\t\tCould not disassemble 0x{:08X} due to error {}\n", instruction, (int)cs_errno(disassemblerMips)); } - if(ShouldServiceInterrupt()) { + /*if(ShouldServiceInterrupt()) { regs.cop0.FireException(ExceptionCode::Interrupt, 0, blockPC); return 1; }*/ @@ -155,7 +155,7 @@ int JIT::Step() { code.add(code.rsp, 8); code.ret(); code.setProtectModeRE(); - /* static auto blockInfoSize = 0; + static auto blockInfoSize = 0; blockInfoSize = code.getSize() - blockInfoSize; Util::trace("\tX86 code (block address = 0x{:016X}):", (uintptr_t)block); @@ -166,7 +166,7 @@ int JIT::Step() { } cs_free(insn, count); - }*/ + } // const auto dump = code.getCode(); // Util::WriteFileBinary(dump, code.getSize(), "jit.dump"); // Util::panic(""); diff --git a/src/backend/core/jit/instructions.cpp b/src/backend/core/jit/instructions.cpp index 7581fea0..84cd6ca1 100644 --- a/src/backend/core/jit/instructions.cpp +++ b/src/backend/core/jit/instructions.cpp @@ -1003,7 +1003,6 @@ void JIT::ldr(u32 instr) { // regs.cop0.FireException(Cop0::GetTLBExceptionCode(regs.cop0.tlbError, Cop0::LOAD), 0, regs.oldPC); Util::panic("[JIT]: Unhandled TLBL exception in LDR!"); } else { - Util::panic("[JIT]: Implement constant LDR!"); const s32 shift = 8 * ((address ^ 7) & 7); const u64 mask = 0xFFFFFFFFFFFFFFFF >> shift; const u64 data = mem.Read(regs, paddr & ~7); @@ -1073,7 +1072,7 @@ void JIT::lhu(u32 instr) { emitMemberFunctionCall(&Cop0::MapVAddr, ®s.cop0); code.mov(code.ARG2, code.ptr[code.rbp + (reinterpret_cast(®s) - reinterpret_cast(this))]); - code.mov(code.ARG3, paddr); + code.mov(code.ARG3, code.qword[code.ARG4]); emitMemberFunctionCall(&Mem::Read, &mem); regs.Write(RT(instr), code.rax); } @@ -1110,13 +1109,15 @@ void JIT::lw(u32 instr) { } code.mov(code.ARG2, Cop0::LOAD); + regs.Read(RS(instr), code.ARG3); code.add(code.ARG3, offset); + code.mov(code.ARG4, reinterpret_cast(&paddr)); emitMemberFunctionCall(&Cop0::MapVAddr, ®s.cop0); code.mov(code.ARG2, code.ptr[code.rbp + (reinterpret_cast(®s) - reinterpret_cast(this))]); - code.mov(code.ARG3, paddr); + code.mov(code.ARG3, code.qword[code.ARG4]); emitMemberFunctionCall(&Mem::Read, &mem); regs.Write(RT(instr), code.rax); } @@ -1366,7 +1367,7 @@ void JIT::sw(const u32 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))); + regs.Read(RT(instr), code.ARG4); emitMemberFunctionCall(&Mem::WriteJIT, &mem); } @@ -1391,7 +1392,7 @@ void JIT::sw(const u32 instr) { 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); + regs.Read(RT(instr), code.ARG4); emitMemberFunctionCall(&Mem::WriteJIT, &mem); } @@ -1400,33 +1401,33 @@ void JIT::sw(const u32 instr) { if (regs.IsRegConstant(RT(instr))) { const s16 offset = instr; - regs.Read(RS(instr), code.rdx); - code.add(code.ARG3, offset); - code.mov(code.ARG2, Cop0::STORE); + regs.Read(RS(instr), code.ARG3); + code.add(code.ARG3, offset); + code.mov(code.ARG4, reinterpret_cast(&physical)); emitMemberFunctionCall(&Cop0::MapVAddr, ®s.cop0); 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))); + code.mov(code.ARG3, code.qword[code.ARG4]); + regs.Read(RT(instr), code.ARG4); emitMemberFunctionCall(&Mem::WriteJIT, &mem); return; } const s16 offset = instr; + code.mov(code.ARG2, Cop0::STORE); + regs.Read(RS(instr), code.rdx); code.add(code.ARG3, offset); - code.mov(code.ARG2, Cop0::STORE); - code.mov(code.ARG4, reinterpret_cast(&physical)); emitMemberFunctionCall(&Cop0::MapVAddr, ®s.cop0); code.mov(code.ARG2, code.ptr[code.rbp + (reinterpret_cast(®s) - reinterpret_cast(this))]); - code.mov(code.ARG3, physical); + code.mov(code.ARG3, code.qword[code.ARG4]); regs.Read(RT(instr), code.ARG4); emitMemberFunctionCall(&Mem::WriteJIT, &mem); } diff --git a/src/frontend/KaizenGui.cpp b/src/frontend/KaizenGui.cpp index 637390af..99667bcd 100644 --- a/src/frontend/KaizenGui.cpp +++ b/src/frontend/KaizenGui.cpp @@ -108,7 +108,7 @@ void KaizenGui::HandleInput(SDL_Event event) { { auto keys = SDL_GetKeyboardState(nullptr); if((keys[SDL_SCANCODE_LCTRL] || keys[SDL_SCANCODE_RCTRL]) && keys[SDL_SCANCODE_O]) { - FileDialog(); + fileDialogOpen = true; } if(core->romLoaded) { @@ -153,7 +153,7 @@ void KaizenGui::RenderUI() { if(ImGui::BeginMainMenuBar()) { if(ImGui::BeginMenu("File")) { if(ImGui::MenuItem("Open", "Ctrl-O")) { - FileDialog(); + fileDialogOpen = true; } if(ImGui::MenuItem("Exit")) { quit = true; @@ -237,6 +237,11 @@ void KaizenGui::RenderUI() { } core->parallel.UpdateScreen(*core.get(), false); + + if(fileDialogOpen) { + fileDialogOpen = false; + FileDialog(); + } } void KaizenGui::LoadROM(const std::string &path) noexcept { diff --git a/src/frontend/KaizenGui.hpp b/src/frontend/KaizenGui.hpp index 44286ad4..148d0779 100644 --- a/src/frontend/KaizenGui.hpp +++ b/src/frontend/KaizenGui.hpp @@ -26,6 +26,7 @@ public: void LoadROM(const std::string &path) noexcept; private: bool aboutOpen = false; + bool fileDialogOpen = false; bool quit = false; std::function emuExitFunc; void FileDialog(); diff --git a/src/utils/log.hpp b/src/utils/log.hpp index 0a2543db..070e71ce 100644 --- a/src/utils/log.hpp +++ b/src/utils/log.hpp @@ -11,7 +11,7 @@ namespace Util { enum LogLevel : u8 { Trace, Debug, Warn, Info, Error, Always }; #ifndef NDEBUG -static constexpr auto globalLogLevel = Debug; +static constexpr auto globalLogLevel = Trace; #else static constexpr auto globalLogLevel = Info; #endif @@ -24,15 +24,15 @@ void print(const std::string &fmt, Args... args) { fmt::print(fmt::emphasis::bold | fg(fmt::color::red), fmt::runtime(fmt), args...); } else if (messageType == Warn) { fmt::print(fg(fmt::color::yellow), fmt::runtime(fmt), args...); - } else if (messageType == Info || messageType == Trace || messageType == Always) { + } else if (messageType == Info || messageType == Always) { fmt::print(fmt::runtime(fmt), args...); - } else if (messageType == Debug) { + } else if (messageType <= Debug) { #ifndef NDEBUG fmt::print(fmt::runtime(fmt), args...); #endif } #else - if (messageType == Debug) { + if (messageType <= Debug) { #ifndef NDEBUG fmt::print(fmt::runtime(fmt), args...); #endif