From a810597ac06cda12d6cba3dc6d68e7e82f209597 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Thu, 20 Aug 2026 10:26:13 +0200 Subject: [PATCH] Implement MMIO for the JIT (by falling back to the interpreter for load/stores from kernel addresses) Fixes the VSH in JIT mode (but NOT ir) --- Core/HLE/HLE.cpp | 3 +++ Core/MIPS/ARM/ArmCompFPU.cpp | 7 +++++++ Core/MIPS/ARM/ArmCompLoadStore.cpp | 8 ++++++++ Core/MIPS/ARM/ArmCompVFPU.cpp | 14 ++++++++++++++ Core/MIPS/ARM64/Arm64CompFPU.cpp | 7 +++++++ Core/MIPS/ARM64/Arm64CompLoadStore.cpp | 7 +++++++ Core/MIPS/ARM64/Arm64CompVFPU.cpp | 15 +++++++++++++++ Core/MIPS/IR/IRCompLoadStore.cpp | 19 +++++++++++++++++-- Core/MIPS/IR/IRCompVFPU.cpp | 14 ++++++++++++++ Core/MIPS/Interpreter.cpp | 17 +++++++++-------- Core/MIPS/x86/CompFPU.cpp | 8 ++++++++ Core/MIPS/x86/CompLoadStore.cpp | 16 ++++++++++++++++ Core/MIPS/x86/CompVFPU.cpp | 14 ++++++++++++++ 13 files changed, 139 insertions(+), 10 deletions(-) diff --git a/Core/HLE/HLE.cpp b/Core/HLE/HLE.cpp index 0a57317cd5..4c2d19d81b 100644 --- a/Core/HLE/HLE.cpp +++ b/Core/HLE/HLE.cpp @@ -1003,6 +1003,9 @@ void CallSyscall(MIPSOpcode op) { void CallSyscallUnresolvedAtPC(u32 pc) { LogBadSyscallAtPC(pc, false); + // Same as the !info path in CallSyscallWithPC - the call has to leave an error in v0, + // otherwise the caller sees a stale value and thinks the unresolved import succeeded. + RETURN(SCE_KERNEL_ERROR_LIBRARY_NOT_YET_LINKED); } void hlePushFuncDesc(std::string_view module, std::string_view funcName) { diff --git a/Core/MIPS/ARM/ArmCompFPU.cpp b/Core/MIPS/ARM/ArmCompFPU.cpp index 00bc4a7eb1..463f9719a0 100644 --- a/Core/MIPS/ARM/ArmCompFPU.cpp +++ b/Core/MIPS/ARM/ArmCompFPU.cpp @@ -95,6 +95,13 @@ void ArmJit::Comp_FPULS(MIPSOpcode op) CONDITIONAL_DISABLE(LSU_FPU); CheckMemoryBreakpoint(); + if (js.kernelMode) { + // Send all memory accesses to the interpreter in kernel mode. + // TODO: Do something faster - but it hardly matters, currently this is VSH-only. + DISABLE; + return; + } + s32 offset = SignExtend16ToS32(op & 0xFFFF); int ft = _FT; MIPSGPReg rs = _RS; diff --git a/Core/MIPS/ARM/ArmCompLoadStore.cpp b/Core/MIPS/ARM/ArmCompLoadStore.cpp index e4e9131a28..8a2fed055f 100644 --- a/Core/MIPS/ARM/ArmCompLoadStore.cpp +++ b/Core/MIPS/ARM/ArmCompLoadStore.cpp @@ -271,6 +271,14 @@ namespace MIPSComp { CONDITIONAL_DISABLE(LSU); CheckMemoryBreakpoint(); + + if (js.kernelMode) { + // Send all memory accesses to the interpreter in kernel mode. + // TODO: Do something faster - but it hardly matters, currently this is VSH-only. + DISABLE; + return; + } + int offset = (signed short)(op&0xFFFF); bool load = false; MIPSGPReg rt = _RT; diff --git a/Core/MIPS/ARM/ArmCompVFPU.cpp b/Core/MIPS/ARM/ArmCompVFPU.cpp index 05ddf8464d..940282070d 100644 --- a/Core/MIPS/ARM/ArmCompVFPU.cpp +++ b/Core/MIPS/ARM/ArmCompVFPU.cpp @@ -229,6 +229,13 @@ namespace MIPSComp CONDITIONAL_DISABLE(LSU_VFPU); CheckMemoryBreakpoint(); + if (js.kernelMode) { + // Send all memory accesses to the interpreter in kernel mode. + // TODO: Do something faster - but it hardly matters, currently this is VSH-only. + DISABLE; + return; + } + s32 offset = (signed short)(op & 0xFFFC); int vt = ((op >> 16) & 0x1f) | ((op & 3) << 5); MIPSGPReg rs = _RS; @@ -334,6 +341,13 @@ namespace MIPSComp CONDITIONAL_DISABLE(LSU_VFPU); CheckMemoryBreakpoint(); + if (js.kernelMode) { + // Send all memory accesses to the interpreter in kernel mode. + // TODO: Do something faster - but it hardly matters, currently this is VSH-only. + DISABLE; + return; + } + int imm = (signed short)(op&0xFFFC); int vt = (((op >> 16) & 0x1f)) | ((op&1) << 5); MIPSGPReg rs = _RS; diff --git a/Core/MIPS/ARM64/Arm64CompFPU.cpp b/Core/MIPS/ARM64/Arm64CompFPU.cpp index fc0060adf3..5f858eeebd 100644 --- a/Core/MIPS/ARM64/Arm64CompFPU.cpp +++ b/Core/MIPS/ARM64/Arm64CompFPU.cpp @@ -83,6 +83,13 @@ void Arm64Jit::Comp_FPULS(MIPSOpcode op) CONDITIONAL_DISABLE(LSU_FPU); CheckMemoryBreakpoint(); + if (js.kernelMode) { + // Send all memory accesses to the interpreter in kernel mode. + // TODO: Do something faster - but it hardly matters, currently this is VSH-only. + DISABLE; + return; + } + s32 offset = SignExtend16ToS32(op & 0xFFFF); int ft = _FT; MIPSGPReg rs = _RS; diff --git a/Core/MIPS/ARM64/Arm64CompLoadStore.cpp b/Core/MIPS/ARM64/Arm64CompLoadStore.cpp index bbb7eb7409..3de6ae3a2d 100644 --- a/Core/MIPS/ARM64/Arm64CompLoadStore.cpp +++ b/Core/MIPS/ARM64/Arm64CompLoadStore.cpp @@ -267,6 +267,13 @@ namespace MIPSComp { CONDITIONAL_DISABLE(LSU); CheckMemoryBreakpoint(); + if (js.kernelMode) { + // Send all memory accesses to the interpreter in kernel mode. + // TODO: Do something faster - but it hardly matters, currently this is VSH-only. + DISABLE; + return; + } + int offset = SignExtend16ToS32(op & 0xFFFF); bool load = false; MIPSGPReg rt = _RT; diff --git a/Core/MIPS/ARM64/Arm64CompVFPU.cpp b/Core/MIPS/ARM64/Arm64CompVFPU.cpp index 48f4868372..da00865bcc 100644 --- a/Core/MIPS/ARM64/Arm64CompVFPU.cpp +++ b/Core/MIPS/ARM64/Arm64CompVFPU.cpp @@ -206,6 +206,14 @@ namespace MIPSComp { CONDITIONAL_DISABLE(LSU_VFPU); CheckMemoryBreakpoint(); + if (js.kernelMode) { + // Send all memory accesses to the interpreter in kernel mode. + // TODO: Do something faster - but it hardly matters, currently this is VSH-only. + // NOTE: This should be done before the $zr check in case there are reads with side effects. + DISABLE; + return; + } + s32 offset = (signed short)(op & 0xFFFC); int vt = ((op >> 16) & 0x1f) | ((op & 3) << 5); MIPSGPReg rs = _RS; @@ -288,6 +296,13 @@ namespace MIPSComp { CONDITIONAL_DISABLE(LSU_VFPU); CheckMemoryBreakpoint(); + if (js.kernelMode) { + // Send all memory accesses to the interpreter in kernel mode. + // TODO: Do something faster - but it hardly matters, currently this is VSH-only. + DISABLE; + return; + } + int imm = (signed short)(op&0xFFFC); int vt = (((op >> 16) & 0x1f)) | ((op&1) << 5); MIPSGPReg rs = _RS; diff --git a/Core/MIPS/IR/IRCompLoadStore.cpp b/Core/MIPS/IR/IRCompLoadStore.cpp index 49b0e740e2..ba4671f028 100644 --- a/Core/MIPS/IR/IRCompLoadStore.cpp +++ b/Core/MIPS/IR/IRCompLoadStore.cpp @@ -51,13 +51,21 @@ namespace MIPSComp { MIPSGPReg rt = _RT; MIPSGPReg rs = _RS; int o = op >> 26; + + CheckMemoryBreakpoint(rs, offset); + + if (js.kernelMode) { + // Send all memory accesses to the interpreter in kernel mode. + // TODO: Do something faster - but it hardly matters, currently this is VSH-only. + DISABLE; + return; + } + if (((op >> 29) & 1) == 0 && rt == MIPS_REG_ZERO) { // Don't load anything into $zr return; } - CheckMemoryBreakpoint(rs, offset); - switch (o) { // Load case 35: @@ -115,6 +123,13 @@ namespace MIPSComp { CheckMemoryBreakpoint(rs, offset); + if (js.kernelMode) { + // Send all memory accesses to the interpreter in kernel mode. + // TODO: Do something faster - but it hardly matters, currently this is VSH-only. + DISABLE; + return; + } + switch (op >> 26) { case 48: // ll ir.Write(IROp::Load32Linked, rt, rs, 0, offset); diff --git a/Core/MIPS/IR/IRCompVFPU.cpp b/Core/MIPS/IR/IRCompVFPU.cpp index e2ebefe456..e5bf32f4e6 100644 --- a/Core/MIPS/IR/IRCompVFPU.cpp +++ b/Core/MIPS/IR/IRCompVFPU.cpp @@ -400,6 +400,13 @@ namespace MIPSComp { CheckMemoryBreakpoint(rs, offset); + if (js.kernelMode) { + // Send all memory accesses to the interpreter in kernel mode. + // TODO: Do something faster - but it hardly matters, currently this is VSH-only. + DISABLE; + return; + } + switch (op >> 26) { case 50: //lv.s ir.Write(IROp::LoadFloat, vfpuBase + voffset[vt], rs, 0, offset); @@ -425,6 +432,13 @@ namespace MIPSComp { CheckMemoryBreakpoint(rs, imm); + if (js.kernelMode) { + // Send all memory accesses to the interpreter in kernel mode. + // TODO: Do something faster - but it hardly matters, currently this is VSH-only. + DISABLE; + return; + } + enum class LSVType { INVALID, LVQ, diff --git a/Core/MIPS/Interpreter.cpp b/Core/MIPS/Interpreter.cpp index 784e9e2f39..8c8af8c931 100644 --- a/Core/MIPS/Interpreter.cpp +++ b/Core/MIPS/Interpreter.cpp @@ -94,10 +94,11 @@ int MIPS_InterpretSingleStep(MIPSState *mips) { return 1; } -// Dummy functions, for any future MMIO support. +// MMIO handling, for limited LLE, just enough for VSH. +// // Unregistered reads return a distinctive poison value (not 0) so it's obvious in a live trace // when some later computation's input traces back to an unimplemented MMIO register, rather -// than looking like an ordinary, legitimate zero (see docs/VSHBootInvestigation.md "Attempt 9"). +// than looking like an ordinary, legitimate zero. constexpr u32 UNKNOWN_MMIO_POISON = 0x1337BEEF; static u8 ReadMMIO_U8(MIPSState *mips, u32 addr) { @@ -105,7 +106,7 @@ static u8 ReadMMIO_U8(MIPSState *mips, u32 addr) { Core_MemoryException(addr, 1, mips->pc, MemoryExceptionType::READ_WORD, "Kernel mode only"); return (u8)UNKNOWN_MMIO_POISON; } - WARN_LOG(Log::CPU, "MMIO Read8 at %08x", addr); + WARN_LOG(Log::CPU, "Unhandled MMIO Read8 at %08x", addr); return (u8)UNKNOWN_MMIO_POISON; } @@ -114,7 +115,7 @@ static u16 ReadMMIO_U16(MIPSState *mips, u32 addr) { Core_MemoryException(addr, 2, mips->pc, MemoryExceptionType::READ_WORD, "Kernel mode only"); return (u8)UNKNOWN_MMIO_POISON; } - WARN_LOG(Log::CPU, "MMIO Read16 at %08x", addr); + WARN_LOG(Log::CPU, "Unhandled MMIO Read16 at %08x", addr); return (u16)UNKNOWN_MMIO_POISON; } @@ -129,7 +130,7 @@ static u32 ReadMMIO_U32(MIPSState *mips, u32 addr) { if (SysconSerialMMIO::IsSysconSerialAddress(addr)) { return SysconSerialMMIO::Read32(addr); } - WARN_LOG(Log::CPU, "MMIO Read32 at %08x", addr); + WARN_LOG(Log::CPU, "Unhandled MMIO Read32 at %08x", addr); return UNKNOWN_MMIO_POISON; } @@ -138,7 +139,7 @@ void WriteMMIO_U8(MIPSState *mips, u32 addr, u8 value) { Core_MemoryException(addr, 1, mips->pc, MemoryExceptionType::WRITE_WORD, "Kernel mode only"); return; } - WARN_LOG(Log::CPU, "MMIO Write8 at %08x = %02x", addr, value); + WARN_LOG(Log::CPU, "Unhandled MMIO Write8 at %08x = %02x", addr, value); } void WriteMMIO_U16(MIPSState *mips, u32 addr, u16 value) { @@ -146,7 +147,7 @@ void WriteMMIO_U16(MIPSState *mips, u32 addr, u16 value) { Core_MemoryException(addr, 2, mips->pc, MemoryExceptionType::WRITE_WORD, "Kernel mode only"); return; } - WARN_LOG(Log::CPU, "MMIO Write16 at %08x = %04x", addr, value); + WARN_LOG(Log::CPU, "Unhandled MMIO Write16 at %08x = %04x", addr, value); } void WriteMMIO_U32(MIPSState *mips, u32 addr, u32 value) { @@ -161,7 +162,7 @@ void WriteMMIO_U32(MIPSState *mips, u32 addr, u32 value) { SysconSerialMMIO::Write32(addr, value); return; } - WARN_LOG(Log::CPU, "MMIO Write32 at %08x = %08x", addr, value); + WARN_LOG(Log::CPU, "Unhandled MMIO Write32 at %08x = %08x", addr, value); } namespace MIPSInt { diff --git a/Core/MIPS/x86/CompFPU.cpp b/Core/MIPS/x86/CompFPU.cpp index 4927975f02..c67c2e593c 100644 --- a/Core/MIPS/x86/CompFPU.cpp +++ b/Core/MIPS/x86/CompFPU.cpp @@ -123,6 +123,14 @@ void Jit::Comp_FPU3op(MIPSOpcode op) { void Jit::Comp_FPULS(MIPSOpcode op) { CONDITIONAL_DISABLE(LSU_FPU); + + if (js.kernelMode) { + // Send all memory accesses to the interpreter in kernel mode. + // TODO: Do something faster - but it hardly matters, currently this is VSH-only. + DISABLE; + return; + } + s32 offset = _IMM16; int ft = _FT; MIPSGPReg rs = _RS; diff --git a/Core/MIPS/x86/CompLoadStore.cpp b/Core/MIPS/x86/CompLoadStore.cpp index 69c8b29963..d010cb3777 100644 --- a/Core/MIPS/x86/CompLoadStore.cpp +++ b/Core/MIPS/x86/CompLoadStore.cpp @@ -289,6 +289,15 @@ namespace MIPSComp { void Jit::Comp_ITypeMem(MIPSOpcode op) { CONDITIONAL_DISABLE(LSU); + + if (js.kernelMode) { + // Send all memory accesses to the interpreter in kernel mode. + // TODO: Do something faster - but it hardly matters, currently this is VSH-only. + // NOTE: This should be done before the $zr check in case there are reads with side effects. + DISABLE; + return; + } + int offset = _IMM16; MIPSGPReg rs = _RS; MIPSGPReg rt = _RT; @@ -412,6 +421,13 @@ namespace MIPSComp { void Jit::Comp_StoreSync(MIPSOpcode op) { CONDITIONAL_DISABLE(LSU); + if (js.kernelMode) { + // Send all memory accesses to the interpreter in kernel mode. + // TODO: Do something faster - but it hardly matters, currently this is VSH-only. + DISABLE; + return; + } + int offset = _IMM16; MIPSGPReg rt = _RT; MIPSGPReg rs = _RS; diff --git a/Core/MIPS/x86/CompVFPU.cpp b/Core/MIPS/x86/CompVFPU.cpp index e5bf9232f2..0470465270 100644 --- a/Core/MIPS/x86/CompVFPU.cpp +++ b/Core/MIPS/x86/CompVFPU.cpp @@ -240,6 +240,13 @@ bool IsOverlapSafe(int dreg, int di, int sn, const u8 sregs[], int tn = 0, const void Jit::Comp_SV(MIPSOpcode op) { CONDITIONAL_DISABLE(LSU_VFPU); + if (js.kernelMode) { + // Send all memory accesses to the interpreter in kernel mode. + // TODO: Do something faster - but it hardly matters, currently this is VSH-only. + DISABLE; + return; + } + s32 imm = (signed short)(op&0xFFFC); int vt = ((op >> 16) & 0x1f) | ((op & 3) << 5); MIPSGPReg rs = _RS; @@ -297,6 +304,13 @@ void Jit::Comp_SV(MIPSOpcode op) { void Jit::Comp_SVQ(MIPSOpcode op) { CONDITIONAL_DISABLE(LSU_VFPU); + if (js.kernelMode) { + // Send all memory accesses to the interpreter in kernel mode. + // TODO: Do something faster - but it hardly matters, currently this is VSH-only. + DISABLE; + return; + } + int imm = (signed short)(op&0xFFFC); int vt = (((op >> 16) & 0x1f)) | ((op&1) << 5); MIPSGPReg rs = _RS;