Some JIT fixes

This commit is contained in:
irisz64
2025-07-04 17:07:54 +02:00
parent 897abe8c2b
commit 444e2f56a3
6 changed files with 32 additions and 26 deletions

View File

@@ -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_) { void Core::LoadROM(const std::string &rom_) {
Stop(); Stop();
rom = rom_; rom = rom_;
cpu->Reset();
std::string archive_types[] = {".zip", ".7z", ".rar", ".tar"}; std::string archive_types[] = {".zip", ".7z", ".rar", ".tar"};

View File

@@ -65,7 +65,7 @@ int JIT::Step() {
} }
Util::trace("[JIT]: Compiling block @ 0x{:016X}:", blockPC); Util::trace("[JIT]: Compiling block @ 0x{:016X}:", blockPC);
// const auto blockInfo = code.getCurr(); const auto blockInfo = code.getCurr();
const auto block = code.getCurr<BlockFn>(); const auto block = code.getCurr<BlockFn>();
blockCache[upperIndex][lowerIndex] = block; blockCache[upperIndex][lowerIndex] = block;
@@ -82,7 +82,7 @@ int JIT::Step() {
code.push(code.rbp); code.push(code.rbp);
code.mov(code.rbp, reinterpret_cast<uintptr_t>(this)); // Load context pointer code.mov(code.rbp, reinterpret_cast<uintptr_t>(this)); // Load context pointer
// cs_insn *insn; cs_insn *insn;
Util::trace("\tMIPS code (guest PC = 0x{:016X}):", blockPC); Util::trace("\tMIPS code (guest PC = 0x{:016X}):", blockPC);
while (!instrInDelaySlot) { while (!instrInDelaySlot) {
// CheckCompareInterrupt(); // CheckCompareInterrupt();
@@ -106,7 +106,7 @@ int JIT::Step() {
const u32 instruction = mem.Read<u32>(regs, paddr); const u32 instruction = mem.Read<u32>(regs, paddr);
/*u32 bswapped = bswap(instruction); u32 bswapped = bswap(instruction);
auto count = cs_disasm(disassemblerMips, reinterpret_cast<const u8 *>(&bswapped), 4, blockPC, 0, &insn); auto count = cs_disasm(disassemblerMips, reinterpret_cast<const u8 *>(&bswapped), 4, blockPC, 0, &insn);
if (count > 0) { 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)); 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); regs.cop0.FireException(ExceptionCode::Interrupt, 0, blockPC);
return 1; return 1;
}*/ }*/
@@ -155,7 +155,7 @@ int JIT::Step() {
code.add(code.rsp, 8); code.add(code.rsp, 8);
code.ret(); code.ret();
code.setProtectModeRE(); code.setProtectModeRE();
/* static auto blockInfoSize = 0; static auto blockInfoSize = 0;
blockInfoSize = code.getSize() - blockInfoSize; blockInfoSize = code.getSize() - blockInfoSize;
Util::trace("\tX86 code (block address = 0x{:016X}):", (uintptr_t)block); Util::trace("\tX86 code (block address = 0x{:016X}):", (uintptr_t)block);
@@ -166,7 +166,7 @@ int JIT::Step() {
} }
cs_free(insn, count); cs_free(insn, count);
}*/ }
// const auto dump = code.getCode(); // const auto dump = code.getCode();
// Util::WriteFileBinary(dump, code.getSize(), "jit.dump"); // Util::WriteFileBinary(dump, code.getSize(), "jit.dump");
// Util::panic(""); // Util::panic("");

View File

@@ -1003,7 +1003,6 @@ void JIT::ldr(u32 instr) {
// regs.cop0.FireException(Cop0::GetTLBExceptionCode(regs.cop0.tlbError, Cop0::LOAD), 0, regs.oldPC); // regs.cop0.FireException(Cop0::GetTLBExceptionCode(regs.cop0.tlbError, Cop0::LOAD), 0, regs.oldPC);
Util::panic("[JIT]: Unhandled TLBL exception in LDR!"); Util::panic("[JIT]: Unhandled TLBL exception in LDR!");
} else { } else {
Util::panic("[JIT]: Implement constant LDR!");
const s32 shift = 8 * ((address ^ 7) & 7); const s32 shift = 8 * ((address ^ 7) & 7);
const u64 mask = 0xFFFFFFFFFFFFFFFF >> shift; const u64 mask = 0xFFFFFFFFFFFFFFFF >> shift;
const u64 data = mem.Read<u64>(regs, paddr & ~7); const u64 data = mem.Read<u64>(regs, paddr & ~7);
@@ -1073,7 +1072,7 @@ void JIT::lhu(u32 instr) {
emitMemberFunctionCall(&Cop0::MapVAddr, &regs.cop0); emitMemberFunctionCall(&Cop0::MapVAddr, &regs.cop0);
code.mov(code.ARG2, code.ptr[code.rbp + (reinterpret_cast<uintptr_t>(&regs) - reinterpret_cast<uintptr_t>(this))]); code.mov(code.ARG2, code.ptr[code.rbp + (reinterpret_cast<uintptr_t>(&regs) - reinterpret_cast<uintptr_t>(this))]);
code.mov(code.ARG3, paddr); code.mov(code.ARG3, code.qword[code.ARG4]);
emitMemberFunctionCall(&Mem::Read<u16>, &mem); emitMemberFunctionCall(&Mem::Read<u16>, &mem);
regs.Write<u16>(RT(instr), code.rax); regs.Write<u16>(RT(instr), code.rax);
} }
@@ -1110,13 +1109,15 @@ void JIT::lw(u32 instr) {
} }
code.mov(code.ARG2, Cop0::LOAD); code.mov(code.ARG2, Cop0::LOAD);
regs.Read<s64>(RS(instr), code.ARG3); regs.Read<s64>(RS(instr), code.ARG3);
code.add(code.ARG3, offset); code.add(code.ARG3, offset);
code.mov(code.ARG4, reinterpret_cast<uintptr_t>(&paddr)); code.mov(code.ARG4, reinterpret_cast<uintptr_t>(&paddr));
emitMemberFunctionCall(&Cop0::MapVAddr, &regs.cop0); emitMemberFunctionCall(&Cop0::MapVAddr, &regs.cop0);
code.mov(code.ARG2, code.ptr[code.rbp + (reinterpret_cast<uintptr_t>(&regs) - reinterpret_cast<uintptr_t>(this))]); code.mov(code.ARG2, code.ptr[code.rbp + (reinterpret_cast<uintptr_t>(&regs) - reinterpret_cast<uintptr_t>(this))]);
code.mov(code.ARG3, paddr); code.mov(code.ARG3, code.qword[code.ARG4]);
emitMemberFunctionCall(&Mem::Read<u32>, &mem); emitMemberFunctionCall(&Mem::Read<u32>, &mem);
regs.Write<s32>(RT(instr), code.rax); regs.Write<s32>(RT(instr), code.rax);
} }
@@ -1366,7 +1367,7 @@ void JIT::sw(const u32 instr) {
code.lea(code.ARG2, code.lea(code.ARG2,
code.ptr[code.rbp + (reinterpret_cast<uintptr_t>(&regs) - reinterpret_cast<uintptr_t>(this))]); code.ptr[code.rbp + (reinterpret_cast<uintptr_t>(&regs) - reinterpret_cast<uintptr_t>(this))]);
code.mov(code.ARG3, physical); code.mov(code.ARG3, physical);
code.mov(code.ARG4, regs.Read<s64>(RT(instr))); regs.Read<s64>(RT(instr), code.ARG4);
emitMemberFunctionCall(&Mem::WriteJIT<u32>, &mem); emitMemberFunctionCall(&Mem::WriteJIT<u32>, &mem);
} }
@@ -1391,7 +1392,7 @@ void JIT::sw(const u32 instr) {
code.mov(code.ARG2, code.mov(code.ARG2,
code.ptr[code.rbp + (reinterpret_cast<uintptr_t>(&regs) - reinterpret_cast<uintptr_t>(this))]); code.ptr[code.rbp + (reinterpret_cast<uintptr_t>(&regs) - reinterpret_cast<uintptr_t>(this))]);
code.mov(code.ARG3, physical); code.mov(code.ARG3, physical);
regs.Read<s64>(RT(instr), code.rcx); regs.Read<s64>(RT(instr), code.ARG4);
emitMemberFunctionCall(&Mem::WriteJIT<u32>, &mem); emitMemberFunctionCall(&Mem::WriteJIT<u32>, &mem);
} }
@@ -1400,33 +1401,33 @@ void JIT::sw(const u32 instr) {
if (regs.IsRegConstant(RT(instr))) { if (regs.IsRegConstant(RT(instr))) {
const s16 offset = instr; const s16 offset = instr;
regs.Read<s64>(RS(instr), code.rdx);
code.add(code.ARG3, offset);
code.mov(code.ARG2, Cop0::STORE); code.mov(code.ARG2, Cop0::STORE);
regs.Read<s64>(RS(instr), code.ARG3);
code.add(code.ARG3, offset);
code.mov(code.ARG4, reinterpret_cast<uintptr_t>(&physical)); code.mov(code.ARG4, reinterpret_cast<uintptr_t>(&physical));
emitMemberFunctionCall(&Cop0::MapVAddr, &regs.cop0); emitMemberFunctionCall(&Cop0::MapVAddr, &regs.cop0);
code.mov(code.ARG2, code.ptr[code.rbp + (reinterpret_cast<uintptr_t>(&regs) - reinterpret_cast<uintptr_t>(this))]); code.mov(code.ARG2, code.ptr[code.rbp + (reinterpret_cast<uintptr_t>(&regs) - reinterpret_cast<uintptr_t>(this))]);
code.mov(code.ARG3, physical); code.mov(code.ARG3, code.qword[code.ARG4]);
code.mov(code.ARG4, regs.Read<s64>(RT(instr))); regs.Read<s64>(RT(instr), code.ARG4);
emitMemberFunctionCall(&Mem::WriteJIT<u32>, &mem); emitMemberFunctionCall(&Mem::WriteJIT<u32>, &mem);
return; return;
} }
const s16 offset = instr; const s16 offset = instr;
code.mov(code.ARG2, Cop0::STORE);
regs.Read<s64>(RS(instr), code.rdx); regs.Read<s64>(RS(instr), code.rdx);
code.add(code.ARG3, offset); code.add(code.ARG3, offset);
code.mov(code.ARG2, Cop0::STORE);
code.mov(code.ARG4, reinterpret_cast<uintptr_t>(&physical)); code.mov(code.ARG4, reinterpret_cast<uintptr_t>(&physical));
emitMemberFunctionCall(&Cop0::MapVAddr, &regs.cop0); emitMemberFunctionCall(&Cop0::MapVAddr, &regs.cop0);
code.mov(code.ARG2, code.ptr[code.rbp + (reinterpret_cast<uintptr_t>(&regs) - reinterpret_cast<uintptr_t>(this))]); code.mov(code.ARG2, code.ptr[code.rbp + (reinterpret_cast<uintptr_t>(&regs) - reinterpret_cast<uintptr_t>(this))]);
code.mov(code.ARG3, physical); code.mov(code.ARG3, code.qword[code.ARG4]);
regs.Read<s64>(RT(instr), code.ARG4); regs.Read<s64>(RT(instr), code.ARG4);
emitMemberFunctionCall(&Mem::WriteJIT<u32>, &mem); emitMemberFunctionCall(&Mem::WriteJIT<u32>, &mem);
} }

View File

@@ -108,7 +108,7 @@ void KaizenGui::HandleInput(SDL_Event event) {
{ {
auto keys = SDL_GetKeyboardState(nullptr); auto keys = SDL_GetKeyboardState(nullptr);
if((keys[SDL_SCANCODE_LCTRL] || keys[SDL_SCANCODE_RCTRL]) && keys[SDL_SCANCODE_O]) { if((keys[SDL_SCANCODE_LCTRL] || keys[SDL_SCANCODE_RCTRL]) && keys[SDL_SCANCODE_O]) {
FileDialog(); fileDialogOpen = true;
} }
if(core->romLoaded) { if(core->romLoaded) {
@@ -153,7 +153,7 @@ void KaizenGui::RenderUI() {
if(ImGui::BeginMainMenuBar()) { if(ImGui::BeginMainMenuBar()) {
if(ImGui::BeginMenu("File")) { if(ImGui::BeginMenu("File")) {
if(ImGui::MenuItem("Open", "Ctrl-O")) { if(ImGui::MenuItem("Open", "Ctrl-O")) {
FileDialog(); fileDialogOpen = true;
} }
if(ImGui::MenuItem("Exit")) { if(ImGui::MenuItem("Exit")) {
quit = true; quit = true;
@@ -237,6 +237,11 @@ void KaizenGui::RenderUI() {
} }
core->parallel.UpdateScreen(*core.get(), false); core->parallel.UpdateScreen(*core.get(), false);
if(fileDialogOpen) {
fileDialogOpen = false;
FileDialog();
}
} }
void KaizenGui::LoadROM(const std::string &path) noexcept { void KaizenGui::LoadROM(const std::string &path) noexcept {

View File

@@ -26,6 +26,7 @@ public:
void LoadROM(const std::string &path) noexcept; void LoadROM(const std::string &path) noexcept;
private: private:
bool aboutOpen = false; bool aboutOpen = false;
bool fileDialogOpen = false;
bool quit = false; bool quit = false;
std::function<void()> emuExitFunc; std::function<void()> emuExitFunc;
void FileDialog(); void FileDialog();

View File

@@ -11,7 +11,7 @@ namespace Util {
enum LogLevel : u8 { Trace, Debug, Warn, Info, Error, Always }; enum LogLevel : u8 { Trace, Debug, Warn, Info, Error, Always };
#ifndef NDEBUG #ifndef NDEBUG
static constexpr auto globalLogLevel = Debug; static constexpr auto globalLogLevel = Trace;
#else #else
static constexpr auto globalLogLevel = Info; static constexpr auto globalLogLevel = Info;
#endif #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...); fmt::print(fmt::emphasis::bold | fg(fmt::color::red), fmt::runtime(fmt), args...);
} else if (messageType == Warn) { } else if (messageType == Warn) {
fmt::print(fg(fmt::color::yellow), fmt::runtime(fmt), args...); 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...); fmt::print(fmt::runtime(fmt), args...);
} else if (messageType == Debug) { } else if (messageType <= Debug) {
#ifndef NDEBUG #ifndef NDEBUG
fmt::print(fmt::runtime(fmt), args...); fmt::print(fmt::runtime(fmt), args...);
#endif #endif
} }
#else #else
if (messageType == Debug) { if (messageType <= Debug) {
#ifndef NDEBUG #ifndef NDEBUG
fmt::print(fmt::runtime(fmt), args...); fmt::print(fmt::runtime(fmt), args...);
#endif #endif