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_) {
Stop();
rom = rom_;
cpu->Reset();
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);
// const auto blockInfo = code.getCurr();
const auto blockInfo = code.getCurr();
const auto block = code.getCurr<BlockFn>();
blockCache[upperIndex][lowerIndex] = block;
@@ -82,7 +82,7 @@ int JIT::Step() {
code.push(code.rbp);
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);
while (!instrInDelaySlot) {
// CheckCompareInterrupt();
@@ -106,7 +106,7 @@ int JIT::Step() {
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);
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("");

View File

@@ -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<u64>(regs, paddr & ~7);
@@ -1073,7 +1072,7 @@ void JIT::lhu(u32 instr) {
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.ARG3, paddr);
code.mov(code.ARG3, code.qword[code.ARG4]);
emitMemberFunctionCall(&Mem::Read<u16>, &mem);
regs.Write<u16>(RT(instr), code.rax);
}
@@ -1110,13 +1109,15 @@ void JIT::lw(u32 instr) {
}
code.mov(code.ARG2, Cop0::LOAD);
regs.Read<s64>(RS(instr), code.ARG3);
code.add(code.ARG3, offset);
code.mov(code.ARG4, reinterpret_cast<uintptr_t>(&paddr));
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.ARG3, paddr);
code.mov(code.ARG3, code.qword[code.ARG4]);
emitMemberFunctionCall(&Mem::Read<u32>, &mem);
regs.Write<s32>(RT(instr), code.rax);
}
@@ -1366,7 +1367,7 @@ void JIT::sw(const u32 instr) {
code.lea(code.ARG2,
code.ptr[code.rbp + (reinterpret_cast<uintptr_t>(&regs) - reinterpret_cast<uintptr_t>(this))]);
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);
}
@@ -1391,7 +1392,7 @@ void JIT::sw(const u32 instr) {
code.mov(code.ARG2,
code.ptr[code.rbp + (reinterpret_cast<uintptr_t>(&regs) - reinterpret_cast<uintptr_t>(this))]);
code.mov(code.ARG3, physical);
regs.Read<s64>(RT(instr), code.rcx);
regs.Read<s64>(RT(instr), code.ARG4);
emitMemberFunctionCall(&Mem::WriteJIT<u32>, &mem);
}
@@ -1400,33 +1401,33 @@ void JIT::sw(const u32 instr) {
if (regs.IsRegConstant(RT(instr))) {
const s16 offset = instr;
regs.Read<s64>(RS(instr), code.rdx);
code.add(code.ARG3, offset);
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));
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.ARG3, physical);
code.mov(code.ARG4, regs.Read<s64>(RT(instr)));
code.mov(code.ARG3, code.qword[code.ARG4]);
regs.Read<s64>(RT(instr), code.ARG4);
emitMemberFunctionCall(&Mem::WriteJIT<u32>, &mem);
return;
}
const s16 offset = instr;
code.mov(code.ARG2, Cop0::STORE);
regs.Read<s64>(RS(instr), code.rdx);
code.add(code.ARG3, offset);
code.mov(code.ARG2, Cop0::STORE);
code.mov(code.ARG4, reinterpret_cast<uintptr_t>(&physical));
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.ARG3, physical);
code.mov(code.ARG3, code.qword[code.ARG4]);
regs.Read<s64>(RT(instr), code.ARG4);
emitMemberFunctionCall(&Mem::WriteJIT<u32>, &mem);
}

View File

@@ -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 {

View File

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

View File

@@ -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