From a1a19e72cd9347d5a75dded76b2b32c000e90e96 Mon Sep 17 00:00:00 2001 From: SimoneN64 Date: Thu, 23 Jan 2025 23:39:53 +0100 Subject: [PATCH] [JIT]: Implement LHU --- src/backend/core/jit/instructions.cpp | 36 +++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/src/backend/core/jit/instructions.cpp b/src/backend/core/jit/instructions.cpp index 6015a347..6bf0fe05 100644 --- a/src/backend/core/jit/instructions.cpp +++ b/src/backend/core/jit/instructions.cpp @@ -916,7 +916,7 @@ void JIT::lb(u32 instr) { if (u32 paddr = 0; !regs.cop0.MapVAddr(Cop0::LOAD, address, paddr)) { // regs.cop0.HandleTLBException(address); // regs.cop0.FireException(Cop0::GetTLBExceptionCode(regs.cop0.tlbError, Cop0::LOAD), 0, regs.oldPC); - Util::panic("[JIT]: Unhandled TLBL exception in LB!"); + Util::panic("[JIT]: Unhandled TLBL exception in LB (pc: 0x{:016X})!", blockPC); } else { code.mov(code.ARG2, code.ptr[code.rbp + (reinterpret_cast(®s) - reinterpret_cast(this))]); @@ -1045,7 +1045,39 @@ void JIT::lh(u32 instr) { Util::panic("[JIT]: Implement non constant LH!"); } -void JIT::lhu(u32) { Util::panic("[JIT]: Implement LHU!"); } +void JIT::lhu(u32 instr) { + u32 paddr; + if (regs.IsRegConstant(RS(instr))) { + const s64 address = regs.Read(RS(instr)) + (s16)instr; + if (check_address_error(0b1, address)) { + regs.cop0.HandleTLBException(address); + regs.cop0.FireException(ExceptionCode::AddressErrorLoad, 0, regs.oldPC); + return; + } + + if (!regs.cop0.MapVAddr(Cop0::LOAD, address, paddr)) { + regs.cop0.HandleTLBException(address); + regs.cop0.FireException(Cop0::GetTLBExceptionCode(regs.cop0.tlbError, Cop0::LOAD), 0, regs.oldPC); + return; + } + + 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); + } + + code.mov(code.ARG2, Cop0::LOAD); + regs.Read(RS(instr), code.ARG3); + code.add(code.ARG3, s16(instr)); + 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); + emitMemberFunctionCall(&Mem::Read, &mem); + regs.Write(RT(instr), code.rax); +} void JIT::ll(u32) { Util::panic("[JIT]: Implement constant LL!"); }