From ffad0acea126c0d30c1fda20269cdffd19a6b1fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Wed, 12 Aug 2026 13:00:20 +0200 Subject: [PATCH 1/7] Plumb an explicit MIPSState *mips through the interpreter's Int_* handlers All ~82 MIPSInt::Int_* functions (Interpreter.cpp/.h, InterpreterVFPU.cpp/.h) now take an explicit MIPSState *mips instead of reaching for the global currentMIPS internally, along with their file-local helpers (DelayBranchTo, SkipLikely, ApplySwizzleS/T, ApplyPrefixD/ST, RetainInvalidSwizzleST, EatPrefixes). MIPSInterpretFunc, Interpret(), ExecInstruction()/InterpreterDispatch.cpp (regenerated), and RunUntilFast() all thread mips through accordingly. Deliberately left on currentMIPS for now: MIPSVFPUUtils.cpp's ReadVector/WriteVector/ReadMatrix/WriteMatrix/VFPURewritePrefix - these are shared with every JIT backend's compile-time VFPU code, so parameterizing them would balloon this into a JIT-wide refactor. This is a partial refactor; that's the next boundary to push on. Several JIT backends (x86 Jit.cpp, ARM/ArmJit.cpp, ARM64/Arm64Jit.cpp, x86/X64IRJit.cpp, RiscV/RiscVJit.cpp, LoongArch64/LoongArch64Jit.cpp, ARM64/Arm64IRJit.cpp) bake the raw interpreter function pointer directly into JIT-generated machine code as their "fall back to the interpreter for this one op" mechanism, with only a single argument register set up for the call. Rather than hand-editing register allocation across four architectures that can't be build-tested here, added MIPSInterpretTrampoline(MIPSOpcode op) - a 1-arg wrapper around MIPSInterpret(currentMIPS, op) - and pointed all 7 such call sites at it instead, leaving that codegen untouched. Two other call sites (JitLogMiss, JitBranchLog) were plain C++ calls and just got the extra argument directly. Verified (Windows x64): PPSSPPWindows/PPSSPPHeadless/UnitTest all build clean, 49/49 unit tests pass. `test.py -g --graphics=software`: interpreter 312/314 (cpu/fpu/fpu is the pre-existing, unrelated interpreter-vs-JIT denormal difference; gpu/rendertarget/copy passes standalone, so was cross-test state bleed in the batch run, not a regression), default JIT 314/314, jit-ir 313/314 (gpu/vertices/morph is an expected difference from the vertex decoder taking a different mode with this core change, not a bug). Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_019SKhm9wKEQzRUsx9mTrrtQ --- Core/MIPS/ARM/ArmJit.cpp | 2 +- Core/MIPS/ARM64/Arm64IRJit.cpp | 2 +- Core/MIPS/ARM64/Arm64Jit.cpp | 2 +- Core/MIPS/Interpreter.cpp | 188 +++---- Core/MIPS/Interpreter.h | 54 +- Core/MIPS/InterpreterDispatch.cpp | 174 +++---- Core/MIPS/InterpreterDispatch.h | 16 +- Core/MIPS/InterpreterVFPU.cpp | 617 ++++++++++++----------- Core/MIPS/InterpreterVFPU.h | 112 ++-- Core/MIPS/LoongArch64/LoongArch64Jit.cpp | 2 +- Core/MIPS/MIPSTables.cpp | 33 +- Core/MIPS/MIPSTables.h | 14 +- Core/MIPS/RiscV/RiscVJit.cpp | 2 +- Core/MIPS/x86/CompBranch.cpp | 2 +- Core/MIPS/x86/Jit.cpp | 4 +- Core/MIPS/x86/X64IRJit.cpp | 2 +- Tools/update-dispatcher.py | 2 +- 17 files changed, 620 insertions(+), 608 deletions(-) diff --git a/Core/MIPS/ARM/ArmJit.cpp b/Core/MIPS/ARM/ArmJit.cpp index 3663ec9c0c..35666e7f79 100644 --- a/Core/MIPS/ARM/ArmJit.cpp +++ b/Core/MIPS/ARM/ArmJit.cpp @@ -569,7 +569,7 @@ void ArmJit::Comp_Generic(MIPSOpcode op) gpr.SetRegImm(SCRATCHREG1, GetCompilerPC()); MovToPC(SCRATCHREG1); gpr.SetRegImm(R0, op.encoding); - QuickCallFunction(R1, (void *)func); + QuickCallFunction(R1, (void *)&MIPSInterpretTrampoline); ApplyRoundingMode(); RestoreDowncount(); } diff --git a/Core/MIPS/ARM64/Arm64IRJit.cpp b/Core/MIPS/ARM64/Arm64IRJit.cpp index f9b206fffc..2a5d38d5be 100644 --- a/Core/MIPS/ARM64/Arm64IRJit.cpp +++ b/Core/MIPS/ARM64/Arm64IRJit.cpp @@ -276,7 +276,7 @@ void Arm64JitBackend::CompIR_Interpret(IRInst inst) { QuickCallFunction(SCRATCH2_64, &NotifyMIPSInterpret); } MOVI2R(X0, inst.constant); - QuickCallFunction(SCRATCH2_64, MIPSGetInterpretFunc(op)); + QuickCallFunction(SCRATCH2_64, &MIPSInterpretTrampoline); WriteDebugProfilerStatus(IRProfilerStatus::IN_JIT); LoadStaticRegisters(); } diff --git a/Core/MIPS/ARM64/Arm64Jit.cpp b/Core/MIPS/ARM64/Arm64Jit.cpp index 8dcdbb562d..cc1d38c90c 100644 --- a/Core/MIPS/ARM64/Arm64Jit.cpp +++ b/Core/MIPS/ARM64/Arm64Jit.cpp @@ -581,7 +581,7 @@ void Arm64Jit::Comp_Generic(MIPSOpcode op) { MOVI2R(SCRATCH1, GetCompilerPC()); MovToPC(SCRATCH1); MOVI2R(W0, op.encoding); - QuickCallFunction(SCRATCH2_64, (void *)func); + QuickCallFunction(SCRATCH2_64, (void *)&MIPSInterpretTrampoline); ApplyRoundingMode(); LoadStaticRegisters(); } diff --git a/Core/MIPS/Interpreter.cpp b/Core/MIPS/Interpreter.cpp index 2ebc6cc318..b3d19e2b8d 100644 --- a/Core/MIPS/Interpreter.cpp +++ b/Core/MIPS/Interpreter.cpp @@ -35,11 +35,11 @@ #include "Core/HLE/HLETables.h" #include "Core/HLE/ReplaceTables.h" -#define R(i) (currentMIPS->r[i]) -#define F(i) (currentMIPS->f[i]) -#define FI(i) (currentMIPS->fi[i]) -#define FsI(i) (currentMIPS->fs[i]) -#define PC (currentMIPS->pc) +#define R(i) (mips->r[i]) +#define F(i) (mips->f[i]) +#define FI(i) (mips->fi[i]) +#define FsI(i) (mips->fs[i]) +#define PC (mips->pc) #define _SIMM16_SHL2 ((u32)(s32)(s16)(op & 0xFFFF) << 2) #define _RS ((op>>21) & 0x1F) @@ -51,27 +51,27 @@ #define _POS ((op>>6 ) & 0x1F) #define _SIZE ((op>>11) & 0x1F) -#define HI currentMIPS->hi -#define LO currentMIPS->lo +#define HI mips->hi +#define LO mips->lo -static inline void DelayBranchTo(u32 where) +static inline void DelayBranchTo(MIPSState *mips, u32 where) { if (!Memory::IsValidAddress(where) || (where & 3) != 0) { Core_ExecException(where, PC, ExecExceptionType::JUMP); } PC += 4; - mipsr4k.nextPC = where; - mipsr4k.inDelaySlot = true; + mips->nextPC = where; + mips->inDelaySlot = true; } -static inline void SkipLikely() { +static inline void SkipLikely(MIPSState *mips) { MIPSInfo delaySlot = MIPSGetInfo(Memory::Read_Instruction(PC + 4, true)); // Don't actually skip if it is a jump (seen in Brooktown High.) if (delaySlot & IS_JUMP) { PC += 4; } else { PC += 8; - --mipsr4k.downcount; + --mips->downcount; } } @@ -95,7 +95,7 @@ int MIPS_SingleStep(MIPSState *mips) { namespace MIPSInt { - void Int_Cache(MIPSOpcode op) + void Int_Cache(MIPSState *mips, MIPSOpcode op) { int imm = SignExtend16ToS32(op); int rs = _RS; @@ -154,37 +154,37 @@ namespace MIPSInt PC += 4; } - void Int_Syscall(MIPSOpcode op) + void Int_Syscall(MIPSState *mips, MIPSOpcode op) { // Need to pre-move PC, as CallSyscall may result in a rescheduling! // To do this neater, we'll need a little generated kernel loop that syscall can jump to and then RFI from // but I don't see a need to bother. - if (mipsr4k.inDelaySlot) + if (mips->inDelaySlot) { - mipsr4k.pc = mipsr4k.nextPC; + mips->pc = mips->nextPC; } else { - mipsr4k.pc += 4; + mips->pc += 4; } - mipsr4k.inDelaySlot = false; + mips->inDelaySlot = false; CallSyscall(op); } - void Int_Sync(MIPSOpcode op) + void Int_Sync(MIPSState *mips, MIPSOpcode op) { //DEBUG_LOG(Log::CPU, "sync"); PC += 4; } - void Int_Break(MIPSOpcode op) + void Int_Break(MIPSState *mips, MIPSOpcode op) { Reporting::ReportMessage("BREAK instruction hit"); Core_BreakException(PC); PC += 4; } - void Int_RelBranch(MIPSOpcode op) + void Int_RelBranch(MIPSState *mips, MIPSOpcode op) { int imm = _SIMM16_SHL2; int rs = _RS; @@ -193,15 +193,15 @@ namespace MIPSInt switch (op >> 26) { - case 4: if (R(rt) == R(rs)) DelayBranchTo(addr); else PC += 4; break; //beq - case 5: if (R(rt) != R(rs)) DelayBranchTo(addr); else PC += 4; break; //bne - case 6: if ((s32)R(rs) <= 0) DelayBranchTo(addr); else PC += 4; break; //blez - case 7: if ((s32)R(rs) > 0) DelayBranchTo(addr); else PC += 4; break; //bgtz + case 4: if (R(rt) == R(rs)) DelayBranchTo(mips, addr); else PC += 4; break; //beq + case 5: if (R(rt) != R(rs)) DelayBranchTo(mips, addr); else PC += 4; break; //bne + case 6: if ((s32)R(rs) <= 0) DelayBranchTo(mips, addr); else PC += 4; break; //blez + case 7: if ((s32)R(rs) > 0) DelayBranchTo(mips, addr); else PC += 4; break; //bgtz - case 20: if (R(rt) == R(rs)) DelayBranchTo(addr); else SkipLikely(); break; //beql - case 21: if (R(rt) != R(rs)) DelayBranchTo(addr); else SkipLikely(); break; //bnel - case 22: if ((s32)R(rs) <= 0) DelayBranchTo(addr); else SkipLikely(); break; //blezl - case 23: if ((s32)R(rs) > 0) DelayBranchTo(addr); else SkipLikely(); break; //bgtzl + case 20: if (R(rt) == R(rs)) DelayBranchTo(mips, addr); else SkipLikely(mips); break; //beql + case 21: if (R(rt) != R(rs)) DelayBranchTo(mips, addr); else SkipLikely(mips); break; //bnel + case 22: if ((s32)R(rs) <= 0) DelayBranchTo(mips, addr); else SkipLikely(mips); break; //blezl + case 23: if ((s32)R(rs) > 0) DelayBranchTo(mips, addr); else SkipLikely(mips); break; //bgtzl default: _dbg_assert_msg_(false,"Trying to interpret instruction that can't be interpreted"); @@ -209,7 +209,7 @@ namespace MIPSInt } } - void Int_RelBranchRI(MIPSOpcode op) + void Int_RelBranchRI(MIPSState *mips, MIPSOpcode op) { int imm = _SIMM16_SHL2; int rs = _RS; @@ -217,14 +217,14 @@ namespace MIPSInt switch ((op>>16) & 0x1F) { - case 0: if ((s32)R(rs) < 0) DelayBranchTo(addr); else PC += 4; break;//bltz - case 1: if ((s32)R(rs) >= 0) DelayBranchTo(addr); else PC += 4; break;//bgez - case 2: if ((s32)R(rs) < 0) DelayBranchTo(addr); else SkipLikely(); break;//bltzl - case 3: if ((s32)R(rs) >= 0) DelayBranchTo(addr); else SkipLikely(); break;//bgezl - case 16: R(MIPS_REG_RA) = PC + 8; if ((s32)R(rs) < 0) DelayBranchTo(addr); else PC += 4; break;//bltzal - case 17: R(MIPS_REG_RA) = PC + 8; if ((s32)R(rs) >= 0) DelayBranchTo(addr); else PC += 4; break;//bgezal - case 18: R(MIPS_REG_RA) = PC + 8; if ((s32)R(rs) < 0) DelayBranchTo(addr); else SkipLikely(); break;//bltzall - case 19: R(MIPS_REG_RA) = PC + 8; if ((s32)R(rs) >= 0) DelayBranchTo(addr); else SkipLikely(); break;//bgezall + case 0: if ((s32)R(rs) < 0) DelayBranchTo(mips, addr); else PC += 4; break;//bltz + case 1: if ((s32)R(rs) >= 0) DelayBranchTo(mips, addr); else PC += 4; break;//bgez + case 2: if ((s32)R(rs) < 0) DelayBranchTo(mips, addr); else SkipLikely(mips); break;//bltzl + case 3: if ((s32)R(rs) >= 0) DelayBranchTo(mips, addr); else SkipLikely(mips); break;//bgezl + case 16: R(MIPS_REG_RA) = PC + 8; if ((s32)R(rs) < 0) DelayBranchTo(mips, addr); else PC += 4; break;//bltzal + case 17: R(MIPS_REG_RA) = PC + 8; if ((s32)R(rs) >= 0) DelayBranchTo(mips, addr); else PC += 4; break;//bgezal + case 18: R(MIPS_REG_RA) = PC + 8; if ((s32)R(rs) < 0) DelayBranchTo(mips, addr); else SkipLikely(mips); break;//bltzall + case 19: R(MIPS_REG_RA) = PC + 8; if ((s32)R(rs) >= 0) DelayBranchTo(mips, addr); else SkipLikely(mips); break;//bgezall default: _dbg_assert_msg_(false,"Trying to interpret instruction that can't be interpreted"); break; @@ -232,58 +232,58 @@ namespace MIPSInt } - void Int_VBranch(MIPSOpcode op) + void Int_VBranch(MIPSState *mips, MIPSOpcode op) { int imm = _SIMM16_SHL2; u32 addr = PC + imm + 4; // x, y, z, w, any, all, (invalid), (invalid) int imm3 = (op>>18)&7; - int val = (currentMIPS->vfpuCtrl[VFPU_CTRL_CC] >> imm3) & 1; + int val = (mips->vfpuCtrl[VFPU_CTRL_CC] >> imm3) & 1; switch ((op >> 16) & 3) { - case 0: if (!val) DelayBranchTo(addr); else PC += 4; break; //bvf - case 1: if ( val) DelayBranchTo(addr); else PC += 4; break; //bvt - case 2: if (!val) DelayBranchTo(addr); else SkipLikely(); break; //bvfl - case 3: if ( val) DelayBranchTo(addr); else SkipLikely(); break; //bvtl + case 0: if (!val) DelayBranchTo(mips, addr); else PC += 4; break; //bvf + case 1: if ( val) DelayBranchTo(mips, addr); else PC += 4; break; //bvt + case 2: if (!val) DelayBranchTo(mips, addr); else SkipLikely(mips); break; //bvfl + case 3: if ( val) DelayBranchTo(mips, addr); else SkipLikely(mips); break; //bvtl } } - void Int_FPUBranch(MIPSOpcode op) + void Int_FPUBranch(MIPSState *mips, MIPSOpcode op) { int imm = _SIMM16_SHL2; u32 addr = PC + imm + 4; switch((op>>16)&0x1f) { - case 0: if (!currentMIPS->fpcond) DelayBranchTo(addr); else PC += 4; break;//bc1f - case 1: if ( currentMIPS->fpcond) DelayBranchTo(addr); else PC += 4; break;//bc1t - case 2: if (!currentMIPS->fpcond) DelayBranchTo(addr); else SkipLikely(); break;//bc1fl - case 3: if ( currentMIPS->fpcond) DelayBranchTo(addr); else SkipLikely(); break;//bc1tl + case 0: if (!mips->fpcond) DelayBranchTo(mips, addr); else PC += 4; break;//bc1f + case 1: if ( mips->fpcond) DelayBranchTo(mips, addr); else PC += 4; break;//bc1t + case 2: if (!mips->fpcond) DelayBranchTo(mips, addr); else SkipLikely(mips); break;//bc1fl + case 3: if ( mips->fpcond) DelayBranchTo(mips, addr); else SkipLikely(mips); break;//bc1tl default: _dbg_assert_msg_(false,"Trying to interpret instruction that can't be interpreted"); break; } } - void Int_JumpType(MIPSOpcode op) + void Int_JumpType(MIPSState *mips, MIPSOpcode op) { - if (mipsr4k.inDelaySlot) + if (mips->inDelaySlot) ERROR_LOG(Log::CPU, "Jump in delay slot :("); u32 off = ((op & 0x03FFFFFF) << 2); - u32 addr = (currentMIPS->pc & 0xF0000000) | off; + u32 addr = (mips->pc & 0xF0000000) | off; switch (op>>26) { case 2: //j - if (!mipsr4k.inDelaySlot) - DelayBranchTo(addr); + if (!mips->inDelaySlot) + DelayBranchTo(mips, addr); break; case 3: //jal R(MIPS_REG_RA) = PC + 8; - if (!mipsr4k.inDelaySlot) - DelayBranchTo(addr); + if (!mips->inDelaySlot) + DelayBranchTo(mips, addr); break; default: _dbg_assert_msg_(false,"Trying to interpret instruction that can't be interpreted"); @@ -291,9 +291,9 @@ namespace MIPSInt } } - void Int_JumpRegType(MIPSOpcode op) + void Int_JumpRegType(MIPSState *mips, MIPSOpcode op) { - if (mipsr4k.inDelaySlot) { + if (mips->inDelaySlot) { // There's one of these in Star Soldier at 0881808c, which seems benign. ERROR_LOG(Log::CPU, "Jump in delay slot :("); } @@ -304,20 +304,20 @@ namespace MIPSInt switch (op & 0x3f) { case 8: //jr - if (!mipsr4k.inDelaySlot) - DelayBranchTo(addr); + if (!mips->inDelaySlot) + DelayBranchTo(mips, addr); break; case 9: //jalr if (rd != 0) R(rd) = PC + 8; // Update rd, but otherwise do not take the branch if we're branching. - if (!mipsr4k.inDelaySlot) - DelayBranchTo(addr); + if (!mips->inDelaySlot) + DelayBranchTo(mips, addr); break; } } - void Int_IType(MIPSOpcode op) { + void Int_IType(MIPSState *mips, MIPSOpcode op) { u32 uimm = op & 0xFFFF; u32 suimm = SignExtend16ToU32(op); s32 simm = SignExtend16ToS32(op); @@ -347,7 +347,7 @@ namespace MIPSInt PC += 4; } - void Int_StoreSync(MIPSOpcode op) { + void Int_StoreSync(MIPSState *mips, MIPSOpcode op) { int imm = (signed short)(op & 0xFFFF); int rt = _RT; int rs = _RS; @@ -363,10 +363,10 @@ namespace MIPSInt } R(rt) = Memory::ReadUnchecked_U32(addr); } - currentMIPS->llBit = 1; + mips->llBit = 1; break; case 56: // sc - if (currentMIPS->llBit) { + if (mips->llBit) { if (!Memory::IsValid4AlignedAddress(addr)) { Core_MemoryException(addr, 4, PC, MemoryExceptionType::WRITE_WORD, "sc"); return; @@ -387,7 +387,7 @@ namespace MIPSInt } - void Int_RType3(MIPSOpcode op) { + void Int_RType3(MIPSState *mips, MIPSOpcode op) { int rt = _RT; int rs = _RS; int rd = _RD; @@ -421,7 +421,7 @@ namespace MIPSInt } - void Int_ITypeMem(MIPSOpcode op) { + void Int_ITypeMem(MIPSState *mips, MIPSOpcode op) { int imm = (signed short)(op&0xFFFF); int rt = _RT; int rs = _RS; @@ -557,7 +557,7 @@ namespace MIPSInt PC += 4; } - void Int_FPULS(MIPSOpcode op) { + void Int_FPULS(MIPSState *mips, MIPSOpcode op) { s32 offset = (s16)(op & 0xFFFF); int ft = _FT; int rs = _RS; @@ -585,7 +585,7 @@ namespace MIPSInt PC += 4; } - void Int_mxc1(MIPSOpcode op) + void Int_mxc1(MIPSState *mips, MIPSOpcode op) { int fs = _FS; int rt = _RT; @@ -599,8 +599,8 @@ namespace MIPSInt case 2: //cfc1 if (rt != 0) { if (fs == 31) { - currentMIPS->fcr31 = (currentMIPS->fcr31 & ~(1<<23)) | ((currentMIPS->fpcond & 1)<<23); - R(rt) = currentMIPS->fcr31; + mips->fcr31 = (mips->fcr31 & ~(1<<23)) | ((mips->fpcond & 1)<<23); + R(rt) = mips->fcr31; } else if (fs == 0) { R(rt) = MIPSState::FCR0_VALUE; } else { @@ -619,8 +619,8 @@ namespace MIPSInt { u32 value = R(rt); if (fs == 31) { - currentMIPS->fcr31 = value & 0x0181FFFF; - currentMIPS->fpcond = (value >> 23) & 1; + mips->fcr31 = value & 0x0181FFFF; + mips->fpcond = (value >> 23) & 1; // Don't bother locking, assuming the CPU can't be reset now anyway. if (MIPSComp::jit) { // In case of DISABLE, we need to tell jit we updated FCR31. @@ -640,7 +640,7 @@ namespace MIPSInt PC += 4; } - void Int_RType2(MIPSOpcode op) + void Int_RType2(MIPSState *mips, MIPSOpcode op) { int rs = _RS; int rd = _RD; @@ -667,7 +667,7 @@ namespace MIPSInt PC += 4; } - void Int_MulDivType(MIPSOpcode op) + void Int_MulDivType(MIPSState *mips, MIPSOpcode op) { int rt = _RT; int rs = _RS; @@ -772,7 +772,7 @@ namespace MIPSInt } - void Int_ShiftType(MIPSOpcode op) + void Int_ShiftType(MIPSState *mips, MIPSOpcode op) { int rt = _RT; int rs = _RS; @@ -826,7 +826,7 @@ namespace MIPSInt PC += 4; } - void Int_Allegrex(MIPSOpcode op) + void Int_Allegrex(MIPSState *mips, MIPSOpcode op) { int rt = _RT; int rd = _RD; @@ -859,7 +859,7 @@ namespace MIPSInt PC += 4; } - void Int_Allegrex2(MIPSOpcode op) + void Int_Allegrex2(MIPSState *mips, MIPSOpcode op) { int rt = _RT; int rd = _RD; @@ -886,7 +886,7 @@ namespace MIPSInt PC += 4; } - void Int_Special2(MIPSOpcode op) + void Int_Special2(MIPSState *mips, MIPSOpcode op) { static int reported = 0; switch (op & 0x3F) @@ -912,7 +912,7 @@ namespace MIPSInt PC += 4; } - void Int_Special3(MIPSOpcode op) + void Int_Special3(MIPSState *mips, MIPSOpcode op) { int rs = _RS; int rt = _RT; @@ -945,7 +945,7 @@ namespace MIPSInt PC += 4; } - void Int_FPU2op(MIPSOpcode op) + void Int_FPU2op(MIPSState *mips, MIPSOpcode op) { int fs = _FS; int fd = _FD; @@ -992,7 +992,7 @@ namespace MIPSInt FsI(fd) = my_isinf(F(fs)) && F(fs) < 0.0f ? -2147483648LL : 2147483647LL; break; } - switch (currentMIPS->fcr31 & 3) + switch (mips->fcr31 & 3) { case 0: FsI(fd) = (int)round_ieee_754(F(fs)); break; // RINT_0 case 1: FsI(fd) = (int)F(fs); break; // CAST_1 @@ -1007,7 +1007,7 @@ namespace MIPSInt PC += 4; } - void Int_FPUComp(MIPSOpcode op) + void Int_FPUComp(MIPSState *mips, MIPSOpcode op) { int fs = _FS; int ft = _FT; @@ -1059,11 +1059,11 @@ namespace MIPSInt cond = false; break; } - currentMIPS->fpcond = cond; + mips->fpcond = cond; PC += 4; } - void Int_FPU3op(MIPSOpcode op) + void Int_FPU3op(MIPSState *mips, MIPSOpcode op) { int ft = _FT; int fs = _FS; @@ -1089,7 +1089,7 @@ namespace MIPSInt PC += 4; } - void Int_Interrupt(MIPSOpcode op) + void Int_Interrupt(MIPSState *mips, MIPSOpcode op) { static int reported = 0; switch (op & 1) @@ -1097,7 +1097,7 @@ namespace MIPSInt case 0: // unlikely to be legitimately used if (!reported) { - Reporting::ReportMessage("INTERRUPT instruction hit (%08x) at %08x", op.encoding, currentMIPS->pc); + Reporting::ReportMessage("INTERRUPT instruction hit (%08x) at %08x", op.encoding, mips->pc); WARN_LOG(Log::CPU, "Disable/Enable Interrupt CPU instruction"); reported = 1; } @@ -1106,7 +1106,7 @@ namespace MIPSInt PC += 4; } - void Int_Emuhack(MIPSOpcode op) + void Int_Emuhack(MIPSState *mips, MIPSOpcode op) { if (((op >> 24) & 3) != EMUOP_CALL_REPLACEMENT) { _dbg_assert_msg_(false, "Trying to interpret emuhack instruction that can't be interpreted"); @@ -1122,20 +1122,20 @@ namespace MIPSInt if (entry->flags & (REPFLAG_HOOKENTER | REPFLAG_HOOKEXIT)) { // Interpret the original instruction under the hook. - MIPSInterpret(currentMIPS, Memory::Read_Instruction(PC, true)); + MIPSInterpret(mips, Memory::Read_Instruction(PC, true)); } else if (cycles < 0) { // Leave PC unchanged, call the replacement again (assumes args are modified.) - currentMIPS->downcount += cycles; + mips->downcount += cycles; } else { - PC = currentMIPS->r[MIPS_REG_RA]; - currentMIPS->downcount -= cycles; + PC = mips->r[MIPS_REG_RA]; + mips->downcount -= cycles; } } else { if (!entry || !entry->replaceFunc) { ERROR_LOG(Log::CPU, "Bad replacement function index %i", index); } // Interpret the original instruction under it. - MIPSInterpret(currentMIPS, Memory::Read_Instruction(PC, true)); + MIPSInterpret(mips, Memory::Read_Instruction(PC, true)); } } } diff --git a/Core/MIPS/Interpreter.h b/Core/MIPS/Interpreter.h index 030a0b9fd3..02dc35244c 100644 --- a/Core/MIPS/Interpreter.h +++ b/Core/MIPS/Interpreter.h @@ -24,32 +24,32 @@ int MIPS_SingleStep(MIPSState *mips); namespace MIPSInt { - void Int_Syscall(MIPSOpcode op); + void Int_Syscall(MIPSState *mips, MIPSOpcode op); - void Int_mxc1(MIPSOpcode op); - void Int_RelBranch(MIPSOpcode op); - void Int_RelBranchRI(MIPSOpcode op); - void Int_IType(MIPSOpcode op); - void Int_ITypeMem(MIPSOpcode op); - void Int_RType2(MIPSOpcode op); - void Int_RType3(MIPSOpcode op); - void Int_ShiftType(MIPSOpcode op); - void Int_MulDivType(MIPSOpcode op); - void Int_JumpType(MIPSOpcode op); - void Int_JumpRegType(MIPSOpcode op); - void Int_Allegrex2(MIPSOpcode op); - void Int_FPULS(MIPSOpcode op); - void Int_FPU3op(MIPSOpcode op); - void Int_FPU2op(MIPSOpcode op); - void Int_Allegrex(MIPSOpcode op); - void Int_FPUComp(MIPSOpcode op); - void Int_FPUBranch(MIPSOpcode op); - void Int_Emuhack(MIPSOpcode op); - void Int_Special2(MIPSOpcode op); - void Int_Special3(MIPSOpcode op); - void Int_Interrupt(MIPSOpcode op); - void Int_Cache(MIPSOpcode op); - void Int_Sync(MIPSOpcode op); - void Int_Break(MIPSOpcode op); - void Int_StoreSync(MIPSOpcode op); + void Int_mxc1(MIPSState *mips, MIPSOpcode op); + void Int_RelBranch(MIPSState *mips, MIPSOpcode op); + void Int_RelBranchRI(MIPSState *mips, MIPSOpcode op); + void Int_IType(MIPSState *mips, MIPSOpcode op); + void Int_ITypeMem(MIPSState *mips, MIPSOpcode op); + void Int_RType2(MIPSState *mips, MIPSOpcode op); + void Int_RType3(MIPSState *mips, MIPSOpcode op); + void Int_ShiftType(MIPSState *mips, MIPSOpcode op); + void Int_MulDivType(MIPSState *mips, MIPSOpcode op); + void Int_JumpType(MIPSState *mips, MIPSOpcode op); + void Int_JumpRegType(MIPSState *mips, MIPSOpcode op); + void Int_Allegrex2(MIPSState *mips, MIPSOpcode op); + void Int_FPULS(MIPSState *mips, MIPSOpcode op); + void Int_FPU3op(MIPSState *mips, MIPSOpcode op); + void Int_FPU2op(MIPSState *mips, MIPSOpcode op); + void Int_Allegrex(MIPSState *mips, MIPSOpcode op); + void Int_FPUComp(MIPSState *mips, MIPSOpcode op); + void Int_FPUBranch(MIPSState *mips, MIPSOpcode op); + void Int_Emuhack(MIPSState *mips, MIPSOpcode op); + void Int_Special2(MIPSState *mips, MIPSOpcode op); + void Int_Special3(MIPSState *mips, MIPSOpcode op); + void Int_Interrupt(MIPSState *mips, MIPSOpcode op); + void Int_Cache(MIPSState *mips, MIPSOpcode op); + void Int_Sync(MIPSState *mips, MIPSOpcode op); + void Int_Break(MIPSState *mips, MIPSOpcode op); + void Int_StoreSync(MIPSState *mips, MIPSOpcode op); } diff --git a/Core/MIPS/InterpreterDispatch.cpp b/Core/MIPS/InterpreterDispatch.cpp index 88790778d9..30885ec9bf 100644 --- a/Core/MIPS/InterpreterDispatch.cpp +++ b/Core/MIPS/InterpreterDispatch.cpp @@ -24,7 +24,7 @@ // Returns the cycle count consumed, or -1 if op isn't a recognized instruction - // callers must fall back to MIPSInterpret() themselves in that case. -int ExecInstruction(MIPSOpcode op) { +int ExecInstruction(MIPSState *mips, MIPSOpcode op) { switch ((op.encoding >> 26) & 0x3f) { case 0: { @@ -36,12 +36,12 @@ int ExecInstruction(MIPSOpcode op) { case 4: case 6: case 7: - MIPSInt::Int_ShiftType(op); + MIPSInt::Int_ShiftType(mips, op); return 1; // jr, jalr case 8: case 9: - MIPSInt::Int_JumpRegType(op); + MIPSInt::Int_JumpRegType(mips, op); return 1; // movz, movn, add, addu, sub, subu, and, or, xor, nor, slt, sltu, max, min case 10: @@ -58,19 +58,19 @@ int ExecInstruction(MIPSOpcode op) { case 43: case 44: case 45: - MIPSInt::Int_RType3(op); + MIPSInt::Int_RType3(mips, op); return 1; // syscall case 12: - MIPSInt::Int_Syscall(op); + MIPSInt::Int_Syscall(mips, op); return 1; // break case 13: - MIPSInt::Int_Break(op); + MIPSInt::Int_Break(mips, op); return 1; // sync case 15: - MIPSInt::Int_Sync(op); + MIPSInt::Int_Sync(mips, op); return 1; // mfhi, mthi, mflo, mtlo, mult, multu, div, divu, madd, maddu, msub, msubu case 16: @@ -85,12 +85,12 @@ int ExecInstruction(MIPSOpcode op) { case 29: case 46: case 47: - MIPSInt::Int_MulDivType(op); + MIPSInt::Int_MulDivType(mips, op); return 1; // clz, clo case 22: case 23: - MIPSInt::Int_RType2(op); + MIPSInt::Int_RType2(mips, op); return 1; default: return -1; @@ -108,7 +108,7 @@ int ExecInstruction(MIPSOpcode op) { case 17: case 18: case 19: - MIPSInt::Int_RelBranchRI(op); + MIPSInt::Int_RelBranchRI(mips, op); return 1; default: return -1; @@ -117,7 +117,7 @@ int ExecInstruction(MIPSOpcode op) { // j, jal case 2: case 3: - MIPSInt::Int_JumpType(op); + MIPSInt::Int_JumpType(mips, op); return 1; // beq, bne, blez, bgtz, beql, bnel, blezl, bgtzl case 4: @@ -128,7 +128,7 @@ int ExecInstruction(MIPSOpcode op) { case 21: case 22: case 23: - MIPSInt::Int_RelBranch(op); + MIPSInt::Int_RelBranch(mips, op); return 1; // addi, addiu, slti, sltiu, andi, ori, xori, lui case 8: @@ -139,7 +139,7 @@ int ExecInstruction(MIPSOpcode op) { case 13: case 14: case 15: - MIPSInt::Int_IType(op); + MIPSInt::Int_IType(mips, op); return 1; case 16: { @@ -175,7 +175,7 @@ int ExecInstruction(MIPSOpcode op) { case 2: case 4: case 6: - MIPSInt::Int_mxc1(op); + MIPSInt::Int_mxc1(mips, op); return 1; case 8: { @@ -185,7 +185,7 @@ int ExecInstruction(MIPSOpcode op) { case 1: case 2: case 3: - MIPSInt::Int_FPUBranch(op); + MIPSInt::Int_FPUBranch(mips, op); return 1; default: return -1; @@ -198,11 +198,11 @@ int ExecInstruction(MIPSOpcode op) { case 0: case 1: case 2: - MIPSInt::Int_FPU3op(op); + MIPSInt::Int_FPU3op(mips, op); return 1; // div.s case 3: - MIPSInt::Int_FPU3op(op); + MIPSInt::Int_FPU3op(mips, op); return 29; // sqrt.s, abs.s, mov.s, neg.s, round.w.s, trunc.w.s, ceil.w.s, floor.w.s, cvt.w.s case 4: @@ -214,11 +214,11 @@ int ExecInstruction(MIPSOpcode op) { case 14: case 15: case 36: - MIPSInt::Int_FPU2op(op); + MIPSInt::Int_FPU2op(mips, op); return 1; // dis.int case 38: - MIPSInt::Int_Interrupt(op); + MIPSInt::Int_Interrupt(mips, op); return 1; // c.f.s, c.un.s, c.eq.s, c.ueq.s, c.olt.s, c.ult.s, c.ole.s, c.ule.s, c.sf.s, c.ngle.s, c.seq.s, c.ngl.s, c.lt.s, c.nge.s, c.le.s, c.ngt.s case 48: @@ -237,7 +237,7 @@ int ExecInstruction(MIPSOpcode op) { case 61: case 62: case 63: - MIPSInt::Int_FPUComp(op); + MIPSInt::Int_FPUComp(mips, op); return 1; default: return -1; @@ -248,7 +248,7 @@ int ExecInstruction(MIPSOpcode op) { switch ((op.encoding >> 0) & 0x3f) { // cvt.s.w case 32: - MIPSInt::Int_FPU2op(op); + MIPSInt::Int_FPU2op(mips, op); return 1; default: return -1; @@ -264,7 +264,7 @@ int ExecInstruction(MIPSOpcode op) { // mfv, mtv case 3: case 7: - MIPSInt::Int_Mftv(op); + MIPSInt::Int_Mftv(mips, op); return 2; case 8: { @@ -274,7 +274,7 @@ int ExecInstruction(MIPSOpcode op) { case 1: case 2: case 3: - MIPSInt::Int_VBranch(op); + MIPSInt::Int_VBranch(mips, op); return 2; default: return -1; @@ -291,11 +291,11 @@ int ExecInstruction(MIPSOpcode op) { case 0: case 1: case 7: - MIPSInt::Int_VecDo3(op); + MIPSInt::Int_VecDo3(mips, op); return 2; // vsbn case 2: - MIPSInt::Int_Vsbn(op); + MIPSInt::Int_Vsbn(mips, op); return 2; default: return -1; @@ -306,27 +306,27 @@ int ExecInstruction(MIPSOpcode op) { switch ((op.encoding >> 23) & 0x7) { // vmul case 0: - MIPSInt::Int_VecDo3(op); + MIPSInt::Int_VecDo3(mips, op); return 2; // vdot case 1: - MIPSInt::Int_VDot(op); + MIPSInt::Int_VDot(mips, op); return 2; // vscl case 2: - MIPSInt::Int_VScl(op); + MIPSInt::Int_VScl(mips, op); return 2; // vhdp case 4: - MIPSInt::Int_VHdp(op); + MIPSInt::Int_VHdp(mips, op); return 2; // vcrs case 5: - MIPSInt::Int_Vcrs(op); + MIPSInt::Int_Vcrs(mips, op); return 2; // vdet case 6: - MIPSInt::Int_Vdet(op); + MIPSInt::Int_Vdet(mips, op); return 2; default: return -1; @@ -337,12 +337,12 @@ int ExecInstruction(MIPSOpcode op) { switch ((op.encoding >> 24) & 0x3) { // RUNBLOCK case 0: - MIPSInt::Int_Emuhack(op); + MIPSInt::Int_Emuhack(mips, op); return 2; // RetKrnl, CallRepl case 1: case 2: - MIPSInt::Int_Emuhack(op); + MIPSInt::Int_Emuhack(mips, op); return 1; default: return -1; @@ -353,24 +353,24 @@ int ExecInstruction(MIPSOpcode op) { switch ((op.encoding >> 23) & 0x7) { // vcmp case 0: - MIPSInt::Int_Vcmp(op); + MIPSInt::Int_Vcmp(mips, op); return 2; // vmin, vmax case 2: case 3: - MIPSInt::Int_Vminmax(op); + MIPSInt::Int_Vminmax(mips, op); return 2; // vscmp case 5: - MIPSInt::Int_Vscmp(op); + MIPSInt::Int_Vscmp(mips, op); return 2; // vsge case 6: - MIPSInt::Int_Vsge(op); + MIPSInt::Int_Vsge(mips, op); return 2; // vslt case 7: - MIPSInt::Int_Vslt(op); + MIPSInt::Int_Vslt(mips, op); return 2; default: return -1; @@ -382,7 +382,7 @@ int ExecInstruction(MIPSOpcode op) { // mfic, mtic case 36: case 38: - MIPSInt::Int_Special2(op); + MIPSInt::Int_Special2(mips, op); return 1; default: return -1; @@ -394,7 +394,7 @@ int ExecInstruction(MIPSOpcode op) { // ext, ins case 0: case 4: - MIPSInt::Int_Special3(op); + MIPSInt::Int_Special3(mips, op); return 1; case 24: case 32: @@ -403,13 +403,13 @@ int ExecInstruction(MIPSOpcode op) { // wsbh, wsbw case 2: case 3: - MIPSInt::Int_Allegrex2(op); + MIPSInt::Int_Allegrex2(mips, op); return 1; // seb, bitrev, seh case 16: case 20: case 24: - MIPSInt::Int_Allegrex(op); + MIPSInt::Int_Allegrex(mips, op); return 1; default: return -1; @@ -432,26 +432,26 @@ int ExecInstruction(MIPSOpcode op) { case 42: case 43: case 46: - MIPSInt::Int_ITypeMem(op); + MIPSInt::Int_ITypeMem(mips, op); return 1; // cache case 47: - MIPSInt::Int_Cache(op); + MIPSInt::Int_Cache(mips, op); return 1; // ll, sc case 48: case 56: - MIPSInt::Int_StoreSync(op); + MIPSInt::Int_StoreSync(mips, op); return 1; // lwc1, swc1 case 49: case 57: - MIPSInt::Int_FPULS(op); + MIPSInt::Int_FPULS(mips, op); return 1; // lv.s, sv.s case 50: case 58: - MIPSInt::Int_SV(op); + MIPSInt::Int_SV(mips, op); return 2; case 52: { @@ -476,16 +476,16 @@ int ExecInstruction(MIPSOpcode op) { case 24: case 26: case 28: - MIPSInt::Int_VV2Op(op); + MIPSInt::Int_VV2Op(mips, op); return 2; // vidt case 3: - MIPSInt::Int_Vidt(op); + MIPSInt::Int_Vidt(mips, op); return 2; // vzero, vone case 6: case 7: - MIPSInt::Int_VVectorInit(op); + MIPSInt::Int_VVectorInit(mips, op); return 2; default: return -1; @@ -496,43 +496,43 @@ int ExecInstruction(MIPSOpcode op) { switch ((op.encoding >> 16) & 0x1f) { // vrnds case 0: - MIPSInt::Int_Vrnds(op); + MIPSInt::Int_Vrnds(mips, op); return 2; // vrndi, vrndf1, vrndf2 case 1: case 2: case 3: - MIPSInt::Int_VrndX(op); + MIPSInt::Int_VrndX(mips, op); return 2; // vf2h case 18: - MIPSInt::Int_Vf2h(op); + MIPSInt::Int_Vf2h(mips, op); return 2; // vh2f case 19: - MIPSInt::Int_Vh2f(op); + MIPSInt::Int_Vh2f(mips, op); return 2; // vsbz case 22: - MIPSInt::Int_Vsbz(op); + MIPSInt::Int_Vsbz(mips, op); return 2; // vlgb case 23: - MIPSInt::Int_Vlgb(op); + MIPSInt::Int_Vlgb(mips, op); return 2; // vuc2ifs, vc2i, vus2i, vs2i case 24: case 25: case 26: case 27: - MIPSInt::Int_Vx2i(op); + MIPSInt::Int_Vx2i(mips, op); return 2; // vi2uc, vi2c, vi2us, vi2s case 28: case 29: case 30: case 31: - MIPSInt::Int_Vi2x(op); + MIPSInt::Int_Vi2x(mips, op); return 2; default: return -1; @@ -543,58 +543,58 @@ int ExecInstruction(MIPSOpcode op) { switch ((op.encoding >> 16) & 0x1f) { // vsrt1 case 0: - MIPSInt::Int_Vsrt1(op); + MIPSInt::Int_Vsrt1(mips, op); return 2; // vsrt2 case 1: - MIPSInt::Int_Vsrt2(op); + MIPSInt::Int_Vsrt2(mips, op); return 2; // vbfy1, vbfy2 case 2: case 3: - MIPSInt::Int_Vbfy(op); + MIPSInt::Int_Vbfy(mips, op); return 2; // vocp case 4: - MIPSInt::Int_Vocp(op); + MIPSInt::Int_Vocp(mips, op); return 2; // vsocp case 5: - MIPSInt::Int_Vsocp(op); + MIPSInt::Int_Vsocp(mips, op); return 2; // vfad case 6: - MIPSInt::Int_Vfad(op); + MIPSInt::Int_Vfad(mips, op); return 2; // vavg case 7: - MIPSInt::Int_Vavg(op); + MIPSInt::Int_Vavg(mips, op); return 2; // vsrt3 case 8: - MIPSInt::Int_Vsrt3(op); + MIPSInt::Int_Vsrt3(mips, op); return 2; // vsrt4 case 9: - MIPSInt::Int_Vsrt4(op); + MIPSInt::Int_Vsrt4(mips, op); return 2; // vsgn case 10: - MIPSInt::Int_Vsgn(op); + MIPSInt::Int_Vsgn(mips, op); return 2; // vmfvc case 16: - MIPSInt::Int_Vmfvc(op); + MIPSInt::Int_Vmfvc(mips, op); return 2; // vmtvc case 17: - MIPSInt::Int_Vmtvc(op); + MIPSInt::Int_Vmtvc(mips, op); return 2; // vt4444, vt5551, vt5650 case 25: case 26: case 27: - MIPSInt::Int_ColorConv(op); + MIPSInt::Int_ColorConv(mips, op); return 2; default: return -1; @@ -602,22 +602,22 @@ int ExecInstruction(MIPSOpcode op) { } // vcst case 3: - MIPSInt::Int_Vcst(op); + MIPSInt::Int_Vcst(mips, op); return 2; // vf2in, vf2iz, vf2iu, vf2id case 16: case 17: case 18: case 19: - MIPSInt::Int_Vf2i(op); + MIPSInt::Int_Vf2i(mips, op); return 2; // vi2f case 20: - MIPSInt::Int_Vi2f(op); + MIPSInt::Int_Vi2f(mips, op); return 2; // vcmov case 21: - MIPSInt::Int_Vcmov(op); + MIPSInt::Int_Vcmov(mips, op); return 2; // vwbn, vwbn, vwbn, vwbn, vwbn, vwbn, vwbn, vwbn case 24: @@ -628,7 +628,7 @@ int ExecInstruction(MIPSOpcode op) { case 29: case 30: case 31: - MIPSInt::Int_Vwbn(op); + MIPSInt::Int_Vwbn(mips, op); return 2; default: return -1; @@ -639,7 +639,7 @@ int ExecInstruction(MIPSOpcode op) { case 54: case 61: case 62: - MIPSInt::Int_SVQ(op); + MIPSInt::Int_SVQ(mips, op); return 2; case 55: { @@ -651,12 +651,12 @@ int ExecInstruction(MIPSOpcode op) { case 3: case 4: case 5: - MIPSInt::Int_VPFX(op); + MIPSInt::Int_VPFX(mips, op); return 2; // viim.s, vfim.s case 6: case 7: - MIPSInt::Int_Viim(op); + MIPSInt::Int_Viim(mips, op); return 2; default: return -1; @@ -670,7 +670,7 @@ int ExecInstruction(MIPSOpcode op) { case 1: case 2: case 3: - MIPSInt::Int_Vmmul(op); + MIPSInt::Int_Vmmul(mips, op); return 2; // v(h)tfm2, v(h)tfm2, v(h)tfm2, v(h)tfm2, v(h)tfm3, v(h)tfm3, v(h)tfm3, v(h)tfm3, v(h)tfm4, v(h)tfm4, v(h)tfm4, v(h)tfm4 case 4: @@ -685,34 +685,34 @@ int ExecInstruction(MIPSOpcode op) { case 13: case 14: case 15: - MIPSInt::Int_Vtfm(op); + MIPSInt::Int_Vtfm(mips, op); return 2; // vmscl, vmscl, vmscl, vmscl case 16: case 17: case 18: case 19: - MIPSInt::Int_Vmscl(op); + MIPSInt::Int_Vmscl(mips, op); return 2; // vcrsp.t/vqmul.q, vcrsp.t/vqmul.q, vcrsp.t/vqmul.q, vcrsp.t/vqmul.q case 20: case 21: case 22: case 23: - MIPSInt::Int_CrossQuat(op); + MIPSInt::Int_CrossQuat(mips, op); return 2; case 28: { switch ((op.encoding >> 16) & 0xf) { // vmmov case 0: - MIPSInt::Int_Vmmov(op); + MIPSInt::Int_Vmmov(mips, op); return 2; // vmidt, vmzero, vmone case 3: case 6: case 7: - MIPSInt::Int_VMatrixInit(op); + MIPSInt::Int_VMatrixInit(mips, op); return 2; default: return -1; @@ -720,7 +720,7 @@ int ExecInstruction(MIPSOpcode op) { } // vrot case 29: - MIPSInt::Int_Vrot(op); + MIPSInt::Int_Vrot(mips, op); return 2; default: return -1; @@ -728,7 +728,7 @@ int ExecInstruction(MIPSOpcode op) { } // vflush case 63: - MIPSInt::Int_Vflush(op); + MIPSInt::Int_Vflush(mips, op); return 2; default: return -1; diff --git a/Core/MIPS/InterpreterDispatch.h b/Core/MIPS/InterpreterDispatch.h index 6767b8249c..e569eabe86 100644 --- a/Core/MIPS/InterpreterDispatch.h +++ b/Core/MIPS/InterpreterDispatch.h @@ -20,11 +20,11 @@ #include "Core/MIPS/MIPS.h" // Fast switch-tree interpreter dispatcher, generated into InterpreterDispatch.cpp by -// GenerateInterpreterDispatch() in MIPSTables.cpp. Executes op on the global currentMIPS -// (same convention as the MIPSInt::Int_* handlers it calls into) and returns the number of -// cycles it consumed - or -1 if op isn't a recognized instruction (an invalid encoding, or -// one of the handful of real instructions with no interpreter implementation, e.g. -// tge/tlt/teq/...). Not total by design: the caller must fall back to MIPSInterpret() on a -// negative return, since deciding what "unhandled" means is a caller policy, not something -// a mechanically generated dispatch tree should embed. -int ExecInstruction(MIPSOpcode op); +// GenerateInterpreterDispatch() in MIPSTables.cpp. Executes op on mips (same convention as +// the MIPSInt::Int_* handlers it calls into) and returns the number of cycles it consumed - +// or -1 if op isn't a recognized instruction (an invalid encoding, or one of the handful of +// real instructions with no interpreter implementation, e.g. tge/tlt/teq/...). Not total by +// design: the caller must fall back to MIPSInterpret() on a negative return, since deciding +// what "unhandled" means is a caller policy, not something a mechanically generated dispatch +// tree should embed. +int ExecInstruction(MIPSState *mips, MIPSOpcode op); diff --git a/Core/MIPS/InterpreterVFPU.cpp b/Core/MIPS/InterpreterVFPU.cpp index 71c673f311..3472e4e59a 100644 --- a/Core/MIPS/InterpreterVFPU.cpp +++ b/Core/MIPS/InterpreterVFPU.cpp @@ -32,15 +32,16 @@ #include "Core/MIPS/MIPS.h" #include "Core/MIPS/Interpreter.h" +#include "Core/MIPS/InterpreterVFPU.h" #include "Core/MIPS/MIPSTables.h" #include "Core/MIPS/MIPSVFPUUtils.h" -#define R(i) (currentMIPS->r[i]) -#define V(i) (currentMIPS->v[voffset[i]]) -#define VI(i) (currentMIPS->vi[voffset[i]]) -#define FI(i) (currentMIPS->fi[i]) -#define FsI(i) (currentMIPS->fs[i]) -#define PC (currentMIPS->pc) +#define R(i) (mips->r[i]) +#define V(i) (mips->v[voffset[i]]) +#define VI(i) (mips->vi[voffset[i]]) +#define FI(i) (mips->fi[i]) +#define FsI(i) (mips->fs[i]) +#define PC (mips->pc) #define _RS ((op>>21) & 0x1F) #define _RT ((op>>16) & 0x1F) @@ -51,8 +52,8 @@ #define _POS ((op>>6 ) & 0x1F) #define _SIZE ((op>>11) & 0x1F) -#define HI currentMIPS->hi -#define LO currentMIPS->lo +#define HI mips->hi +#define LO mips->lo #ifndef M_LOG2E #define M_E 2.71828182845904523536f @@ -101,7 +102,7 @@ inline float nanclamp(float f, float lower, float upper) return nanmin(nanmax(f, lower), upper); } -static void ApplyPrefixST(float *r, u32 data, VectorSize size, float invalid = 0.0f) { +static void ApplyPrefixST(MIPSState *mips, float *r, u32 data, VectorSize size, float invalid = 0.0f) { // Check for no prefix. if (data == 0xe4) return; @@ -123,7 +124,7 @@ static void ApplyPrefixST(float *r, u32 data, VectorSize size, float invalid = 0 if (!constants) { if (regnum >= n) { // We mostly handle this now, but still worth reporting. - ERROR_LOG_REPORT(Log::CPU, "Invalid VFPU swizzle: %08x: %i / %d at PC = %08x (%s)", data, regnum, n, currentMIPS->pc, MIPSDisasmAt(currentMIPS->pc).c_str()); + ERROR_LOG_REPORT(Log::CPU, "Invalid VFPU swizzle: %08x: %i / %d at PC = %08x (%s)", data, regnum, n, mips->pc, MIPSDisasmAt(mips->pc).c_str()); } r[i] = origV[regnum]; if (abs) @@ -137,19 +138,19 @@ static void ApplyPrefixST(float *r, u32 data, VectorSize size, float invalid = 0 } } -inline void ApplySwizzleS(float *v, VectorSize size, float invalid = 0.0f) +inline void ApplySwizzleS(MIPSState *mips, float *v, VectorSize size, float invalid = 0.0f) { - ApplyPrefixST(v, currentMIPS->vfpuCtrl[VFPU_CTRL_SPREFIX], size, invalid); + ApplyPrefixST(mips, v, mips->vfpuCtrl[VFPU_CTRL_SPREFIX], size, invalid); } -inline void ApplySwizzleT(float *v, VectorSize size, float invalid = 0.0f) +inline void ApplySwizzleT(MIPSState *mips, float *v, VectorSize size, float invalid = 0.0f) { - ApplyPrefixST(v, currentMIPS->vfpuCtrl[VFPU_CTRL_TPREFIX], size, invalid); + ApplyPrefixST(mips, v, mips->vfpuCtrl[VFPU_CTRL_TPREFIX], size, invalid); } -void ApplyPrefixD(float *v, VectorSize size, bool onlyWriteMask = false) +void ApplyPrefixD(MIPSState *mips, float *v, VectorSize size, bool onlyWriteMask = false) { - u32 data = currentMIPS->vfpuCtrl[VFPU_CTRL_DPREFIX]; + u32 data = mips->vfpuCtrl[VFPU_CTRL_DPREFIX]; if (!data || onlyWriteMask) return; int n = GetNumVectorElements(size); @@ -163,11 +164,11 @@ void ApplyPrefixD(float *v, VectorSize size, bool onlyWriteMask = false) } } -static void RetainInvalidSwizzleST(float *d, VectorSize sz) { +static void RetainInvalidSwizzleST(MIPSState *mips, float *d, VectorSize sz) { // Somehow it's like a supernan, maybe wires through to zero? // Doesn't apply to all ops. - int sPrefix = currentMIPS->vfpuCtrl[VFPU_CTRL_SPREFIX]; - int tPrefix = currentMIPS->vfpuCtrl[VFPU_CTRL_TPREFIX]; + int sPrefix = mips->vfpuCtrl[VFPU_CTRL_SPREFIX]; + int tPrefix = mips->vfpuCtrl[VFPU_CTRL_TPREFIX]; int n = GetNumVectorElements(sz); // TODO: We can probably do some faster check of sPrefix and tPrefix to skip over this loop. @@ -181,26 +182,26 @@ static void RetainInvalidSwizzleST(float *d, VectorSize sz) { } } -void EatPrefixes() +void EatPrefixes(MIPSState *mips) { - currentMIPS->vfpuCtrl[VFPU_CTRL_SPREFIX] = 0xe4; // passthru - currentMIPS->vfpuCtrl[VFPU_CTRL_TPREFIX] = 0xe4; // passthru - currentMIPS->vfpuCtrl[VFPU_CTRL_DPREFIX] = 0; + mips->vfpuCtrl[VFPU_CTRL_SPREFIX] = 0xe4; // passthru + mips->vfpuCtrl[VFPU_CTRL_TPREFIX] = 0xe4; // passthru + mips->vfpuCtrl[VFPU_CTRL_DPREFIX] = 0; } namespace MIPSInt { - void Int_VPFX(MIPSOpcode op) + void Int_VPFX(MIPSState *mips, MIPSOpcode op) { int data = op & 0x000FFFFF; int regnum = (op >> 24) & 3; if (regnum == VFPU_CTRL_DPREFIX) data &= 0x00000FFF; - currentMIPS->vfpuCtrl[VFPU_CTRL_SPREFIX + regnum] = data; + mips->vfpuCtrl[VFPU_CTRL_SPREFIX + regnum] = data; PC += 4; } - void Int_SVQ(MIPSOpcode op) { + void Int_SVQ(MIPSState *mips, MIPSOpcode op) { int imm = SignExtend16ToS32(op & 0xFFFC); int rs = _RS; int vt = (((op >> 16) & 0x1f)) | ((op&1) << 5); @@ -314,7 +315,7 @@ namespace MIPSInt PC += 4; } - void Int_VMatrixInit(MIPSOpcode op) { + void Int_VMatrixInit(MIPSState *mips, MIPSOpcode op) { static const float idt[16] = { 1,0,0,0, 0,1,0,0, @@ -344,12 +345,12 @@ namespace MIPSInt default: _dbg_assert_msg_(false,"Trying to interpret instruction that can't be interpreted"); PC += 4; - EatPrefixes(); + EatPrefixes(mips); return; } // The S prefix generates constants, but only for the final (possibly transposed) row. - if (currentMIPS->vfpuCtrl[VFPU_CTRL_SPREFIX] & 0xF0F00) { + if (mips->vfpuCtrl[VFPU_CTRL_SPREFIX] & 0xF0F00) { float prefixed[16]; memcpy(prefixed, m, sizeof(prefixed)); @@ -376,17 +377,17 @@ namespace MIPSInt _dbg_assert_msg_( 0, "Unknown matrix init op"); break; } - ApplyPrefixST(&prefixed[off * 4], VFPURewritePrefix(VFPU_CTRL_SPREFIX, sprefixRemove, sprefixAdd), V_Quad); + ApplyPrefixST(mips, &prefixed[off * 4], VFPURewritePrefix(VFPU_CTRL_SPREFIX, sprefixRemove, sprefixAdd), V_Quad); WriteMatrix(prefixed, sz, vd); } else { // Write mask applies to the final (maybe transposed) row. Sat causes hang. WriteMatrix(m, sz, vd); } PC += 4; - EatPrefixes(); + EatPrefixes(mips); } - void Int_VVectorInit(MIPSOpcode op) + void Int_VVectorInit(MIPSState *mips, MIPSOpcode op) { int vd = _VD; VectorSize sz = GetVecSize(op); @@ -399,23 +400,23 @@ namespace MIPSInt default: _dbg_assert_msg_( 0, "Trying to interpret instruction that can't be interpreted"); PC += 4; - EatPrefixes(); + EatPrefixes(mips); return; } // The S prefix generates constants, but negate is still respected. u32 sprefixRemove = VFPU_ANY_SWIZZLE(); u32 sprefixAdd = VFPU_MAKE_CONSTANTS(constant, constant, constant, constant); - ApplyPrefixST(d, VFPURewritePrefix(VFPU_CTRL_SPREFIX, sprefixRemove, sprefixAdd), sz); + ApplyPrefixST(mips, d, VFPURewritePrefix(VFPU_CTRL_SPREFIX, sprefixRemove, sprefixAdd), sz); - ApplyPrefixD(d, sz); + ApplyPrefixD(mips, d, sz); WriteVector(d, sz, vd); - EatPrefixes(); + EatPrefixes(mips); PC += 4; } - void Int_Viim(MIPSOpcode op) { + void Int_Viim(MIPSState *mips, MIPSOpcode op) { int vt = _VT; s32 imm = SignExtend16ToS32(op & 0xFFFF); u16 uimm16 = (op&0xFFFF); @@ -430,13 +431,13 @@ namespace MIPSInt f[0] = 0; } - ApplyPrefixD(f, V_Single); + ApplyPrefixD(mips, f, V_Single); WriteVector(f, V_Single, vt); PC += 4; - EatPrefixes(); + EatPrefixes(mips); } - void Int_Vidt(MIPSOpcode op) { + void Int_Vidt(MIPSState *mips, MIPSOpcode op) { int vd = _VD; VectorSize sz = GetVecSize(op); float f[4]; @@ -452,16 +453,16 @@ namespace MIPSInt u32 sprefixRemove = VFPU_ANY_SWIZZLE(); u32 sprefixAdd = VFPU_MAKE_CONSTANTS(constX, constY, constZ, constW); - ApplyPrefixST(f, VFPURewritePrefix(VFPU_CTRL_SPREFIX, sprefixRemove, sprefixAdd), sz); + ApplyPrefixST(mips, f, VFPURewritePrefix(VFPU_CTRL_SPREFIX, sprefixRemove, sprefixAdd), sz); - ApplyPrefixD(f, sz); + ApplyPrefixD(mips, f, sz); WriteVector(f, sz, vd); PC += 4; - EatPrefixes(); + EatPrefixes(mips); } // The test really needs some work. - void Int_Vmmul(MIPSOpcode op) { + void Int_Vmmul(MIPSState *mips, MIPSOpcode op) { float s[16]{}, t[16]{}, d[16]; int vd = _VD; @@ -480,8 +481,8 @@ namespace MIPSInt union { float f; uint32_t u; } sum = { 0.0f }; if (a == n - 1 && b == n - 1) { // S and T prefixes work on the final (or maybe first, in reverse?) dot. - ApplySwizzleS(&s[b * 4], V_Quad); - ApplySwizzleT(&t[a * 4], V_Quad); + ApplySwizzleS(mips, &s[b * 4], V_Quad); + ApplySwizzleT(mips, &t[a * 4], V_Quad); } if (useAccurateDot) { @@ -508,16 +509,16 @@ namespace MIPSInt } // The D prefix applies ONLY to the final element, but sat does work. - u32 lastmask = (currentMIPS->vfpuCtrl[VFPU_CTRL_DPREFIX] & (1 << 8)) << (n - 1); - u32 lastsat = (currentMIPS->vfpuCtrl[VFPU_CTRL_DPREFIX] & 3) << (n + n - 2); - currentMIPS->vfpuCtrl[VFPU_CTRL_DPREFIX] = lastmask | lastsat; - ApplyPrefixD(&d[4 * (n - 1)], V_Quad, false); + u32 lastmask = (mips->vfpuCtrl[VFPU_CTRL_DPREFIX] & (1 << 8)) << (n - 1); + u32 lastsat = (mips->vfpuCtrl[VFPU_CTRL_DPREFIX] & 3) << (n + n - 2); + mips->vfpuCtrl[VFPU_CTRL_DPREFIX] = lastmask | lastsat; + ApplyPrefixD(mips, &d[4 * (n - 1)], V_Quad, false); WriteMatrix(d, sz, vd); PC += 4; - EatPrefixes(); + EatPrefixes(mips); } - void Int_Vmscl(MIPSOpcode op) { + void Int_Vmscl(MIPSState *mips, MIPSOpcode op) { float s[16]{}, t[4]{}, d[16]; int vd = _VD; @@ -536,27 +537,27 @@ namespace MIPSInt } // S prefix applies to the last row. - ApplySwizzleS(&s[(n - 1) * 4], V_Quad); + ApplySwizzleS(mips, &s[(n - 1) * 4], V_Quad); // T prefix applies only for the last row, and is used per element. // This is like vscl, but instead of zzzz it uses xxxx. int tlane = (vt >> 5) & 3; t[tlane] = t[0]; u32 tprefixRemove = VFPU_ANY_SWIZZLE(); u32 tprefixAdd = VFPU_SWIZZLE(tlane, tlane, tlane, tlane); - ApplyPrefixST(t, VFPURewritePrefix(VFPU_CTRL_TPREFIX, tprefixRemove, tprefixAdd), V_Quad); + ApplyPrefixST(mips, t, VFPURewritePrefix(VFPU_CTRL_TPREFIX, tprefixRemove, tprefixAdd), V_Quad); for (int b = 0; b < n; b++) { d[(n - 1) * 4 + b] = s[(n - 1) * 4 + b] * t[b]; } // The D prefix is applied to the last row. - ApplyPrefixD(&d[(n - 1) * 4], V_Quad); + ApplyPrefixD(mips, &d[(n - 1) * 4], V_Quad); WriteMatrix(d, sz, vd); PC += 4; - EatPrefixes(); + EatPrefixes(mips); } - void Int_Vmmov(MIPSOpcode op) { + void Int_Vmmov(MIPSState *mips, MIPSOpcode op) { float s[16]{}; int vd = _VD; int vs = _VS; @@ -564,23 +565,23 @@ namespace MIPSInt ReadMatrix(s, sz, vs); // S and D prefixes are applied to the last row. int off = GetMatrixSide(sz) - 1; - ApplySwizzleS(&s[off * 4], V_Quad); - ApplyPrefixD(&s[off * 4], V_Quad); + ApplySwizzleS(mips, &s[off * 4], V_Quad); + ApplyPrefixD(mips, &s[off * 4], V_Quad); WriteMatrix(s, sz, vd); PC += 4; - EatPrefixes(); + EatPrefixes(mips); } - void Int_Vflush(MIPSOpcode op) + void Int_Vflush(MIPSState *mips, MIPSOpcode op) { VERBOSE_LOG(Log::CPU, "vflush"); PC += 4; // Anything with 0xFC000000 is a nop, but only 0xFFFF0000 retains prefixes. if ((op & 0xFFFF0000) != 0xFFFF0000) - EatPrefixes(); + EatPrefixes(mips); } - void Int_VV2Op(MIPSOpcode op) { + void Int_VV2Op(MIPSState *mips, MIPSOpcode op) { float s[4], d[4]; int vd = _VD; int vs = _VS; @@ -591,10 +592,10 @@ namespace MIPSInt // Some of these are prefix hacks (affects constants, etc.) switch (optype) { case 1: - ApplyPrefixST(s, VFPURewritePrefix(VFPU_CTRL_SPREFIX, 0, VFPU_ABS(1, 1, 1, 1)), sz); + ApplyPrefixST(mips, s, VFPURewritePrefix(VFPU_CTRL_SPREFIX, 0, VFPU_ABS(1, 1, 1, 1)), sz); break; case 2: - ApplyPrefixST(s, VFPURewritePrefix(VFPU_CTRL_SPREFIX, 0, VFPU_NEGATE(1, 1, 1, 1)), sz); + ApplyPrefixST(mips, s, VFPURewritePrefix(VFPU_CTRL_SPREFIX, 0, VFPU_NEGATE(1, 1, 1, 1)), sz); break; case 16: case 17: @@ -605,19 +606,19 @@ namespace MIPSInt case 22: case 23: // Similar to vdiv. Some of the behavior using the invalid constant is iffy. - ApplySwizzleS(&s[n - 1], V_Single, INFINITY); + ApplySwizzleS(mips, &s[n - 1], V_Single, INFINITY); break; case 24: case 26: // Similar to above, but also ignores negate. - ApplyPrefixST(&s[n - 1], VFPURewritePrefix(VFPU_CTRL_SPREFIX, VFPU_NEGATE(1, 0, 0, 0), 0), V_Single, -INFINITY); + ApplyPrefixST(mips, &s[n - 1], VFPURewritePrefix(VFPU_CTRL_SPREFIX, VFPU_NEGATE(1, 0, 0, 0), 0), V_Single, -INFINITY); break; case 28: // Similar to above, but also ignores negate. - ApplyPrefixST(&s[n - 1], VFPURewritePrefix(VFPU_CTRL_SPREFIX, VFPU_NEGATE(1, 0, 0, 0), 0), V_Single, INFINITY); + ApplyPrefixST(mips, &s[n - 1], VFPURewritePrefix(VFPU_CTRL_SPREFIX, VFPU_NEGATE(1, 0, 0, 0), 0), V_Single, INFINITY); break; default: - ApplySwizzleS(s, sz); + ApplySwizzleS(mips, s, sz); break; } for (int i = 0; i < (int)n; i++) { @@ -648,7 +649,7 @@ namespace MIPSInt // vsat1 is a prefix hack, so 0:1 doesn't apply. Others don't process sat at all. switch (optype) { case 5: - ApplyPrefixD(d, sz, true); + ApplyPrefixD(mips, d, sz, true); break; case 16: case 17: @@ -663,21 +664,21 @@ namespace MIPSInt case 28: { // Only the last element gets the mask applied. - u32 lastmask = (currentMIPS->vfpuCtrl[VFPU_CTRL_DPREFIX] & (1 << 8)) << (n - 1); - u32 lastsat = (currentMIPS->vfpuCtrl[VFPU_CTRL_DPREFIX] & 3) << (n + n - 2); - currentMIPS->vfpuCtrl[VFPU_CTRL_DPREFIX] = lastmask | lastsat; - ApplyPrefixD(d, sz); + u32 lastmask = (mips->vfpuCtrl[VFPU_CTRL_DPREFIX] & (1 << 8)) << (n - 1); + u32 lastsat = (mips->vfpuCtrl[VFPU_CTRL_DPREFIX] & 3) << (n + n - 2); + mips->vfpuCtrl[VFPU_CTRL_DPREFIX] = lastmask | lastsat; + ApplyPrefixD(mips, d, sz); break; } default: - ApplyPrefixD(d, sz); + ApplyPrefixD(mips, d, sz); } WriteVector(d, sz, vd); PC += 4; - EatPrefixes(); + EatPrefixes(mips); } - void Int_Vocp(MIPSOpcode op) { + void Int_Vocp(MIPSState *mips, MIPSOpcode op) { float s[4], t[4], d[4]; int vd = _VD; int vs = _VS; @@ -686,26 +687,26 @@ namespace MIPSInt // S prefix forces the negate flags. u32 sprefixAdd = VFPU_NEGATE(1, 1, 1, 1); - ApplyPrefixST(s, VFPURewritePrefix(VFPU_CTRL_SPREFIX, 0, sprefixAdd), sz); + ApplyPrefixST(mips, s, VFPURewritePrefix(VFPU_CTRL_SPREFIX, 0, sprefixAdd), sz); // T prefix forces constants on and regnum to 1. // That means negate still works, and abs activates a different constant. u32 tprefixRemove = VFPU_ANY_SWIZZLE(); u32 tprefixAdd = VFPU_MAKE_CONSTANTS(VFPUConst::ONE, VFPUConst::ONE, VFPUConst::ONE, VFPUConst::ONE); - ApplyPrefixST(t, VFPURewritePrefix(VFPU_CTRL_TPREFIX, tprefixRemove, tprefixAdd), sz); + ApplyPrefixST(mips, t, VFPURewritePrefix(VFPU_CTRL_TPREFIX, tprefixRemove, tprefixAdd), sz); for (int i = 0; i < GetNumVectorElements(sz); i++) { // Always positive NaN. Note that s is always negated from the registers. d[i] = my_isnan(s[i]) ? fabsf(s[i]) : t[i] + s[i]; } - RetainInvalidSwizzleST(d, sz); - ApplyPrefixD(d, sz); + RetainInvalidSwizzleST(mips, d, sz); + ApplyPrefixD(mips, d, sz); WriteVector(d, sz, vd); PC += 4; - EatPrefixes(); + EatPrefixes(mips); } - void Int_Vsocp(MIPSOpcode op) { + void Int_Vsocp(MIPSState *mips, MIPSOpcode op) { float s[4], t[4], d[4]; int vd = _VD; int vs = _VS; @@ -719,13 +720,13 @@ namespace MIPSInt // abs works, and applies to final position (not source.) u32 sprefixRemove = VFPU_ANY_SWIZZLE() | VFPU_NEGATE(1, 1, 1, 1); u32 sprefixAdd = VFPU_SWIZZLE(0, 0, 1, 1) | VFPU_NEGATE(1, 0, 1, 0); - ApplyPrefixST(s, VFPURewritePrefix(VFPU_CTRL_SPREFIX, sprefixRemove, sprefixAdd), outSize); + ApplyPrefixST(mips, s, VFPURewritePrefix(VFPU_CTRL_SPREFIX, sprefixRemove, sprefixAdd), outSize); // T prefix forces constants on and regnum to 1, 0, 1, 0. // That means negate still works, and abs activates a different constant. u32 tprefixRemove = VFPU_ANY_SWIZZLE(); u32 tprefixAdd = VFPU_MAKE_CONSTANTS(VFPUConst::ONE, VFPUConst::ZERO, VFPUConst::ONE, VFPUConst::ZERO); - ApplyPrefixST(t, VFPURewritePrefix(VFPU_CTRL_TPREFIX, tprefixRemove, tprefixAdd), outSize); + ApplyPrefixST(mips, t, VFPURewritePrefix(VFPU_CTRL_TPREFIX, tprefixRemove, tprefixAdd), outSize); // Essentially D prefix saturation is forced. d[0] = nanclamp(t[0] + s[0], 0.0f, 1.0f); @@ -734,13 +735,13 @@ namespace MIPSInt d[2] = nanclamp(t[2] + s[2], 0.0f, 1.0f); d[3] = nanclamp(t[3] + s[3], 0.0f, 1.0f); } - ApplyPrefixD(d, sz, true); + ApplyPrefixD(mips, d, sz, true); WriteVector(d, outSize, vd); PC += 4; - EatPrefixes(); + EatPrefixes(mips); } - void Int_Vsgn(MIPSOpcode op) { + void Int_Vsgn(MIPSState *mips, MIPSOpcode op) { float s[4], t[4], d[4]; int vd = _VD; int vs = _VS; @@ -750,14 +751,14 @@ namespace MIPSInt // Not sure who would do this, but using abs/neg allows a compare against 3 or -3. u32 tprefixRemove = VFPU_ANY_SWIZZLE(); u32 tprefixAdd = VFPU_MAKE_CONSTANTS(VFPUConst::ZERO, VFPUConst::ZERO, VFPUConst::ZERO, VFPUConst::ZERO); - ApplyPrefixST(t, VFPURewritePrefix(VFPU_CTRL_TPREFIX, tprefixRemove, tprefixAdd), sz); + ApplyPrefixST(mips, t, VFPURewritePrefix(VFPU_CTRL_TPREFIX, tprefixRemove, tprefixAdd), sz); int n = GetNumVectorElements(sz); if (n < 4) { // Compare with a swizzled value out of bounds always produces 0. memcpy(&s[n], &t[n], sizeof(float) * (4 - n)); } - ApplySwizzleS(s, V_Quad); + ApplySwizzleS(mips, s, V_Quad); for (int i = 0; i < n; i++) { float diff = s[i] - t[i]; @@ -771,10 +772,10 @@ namespace MIPSInt else d[i] = -1.0f; } - ApplyPrefixD(d, sz); + ApplyPrefixD(mips, d, sz); WriteVector(d, sz, vd); PC += 4; - EatPrefixes(); + EatPrefixes(mips); } inline int round_vfpu_n(double param) { @@ -782,7 +783,7 @@ namespace MIPSInt return (int)round_ieee_754(param); } - void Int_Vf2i(MIPSOpcode op) { + void Int_Vf2i(MIPSState *mips, MIPSOpcode op) { float s[4]; int d[4]; int vd = _VD; @@ -792,7 +793,7 @@ namespace MIPSInt VectorSize sz = GetVecSize(op); ReadVector(s, sz, vs); // Negate, abs, and constants apply as you'd expect to the bits. - ApplySwizzleS(s, sz); + ApplySwizzleS(mips, s, sz); for (int i = 0; i < GetNumVectorElements(sz); i++) { if (my_isnan(s[i])) { d[i] = 0x7FFFFFFF; @@ -816,13 +817,13 @@ namespace MIPSInt } } // Does not apply sat, but does apply mask. - ApplyPrefixD(reinterpret_cast(d), sz, true); + ApplyPrefixD(mips, reinterpret_cast(d), sz, true); WriteVector(reinterpret_cast(d), sz, vd); PC += 4; - EatPrefixes(); + EatPrefixes(mips); } - void Int_Vi2f(MIPSOpcode op) { + void Int_Vi2f(MIPSState *mips, MIPSOpcode op) { int s[4]; float d[4]; int vd = _VD; @@ -832,25 +833,25 @@ namespace MIPSInt VectorSize sz = GetVecSize(op); ReadVector(reinterpret_cast(s), sz, vs); // Negate, abs, and constants apply as you'd expect to the bits. - ApplySwizzleS(reinterpret_cast(s), sz); + ApplySwizzleS(mips, reinterpret_cast(s), sz); for (int i = 0; i < GetNumVectorElements(sz); i++) { d[i] = (float)s[i] * mult; } // Sat and mask apply normally. - ApplyPrefixD(d, sz); + ApplyPrefixD(mips, d, sz); WriteVector(d, sz, vd); PC += 4; - EatPrefixes(); + EatPrefixes(mips); } - void Int_Vh2f(MIPSOpcode op) { + void Int_Vh2f(MIPSState *mips, MIPSOpcode op) { u32 s[4]; float d[4]; int vd = _VD; int vs = _VS; VectorSize sz = GetVecSize(op); ReadVector(reinterpret_cast(s), sz, vs); - ApplySwizzleS(reinterpret_cast(s), sz); + ApplySwizzleS(mips, reinterpret_cast(s), sz); VectorSize outsize = V_Pair; switch (sz) { @@ -869,13 +870,13 @@ namespace MIPSInt d[3] = ExpandHalf(s[1] >> 16); break; } - ApplyPrefixD(d, outsize); + ApplyPrefixD(mips, d, outsize); WriteVector(d, outsize, vd); PC += 4; - EatPrefixes(); + EatPrefixes(mips); } - void Int_Vf2h(MIPSOpcode op) { + void Int_Vf2h(MIPSState *mips, MIPSOpcode op) { float s[4]{}; u32 d[4]; int vd = _VD; @@ -883,9 +884,9 @@ namespace MIPSInt VectorSize sz = GetVecSize(op); ReadVector(s, sz, vs); // Swizzle can cause V_Single to properly write both components. - ApplySwizzleS(s, V_Quad); + ApplySwizzleS(mips, s, V_Quad); // Negate should not actually apply to invalid swizzle. - RetainInvalidSwizzleST(s, V_Quad); + RetainInvalidSwizzleST(mips, s, V_Quad); VectorSize outsize = V_Single; switch (sz) { @@ -905,20 +906,20 @@ namespace MIPSInt ERROR_LOG_REPORT(Log::CPU, "vf2h with invalid elements"); break; } - ApplyPrefixD(reinterpret_cast(d), outsize); + ApplyPrefixD(mips, reinterpret_cast(d), outsize); WriteVector(reinterpret_cast(d), outsize, vd); PC += 4; - EatPrefixes(); + EatPrefixes(mips); } - void Int_Vx2i(MIPSOpcode op) { + void Int_Vx2i(MIPSState *mips, MIPSOpcode op) { u32 s[4], d[4]{}; int vd = _VD; int vs = _VS; VectorSize sz = GetVecSize(op); VectorSize oz = sz; ReadVector(reinterpret_cast(s), sz, vs); - ApplySwizzleS(reinterpret_cast(s), sz); + ApplySwizzleS(mips, reinterpret_cast(s), sz); // TODO: Similar to colorconv, invalid swizzle seems to reuse last output. switch ((op >> 16) & 3) { @@ -1009,13 +1010,13 @@ namespace MIPSInt } // Saturation does in fact apply. - ApplyPrefixD(reinterpret_cast(d),oz); + ApplyPrefixD(mips, reinterpret_cast(d),oz); WriteVector(reinterpret_cast(d), oz, vd); PC += 4; - EatPrefixes(); + EatPrefixes(mips); } - void Int_Vi2x(MIPSOpcode op) { + void Int_Vi2x(MIPSState *mips, MIPSOpcode op) { int s[4]{}; u32 d[2]{}; const int vd = _VD; @@ -1024,7 +1025,7 @@ namespace MIPSInt VectorSize oz; ReadVector(reinterpret_cast(s), sz, vs); // Negate, const, etc. apply as expected. - ApplySwizzleS(reinterpret_cast(s), V_Quad); + ApplySwizzleS(mips, reinterpret_cast(s), V_Quad); // TODO: Similar to colorconv, invalid swizzle seems to reuse last output. switch ((op >> 16) & 3) { @@ -1098,13 +1099,13 @@ namespace MIPSInt break; } // D prefix applies as expected. - ApplyPrefixD(reinterpret_cast(d), oz); + ApplyPrefixD(mips, reinterpret_cast(d), oz); WriteVector(reinterpret_cast(d), oz, vd); PC += 4; - EatPrefixes(); + EatPrefixes(mips); } - void Int_ColorConv(MIPSOpcode op) + void Int_ColorConv(MIPSState *mips, MIPSOpcode op) { int vd = _VD; int vs = _VS; @@ -1112,7 +1113,7 @@ namespace MIPSInt VectorSize isz = GetVecSize(op); VectorSize sz = V_Quad; ReadVector(reinterpret_cast(s), sz, vs); - ApplySwizzleS(reinterpret_cast(s), sz); + ApplySwizzleS(mips, reinterpret_cast(s), sz); u16 colors[4]; // TODO: Invalid swizzle values almost seem to use the last value converted in a // previous execution of these ops. It's a bit odd. @@ -1152,13 +1153,13 @@ namespace MIPSInt colors[i] = col; } u32 ov[2] = {(u32)colors[0] | (colors[1] << 16), (u32)colors[2] | (colors[3] << 16)}; - ApplyPrefixD(reinterpret_cast(ov), V_Pair); + ApplyPrefixD(mips, reinterpret_cast(ov), V_Pair); WriteVector((const float *)ov, isz == V_Single ? V_Single : V_Pair, vd); PC += 4; - EatPrefixes(); + EatPrefixes(mips); } - void Int_VDot(MIPSOpcode op) { + void Int_VDot(MIPSState *mips, MIPSOpcode op) { float s[4]{}, t[4]{}; union { float f; uint32_t u; } d; int vd = _VD; @@ -1166,9 +1167,9 @@ namespace MIPSInt int vt = _VT; VectorSize sz = GetVecSize(op); ReadVector(s, sz, vs); - ApplySwizzleS(s, V_Quad); + ApplySwizzleS(mips, s, V_Quad); ReadVector(t, sz, vt); - ApplySwizzleT(t, V_Quad); + ApplySwizzleT(mips, t, V_Quad); if (USE_VFPU_DOT) { d.f = vfpu_dot(s, t); @@ -1184,13 +1185,13 @@ namespace MIPSInt } } - ApplyPrefixD(&d.f, V_Single); + ApplyPrefixD(mips, &d.f, V_Single); WriteVector(&d.f, V_Single, vd); PC += 4; - EatPrefixes(); + EatPrefixes(mips); } - void Int_VHdp(MIPSOpcode op) { + void Int_VHdp(MIPSState *mips, MIPSOpcode op) { float s[4]{}, t[4]{}; float d; int vd = _VD; @@ -1199,7 +1200,7 @@ namespace MIPSInt VectorSize sz = GetVecSize(op); ReadVector(s, sz, vs); ReadVector(t, sz, vt); - ApplySwizzleT(t, V_Quad); + ApplySwizzleT(mips, t, V_Quad); // S prefix forces constant 1 for the last element (w for quad.) // Otherwise it is the same as vdot. @@ -1218,7 +1219,7 @@ namespace MIPSInt sprefixRemove = VFPU_SWIZZLE(3, 0, 0, 0); sprefixAdd = VFPU_MAKE_CONSTANTS(VFPUConst::ONE, VFPUConst::NONE, VFPUConst::NONE, VFPUConst::NONE); } - ApplyPrefixST(s, VFPURewritePrefix(VFPU_CTRL_SPREFIX, sprefixRemove, sprefixAdd), V_Quad); + ApplyPrefixST(mips, s, VFPURewritePrefix(VFPU_CTRL_SPREFIX, sprefixRemove, sprefixAdd), V_Quad); float sum = 0.0f; if (USE_VFPU_DOT) { @@ -1229,13 +1230,13 @@ namespace MIPSInt } } d = my_isnan(sum) ? fabsf(sum) : sum; - ApplyPrefixD(&d, V_Single); + ApplyPrefixD(mips, &d, V_Single); WriteVector(&d, V_Single, vd); PC += 4; - EatPrefixes(); + EatPrefixes(mips); } - void Int_Vbfy(MIPSOpcode op) { + void Int_Vbfy(MIPSState *mips, MIPSOpcode op) { float s[4]{}, t[4]{}, d[4]; int vd = _VD; int vs = _VS; @@ -1247,13 +1248,13 @@ namespace MIPSInt // vbfy2 // S prefix forces the negate flags (so z and w are negative.) u32 sprefixAdd = VFPU_NEGATE(0, 0, 1, 1); - ApplyPrefixST(s, VFPURewritePrefix(VFPU_CTRL_SPREFIX, 0, sprefixAdd), sz); + ApplyPrefixST(mips, s, VFPURewritePrefix(VFPU_CTRL_SPREFIX, 0, sprefixAdd), sz); // T prefix forces swizzle (zwxy.) // That means negate still works, but constants are a bit weird. u32 tprefixRemove = VFPU_ANY_SWIZZLE(); u32 tprefixAdd = VFPU_SWIZZLE(2, 3, 0, 1); - ApplyPrefixST(t, VFPURewritePrefix(VFPU_CTRL_TPREFIX, tprefixRemove, tprefixAdd), sz); + ApplyPrefixST(mips, t, VFPURewritePrefix(VFPU_CTRL_TPREFIX, tprefixRemove, tprefixAdd), sz); // Other sizes don't seem completely predictable. if (sz != V_Quad) { @@ -1263,13 +1264,13 @@ namespace MIPSInt // vbfy1 // S prefix forces the negate flags (so y and w are negative.) u32 sprefixAdd = VFPU_NEGATE(0, 1, 0, 1); - ApplyPrefixST(s, VFPURewritePrefix(VFPU_CTRL_SPREFIX, 0, sprefixAdd), sz); + ApplyPrefixST(mips, s, VFPURewritePrefix(VFPU_CTRL_SPREFIX, 0, sprefixAdd), sz); // T prefix forces swizzle (yxwz.) // That means negate still works, but constants are a bit weird. u32 tprefixRemove = VFPU_ANY_SWIZZLE(); u32 tprefixAdd = VFPU_SWIZZLE(1, 0, 3, 2); - ApplyPrefixST(t, VFPURewritePrefix(VFPU_CTRL_TPREFIX, tprefixRemove, tprefixAdd), sz); + ApplyPrefixST(mips, t, VFPURewritePrefix(VFPU_CTRL_TPREFIX, tprefixRemove, tprefixAdd), sz); if (sz != V_Quad && sz != V_Pair) { ERROR_LOG_REPORT_ONCE(vbfy2, Log::CPU, "vfby1 with incorrect size"); @@ -1281,117 +1282,117 @@ namespace MIPSInt d[2] = s[2] + t[2]; d[3] = s[3] + t[3]; - ApplyPrefixD(d, sz); + ApplyPrefixD(mips, d, sz); WriteVector(d, sz, vd); PC += 4; - EatPrefixes(); + EatPrefixes(mips); } - void Int_Vsrt1(MIPSOpcode op) { + void Int_Vsrt1(MIPSState *mips, MIPSOpcode op) { float s[4], t[4], d[4]; int vd = _VD; int vs = _VS; VectorSize sz = GetVecSize(op); ReadVector(s, sz, vs); - ApplySwizzleS(s, sz); + ApplySwizzleS(mips, s, sz); ReadVector(t, sz, vs); // T is force swizzled to yxwz from S. u32 tprefixRemove = VFPU_SWIZZLE(3, 3, 3, 3); u32 tprefixAdd = VFPU_SWIZZLE(1, 0, 3, 2); - ApplyPrefixST(t, VFPURewritePrefix(VFPU_CTRL_TPREFIX, tprefixRemove, tprefixAdd), sz); + ApplyPrefixST(mips, t, VFPURewritePrefix(VFPU_CTRL_TPREFIX, tprefixRemove, tprefixAdd), sz); // TODO: May mishandle NAN / negative zero / etc. d[0] = std::min(s[0], t[0]); d[1] = std::max(s[1], t[1]); d[2] = std::min(s[2], t[2]); d[3] = std::max(s[3], t[3]); - RetainInvalidSwizzleST(d, sz); - ApplyPrefixD(d, sz); + RetainInvalidSwizzleST(mips, d, sz); + ApplyPrefixD(mips, d, sz); WriteVector(d, sz, vd); PC += 4; - EatPrefixes(); + EatPrefixes(mips); } - void Int_Vsrt2(MIPSOpcode op) { + void Int_Vsrt2(MIPSState *mips, MIPSOpcode op) { float s[4], t[4], d[4]; int vd = _VD; int vs = _VS; VectorSize sz = GetVecSize(op); ReadVector(s, sz, vs); - ApplySwizzleS(s, sz); + ApplySwizzleS(mips, s, sz); ReadVector(t, sz, vs); // T is force swizzled to wzyx from S. u32 tprefixRemove = VFPU_SWIZZLE(3, 3, 3, 3); u32 tprefixAdd = VFPU_SWIZZLE(3, 2, 1, 0); - ApplyPrefixST(t, VFPURewritePrefix(VFPU_CTRL_TPREFIX, tprefixRemove, tprefixAdd), sz); + ApplyPrefixST(mips, t, VFPURewritePrefix(VFPU_CTRL_TPREFIX, tprefixRemove, tprefixAdd), sz); // TODO: May mishandle NAN / negative zero / etc. d[0] = std::min(s[0], t[0]); d[1] = std::min(s[1], t[1]); d[2] = std::max(s[2], t[2]); d[3] = std::max(s[3], t[3]); - RetainInvalidSwizzleST(d, sz); - ApplyPrefixD(d, sz); + RetainInvalidSwizzleST(mips, d, sz); + ApplyPrefixD(mips, d, sz); WriteVector(d, sz, vd); PC += 4; - EatPrefixes(); + EatPrefixes(mips); } - void Int_Vsrt3(MIPSOpcode op) { + void Int_Vsrt3(MIPSState *mips, MIPSOpcode op) { float s[4], t[4], d[4]; int vd = _VD; int vs = _VS; VectorSize sz = GetVecSize(op); ReadVector(s, sz, vs); - ApplySwizzleS(s, sz); + ApplySwizzleS(mips, s, sz); ReadVector(t, sz, vs); // T is force swizzled to yxwz from S. u32 tprefixRemove = VFPU_SWIZZLE(3, 3, 3, 3); u32 tprefixAdd = VFPU_SWIZZLE(1, 0, 3, 2); - ApplyPrefixST(t, VFPURewritePrefix(VFPU_CTRL_TPREFIX, tprefixRemove, tprefixAdd), sz); + ApplyPrefixST(mips, t, VFPURewritePrefix(VFPU_CTRL_TPREFIX, tprefixRemove, tprefixAdd), sz); // TODO: May mishandle NAN / negative zero / etc. d[0] = std::max(s[0], t[0]); d[1] = std::min(s[1], t[1]); d[2] = std::max(s[2], t[2]); d[3] = std::min(s[3], t[3]); - RetainInvalidSwizzleST(d, sz); - ApplyPrefixD(d, sz); + RetainInvalidSwizzleST(mips, d, sz); + ApplyPrefixD(mips, d, sz); WriteVector(d, sz, vd); PC += 4; - EatPrefixes(); + EatPrefixes(mips); } - void Int_Vsrt4(MIPSOpcode op) { + void Int_Vsrt4(MIPSState *mips, MIPSOpcode op) { float s[4], t[4], d[4]; int vd = _VD; int vs = _VS; VectorSize sz = GetVecSize(op); ReadVector(s, sz, vs); - ApplySwizzleS(s, sz); + ApplySwizzleS(mips, s, sz); ReadVector(t, sz, vs); // T is force swizzled to wzyx from S. u32 tprefixRemove = VFPU_SWIZZLE(3, 3, 3, 3); u32 tprefixAdd = VFPU_SWIZZLE(3, 2, 1, 0); - ApplyPrefixST(t, VFPURewritePrefix(VFPU_CTRL_TPREFIX, tprefixRemove, tprefixAdd), sz); + ApplyPrefixST(mips, t, VFPURewritePrefix(VFPU_CTRL_TPREFIX, tprefixRemove, tprefixAdd), sz); // TODO: May mishandle NAN / negative zero / etc. d[0] = std::max(s[0], t[0]); d[1] = std::max(s[1], t[1]); d[2] = std::min(s[2], t[2]); d[3] = std::min(s[3], t[3]); - RetainInvalidSwizzleST(d, sz); - ApplyPrefixD(d, sz); + RetainInvalidSwizzleST(mips, d, sz); + ApplyPrefixD(mips, d, sz); WriteVector(d, sz, vd); PC += 4; - EatPrefixes(); + EatPrefixes(mips); } - void Int_Vcrs(MIPSOpcode op) { + void Int_Vcrs(MIPSState *mips, MIPSOpcode op) { //half a cross product float s[4]{}, t[4]{}, d[4]; int vd = _VD; @@ -1405,24 +1406,24 @@ namespace MIPSInt // That means negate still works, but constants are a bit weird. u32 sprefixRemove = VFPU_SWIZZLE(3, 3, 3, 0); u32 sprefixAdd = VFPU_SWIZZLE(1, 2, 0, 0); - ApplyPrefixST(s, VFPURewritePrefix(VFPU_CTRL_SPREFIX, sprefixRemove, sprefixAdd), sz); + ApplyPrefixST(mips, s, VFPURewritePrefix(VFPU_CTRL_SPREFIX, sprefixRemove, sprefixAdd), sz); // T prefix forces swizzle (zxy?.) u32 tprefixRemove = VFPU_SWIZZLE(3, 3, 3, 0); u32 tprefixAdd = VFPU_SWIZZLE(2, 0, 1, 0); - ApplyPrefixST(t, VFPURewritePrefix(VFPU_CTRL_TPREFIX, tprefixRemove, tprefixAdd), sz); + ApplyPrefixST(mips, t, VFPURewritePrefix(VFPU_CTRL_TPREFIX, tprefixRemove, tprefixAdd), sz); d[0] = s[0] * t[0]; d[1] = s[1] * t[1]; d[2] = s[2] * t[2]; d[3] = s[3] * t[3]; - ApplyPrefixD(d, sz); + ApplyPrefixD(mips, d, sz); WriteVector(d, sz, vd); PC += 4; - EatPrefixes(); + EatPrefixes(mips); } - void Int_Vdet(MIPSOpcode op) { + void Int_Vdet(MIPSState *mips, MIPSOpcode op) { float s[4]{}, t[4]{}, d[4]; int vd = _VD; int vs = _VS; @@ -1430,7 +1431,7 @@ namespace MIPSInt VectorSize sz = GetVecSize(op); // This is normally V_Pair. Unfilled s/t values are treated as zero. ReadVector(s, sz, vs); - ApplySwizzleS(s, V_Quad); + ApplySwizzleS(mips, s, V_Quad); ReadVector(t, sz, vt); // T prefix forces swizzle for x and y (yx??.) @@ -1438,7 +1439,7 @@ namespace MIPSInt // Note: there is no forced negation here. u32 tprefixRemove = VFPU_SWIZZLE(3, 3, 0, 0); u32 tprefixAdd = VFPU_SWIZZLE(1, 0, 0, 0); - ApplyPrefixST(t, VFPURewritePrefix(VFPU_CTRL_TPREFIX, tprefixRemove, tprefixAdd), V_Quad); + ApplyPrefixST(mips, t, VFPURewritePrefix(VFPU_CTRL_TPREFIX, tprefixRemove, tprefixAdd), V_Quad); if (USE_VFPU_DOT) { s[1] = -s[1]; @@ -1448,25 +1449,25 @@ namespace MIPSInt d[0] += s[2] * t[2] + s[3] * t[3]; } - ApplyPrefixD(d, V_Single); + ApplyPrefixD(mips, d, V_Single); WriteVector(d, V_Single, vd); PC += 4; - EatPrefixes(); + EatPrefixes(mips); } - void Int_Vfad(MIPSOpcode op) { + void Int_Vfad(MIPSState *mips, MIPSOpcode op) { float s[4]{}, t[4]{}; float d; int vd = _VD; int vs = _VS; VectorSize sz = GetVecSize(op); ReadVector(s, sz, vs); - ApplySwizzleS(s, V_Quad); + ApplySwizzleS(mips, s, V_Quad); // T prefix generates constants, but abs can change the constant. u32 tprefixRemove = VFPU_ANY_SWIZZLE(); u32 tprefixAdd = VFPU_MAKE_CONSTANTS(VFPUConst::ONE, VFPUConst::ONE, VFPUConst::ONE, VFPUConst::ONE); - ApplyPrefixST(t, VFPURewritePrefix(VFPU_CTRL_TPREFIX, tprefixRemove, tprefixAdd), V_Quad); + ApplyPrefixST(mips, t, VFPURewritePrefix(VFPU_CTRL_TPREFIX, tprefixRemove, tprefixAdd), V_Quad); if (USE_VFPU_DOT) { d = vfpu_dot(s, t); @@ -1476,20 +1477,20 @@ namespace MIPSInt d += s[i] * t[i]; } } - ApplyPrefixD(&d, V_Single); + ApplyPrefixD(mips, &d, V_Single); WriteVector(&d, V_Single, vd); PC += 4; - EatPrefixes(); + EatPrefixes(mips); } - void Int_Vavg(MIPSOpcode op) { + void Int_Vavg(MIPSState *mips, MIPSOpcode op) { float s[4]{}, t[4]{}; float d; int vd = _VD; int vs = _VS; VectorSize sz = GetVecSize(op); ReadVector(s, sz, vs); - ApplySwizzleS(s, V_Quad); + ApplySwizzleS(mips, s, V_Quad); // T prefix generates constants, but supports negate. u32 tprefixRemove = VFPU_ANY_SWIZZLE() | VFPU_ABS(1, 1, 1, 1); @@ -1504,7 +1505,7 @@ namespace MIPSInt tprefixAdd = VFPU_MAKE_CONSTANTS(VFPUConst::FOURTH, VFPUConst::FOURTH, VFPUConst::FOURTH, VFPUConst::FOURTH); else tprefixAdd = 0; - ApplyPrefixST(t, VFPURewritePrefix(VFPU_CTRL_TPREFIX, tprefixRemove, tprefixAdd), V_Quad); + ApplyPrefixST(mips, t, VFPURewritePrefix(VFPU_CTRL_TPREFIX, tprefixRemove, tprefixAdd), V_Quad); if (USE_VFPU_DOT) { d = vfpu_dot(s, t); @@ -1514,20 +1515,20 @@ namespace MIPSInt d += s[i] * t[i]; } } - ApplyPrefixD(&d, V_Single); + ApplyPrefixD(mips, &d, V_Single); WriteVector(&d, V_Single, vd); PC += 4; - EatPrefixes(); + EatPrefixes(mips); } - void Int_VScl(MIPSOpcode op) { + void Int_VScl(MIPSState *mips, MIPSOpcode op) { float s[4], t[4], d[4]; int vd = _VD; int vs = _VS; int vt = _VT; VectorSize sz = GetVecSize(op); ReadVector(s, sz, vs); - ApplySwizzleS(s, sz); + ApplySwizzleS(mips, s, sz); // T prefix forces swizzle (zzzz for some reason, so we force V_Quad.) // That means negate still works, but constants are a bit weird. @@ -1535,29 +1536,29 @@ namespace MIPSInt t[tlane] = V(vt); u32 tprefixRemove = VFPU_ANY_SWIZZLE(); u32 tprefixAdd = VFPU_SWIZZLE(tlane, tlane, tlane, tlane); - ApplyPrefixST(t, VFPURewritePrefix(VFPU_CTRL_TPREFIX, tprefixRemove, tprefixAdd), V_Quad); + ApplyPrefixST(mips, t, VFPURewritePrefix(VFPU_CTRL_TPREFIX, tprefixRemove, tprefixAdd), V_Quad); int n = GetNumVectorElements(sz); for (int i = 0; i < n; i++) { d[i] = s[i] * t[i]; } - ApplyPrefixD(d, sz); + ApplyPrefixD(mips, d, sz); WriteVector(d, sz, vd); PC += 4; - EatPrefixes(); + EatPrefixes(mips); } - void Int_Vrnds(MIPSOpcode op) { + void Int_Vrnds(MIPSState *mips, MIPSOpcode op) { int vd = _VD; int seed = VI(vd); // Swizzles apply a constant value, constants/abs/neg work to vary the seed. - ApplySwizzleS(reinterpret_cast(&seed), V_Single); - vrnd_init(uint32_t(seed), currentMIPS->vfpuCtrl + VFPU_CTRL_RCX0); + ApplySwizzleS(mips, reinterpret_cast(&seed), V_Single); + vrnd_init(uint32_t(seed), mips->vfpuCtrl + VFPU_CTRL_RCX0); PC += 4; - EatPrefixes(); + EatPrefixes(mips); } - void Int_VrndX(MIPSOpcode op) { + void Int_VrndX(MIPSState *mips, MIPSOpcode op) { FloatBits d; int vd = _VD; VectorSize sz = GetVecSize(op); @@ -1565,24 +1566,24 @@ namespace MIPSInt // Values are written in backwards order. for (int i = n - 1; i >= 0; i--) { switch ((op >> 16) & 0x1f) { - case 1: d.u[i] = vrnd_generate(currentMIPS->vfpuCtrl + VFPU_CTRL_RCX0); break; // vrndi - case 2: d.u[i] = 0x3F800000 | (vrnd_generate(currentMIPS->vfpuCtrl + VFPU_CTRL_RCX0) & 0x007FFFFF); break; // vrndf1 (>= 1, < 2) - case 3: d.u[i] = 0x40000000 | (vrnd_generate(currentMIPS->vfpuCtrl + VFPU_CTRL_RCX0) & 0x007FFFFF); break; // vrndf2 (>= 2, < 4) + case 1: d.u[i] = vrnd_generate(mips->vfpuCtrl + VFPU_CTRL_RCX0); break; // vrndi + case 2: d.u[i] = 0x3F800000 | (vrnd_generate(mips->vfpuCtrl + VFPU_CTRL_RCX0) & 0x007FFFFF); break; // vrndf1 (>= 1, < 2) + case 3: d.u[i] = 0x40000000 | (vrnd_generate(mips->vfpuCtrl + VFPU_CTRL_RCX0) & 0x007FFFFF); break; // vrndf2 (>= 2, < 4) default: _dbg_assert_msg_(false,"Trying to interpret instruction that can't be interpreted"); } } // D prefix is broken and applies to the last element only (mask and sat.) - u32 lastmask = (currentMIPS->vfpuCtrl[VFPU_CTRL_DPREFIX] & (1 << 8)) << (n - 1); - u32 lastsat = (currentMIPS->vfpuCtrl[VFPU_CTRL_DPREFIX] & 3) << (n + n - 2); - currentMIPS->vfpuCtrl[VFPU_CTRL_DPREFIX] = lastmask | lastsat; - ApplyPrefixD(d.f, sz); + u32 lastmask = (mips->vfpuCtrl[VFPU_CTRL_DPREFIX] & (1 << 8)) << (n - 1); + u32 lastsat = (mips->vfpuCtrl[VFPU_CTRL_DPREFIX] & 3) << (n + n - 2); + mips->vfpuCtrl[VFPU_CTRL_DPREFIX] = lastmask | lastsat; + ApplyPrefixD(mips, d.f, sz); WriteVector(d.f, sz, vd); PC += 4; - EatPrefixes(); + EatPrefixes(mips); } // Generates one line of a rotation matrix around one of the three axes - void Int_Vrot(MIPSOpcode op) { + void Int_Vrot(MIPSState *mips, MIPSOpcode op) { float d[4]{}; int vd = _VD; int vs = _VS; @@ -1593,7 +1594,7 @@ namespace MIPSInt int cosineLane = imm & 3; float sine, cosine; - if (currentMIPS->vfpuCtrl[VFPU_CTRL_SPREFIX] == 0x000E4) { + if (mips->vfpuCtrl[VFPU_CTRL_SPREFIX] == 0x000E4) { vfpu_sincos(V(vs), sine, cosine); if (negSin) sine = -sine; @@ -1604,7 +1605,7 @@ namespace MIPSInt u32 sprefixRemove = VFPU_NEGATE(1, 0, 0, 0); // We apply negSin later, not here. This handles zero a bit better. u32 sprefixAdd = VFPU_NEGATE(0, 0, 0, 0); - ApplyPrefixST(s, VFPURewritePrefix(VFPU_CTRL_SPREFIX, sprefixRemove, sprefixAdd), V_Single); + ApplyPrefixST(mips, s, VFPURewritePrefix(VFPU_CTRL_SPREFIX, sprefixRemove, sprefixAdd), V_Single); // Cosine ignores all prefixes, so take the original. cosine = vfpu_cos(V(vs)); @@ -1612,7 +1613,7 @@ namespace MIPSInt if (negSin) sine = -sine; - RetainInvalidSwizzleST(&sine, V_Single); + RetainInvalidSwizzleST(mips, &sine, V_Single); } if (sineLane == cosineLane) { @@ -1642,14 +1643,14 @@ namespace MIPSInt // D prefix works, just not for the cosine lane. uint32_t dprefixRemove = (3 << cosineLane) | (1 << (8 + cosineLane)); - currentMIPS->vfpuCtrl[VFPU_CTRL_DPREFIX] &= 0xFFFFF ^ dprefixRemove; - ApplyPrefixD(d, sz); + mips->vfpuCtrl[VFPU_CTRL_DPREFIX] &= 0xFFFFF ^ dprefixRemove; + ApplyPrefixD(mips, d, sz); WriteVector(d, sz, vd); PC += 4; - EatPrefixes(); + EatPrefixes(mips); } - void Int_Vtfm(MIPSOpcode op) { + void Int_Vtfm(MIPSState *mips, MIPSOpcode op) { float s[16]{}, t[4]{}; FloatBits d; int vd = _VD; @@ -1700,7 +1701,7 @@ namespace MIPSInt // S and T prefixes apply for the final row only. // The T prefix is used to apply zero/one constants, but abs still changes it. - ApplySwizzleS(&s[ins * 4], V_Quad); + ApplySwizzleS(mips, &s[ins * 4], V_Quad); VFPUConst constX = VFPUConst::NONE; VFPUConst constY = n < 2 ? VFPUConst::ZERO : VFPUConst::NONE; VFPUConst constZ = n < 3 ? VFPUConst::ZERO : VFPUConst::NONE; @@ -1716,7 +1717,7 @@ namespace MIPSInt } u32 tprefixRemove = VFPU_SWIZZLE(0, n < 2 ? 3 : 0, n < 3 ? 3 : 0, n < 4 ? 3 : 0); u32 tprefixAdd = VFPU_MAKE_CONSTANTS(constX, constY, constZ, constW); - ApplyPrefixST(t, VFPURewritePrefix(VFPU_CTRL_TPREFIX, tprefixRemove, tprefixAdd), V_Quad); + ApplyPrefixST(mips, t, VFPURewritePrefix(VFPU_CTRL_TPREFIX, tprefixRemove, tprefixAdd), V_Quad); // Really this is the operation all rows probably use (with constant wiring.) if (USE_VFPU_DOT) { @@ -1735,16 +1736,16 @@ namespace MIPSInt } // D prefix applies to the last element only. - u32 lastmask = (currentMIPS->vfpuCtrl[VFPU_CTRL_DPREFIX] & (1 << 8)) << ins; - u32 lastsat = (currentMIPS->vfpuCtrl[VFPU_CTRL_DPREFIX] & 3) << (ins + ins); - currentMIPS->vfpuCtrl[VFPU_CTRL_DPREFIX] = lastmask | lastsat; - ApplyPrefixD(d.f, sz); + u32 lastmask = (mips->vfpuCtrl[VFPU_CTRL_DPREFIX] & (1 << 8)) << ins; + u32 lastsat = (mips->vfpuCtrl[VFPU_CTRL_DPREFIX] & 3) << (ins + ins); + mips->vfpuCtrl[VFPU_CTRL_DPREFIX] = lastmask | lastsat; + ApplyPrefixD(mips, d.f, sz); WriteVector(d.f, sz, vd); PC += 4; - EatPrefixes(); + EatPrefixes(mips); } - void Int_SV(MIPSOpcode op) + void Int_SV(MIPSState *mips, MIPSOpcode op) { s32 imm = SignExtend16ToS32(op & 0xFFFC); int vt = ((op >> 16) & 0x1f) | ((op & 3) << 5); @@ -1775,7 +1776,7 @@ namespace MIPSInt } - void Int_Mftv(MIPSOpcode op) + void Int_Mftv(MIPSState *mips, MIPSOpcode op) { int imm = op & 0xFF; int rt = _RT; @@ -1787,7 +1788,7 @@ namespace MIPSInt if (imm < 128) { R(rt) = VI(imm); } else if (imm < 128 + VFPU_CTRL_MAX) { //mfvc - R(rt) = currentMIPS->vfpuCtrl[imm - 128]; + R(rt) = mips->vfpuCtrl[imm - 128]; } else { //ERROR - maybe need to make this value too an "interlock" value? _dbg_assert_msg_(false,"mfv - invalid register"); @@ -1801,7 +1802,7 @@ namespace MIPSInt } else if (imm < 128 + VFPU_CTRL_MAX) { //mtvc u32 mask; if (GetVFPUCtrlMask(imm - 128, &mask)) { - currentMIPS->vfpuCtrl[imm - 128] = R(rt) & mask; + mips->vfpuCtrl[imm - 128] = R(rt) & mask; } } else { //ERROR @@ -1816,30 +1817,30 @@ namespace MIPSInt PC += 4; } - void Int_Vmfvc(MIPSOpcode op) { + void Int_Vmfvc(MIPSState *mips, MIPSOpcode op) { int vd = _VD; int imm = (op >> 8) & 0x7F; if (imm < VFPU_CTRL_MAX) { - VI(vd) = currentMIPS->vfpuCtrl[imm]; + VI(vd) = mips->vfpuCtrl[imm]; } else { VI(vd) = 0; } PC += 4; } - void Int_Vmtvc(MIPSOpcode op) { + void Int_Vmtvc(MIPSState *mips, MIPSOpcode op) { int vs = _VS; int imm = op & 0x7F; if (imm < VFPU_CTRL_MAX) { u32 mask; if (GetVFPUCtrlMask(imm, &mask)) { - currentMIPS->vfpuCtrl[imm] = VI(vs) & mask; + mips->vfpuCtrl[imm] = VI(vs) & mask; } } PC += 4; } - void Int_Vcst(MIPSOpcode op) + void Int_Vcst(MIPSState *mips, MIPSOpcode op) { int conNum = (op >> 16) & 0x1f; int vd = _VD; @@ -1847,13 +1848,13 @@ namespace MIPSInt VectorSize sz = GetVecSize(op); float c = cst_constants[conNum]; float temp[4] = {c,c,c,c}; - ApplyPrefixD(temp, sz); + ApplyPrefixD(mips, temp, sz); WriteVector(temp, sz, vd); PC += 4; - EatPrefixes(); + EatPrefixes(mips); } - void Int_Vcmp(MIPSOpcode op) + void Int_Vcmp(MIPSState *mips, MIPSOpcode op) { int vs = _VS; int vt = _VT; @@ -1863,9 +1864,9 @@ namespace MIPSInt float s[4]; float t[4]; ReadVector(s, sz, vs); - ApplySwizzleS(s, sz); + ApplySwizzleS(mips, s, sz); ReadVector(t, sz, vt); - ApplySwizzleT(t, sz); + ApplySwizzleT(mips, t, sz); int cc = 0; int or_val = 0; int and_val = 1; @@ -1899,7 +1900,7 @@ namespace MIPSInt default: _dbg_assert_msg_(false,"Unsupported vcmp condition code %d", cond); PC += 4; - EatPrefixes(); + EatPrefixes(mips); return; } cc |= (c<vfpuCtrl[VFPU_CTRL_CC] = - (currentMIPS->vfpuCtrl[VFPU_CTRL_CC] & ~affected_bits) | + mips->vfpuCtrl[VFPU_CTRL_CC] = + (mips->vfpuCtrl[VFPU_CTRL_CC] & ~affected_bits) | ((cc | (or_val << 4) | (and_val << 5)) & affected_bits); PC += 4; - EatPrefixes(); + EatPrefixes(mips); } - void Int_Vminmax(MIPSOpcode op) { + void Int_Vminmax(MIPSState *mips, MIPSOpcode op) { FloatBits s, t, d; int vt = _VT; int vs = _VS; @@ -1925,9 +1926,9 @@ namespace MIPSInt int numElements = GetNumVectorElements(sz); ReadVector(s.f, sz, vs); - ApplySwizzleS(s.f, sz); + ApplySwizzleS(mips, s.f, sz); ReadVector(t.f, sz, vt); - ApplySwizzleT(t.f, sz); + ApplySwizzleT(mips, t.f, sz); // If both are zero, take t's sign. // Otherwise: -NAN < -INF < real < INF < NAN (higher mantissa is farther from 0.) @@ -1966,26 +1967,26 @@ namespace MIPSInt default: _dbg_assert_msg_(false,"unknown min/max op %d", cond); PC += 4; - EatPrefixes(); + EatPrefixes(mips); return; } - RetainInvalidSwizzleST(d.f, sz); - ApplyPrefixD(d.f, sz); + RetainInvalidSwizzleST(mips, d.f, sz); + ApplyPrefixD(mips, d.f, sz); WriteVector(d.f, sz, vd); PC += 4; - EatPrefixes(); + EatPrefixes(mips); } - void Int_Vscmp(MIPSOpcode op) { + void Int_Vscmp(MIPSState *mips, MIPSOpcode op) { FloatBits s, t, d; int vt = _VT; int vs = _VS; int vd = _VD; VectorSize sz = GetVecSize(op); ReadVector(s.f, sz, vs); - ApplySwizzleS(s.f, sz); + ApplySwizzleS(mips, s.f, sz); ReadVector(t.f, sz, vt); - ApplySwizzleT(t.f, sz); + ApplySwizzleT(mips, t.f, sz); int n = GetNumVectorElements(sz); for (int i = 0; i < n ; i++) { float a = s.f[i] - t.f[i]; @@ -1999,14 +2000,14 @@ namespace MIPSInt d.f[i] = (float)((0.0f < a) - (a < 0.0f)); } } - RetainInvalidSwizzleST(d.f, sz); - ApplyPrefixD(d.f, sz); + RetainInvalidSwizzleST(mips, d.f, sz); + ApplyPrefixD(mips, d.f, sz); WriteVector(d.f, sz, vd); PC += 4; - EatPrefixes(); + EatPrefixes(mips); } - void Int_Vsge(MIPSOpcode op) { + void Int_Vsge(MIPSState *mips, MIPSOpcode op) { float s[4], t[4], d[4]; int vt = _VT; int vs = _VS; @@ -2014,24 +2015,24 @@ namespace MIPSInt VectorSize sz = GetVecSize(op); int numElements = GetNumVectorElements(sz); ReadVector(s, sz, vs); - ApplySwizzleS(s, sz); + ApplySwizzleS(mips, s, sz); ReadVector(t, sz, vt); - ApplySwizzleT(t, sz); + ApplySwizzleT(mips, t, sz); for (int i = 0; i < numElements; i++) { if ( my_isnan(s[i]) || my_isnan(t[i]) ) d[i] = 0.0f; else d[i] = s[i] >= t[i] ? 1.0f : 0.0f; } - RetainInvalidSwizzleST(d, sz); + RetainInvalidSwizzleST(mips, d, sz); // The clamp cannot matter, so skip it. - ApplyPrefixD(d, sz, true); + ApplyPrefixD(mips, d, sz, true); WriteVector(d, sz, vd); PC += 4; - EatPrefixes(); + EatPrefixes(mips); } - void Int_Vslt(MIPSOpcode op) { + void Int_Vslt(MIPSState *mips, MIPSOpcode op) { float s[4], t[4], d[4]; int vt = _VT; int vs = _VS; @@ -2039,25 +2040,25 @@ namespace MIPSInt VectorSize sz = GetVecSize(op); int numElements = GetNumVectorElements(sz); ReadVector(s, sz, vs); - ApplySwizzleS(s, sz); + ApplySwizzleS(mips, s, sz); ReadVector(t, sz, vt); - ApplySwizzleT(t, sz); + ApplySwizzleT(mips, t, sz); for (int i = 0; i < numElements; i++) { if ( my_isnan(s[i]) || my_isnan(t[i]) ) d[i] = 0.0f; else d[i] = s[i] < t[i] ? 1.0f : 0.0f; } - RetainInvalidSwizzleST(d, sz); + RetainInvalidSwizzleST(mips, d, sz); // The clamp cannot matter, so skip it. - ApplyPrefixD(d, sz, true); + ApplyPrefixD(mips, d, sz, true); WriteVector(d, sz, vd); PC += 4; - EatPrefixes(); + EatPrefixes(mips); } - void Int_Vcmov(MIPSOpcode op) { + void Int_Vcmov(MIPSState *mips, MIPSOpcode op) { int vs = _VS; int vd = _VD; int tf = (op >> 19) & 1; @@ -2067,12 +2068,12 @@ namespace MIPSInt float s[4]; float d[4]; ReadVector(s, sz, vs); - ApplySwizzleS(s, sz); + ApplySwizzleS(mips, s, sz); // Not only is D read (as T), but the T prefix applies to it. ReadVector(d, sz, vd); - ApplySwizzleT(d, sz); + ApplySwizzleT(mips, d, sz); - int CC = currentMIPS->vfpuCtrl[VFPU_CTRL_CC]; + int CC = mips->vfpuCtrl[VFPU_CTRL_CC]; if (imm3 < 6) { if (((CC >> imm3) & 1) == !tf) { @@ -2087,13 +2088,13 @@ namespace MIPSInt } else { ERROR_LOG_REPORT(Log::CPU, "Bad Imm3 in cmov: %d", imm3); } - ApplyPrefixD(d, sz); + ApplyPrefixD(mips, d, sz); WriteVector(d, sz, vd); PC += 4; - EatPrefixes(); + EatPrefixes(mips); } - void Int_VecDo3(MIPSOpcode op) { + void Int_VecDo3(MIPSState *mips, MIPSOpcode op) { float s[4], t[4]; FloatBits d; int vd = _VD; @@ -2127,14 +2128,14 @@ namespace MIPSInt ReadVector(s, sz, vs); ReadVector(t, sz, vt); if (optype != 7) { - ApplySwizzleS(s, sz); - ApplySwizzleT(t, sz); + ApplySwizzleS(mips, s, sz); + ApplySwizzleT(mips, t, sz); } else { // The prefix handling of S/T is a bit odd, probably the HW doesn't do it in parallel. // The X prefix is applied to the last element in sz. // TODO: This doesn't match exactly for a swizzle past x in some cases... - ApplySwizzleS(&s[n - 1], V_Single, -INFINITY); - ApplySwizzleT(&t[n - 1], V_Single, -INFINITY); + ApplySwizzleS(mips, &s[n - 1], V_Single, -INFINITY); + ApplySwizzleT(mips, &t[n - 1], V_Single, -INFINITY); } for (int i = 0; i < (int)n; i++) { @@ -2156,20 +2157,20 @@ namespace MIPSInt // For vdiv only, the D prefix only applies mask (and like S/T, x applied to last.) if (optype == 7) { - u32 lastmask = (currentMIPS->vfpuCtrl[VFPU_CTRL_DPREFIX] & (1 << 8)) << (n - 1); - u32 lastsat = (currentMIPS->vfpuCtrl[VFPU_CTRL_DPREFIX] & 3) << (n + n - 2); - currentMIPS->vfpuCtrl[VFPU_CTRL_DPREFIX] = lastmask | lastsat; - ApplyPrefixD(d.f, sz); + u32 lastmask = (mips->vfpuCtrl[VFPU_CTRL_DPREFIX] & (1 << 8)) << (n - 1); + u32 lastsat = (mips->vfpuCtrl[VFPU_CTRL_DPREFIX] & 3) << (n + n - 2); + mips->vfpuCtrl[VFPU_CTRL_DPREFIX] = lastmask | lastsat; + ApplyPrefixD(mips, d.f, sz); } else { - RetainInvalidSwizzleST(d.f, sz); - ApplyPrefixD(d.f, sz); + RetainInvalidSwizzleST(mips, d.f, sz); + ApplyPrefixD(mips, d.f, sz); } WriteVector(d.f, sz, vd); PC += 4; - EatPrefixes(); + EatPrefixes(mips); } - void Int_CrossQuat(MIPSOpcode op) { + void Int_CrossQuat(MIPSState *mips, MIPSOpcode op) { float s[4]{}, t[4]{}, d[4]; int vd = _VD; int vs = _VS; @@ -2197,8 +2198,8 @@ namespace MIPSInt // T prefix forces swizzle and negate, can be used to have weird constants. tprefixAdd = VFPU_SWIZZLE(1, 0, 3, 2) | VFPU_NEGATE(0, 1, 0, 0); - ApplyPrefixST(t, VFPURewritePrefix(VFPU_CTRL_TPREFIX, tprefixRemove, tprefixAdd), V_Quad); - ApplySwizzleS(s, V_Quad); + ApplyPrefixST(mips, t, VFPURewritePrefix(VFPU_CTRL_TPREFIX, tprefixRemove, tprefixAdd), V_Quad); + ApplySwizzleS(mips, s, V_Quad); if (USE_VFPU_DOT) { // TODO: But flush any infs to 0? This seems sketchy. for (int i = 0; i < 4; ++i) { @@ -2231,8 +2232,8 @@ namespace MIPSInt // T prefix forces swizzle and negate, can be used to have weird constants. tprefixAdd = VFPU_SWIZZLE(0, 1, 2, 3) | VFPU_NEGATE(1, 1, 1, 0); - ApplyPrefixST(t, VFPURewritePrefix(VFPU_CTRL_TPREFIX, tprefixRemove, tprefixAdd), V_Quad); - ApplySwizzleS(s, sz); + ApplyPrefixST(mips, t, VFPURewritePrefix(VFPU_CTRL_TPREFIX, tprefixRemove, tprefixAdd), V_Quad); + ApplySwizzleS(mips, s, sz); if (USE_VFPU_DOT) d[3] = vfpu_dot(s, t); else @@ -2245,8 +2246,8 @@ namespace MIPSInt d[0] = 0; tprefixAdd = VFPU_SWIZZLE(0, 0, 0, 0) | VFPU_NEGATE(0, 0, 0, 0); - ApplyPrefixST(t, VFPURewritePrefix(VFPU_CTRL_TPREFIX, tprefixRemove, tprefixAdd), V_Quad); - ApplySwizzleS(s, V_Quad); + ApplyPrefixST(mips, t, VFPURewritePrefix(VFPU_CTRL_TPREFIX, tprefixRemove, tprefixAdd), V_Quad); + ApplySwizzleS(mips, s, V_Quad); // It's possible to populate a value by swizzling s[2]. d[1] = s[2] * t[2]; break; @@ -2263,20 +2264,20 @@ namespace MIPSInt // D prefix applies to the last element only (mask and sat) for pair and larger. if (sz != V_Single) { - u32 lastmask = (currentMIPS->vfpuCtrl[VFPU_CTRL_DPREFIX] & (1 << 8)) << (n - 1); - u32 lastsat = (currentMIPS->vfpuCtrl[VFPU_CTRL_DPREFIX] & 3) << (n + n - 2); - currentMIPS->vfpuCtrl[VFPU_CTRL_DPREFIX] = lastmask | lastsat; - ApplyPrefixD(d, sz); + u32 lastmask = (mips->vfpuCtrl[VFPU_CTRL_DPREFIX] & (1 << 8)) << (n - 1); + u32 lastsat = (mips->vfpuCtrl[VFPU_CTRL_DPREFIX] & 3) << (n + n - 2); + mips->vfpuCtrl[VFPU_CTRL_DPREFIX] = lastmask | lastsat; + ApplyPrefixD(mips, d, sz); } else { // Single always seems to write out zero. - currentMIPS->vfpuCtrl[VFPU_CTRL_DPREFIX] = 0; + mips->vfpuCtrl[VFPU_CTRL_DPREFIX] = 0; } WriteVector(d, sz, vd); PC += 4; - EatPrefixes(); + EatPrefixes(mips); } - void Int_Vlgb(MIPSOpcode op) { + void Int_Vlgb(MIPSState *mips, MIPSOpcode op) { // Vector log binary (extract exponent) FloatBits d, s; int vd = _VD; @@ -2284,7 +2285,7 @@ namespace MIPSInt VectorSize sz = GetVecSize(op); ReadVector(s.f, sz, vs); - ApplySwizzleS(s.f, sz); + ApplySwizzleS(mips, s.f, sz); int exp = (s.u[0] & 0x7F800000) >> 23; if (exp == 0xFF) { @@ -2300,14 +2301,14 @@ namespace MIPSInt d.u[i] = s.u[i]; } - RetainInvalidSwizzleST(d.f, sz); - ApplyPrefixD(d.f, sz); + RetainInvalidSwizzleST(mips, d.f, sz); + ApplyPrefixD(mips, d.f, sz); WriteVector(d.f, sz, vd); PC += 4; - EatPrefixes(); + EatPrefixes(mips); } - void Int_Vwbn(MIPSOpcode op) { + void Int_Vwbn(MIPSState *mips, MIPSOpcode op) { FloatBits d, s; int vd = _VD; int vs = _VS; @@ -2315,7 +2316,7 @@ namespace MIPSInt u8 exp = (u8)((op >> 16) & 0xFF); ReadVector(s.f, sz, vs); - ApplySwizzleS(s.f, sz); + ApplySwizzleS(mips, s.f, sz); u32 sigbit = s.u[0] & 0x80000000; u32 prevExp = (s.u[0] & 0x7F800000) >> 23; @@ -2338,14 +2339,14 @@ namespace MIPSInt d.u[i] = s.u[i]; } - RetainInvalidSwizzleST(d.f, sz); - ApplyPrefixD(d.f, sz); + RetainInvalidSwizzleST(mips, d.f, sz); + ApplyPrefixD(mips, d.f, sz); WriteVector(d.f, sz, vd); PC += 4; - EatPrefixes(); + EatPrefixes(mips); } - void Int_Vsbn(MIPSOpcode op) { + void Int_Vsbn(MIPSState *mips, MIPSOpcode op) { FloatBits d, s, t; int vd = _VD; int vs = _VS; @@ -2353,9 +2354,9 @@ namespace MIPSInt VectorSize sz = GetVecSize(op); ReadVector(s.f, sz, vs); - ApplySwizzleS(s.f, sz); + ApplySwizzleS(mips, s.f, sz); ReadVector(t.f, sz, vt); - ApplySwizzleT(t.f, sz); + ApplySwizzleT(mips, t.f, sz); // Swizzle does apply to the value read as an integer. u8 exp = (u8)(127 + t.i[0]); @@ -2372,13 +2373,13 @@ namespace MIPSInt d.u[i] = s.u[i]; } - ApplyPrefixD(d.f, sz); + ApplyPrefixD(mips, d.f, sz); WriteVector(d.f, sz, vd); PC += 4; - EatPrefixes(); + EatPrefixes(mips); } - void Int_Vsbz(MIPSOpcode op) { + void Int_Vsbz(MIPSState *mips, MIPSOpcode op) { // Vector scale by zero (set exp to 0 to extract mantissa) FloatBits d, s; int vd = _VD; @@ -2386,7 +2387,7 @@ namespace MIPSInt VectorSize sz = GetVecSize(op); ReadVector(s.f, sz, vs); - ApplySwizzleS(s.f, sz); + ApplySwizzleS(mips, s.f, sz); // NAN and denormals pass through. if (my_isnan(s.f[0]) || (s.u[0] & 0x7F800000) == 0) { @@ -2400,9 +2401,9 @@ namespace MIPSInt d.u[i] = s.u[i]; } - ApplyPrefixD(d.f, sz); + ApplyPrefixD(mips, d.f, sz); WriteVector(d.f, sz, vd); PC += 4; - EatPrefixes(); + EatPrefixes(mips); } } diff --git a/Core/MIPS/InterpreterVFPU.h b/Core/MIPS/InterpreterVFPU.h index e703a57f7b..57c567ce65 100644 --- a/Core/MIPS/InterpreterVFPU.h +++ b/Core/MIPS/InterpreterVFPU.h @@ -20,63 +20,61 @@ #include "Common/CommonTypes.h" #include "Core/MIPS/MIPS.h" -int MIPS_SingleStep(); - namespace MIPSInt { - void Int_SV(MIPSOpcode op); - void Int_SVQ(MIPSOpcode op); - void Int_Mftv(MIPSOpcode op); - void Int_VecDo3(MIPSOpcode op); - void Int_Vcst(MIPSOpcode op); - void Int_VMatrixInit(MIPSOpcode op); - void Int_VVectorInit(MIPSOpcode op); - void Int_Vmmul(MIPSOpcode op); - void Int_Vmscl(MIPSOpcode op); - void Int_Vmmov(MIPSOpcode op); - void Int_VV2Op(MIPSOpcode op); - void Int_Vrot(MIPSOpcode op); - void Int_VDot(MIPSOpcode op); - void Int_VHdp(MIPSOpcode op); - void Int_Vavg(MIPSOpcode op); - void Int_Vfad(MIPSOpcode op); - void Int_Vocp(MIPSOpcode op); - void Int_Vsocp(MIPSOpcode op); - void Int_Vsgn(MIPSOpcode op); - void Int_Vtfm(MIPSOpcode op); - void Int_Viim(MIPSOpcode op); - void Int_VScl(MIPSOpcode op); - void Int_Vidt(MIPSOpcode op); - void Int_Vcmp(MIPSOpcode op); - void Int_Vminmax(MIPSOpcode op); - void Int_Vscmp(MIPSOpcode op); - void Int_Vcrs(MIPSOpcode op); - void Int_Vdet(MIPSOpcode op); - void Int_Vcmov(MIPSOpcode op); - void Int_CrossQuat(MIPSOpcode op); - void Int_VPFX(MIPSOpcode op); - void Int_Vflush(MIPSOpcode op); - void Int_Vbfy(MIPSOpcode op); - void Int_Vsrt1(MIPSOpcode op); - void Int_Vsrt2(MIPSOpcode op); - void Int_Vsrt3(MIPSOpcode op); - void Int_Vsrt4(MIPSOpcode op); - void Int_Vf2i(MIPSOpcode op); - void Int_Vi2f(MIPSOpcode op); - void Int_Vi2x(MIPSOpcode op); - void Int_Vx2i(MIPSOpcode op); - void Int_VBranch(MIPSOpcode op); - void Int_Vrnds(MIPSOpcode op); - void Int_VrndX(MIPSOpcode op); - void Int_ColorConv(MIPSOpcode op); - void Int_Vh2f(MIPSOpcode op); - void Int_Vf2h(MIPSOpcode op); - void Int_Vsge(MIPSOpcode op); - void Int_Vslt(MIPSOpcode op); - void Int_Vmfvc(MIPSOpcode op); - void Int_Vmtvc(MIPSOpcode op); - void Int_Vlgb(MIPSOpcode op); - void Int_Vwbn(MIPSOpcode op); - void Int_Vsbn(MIPSOpcode op); - void Int_Vsbz(MIPSOpcode op); + void Int_SV(MIPSState *mips, MIPSOpcode op); + void Int_SVQ(MIPSState *mips, MIPSOpcode op); + void Int_Mftv(MIPSState *mips, MIPSOpcode op); + void Int_VecDo3(MIPSState *mips, MIPSOpcode op); + void Int_Vcst(MIPSState *mips, MIPSOpcode op); + void Int_VMatrixInit(MIPSState *mips, MIPSOpcode op); + void Int_VVectorInit(MIPSState *mips, MIPSOpcode op); + void Int_Vmmul(MIPSState *mips, MIPSOpcode op); + void Int_Vmscl(MIPSState *mips, MIPSOpcode op); + void Int_Vmmov(MIPSState *mips, MIPSOpcode op); + void Int_VV2Op(MIPSState *mips, MIPSOpcode op); + void Int_Vrot(MIPSState *mips, MIPSOpcode op); + void Int_VDot(MIPSState *mips, MIPSOpcode op); + void Int_VHdp(MIPSState *mips, MIPSOpcode op); + void Int_Vavg(MIPSState *mips, MIPSOpcode op); + void Int_Vfad(MIPSState *mips, MIPSOpcode op); + void Int_Vocp(MIPSState *mips, MIPSOpcode op); + void Int_Vsocp(MIPSState *mips, MIPSOpcode op); + void Int_Vsgn(MIPSState *mips, MIPSOpcode op); + void Int_Vtfm(MIPSState *mips, MIPSOpcode op); + void Int_Viim(MIPSState *mips, MIPSOpcode op); + void Int_VScl(MIPSState *mips, MIPSOpcode op); + void Int_Vidt(MIPSState *mips, MIPSOpcode op); + void Int_Vcmp(MIPSState *mips, MIPSOpcode op); + void Int_Vminmax(MIPSState *mips, MIPSOpcode op); + void Int_Vscmp(MIPSState *mips, MIPSOpcode op); + void Int_Vcrs(MIPSState *mips, MIPSOpcode op); + void Int_Vdet(MIPSState *mips, MIPSOpcode op); + void Int_Vcmov(MIPSState *mips, MIPSOpcode op); + void Int_CrossQuat(MIPSState *mips, MIPSOpcode op); + void Int_VPFX(MIPSState *mips, MIPSOpcode op); + void Int_Vflush(MIPSState *mips, MIPSOpcode op); + void Int_Vbfy(MIPSState *mips, MIPSOpcode op); + void Int_Vsrt1(MIPSState *mips, MIPSOpcode op); + void Int_Vsrt2(MIPSState *mips, MIPSOpcode op); + void Int_Vsrt3(MIPSState *mips, MIPSOpcode op); + void Int_Vsrt4(MIPSState *mips, MIPSOpcode op); + void Int_Vf2i(MIPSState *mips, MIPSOpcode op); + void Int_Vi2f(MIPSState *mips, MIPSOpcode op); + void Int_Vi2x(MIPSState *mips, MIPSOpcode op); + void Int_Vx2i(MIPSState *mips, MIPSOpcode op); + void Int_VBranch(MIPSState *mips, MIPSOpcode op); + void Int_Vrnds(MIPSState *mips, MIPSOpcode op); + void Int_VrndX(MIPSState *mips, MIPSOpcode op); + void Int_ColorConv(MIPSState *mips, MIPSOpcode op); + void Int_Vh2f(MIPSState *mips, MIPSOpcode op); + void Int_Vf2h(MIPSState *mips, MIPSOpcode op); + void Int_Vsge(MIPSState *mips, MIPSOpcode op); + void Int_Vslt(MIPSState *mips, MIPSOpcode op); + void Int_Vmfvc(MIPSState *mips, MIPSOpcode op); + void Int_Vmtvc(MIPSState *mips, MIPSOpcode op); + void Int_Vlgb(MIPSState *mips, MIPSOpcode op); + void Int_Vwbn(MIPSState *mips, MIPSOpcode op); + void Int_Vsbn(MIPSState *mips, MIPSOpcode op); + void Int_Vsbz(MIPSState *mips, MIPSOpcode op); } diff --git a/Core/MIPS/LoongArch64/LoongArch64Jit.cpp b/Core/MIPS/LoongArch64/LoongArch64Jit.cpp index cbb5869573..7d7b028645 100644 --- a/Core/MIPS/LoongArch64/LoongArch64Jit.cpp +++ b/Core/MIPS/LoongArch64/LoongArch64Jit.cpp @@ -259,7 +259,7 @@ void LoongArch64JitBackend::CompIR_Interpret(IRInst inst) { QuickCallFunction(&NotifyMIPSInterpret, SCRATCH2); } LI(R4, (int32_t)inst.constant); - QuickCallFunction((const u8 *)MIPSGetInterpretFunc(op), SCRATCH2); + QuickCallFunction((const u8 *)&MIPSInterpretTrampoline, SCRATCH2); WriteDebugProfilerStatus(IRProfilerStatus::IN_JIT); LoadStaticRegisters(); } diff --git a/Core/MIPS/MIPSTables.cpp b/Core/MIPS/MIPSTables.cpp index 45b4e38b33..ddcc8b1192 100644 --- a/Core/MIPS/MIPSTables.cpp +++ b/Core/MIPS/MIPSTables.cpp @@ -976,7 +976,7 @@ static void EmitDispatchLevel(std::string &out, MipsEncoding encoding, int inden out += ind + StringFromFormat("// %s\n", names.c_str()); for (u32 idx : group) out += ind + StringFromFormat("case %d:\n", idx); - out += ind2 + StringFromFormat("MIPSInt::%s(op);\n", instr.interpretName); + out += ind2 + StringFromFormat("MIPSInt::%s(mips, op);\n", instr.interpretName); out += ind2 + StringFromFormat("return %d;\n", (int)instr.flags.cycles); } else { for (u32 idx : group) @@ -985,7 +985,7 @@ static void EmitDispatchLevel(std::string &out, MipsEncoding encoding, int inden EmitDispatchLevel(out, instr.altEncoding, indent + 1); out += ind + "}\n"; // No trailing return here - the nested switch above always either returns - // a value directly from a case, or falls to its own default's "goto slow_path;". + // a value directly from a case, or falls to its own default's "return -1;". } } @@ -995,15 +995,15 @@ static void EmitDispatchLevel(std::string &out, MipsEncoding encoding, int inden } // Generates a full, compilable Core/MIPS/InterpreterDispatch.cpp: a fast -// int ExecInstruction(MIPSOpcode op) dispatcher, built by resolving the tables above into -// a nested switch tree at generation time, so each real instruction is reached by a direct -// call instead of MIPSGetInstruction()'s per-instruction table walk plus indirect call -// through instr->interpret. Leaves call straight into the existing MIPSInt::Int_* handlers -// - the tables only record which handler an opcode maps to, not the handler's behavior, so -// that's the only thing there is to call - and return that instruction's fixed cycle count -// (baked in at generation time, same value MIPSGetInstructionCycleEstimate() would have -// returned) so the caller can still track downcount. Operates on the global currentMIPS, -// same as the Int_* handlers do. +// int ExecInstruction(MIPSState *mips, MIPSOpcode op) dispatcher, built by resolving the +// tables above into a nested switch tree at generation time, so each real instruction is +// reached by a direct call instead of MIPSGetInstruction()'s per-instruction table walk plus +// indirect call through instr->interpret. Leaves call straight into the existing +// MIPSInt::Int_* handlers - the tables only record which handler an opcode maps to, not the +// handler's behavior, so that's the only thing there is to call - and return that +// instruction's fixed cycle count (baked in at generation time, same value +// MIPSGetInstructionCycleEstimate() would have returned) so the caller can still track +// downcount. // // The generated function is deliberately not total: most of the 32-bit opcode space doesn't // decode to anything (either a genuinely invalid encoding, or a real-but-uninterpreted @@ -1036,7 +1036,7 @@ std::string GenerateInterpreterDispatch() { out += "#include \"Core/MIPS/InterpreterVFPU.h\"\n\n"; out += "// Returns the cycle count consumed, or -1 if op isn't a recognized instruction -\n"; out += "// callers must fall back to MIPSInterpret() themselves in that case.\n"; - out += "int ExecInstruction(MIPSOpcode op) {\n"; + out += "int ExecInstruction(MIPSState *mips, MIPSOpcode op) {\n"; EmitDispatchLevel(out, Imme, 1); out += "}\n"; return out; @@ -1097,7 +1097,7 @@ static void HandleUnknownInstruction(MIPSState *mips, MIPSOpcode op) { static inline void Interpret(MIPSState *mips, const MIPSInstruction *instr, MIPSOpcode op) { if (instr && instr->interpret) { - instr->interpret(op); + instr->interpret(mips, op); } else { HandleUnknownInstruction(mips, op); } @@ -1114,6 +1114,11 @@ void MIPSInterpret(MIPSState *mips, MIPSOpcode op) { Interpret(mips, instr, op); } +// See the declaration comment in MIPSTables.h. +void CDECL MIPSInterpretTrampoline(MIPSOpcode op) { + MIPSInterpret(currentMIPS, op); +} + static inline void RunUntilFast(MIPSState *curMips) { // NEVER stop in a delay slot! while (curMips->downcount >= 0 && coreState == CORE_RUNNING_CPU) { @@ -1125,7 +1130,7 @@ static inline void RunUntilFast(MIPSState *curMips) { MIPSOpcode op = MIPSOpcode(Memory::ReadUnchecked_U32(curMips->pc)); bool wasInDelaySlot = curMips->inDelaySlot; - int cycles = ExecInstruction(op); + int cycles = ExecInstruction(curMips, op); if (cycles < 0) { // Not a recognized instruction (invalid encoding, or a known instruction // with no interpreter implementation, e.g. tge/tlt/teq/...). No point diff --git a/Core/MIPS/MIPSTables.h b/Core/MIPS/MIPSTables.h index 33aba3fb0e..2e64ca58db 100644 --- a/Core/MIPS/MIPSTables.h +++ b/Core/MIPS/MIPSTables.h @@ -122,7 +122,7 @@ struct MIPSInfo { }; typedef void (CDECL *MIPSDisFunc)(MIPSOpcode opcode, uint32_t pc, char *out, size_t outSize); -typedef void (CDECL *MIPSInterpretFunc)(MIPSOpcode opcode); +typedef void (CDECL *MIPSInterpretFunc)(MIPSState *mips, MIPSOpcode opcode); namespace MIPSComp { class MIPSFrontendInterface; @@ -135,12 +135,20 @@ void MIPSInterpret(MIPSState *mips, MIPSOpcode op); //only for those rare ones int MIPSInterpret_RunUntil(MIPSState *mips, u64 globalTicks); MIPSInterpretFunc MIPSGetInterpretFunc(MIPSOpcode op); +// 1-arg (MIPSOpcode only) trampoline around MIPSInterpret(currentMIPS, op), for JIT backends +// (x86/ARM/ARM64/RiscV/LoongArch64 Comp_Generic / CompIR_Interpret) that bake a raw function +// pointer directly into generated machine code as their interpreter fallback - that codegen +// only arranges a single MIPSOpcode argument before the call, so it can't target a real +// MIPSInterpretFunc (now 2-arg) without also being taught to pass an explicit MIPSState*. +// TODO: teach each JIT's codegen to pass mips explicitly, then delete this. +void CDECL MIPSInterpretTrampoline(MIPSOpcode op); + int MIPSGetInstructionCycleEstimate(MIPSOpcode op); int MIPSGetMemoryAccessSize(MIPSOpcode op); const char *MIPSGetName(MIPSOpcode op); std::string MIPSDisasmAt(u32 compilerPC); // Generates the full contents of Core/MIPS/InterpreterDispatch.cpp: a fast switch-tree -// int ExecInstruction(MIPSOpcode op) dispatcher, derived from the tables in MIPSTables.cpp. -// See GenerateInterpreterDispatch()'s comment (in the .cpp) for details. +// int ExecInstruction(MIPSState *mips, MIPSOpcode op) dispatcher, derived from the tables in +// MIPSTables.cpp. See GenerateInterpreterDispatch()'s comment (in the .cpp) for details. std::string GenerateInterpreterDispatch(); diff --git a/Core/MIPS/RiscV/RiscVJit.cpp b/Core/MIPS/RiscV/RiscVJit.cpp index 2fd9a34523..87181c989f 100644 --- a/Core/MIPS/RiscV/RiscVJit.cpp +++ b/Core/MIPS/RiscV/RiscVJit.cpp @@ -260,7 +260,7 @@ void RiscVJitBackend::CompIR_Interpret(IRInst inst) { QuickCallFunction(&NotifyMIPSInterpret, SCRATCH2); } LI(X10, (int32_t)inst.constant); - QuickCallFunction((const u8 *)MIPSGetInterpretFunc(op), SCRATCH2); + QuickCallFunction((const u8 *)&MIPSInterpretTrampoline, SCRATCH2); WriteDebugProfilerStatus(IRProfilerStatus::IN_JIT); LoadStaticRegisters(); } diff --git a/Core/MIPS/x86/CompBranch.cpp b/Core/MIPS/x86/CompBranch.cpp index c847c342ed..8db2c28883 100644 --- a/Core/MIPS/x86/CompBranch.cpp +++ b/Core/MIPS/x86/CompBranch.cpp @@ -85,7 +85,7 @@ static void JitBranchLog(MIPSOpcode op, u32 pc) { MIPSInterpretFunc func = MIPSGetInterpretFunc(op); MIPSInfo info = MIPSGetInfo(op); - func(op); + func(currentMIPS, op); // Branch taken, use nextPC. if (currentMIPS->inDelaySlot) diff --git a/Core/MIPS/x86/Jit.cpp b/Core/MIPS/x86/Jit.cpp index 68f4986340..3993b31c1e 100644 --- a/Core/MIPS/x86/Jit.cpp +++ b/Core/MIPS/x86/Jit.cpp @@ -111,7 +111,7 @@ static void JitLogMiss(MIPSOpcode op) notJitOps[MIPSGetName(op)]++; MIPSInterpretFunc func = MIPSGetInterpretFunc(op); - func(op); + func(currentMIPS, op); } #ifdef _MSC_VER @@ -626,7 +626,7 @@ void Jit::Comp_Generic(MIPSOpcode op) { if (USE_JIT_MISSMAP) ABI_CallFunctionC(&JitLogMiss, op.encoding); else - ABI_CallFunctionC(func, op.encoding); + ABI_CallFunctionC(&MIPSInterpretTrampoline, op.encoding); ApplyRoundingMode(); } else { // These are basically always due to some kind of crash or corruption now. diff --git a/Core/MIPS/x86/X64IRJit.cpp b/Core/MIPS/x86/X64IRJit.cpp index fbfcf9ff9c..c391e97985 100644 --- a/Core/MIPS/x86/X64IRJit.cpp +++ b/Core/MIPS/x86/X64IRJit.cpp @@ -256,7 +256,7 @@ void X64JitBackend::CompIR_Interpret(IRInst inst) { if (DebugStatsEnabled()) { ABI_CallFunctionP((const void *)&NotifyMIPSInterpret, (void *)MIPSGetName(op)); } - ABI_CallFunctionC((const void *)MIPSGetInterpretFunc(op), inst.constant); + ABI_CallFunctionC((const void *)&MIPSInterpretTrampoline, inst.constant); WriteDebugProfilerStatus(IRProfilerStatus::IN_JIT); LoadStaticRegisters(); } diff --git a/Tools/update-dispatcher.py b/Tools/update-dispatcher.py index e04d1e6bea..a96ac09fb4 100644 --- a/Tools/update-dispatcher.py +++ b/Tools/update-dispatcher.py @@ -75,7 +75,7 @@ def main(): # Sanity check before clobbering the tracked file - a stale/broken binary should # fail loudly here rather than silently truncating InterpreterDispatch.cpp. - if b"int ExecInstruction(MIPSOpcode op)" not in generated: + if b"int ExecInstruction(MIPSState *mips, MIPSOpcode op)" not in generated: sys.stderr.write("error: generated output doesn't look right (missing ExecInstruction) - not overwriting %s\n" % OUT_PATH) return 1 From b10e4ad1b560240fbb475a5c2af327bc27fb10cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Wed, 12 Aug 2026 13:31:36 +0200 Subject: [PATCH 2/7] Code style improvement, handle unknown instructions with a pseudo CPU exception --- Core/Core.cpp | 1 + Core/Core.h | 1 + Core/MIPS/Interpreter.cpp | 143 ++++++++++++++------------------------ Core/MIPS/MIPSTables.cpp | 97 +++++++++++--------------- 4 files changed, 95 insertions(+), 147 deletions(-) diff --git a/Core/Core.cpp b/Core/Core.cpp index 67133ecb60..f7caa1646d 100644 --- a/Core/Core.cpp +++ b/Core/Core.cpp @@ -640,6 +640,7 @@ const char *ExecExceptionTypeAsString(ExecExceptionType type) { switch (type) { case ExecExceptionType::JUMP: return "CPU Jump"; case ExecExceptionType::THREAD: return "Thread switch"; + case ExecExceptionType::ILLEGAL: return "Illegal instruction"; // or unknown, but I think we have all now. default: return "N/A"; } diff --git a/Core/Core.h b/Core/Core.h index 632c9f11c9..1485875de0 100644 --- a/Core/Core.h +++ b/Core/Core.h @@ -207,6 +207,7 @@ enum class MemoryExceptionType { enum class ExecExceptionType { JUMP, THREAD, + ILLEGAL, }; void Core_MemoryException(u32 address, u32 accessSize, u32 pc, MemoryExceptionType type, std::string_view additionalInfo = ""); diff --git a/Core/MIPS/Interpreter.cpp b/Core/MIPS/Interpreter.cpp index b3d19e2b8d..a16c9e6856 100644 --- a/Core/MIPS/Interpreter.cpp +++ b/Core/MIPS/Interpreter.cpp @@ -54,8 +54,7 @@ #define HI mips->hi #define LO mips->lo -static inline void DelayBranchTo(MIPSState *mips, u32 where) -{ +static inline void DelayBranchTo(MIPSState *mips, u32 where) { if (!Memory::IsValidAddress(where) || (where & 3) != 0) { Core_ExecException(where, PC, ExecExceptionType::JUMP); } @@ -93,10 +92,8 @@ int MIPS_SingleStep(MIPSState *mips) { return 1; } -namespace MIPSInt -{ - void Int_Cache(MIPSState *mips, MIPSOpcode op) - { +namespace MIPSInt { + void Int_Cache(MIPSState *mips, MIPSOpcode op) { int imm = SignExtend16ToS32(op); int rs = _RS; uint32_t addr = R(rs) + imm; @@ -154,38 +151,31 @@ namespace MIPSInt PC += 4; } - void Int_Syscall(MIPSState *mips, MIPSOpcode op) - { + void Int_Syscall(MIPSState *mips, MIPSOpcode op) { // Need to pre-move PC, as CallSyscall may result in a rescheduling! // To do this neater, we'll need a little generated kernel loop that syscall can jump to and then RFI from // but I don't see a need to bother. - if (mips->inDelaySlot) - { + if (mips->inDelaySlot) { mips->pc = mips->nextPC; - } - else - { + } else { mips->pc += 4; } mips->inDelaySlot = false; CallSyscall(op); } - void Int_Sync(MIPSState *mips, MIPSOpcode op) - { + void Int_Sync(MIPSState *mips, MIPSOpcode op) { //DEBUG_LOG(Log::CPU, "sync"); PC += 4; } - void Int_Break(MIPSState *mips, MIPSOpcode op) - { + void Int_Break(MIPSState *mips, MIPSOpcode op) { Reporting::ReportMessage("BREAK instruction hit"); Core_BreakException(PC); PC += 4; } - void Int_RelBranch(MIPSState *mips, MIPSOpcode op) - { + void Int_RelBranch(MIPSState *mips, MIPSOpcode op) { int imm = _SIMM16_SHL2; int rs = _RS; int rt = _RT; @@ -209,14 +199,12 @@ namespace MIPSInt } } - void Int_RelBranchRI(MIPSState *mips, MIPSOpcode op) - { + void Int_RelBranchRI(MIPSState *mips, MIPSOpcode op) { int imm = _SIMM16_SHL2; int rs = _RS; u32 addr = PC + imm + 4; - switch ((op>>16) & 0x1F) - { + switch ((op>>16) & 0x1F) { case 0: if ((s32)R(rs) < 0) DelayBranchTo(mips, addr); else PC += 4; break;//bltz case 1: if ((s32)R(rs) >= 0) DelayBranchTo(mips, addr); else PC += 4; break;//bgez case 2: if ((s32)R(rs) < 0) DelayBranchTo(mips, addr); else SkipLikely(mips); break;//bltzl @@ -231,9 +219,7 @@ namespace MIPSInt } } - - void Int_VBranch(MIPSState *mips, MIPSOpcode op) - { + void Int_VBranch(MIPSState *mips, MIPSOpcode op) { int imm = _SIMM16_SHL2; u32 addr = PC + imm + 4; @@ -241,8 +227,7 @@ namespace MIPSInt int imm3 = (op>>18)&7; int val = (mips->vfpuCtrl[VFPU_CTRL_CC] >> imm3) & 1; - switch ((op >> 16) & 3) - { + switch ((op >> 16) & 3) { case 0: if (!val) DelayBranchTo(mips, addr); else PC += 4; break; //bvf case 1: if ( val) DelayBranchTo(mips, addr); else PC += 4; break; //bvt case 2: if (!val) DelayBranchTo(mips, addr); else SkipLikely(mips); break; //bvfl @@ -250,11 +235,10 @@ namespace MIPSInt } } - void Int_FPUBranch(MIPSState *mips, MIPSOpcode op) - { + void Int_FPUBranch(MIPSState *mips, MIPSOpcode op) { int imm = _SIMM16_SHL2; u32 addr = PC + imm + 4; - switch((op>>16)&0x1f) + switch((op >> 16) & 0x1f) { case 0: if (!mips->fpcond) DelayBranchTo(mips, addr); else PC += 4; break;//bc1f case 1: if ( mips->fpcond) DelayBranchTo(mips, addr); else PC += 4; break;//bc1t @@ -266,16 +250,16 @@ namespace MIPSInt } } - void Int_JumpType(MIPSState *mips, MIPSOpcode op) - { - if (mips->inDelaySlot) - ERROR_LOG(Log::CPU, "Jump in delay slot :("); + void Int_JumpType(MIPSState *mips, MIPSOpcode op) { + if (mips->inDelaySlot) { + // There's one of these in Star Soldier at 0881808c, which seems benign. + ERROR_LOG(Log::CPU, "Jump in delay slot at %08x", mips->pc); + } - u32 off = ((op & 0x03FFFFFF) << 2); - u32 addr = (mips->pc & 0xF0000000) | off; + const u32 off = ((op & 0x03FFFFFF) << 2); + const u32 addr = (mips->pc & 0xF0000000) | off; - switch (op>>26) - { + switch (op >> 26) { case 2: //j if (!mips->inDelaySlot) DelayBranchTo(mips, addr); @@ -291,18 +275,16 @@ namespace MIPSInt } } - void Int_JumpRegType(MIPSState *mips, MIPSOpcode op) - { + void Int_JumpRegType(MIPSState *mips, MIPSOpcode op) { if (mips->inDelaySlot) { // There's one of these in Star Soldier at 0881808c, which seems benign. - ERROR_LOG(Log::CPU, "Jump in delay slot :("); + ERROR_LOG(Log::CPU, "Jump in delay slot at %08x", mips->pc); } int rs = _RS; int rd = _RD; u32 addr = R(rs); - switch (op & 0x3f) - { + switch (op & 0x3f) { case 8: //jr if (!mips->inDelaySlot) DelayBranchTo(mips, addr); @@ -353,8 +335,7 @@ namespace MIPSInt int rs = _RS; u32 addr = R(rs) + imm; - switch (op >> 26) - { + switch (op >> 26) { case 48: // ll if (rt != 0) { if (!Memory::IsValid4AlignedAddress(addr)) { @@ -386,7 +367,6 @@ namespace MIPSInt PC += 4; } - void Int_RType3(MIPSState *mips, MIPSOpcode op) { int rt = _RT; int rs = _RS; @@ -640,20 +620,17 @@ namespace MIPSInt PC += 4; } - void Int_RType2(MIPSState *mips, MIPSOpcode op) - { + void Int_RType2(MIPSState *mips, MIPSOpcode op) { int rs = _RS; int rd = _RD; // Don't change $zr. - if (rd == 0) - { + if (rd == 0) { PC += 4; return; } - switch (op & 63) - { + switch (op & 63) { case 22: //clz R(rd) = clz32(R(rs)); break; @@ -788,7 +765,7 @@ namespace MIPSInt switch (op & 0x3f) { - case 0: R(rd) = R(rt) << sa; break; //sll + case 0: R(rd) = R(rt) << sa; break; //sll case 2: if (_RS == 0) //srl { @@ -803,21 +780,19 @@ namespace MIPSInt else goto wrong; - case 3: R(rd) = (u32)(((s32)R(rt)) >> sa); break; //sra - case 4: R(rd) = R(rt) << (R(rs)&0x1F); break; //sllv + case 3: R(rd) = (u32)(((s32)R(rt)) >> sa); break; //sra + case 4: R(rd) = R(rt) << (R(rs) & 0x1F); break; //sllv case 6: - if (_FD == 0) //srlv - { + if (_FD == 0) { //srlv R(rd) = R(rt) >> (R(rs)&0x1F); break; - } - else if (_FD == 1) // rotrv - { + } else if (_FD == 1) { // rotrv R(rd) = __rotr(R(rt), R(rs)); break; + } else { + goto wrong; } - else goto wrong; - case 7: R(rd) = (u32)(((s32)R(rt)) >> (R(rs)&0x1F)); break; //srav + case 7: R(rd) = (u32)(((s32)R(rt)) >> (R(rs) & 0x1F)); break; //srav default: wrong: _dbg_assert_msg_(false,"Trying to interpret instruction that can't be interpreted"); @@ -826,20 +801,17 @@ namespace MIPSInt PC += 4; } - void Int_Allegrex(MIPSState *mips, MIPSOpcode op) - { + void Int_Allegrex(MIPSState *mips, MIPSOpcode op) { int rt = _RT; int rd = _RD; // Don't change $zr. - if (rd == 0) - { + if (rd == 0) { PC += 4; return; } - switch((op>>6)&31) - { + switch ((op >> 6) & 31) { case 16: // seb R(rd) = SignExtend8ToU32(R(rt)); break; @@ -859,20 +831,17 @@ namespace MIPSInt PC += 4; } - void Int_Allegrex2(MIPSState *mips, MIPSOpcode op) - { + void Int_Allegrex2(MIPSState *mips, MIPSOpcode op) { int rt = _RT; int rd = _RD; // Don't change $zr. - if (rd == 0) - { + if (rd == 0) { PC += 4; return; } - switch (op & 0x3ff) - { + switch (op & 0x3ff) { case 0xA0: //wsbh R(rd) = ((R(rt) & 0xFF00FF00) >> 8) | ((R(rt) & 0x00FF00FF) << 8); break; @@ -886,11 +855,9 @@ namespace MIPSInt PC += 4; } - void Int_Special2(MIPSState *mips, MIPSOpcode op) - { + void Int_Special2(MIPSState *mips, MIPSOpcode op) { static int reported = 0; - switch (op & 0x3F) - { + switch (op & 0x3F) { case 36: // mfic // move from interrupt controller, not implemented // See related report https://report.ppsspp.org/logs/kind/316 for possible locations. @@ -912,8 +879,7 @@ namespace MIPSInt PC += 4; } - void Int_Special3(MIPSState *mips, MIPSOpcode op) - { + void Int_Special3(MIPSState *mips, MIPSOpcode op) { int rs = _RS; int rt = _RT; int pos = _POS; @@ -945,8 +911,7 @@ namespace MIPSInt PC += 4; } - void Int_FPU2op(MIPSState *mips, MIPSOpcode op) - { + void Int_FPU2op(MIPSState *mips, MIPSOpcode op) { int fs = _FS; int fd = _FD; @@ -1007,8 +972,7 @@ namespace MIPSInt PC += 4; } - void Int_FPUComp(MIPSState *mips, MIPSOpcode op) - { + void Int_FPUComp(MIPSState *mips, MIPSOpcode op) { int fs = _FS; int ft = _FT; bool cond; @@ -1063,8 +1027,7 @@ namespace MIPSInt PC += 4; } - void Int_FPU3op(MIPSState *mips, MIPSOpcode op) - { + void Int_FPU3op(MIPSState *mips, MIPSOpcode op) { int ft = _FT; int fs = _FS; int fd = _FD; @@ -1089,8 +1052,7 @@ namespace MIPSInt PC += 4; } - void Int_Interrupt(MIPSState *mips, MIPSOpcode op) - { + void Int_Interrupt(MIPSState *mips, MIPSOpcode op) { static int reported = 0; switch (op & 1) { @@ -1106,8 +1068,7 @@ namespace MIPSInt PC += 4; } - void Int_Emuhack(MIPSState *mips, MIPSOpcode op) - { + void Int_Emuhack(MIPSState *mips, MIPSOpcode op) { if (((op >> 24) & 3) != EMUOP_CALL_REPLACEMENT) { _dbg_assert_msg_(false, "Trying to interpret emuhack instruction that can't be interpreted"); } diff --git a/Core/MIPS/MIPSTables.cpp b/Core/MIPS/MIPSTables.cpp index ddcc8b1192..cfd28a63db 100644 --- a/Core/MIPS/MIPSTables.cpp +++ b/Core/MIPS/MIPSTables.cpp @@ -1082,24 +1082,11 @@ void MIPSDisAsm(MIPSOpcode op, u32 pc, char *out, size_t outSize, bool tabsToSpa } } -// Shared by both Interpret() below (the MIPSGetInstruction()-based slow path, still used by -// RunUntilWithChecks) and RunUntilFast()'s -1 handling (ExecInstruction() is generated from -// the exact same tables MIPSGetInstruction() walks, so it has no better information to offer -// here - no point re-walking those tables just to rediscover "no interpreter for this op"). -static void HandleUnknownInstruction(MIPSState *mips, MIPSOpcode op) { - ERROR_LOG_REPORT(Log::CPU, "Unknown instruction %08x at %08x", op.encoding, mips->pc); - // Try to disassemble it - char disasm[256]; - MIPSDisAsm(op, mips->pc, disasm, sizeof(disasm)); - _dbg_assert_msg_(0, "%s", disasm); - mips->pc += 4; -} - static inline void Interpret(MIPSState *mips, const MIPSInstruction *instr, MIPSOpcode op) { if (instr && instr->interpret) { instr->interpret(mips, op); } else { - HandleUnknownInstruction(mips, op); + Core_ExecException(mips->pc, mips->pc, ExecExceptionType::ILLEGAL); } } @@ -1119,89 +1106,86 @@ void CDECL MIPSInterpretTrampoline(MIPSOpcode op) { MIPSInterpret(currentMIPS, op); } -static inline void RunUntilFast(MIPSState *curMips) { +static inline void RunUntilFast(MIPSState *mips) { // NEVER stop in a delay slot! - while (curMips->downcount >= 0 && coreState == CORE_RUNNING_CPU) { + while (mips->downcount >= 0 && coreState == CORE_RUNNING_CPU) { do { - if (!Memory::IsValid4AlignedAddress(curMips->pc)) { - Core_ExecException(curMips->pc, curMips->pc, ExecExceptionType::JUMP); + if (!Memory::IsValid4AlignedAddress(mips->pc)) { + Core_ExecException(mips->pc, mips->pc, ExecExceptionType::JUMP); return; } - MIPSOpcode op = MIPSOpcode(Memory::ReadUnchecked_U32(curMips->pc)); + MIPSOpcode op = MIPSOpcode(Memory::ReadUnchecked_U32(mips->pc)); - bool wasInDelaySlot = curMips->inDelaySlot; - int cycles = ExecInstruction(curMips, op); + bool wasInDelaySlot = mips->inDelaySlot; + int cycles = ExecInstruction(mips, op); if (cycles < 0) { - // Not a recognized instruction (invalid encoding, or a known instruction - // with no interpreter implementation, e.g. tge/tlt/teq/...). No point - // calling MIPSGetInstruction() here - see HandleUnknownInstruction()'s - // comment. Every such case has cycles == 1 today (same as - // GetInstructionCycleEstimate()'s default for a null/flagless instr). - HandleUnknownInstruction(curMips, op); - cycles = 1; + // Not a recognized instruction (invalid encoding, or an unimplemented kernel-mode only instruction + // with no interpreter implementation, e.g. tge/tlt/teq/). + Core_ExecException(mips->pc, mips->pc, ExecExceptionType::ILLEGAL); + break; } - curMips->downcount -= cycles; + mips->downcount -= cycles; // The reason we have to check this is the delay slot hack in Int_Syscall. - if (curMips->inDelaySlot && wasInDelaySlot) { - curMips->pc = curMips->nextPC; - curMips->inDelaySlot = false; + if (mips->inDelaySlot && wasInDelaySlot) { + mips->pc = mips->nextPC; + mips->inDelaySlot = false; } - } while (curMips->inDelaySlot); + } while (mips->inDelaySlot); } } #define _RS(op) ((op>>21) & 0x1F) -static void RunUntilWithChecks(MIPSState *curMips, u64 globalTicks) { +static void RunUntilWithChecks(MIPSState *mips, u64 globalTicks) { // NEVER stop in a delay slot! bool hasBPs = g_breakpoints.HasBreakPoints(); bool hasMCs = g_breakpoints.HasMemChecks(); - while (curMips->downcount >= 0 && coreState == CORE_RUNNING_CPU) { + while (mips->downcount >= 0 && coreState == CORE_RUNNING_CPU) { do { - if (!Memory::IsValid4AlignedAddress(curMips->pc)) { - Core_ExecException(curMips->pc, curMips->pc, ExecExceptionType::JUMP); + if (!Memory::IsValid4AlignedAddress(mips->pc)) { + Core_ExecException(mips->pc, mips->pc, ExecExceptionType::JUMP); return; } - MIPSOpcode op = MIPSOpcode(Memory::ReadUnchecked_U32(curMips->pc)); + MIPSOpcode op = MIPSOpcode(Memory::ReadUnchecked_U32(mips->pc)); // Replacements and similar are processed here, intentionally. const MIPSInstruction *instr = MIPSGetInstruction(op); // Check for breakpoint - if (hasBPs && g_breakpoints.IsAddressBreakPoint(curMips->pc) && g_breakpoints.CheckSkipFirst() != curMips->pc) { - auto cond = g_breakpoints.GetBreakPointCondition(curMips->pc); + if (hasBPs && g_breakpoints.IsAddressBreakPoint(mips->pc) && g_breakpoints.CheckSkipFirst() != mips->pc) { + auto cond = g_breakpoints.GetBreakPointCondition(mips->pc); if (!cond || cond->Evaluate()) { - Core_Break(BreakReason::CpuBreakpoint, curMips->pc); - if (g_breakpoints.IsTempBreakPoint(curMips->pc)) - g_breakpoints.RemoveBreakPoint(curMips->pc); + Core_Break(BreakReason::CpuBreakpoint, mips->pc); + if (g_breakpoints.IsTempBreakPoint(mips->pc)) + g_breakpoints.RemoveBreakPoint(mips->pc); break; } } - if (hasMCs && (instr->flags & (IN_MEM | OUT_MEM)) != 0 && g_breakpoints.CheckSkipFirst() != curMips->pc && instr->interpret != &Int_Syscall) { + if (hasMCs && (instr->flags & (IN_MEM | OUT_MEM)) != 0 && g_breakpoints.CheckSkipFirst() != mips->pc && instr->interpret != &Int_Syscall) { // This is common for all IN_MEM/OUT_MEM funcs. int offset = (instr->flags & IS_VFPU) != 0 ? SignExtend16ToS32(op & 0xFFFC) : SignExtend16ToS32(op); - u32 addr = (curMips->r[_RS(op)] + offset) & 0xFFFFFFFC; + u32 addr = (mips->r[_RS(op)] + offset) & 0xFFFFFFFC; int sz = MIPSGetMemoryAccessSize(op); if ((instr->flags & IN_MEM) != 0) - g_breakpoints.ExecMemCheck(addr, false, sz, curMips->pc, "interpret"); + g_breakpoints.ExecMemCheck(addr, false, sz, mips->pc, "interpret"); if ((instr->flags & OUT_MEM) != 0) - g_breakpoints.ExecMemCheck(addr, true, sz, curMips->pc, "interpret"); + g_breakpoints.ExecMemCheck(addr, true, sz, mips->pc, "interpret"); // If it tripped, bail without running. if (coreState == CORE_STEPPING_CPU) break; } - bool wasInDelaySlot = curMips->inDelaySlot; - Interpret(curMips, instr, op); - curMips->downcount -= GetInstructionCycleEstimate(instr); + bool wasInDelaySlot = mips->inDelaySlot; + Interpret(mips, instr, op); + mips->downcount -= GetInstructionCycleEstimate(instr); // The reason we have to check this is the delay slot hack in Int_Syscall. - if (curMips->inDelaySlot && wasInDelaySlot) { - curMips->pc = curMips->nextPC; - curMips->inDelaySlot = false; + if (mips->inDelaySlot && wasInDelaySlot) { + mips->pc = mips->nextPC; + mips->inDelaySlot = false; } - } while (curMips->inDelaySlot); + } while (mips->inDelaySlot); if (CoreTiming::GetTicks() > globalTicks) return; @@ -1214,10 +1198,11 @@ int MIPSInterpret_RunUntil(MIPSState *curMips, u64 globalTicks) { CoreTiming::Advance(); uint64_t ticksLeft = globalTicks - CoreTiming::GetTicks(); - if (g_breakpoints.HasBreakPoints() || g_breakpoints.HasMemChecks() || ticksLeft <= curMips->downcount) + if (g_breakpoints.HasBreakPoints() || g_breakpoints.HasMemChecks() || ticksLeft <= curMips->downcount) { RunUntilWithChecks(curMips, globalTicks); - else + } else { RunUntilFast(curMips); + } if (CoreTiming::GetTicks() > globalTicks) { // DEBUG_LOG(Log::CPU, "Hit the max ticks, bailing 1 : %llu, %llu", globalTicks, CoreTiming::GetTicks()); From c9c886d78fa41a731d3851ac1e059c53a53d281c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Wed, 12 Aug 2026 13:39:43 +0200 Subject: [PATCH 3/7] Plumb a MIPS context into ReadVector etc. --- Core/Debugger/Breakpoints.cpp | 2 +- Core/MIPS/InterpreterVFPU.cpp | 294 +++++++++++++++++----------------- Core/MIPS/MIPSAnalyst.cpp | 10 +- Core/MIPS/MIPSAnalyst.h | 2 +- Core/MIPS/MIPSVFPUUtils.cpp | 48 +++--- Core/MIPS/MIPSVFPUUtils.h | 10 +- 6 files changed, 183 insertions(+), 183 deletions(-) diff --git a/Core/Debugger/Breakpoints.cpp b/Core/Debugger/Breakpoints.cpp index 58ef387047..4674346243 100644 --- a/Core/Debugger/Breakpoints.cpp +++ b/Core/Debugger/Breakpoints.cpp @@ -475,7 +475,7 @@ BreakAction BreakpointManager::ExecOpMemCheck(u32 address, u32 pc) { int mask = MEMCHECK_WRITE | MEMCHECK_WRITE_ONCHANGE; bool apply = false; if (write && (check->cond & mask) == mask) { - if (MIPSAnalyst::OpWouldChangeMemory(pc, address, size)) { + if (MIPSAnalyst::OpWouldChangeMemory(currentMIPS, pc, address, size)) { apply = true; } } else { diff --git a/Core/MIPS/InterpreterVFPU.cpp b/Core/MIPS/InterpreterVFPU.cpp index 3472e4e59a..d378158cf8 100644 --- a/Core/MIPS/InterpreterVFPU.cpp +++ b/Core/MIPS/InterpreterVFPU.cpp @@ -214,7 +214,7 @@ namespace MIPSInt case 53: //lvl.q/lvr.q { float d[4]; - ReadVector(d, V_Quad, vt); + ReadVector(mips, d, V_Quad, vt); int offset = (addr >> 2) & 3; if ((op & 2) == 0) { if (!Memory::IsValid4AlignedAddress(addr)) { @@ -235,7 +235,7 @@ namespace MIPSInt d[i] = Memory::ReadUnchecked_Float(addr + 4 * i); } } - WriteVector(d, V_Quad, vt); + WriteVector(mips, d, V_Quad, vt); } break; @@ -247,7 +247,7 @@ namespace MIPSInt #ifndef COMMON_BIG_ENDIAN cf = reinterpret_cast(Memory::GetPointerUnchecked(addr)); if (cf) - WriteVector(cf, V_Quad, vt); + WriteVector(mips, cf, V_Quad, vt); #else float lvqd[4]; @@ -256,14 +256,14 @@ namespace MIPSInt lvqd[2] = Memory::ReadUnchecked_Float(addr + 8); lvqd[3] = Memory::ReadUnchecked_Float(addr + 12); - WriteVector(lvqd, V_Quad, vt); + WriteVector(mips, lvqd, V_Quad, vt); #endif break; case 61: // svl.q/svr.q { float d[4]; - ReadVector(d, V_Quad, vt); + ReadVector(mips, d, V_Quad, vt); int offset = (addr >> 2) & 3; if ((op & 2) == 0) { if (!Memory::IsValid4AlignedAddress(addr)) { @@ -295,11 +295,11 @@ namespace MIPSInt #ifndef COMMON_BIG_ENDIAN f = reinterpret_cast(Memory::GetPointerWriteUnchecked(addr)); if (f) { - ReadVector(f, V_Quad, vt); + ReadVector(mips, f, V_Quad, vt); } #else float svqd[4]; - ReadVector(svqd, V_Quad, vt); + ReadVector(mips, svqd, V_Quad, vt); Memory::WriteUnchecked_Float(svqd[0], addr); Memory::WriteUnchecked_Float(svqd[1], addr + 4); @@ -377,11 +377,11 @@ namespace MIPSInt _dbg_assert_msg_( 0, "Unknown matrix init op"); break; } - ApplyPrefixST(mips, &prefixed[off * 4], VFPURewritePrefix(VFPU_CTRL_SPREFIX, sprefixRemove, sprefixAdd), V_Quad); - WriteMatrix(prefixed, sz, vd); + ApplyPrefixST(mips, &prefixed[off * 4], VFPURewritePrefix(mips, VFPU_CTRL_SPREFIX, sprefixRemove, sprefixAdd), V_Quad); + WriteMatrix(mips, prefixed, sz, vd); } else { // Write mask applies to the final (maybe transposed) row. Sat causes hang. - WriteMatrix(m, sz, vd); + WriteMatrix(mips, m, sz, vd); } PC += 4; EatPrefixes(mips); @@ -407,10 +407,10 @@ namespace MIPSInt // The S prefix generates constants, but negate is still respected. u32 sprefixRemove = VFPU_ANY_SWIZZLE(); u32 sprefixAdd = VFPU_MAKE_CONSTANTS(constant, constant, constant, constant); - ApplyPrefixST(mips, d, VFPURewritePrefix(VFPU_CTRL_SPREFIX, sprefixRemove, sprefixAdd), sz); + ApplyPrefixST(mips, d, VFPURewritePrefix(mips,VFPU_CTRL_SPREFIX, sprefixRemove, sprefixAdd), sz); ApplyPrefixD(mips, d, sz); - WriteVector(d, sz, vd); + WriteVector(mips, d, sz, vd); EatPrefixes(mips); PC += 4; @@ -432,7 +432,7 @@ namespace MIPSInt } ApplyPrefixD(mips, f, V_Single); - WriteVector(f, V_Single, vt); + WriteVector(mips, f, V_Single, vt); PC += 4; EatPrefixes(mips); } @@ -453,10 +453,10 @@ namespace MIPSInt u32 sprefixRemove = VFPU_ANY_SWIZZLE(); u32 sprefixAdd = VFPU_MAKE_CONSTANTS(constX, constY, constZ, constW); - ApplyPrefixST(mips, f, VFPURewritePrefix(VFPU_CTRL_SPREFIX, sprefixRemove, sprefixAdd), sz); + ApplyPrefixST(mips, f, VFPURewritePrefix(mips, VFPU_CTRL_SPREFIX, sprefixRemove, sprefixAdd), sz); ApplyPrefixD(mips, f, sz); - WriteVector(f, sz, vd); + WriteVector(mips, f, sz, vd); PC += 4; EatPrefixes(mips); } @@ -471,8 +471,8 @@ namespace MIPSInt MatrixSize sz = GetMtxSize(op); int n = GetMatrixSide(sz); - ReadMatrix(s, sz, vs); - ReadMatrix(t, sz, vt); + ReadMatrix(mips, s, sz, vs); + ReadMatrix(mips, t, sz, vt); // TODO: Always use the more accurate path in interpreter? bool useAccurateDot = USE_VFPU_DOT || PSP_CoreParameter().compat.flags().MoreAccurateVMMUL; @@ -513,7 +513,7 @@ namespace MIPSInt u32 lastsat = (mips->vfpuCtrl[VFPU_CTRL_DPREFIX] & 3) << (n + n - 2); mips->vfpuCtrl[VFPU_CTRL_DPREFIX] = lastmask | lastsat; ApplyPrefixD(mips, &d[4 * (n - 1)], V_Quad, false); - WriteMatrix(d, sz, vd); + WriteMatrix(mips, d, sz, vd); PC += 4; EatPrefixes(mips); } @@ -527,8 +527,8 @@ namespace MIPSInt MatrixSize sz = GetMtxSize(op); int n = GetMatrixSide(sz); - ReadMatrix(s, sz, vs); - ReadVector(t, V_Single, vt); + ReadMatrix(mips, s, sz, vs); + ReadVector(mips, t, V_Single, vt); for (int a = 0; a < n - 1; a++) { for (int b = 0; b < n; b++) { @@ -544,7 +544,7 @@ namespace MIPSInt t[tlane] = t[0]; u32 tprefixRemove = VFPU_ANY_SWIZZLE(); u32 tprefixAdd = VFPU_SWIZZLE(tlane, tlane, tlane, tlane); - ApplyPrefixST(mips, t, VFPURewritePrefix(VFPU_CTRL_TPREFIX, tprefixRemove, tprefixAdd), V_Quad); + ApplyPrefixST(mips, t, VFPURewritePrefix(mips, VFPU_CTRL_TPREFIX, tprefixRemove, tprefixAdd), V_Quad); for (int b = 0; b < n; b++) { d[(n - 1) * 4 + b] = s[(n - 1) * 4 + b] * t[b]; @@ -552,7 +552,7 @@ namespace MIPSInt // The D prefix is applied to the last row. ApplyPrefixD(mips, &d[(n - 1) * 4], V_Quad); - WriteMatrix(d, sz, vd); + WriteMatrix(mips, d, sz, vd); PC += 4; EatPrefixes(mips); } @@ -562,12 +562,12 @@ namespace MIPSInt int vd = _VD; int vs = _VS; MatrixSize sz = GetMtxSize(op); - ReadMatrix(s, sz, vs); + ReadMatrix(mips, s, sz, vs); // S and D prefixes are applied to the last row. int off = GetMatrixSide(sz) - 1; ApplySwizzleS(mips, &s[off * 4], V_Quad); ApplyPrefixD(mips, &s[off * 4], V_Quad); - WriteMatrix(s, sz, vd); + WriteMatrix(mips, s, sz, vd); PC += 4; EatPrefixes(mips); } @@ -588,14 +588,14 @@ namespace MIPSInt int optype = (op >> 16) & 0x1f; VectorSize sz = GetVecSize(op); u32 n = GetNumVectorElements(sz); - ReadVector(s, sz, vs); + ReadVector(mips, s, sz, vs); // Some of these are prefix hacks (affects constants, etc.) switch (optype) { case 1: - ApplyPrefixST(mips, s, VFPURewritePrefix(VFPU_CTRL_SPREFIX, 0, VFPU_ABS(1, 1, 1, 1)), sz); + ApplyPrefixST(mips, s, VFPURewritePrefix(mips, VFPU_CTRL_SPREFIX, 0, VFPU_ABS(1, 1, 1, 1)), sz); break; case 2: - ApplyPrefixST(mips, s, VFPURewritePrefix(VFPU_CTRL_SPREFIX, 0, VFPU_NEGATE(1, 1, 1, 1)), sz); + ApplyPrefixST(mips, s, VFPURewritePrefix(mips, VFPU_CTRL_SPREFIX, 0, VFPU_NEGATE(1, 1, 1, 1)), sz); break; case 16: case 17: @@ -611,11 +611,11 @@ namespace MIPSInt case 24: case 26: // Similar to above, but also ignores negate. - ApplyPrefixST(mips, &s[n - 1], VFPURewritePrefix(VFPU_CTRL_SPREFIX, VFPU_NEGATE(1, 0, 0, 0), 0), V_Single, -INFINITY); + ApplyPrefixST(mips, &s[n - 1], VFPURewritePrefix(mips, VFPU_CTRL_SPREFIX, VFPU_NEGATE(1, 0, 0, 0), 0), V_Single, -INFINITY); break; case 28: // Similar to above, but also ignores negate. - ApplyPrefixST(mips, &s[n - 1], VFPURewritePrefix(VFPU_CTRL_SPREFIX, VFPU_NEGATE(1, 0, 0, 0), 0), V_Single, INFINITY); + ApplyPrefixST(mips, &s[n - 1], VFPURewritePrefix(mips, VFPU_CTRL_SPREFIX, VFPU_NEGATE(1, 0, 0, 0), 0), V_Single, INFINITY); break; default: ApplySwizzleS(mips, s, sz); @@ -673,7 +673,7 @@ namespace MIPSInt default: ApplyPrefixD(mips, d, sz); } - WriteVector(d, sz, vd); + WriteVector(mips, d, sz, vd); PC += 4; EatPrefixes(mips); } @@ -683,17 +683,17 @@ namespace MIPSInt int vd = _VD; int vs = _VS; VectorSize sz = GetVecSize(op); - ReadVector(s, sz, vs); + ReadVector(mips, s, sz, vs); // S prefix forces the negate flags. u32 sprefixAdd = VFPU_NEGATE(1, 1, 1, 1); - ApplyPrefixST(mips, s, VFPURewritePrefix(VFPU_CTRL_SPREFIX, 0, sprefixAdd), sz); + ApplyPrefixST(mips, s, VFPURewritePrefix(mips, VFPU_CTRL_SPREFIX, 0, sprefixAdd), sz); // T prefix forces constants on and regnum to 1. // That means negate still works, and abs activates a different constant. u32 tprefixRemove = VFPU_ANY_SWIZZLE(); u32 tprefixAdd = VFPU_MAKE_CONSTANTS(VFPUConst::ONE, VFPUConst::ONE, VFPUConst::ONE, VFPUConst::ONE); - ApplyPrefixST(mips, t, VFPURewritePrefix(VFPU_CTRL_TPREFIX, tprefixRemove, tprefixAdd), sz); + ApplyPrefixST(mips, t, VFPURewritePrefix(mips, VFPU_CTRL_TPREFIX, tprefixRemove, tprefixAdd), sz); for (int i = 0; i < GetNumVectorElements(sz); i++) { // Always positive NaN. Note that s is always negated from the registers. @@ -701,7 +701,7 @@ namespace MIPSInt } RetainInvalidSwizzleST(mips, d, sz); ApplyPrefixD(mips, d, sz); - WriteVector(d, sz, vd); + WriteVector(mips, d, sz, vd); PC += 4; EatPrefixes(mips); } @@ -714,19 +714,19 @@ namespace MIPSInt VectorSize outSize = GetDoubleVectorSizeSafe(sz); if (outSize == V_Invalid) outSize = V_Quad; - ReadVector(s, sz, vs); + ReadVector(mips, s, sz, vs); // S prefix forces negate in even/odd and xxyy swizzle. // abs works, and applies to final position (not source.) u32 sprefixRemove = VFPU_ANY_SWIZZLE() | VFPU_NEGATE(1, 1, 1, 1); u32 sprefixAdd = VFPU_SWIZZLE(0, 0, 1, 1) | VFPU_NEGATE(1, 0, 1, 0); - ApplyPrefixST(mips, s, VFPURewritePrefix(VFPU_CTRL_SPREFIX, sprefixRemove, sprefixAdd), outSize); + ApplyPrefixST(mips, s, VFPURewritePrefix(mips, VFPU_CTRL_SPREFIX, sprefixRemove, sprefixAdd), outSize); // T prefix forces constants on and regnum to 1, 0, 1, 0. // That means negate still works, and abs activates a different constant. u32 tprefixRemove = VFPU_ANY_SWIZZLE(); u32 tprefixAdd = VFPU_MAKE_CONSTANTS(VFPUConst::ONE, VFPUConst::ZERO, VFPUConst::ONE, VFPUConst::ZERO); - ApplyPrefixST(mips, t, VFPURewritePrefix(VFPU_CTRL_TPREFIX, tprefixRemove, tprefixAdd), outSize); + ApplyPrefixST(mips, t, VFPURewritePrefix(mips, VFPU_CTRL_TPREFIX, tprefixRemove, tprefixAdd), outSize); // Essentially D prefix saturation is forced. d[0] = nanclamp(t[0] + s[0], 0.0f, 1.0f); @@ -736,7 +736,7 @@ namespace MIPSInt d[3] = nanclamp(t[3] + s[3], 0.0f, 1.0f); } ApplyPrefixD(mips, d, sz, true); - WriteVector(d, outSize, vd); + WriteVector(mips, d, outSize, vd); PC += 4; EatPrefixes(mips); } @@ -746,12 +746,12 @@ namespace MIPSInt int vd = _VD; int vs = _VS; VectorSize sz = GetVecSize(op); - ReadVector(s, sz, vs); + ReadVector(mips, s, sz, vs); // Not sure who would do this, but using abs/neg allows a compare against 3 or -3. u32 tprefixRemove = VFPU_ANY_SWIZZLE(); u32 tprefixAdd = VFPU_MAKE_CONSTANTS(VFPUConst::ZERO, VFPUConst::ZERO, VFPUConst::ZERO, VFPUConst::ZERO); - ApplyPrefixST(mips, t, VFPURewritePrefix(VFPU_CTRL_TPREFIX, tprefixRemove, tprefixAdd), sz); + ApplyPrefixST(mips, t, VFPURewritePrefix(mips, VFPU_CTRL_TPREFIX, tprefixRemove, tprefixAdd), sz); int n = GetNumVectorElements(sz); if (n < 4) { @@ -773,7 +773,7 @@ namespace MIPSInt d[i] = -1.0f; } ApplyPrefixD(mips, d, sz); - WriteVector(d, sz, vd); + WriteVector(mips, d, sz, vd); PC += 4; EatPrefixes(mips); } @@ -791,7 +791,7 @@ namespace MIPSInt int imm = (op >> 16) & 0x1f; float mult = (float)(1UL << imm); VectorSize sz = GetVecSize(op); - ReadVector(s, sz, vs); + ReadVector(mips, s, sz, vs); // Negate, abs, and constants apply as you'd expect to the bits. ApplySwizzleS(mips, s, sz); for (int i = 0; i < GetNumVectorElements(sz); i++) { @@ -818,7 +818,7 @@ namespace MIPSInt } // Does not apply sat, but does apply mask. ApplyPrefixD(mips, reinterpret_cast(d), sz, true); - WriteVector(reinterpret_cast(d), sz, vd); + WriteVector(mips, reinterpret_cast(d), sz, vd); PC += 4; EatPrefixes(mips); } @@ -831,7 +831,7 @@ namespace MIPSInt int imm = (op >> 16) & 0x1f; float mult = 1.0f/(float)(1UL << imm); VectorSize sz = GetVecSize(op); - ReadVector(reinterpret_cast(s), sz, vs); + ReadVector(mips, reinterpret_cast(s), sz, vs); // Negate, abs, and constants apply as you'd expect to the bits. ApplySwizzleS(mips, reinterpret_cast(s), sz); for (int i = 0; i < GetNumVectorElements(sz); i++) { @@ -839,7 +839,7 @@ namespace MIPSInt } // Sat and mask apply normally. ApplyPrefixD(mips, d, sz); - WriteVector(d, sz, vd); + WriteVector(mips, d, sz, vd); PC += 4; EatPrefixes(mips); } @@ -850,7 +850,7 @@ namespace MIPSInt int vd = _VD; int vs = _VS; VectorSize sz = GetVecSize(op); - ReadVector(reinterpret_cast(s), sz, vs); + ReadVector(mips, reinterpret_cast(s), sz, vs); ApplySwizzleS(mips, reinterpret_cast(s), sz); VectorSize outsize = V_Pair; @@ -871,7 +871,7 @@ namespace MIPSInt break; } ApplyPrefixD(mips, d, outsize); - WriteVector(d, outsize, vd); + WriteVector(mips, d, outsize, vd); PC += 4; EatPrefixes(mips); } @@ -882,7 +882,7 @@ namespace MIPSInt int vd = _VD; int vs = _VS; VectorSize sz = GetVecSize(op); - ReadVector(s, sz, vs); + ReadVector(mips, s, sz, vs); // Swizzle can cause V_Single to properly write both components. ApplySwizzleS(mips, s, V_Quad); // Negate should not actually apply to invalid swizzle. @@ -907,7 +907,7 @@ namespace MIPSInt break; } ApplyPrefixD(mips, reinterpret_cast(d), outsize); - WriteVector(reinterpret_cast(d), outsize, vd); + WriteVector(mips, reinterpret_cast(d), outsize, vd); PC += 4; EatPrefixes(mips); } @@ -918,7 +918,7 @@ namespace MIPSInt int vs = _VS; VectorSize sz = GetVecSize(op); VectorSize oz = sz; - ReadVector(reinterpret_cast(s), sz, vs); + ReadVector(mips, reinterpret_cast(s), sz, vs); ApplySwizzleS(mips, reinterpret_cast(s), sz); // TODO: Similar to colorconv, invalid swizzle seems to reuse last output. @@ -1011,7 +1011,7 @@ namespace MIPSInt // Saturation does in fact apply. ApplyPrefixD(mips, reinterpret_cast(d),oz); - WriteVector(reinterpret_cast(d), oz, vd); + WriteVector(mips, reinterpret_cast(d), oz, vd); PC += 4; EatPrefixes(mips); } @@ -1023,7 +1023,7 @@ namespace MIPSInt const int vs = _VS; const VectorSize sz = GetVecSize(op); VectorSize oz; - ReadVector(reinterpret_cast(s), sz, vs); + ReadVector(mips, reinterpret_cast(s), sz, vs); // Negate, const, etc. apply as expected. ApplySwizzleS(mips, reinterpret_cast(s), V_Quad); @@ -1100,7 +1100,7 @@ namespace MIPSInt } // D prefix applies as expected. ApplyPrefixD(mips, reinterpret_cast(d), oz); - WriteVector(reinterpret_cast(d), oz, vd); + WriteVector(mips, reinterpret_cast(d), oz, vd); PC += 4; EatPrefixes(mips); } @@ -1112,7 +1112,7 @@ namespace MIPSInt u32 s[4]; VectorSize isz = GetVecSize(op); VectorSize sz = V_Quad; - ReadVector(reinterpret_cast(s), sz, vs); + ReadVector(mips, reinterpret_cast(s), sz, vs); ApplySwizzleS(mips, reinterpret_cast(s), sz); u16 colors[4]; // TODO: Invalid swizzle values almost seem to use the last value converted in a @@ -1154,7 +1154,7 @@ namespace MIPSInt } u32 ov[2] = {(u32)colors[0] | (colors[1] << 16), (u32)colors[2] | (colors[3] << 16)}; ApplyPrefixD(mips, reinterpret_cast(ov), V_Pair); - WriteVector((const float *)ov, isz == V_Single ? V_Single : V_Pair, vd); + WriteVector(mips, (const float *)ov, isz == V_Single ? V_Single : V_Pair, vd); PC += 4; EatPrefixes(mips); } @@ -1166,9 +1166,9 @@ namespace MIPSInt int vs = _VS; int vt = _VT; VectorSize sz = GetVecSize(op); - ReadVector(s, sz, vs); + ReadVector(mips, s, sz, vs); ApplySwizzleS(mips, s, V_Quad); - ReadVector(t, sz, vt); + ReadVector(mips, t, sz, vt); ApplySwizzleT(mips, t, V_Quad); if (USE_VFPU_DOT) { @@ -1186,7 +1186,7 @@ namespace MIPSInt } ApplyPrefixD(mips, &d.f, V_Single); - WriteVector(&d.f, V_Single, vd); + WriteVector(mips, &d.f, V_Single, vd); PC += 4; EatPrefixes(mips); } @@ -1198,8 +1198,8 @@ namespace MIPSInt int vs = _VS; int vt = _VT; VectorSize sz = GetVecSize(op); - ReadVector(s, sz, vs); - ReadVector(t, sz, vt); + ReadVector(mips, s, sz, vs); + ReadVector(mips, t, sz, vt); ApplySwizzleT(mips, t, V_Quad); // S prefix forces constant 1 for the last element (w for quad.) @@ -1219,7 +1219,7 @@ namespace MIPSInt sprefixRemove = VFPU_SWIZZLE(3, 0, 0, 0); sprefixAdd = VFPU_MAKE_CONSTANTS(VFPUConst::ONE, VFPUConst::NONE, VFPUConst::NONE, VFPUConst::NONE); } - ApplyPrefixST(mips, s, VFPURewritePrefix(VFPU_CTRL_SPREFIX, sprefixRemove, sprefixAdd), V_Quad); + ApplyPrefixST(mips, s, VFPURewritePrefix(mips, VFPU_CTRL_SPREFIX, sprefixRemove, sprefixAdd), V_Quad); float sum = 0.0f; if (USE_VFPU_DOT) { @@ -1231,7 +1231,7 @@ namespace MIPSInt } d = my_isnan(sum) ? fabsf(sum) : sum; ApplyPrefixD(mips, &d, V_Single); - WriteVector(&d, V_Single, vd); + WriteVector(mips, &d, V_Single, vd); PC += 4; EatPrefixes(mips); } @@ -1241,20 +1241,20 @@ namespace MIPSInt int vd = _VD; int vs = _VS; VectorSize sz = GetVecSize(op); - ReadVector(s, sz, vs); - ReadVector(t, sz, vs); + ReadVector(mips, s, sz, vs); + ReadVector(mips, t, sz, vs); if (op & 0x10000) { // vbfy2 // S prefix forces the negate flags (so z and w are negative.) u32 sprefixAdd = VFPU_NEGATE(0, 0, 1, 1); - ApplyPrefixST(mips, s, VFPURewritePrefix(VFPU_CTRL_SPREFIX, 0, sprefixAdd), sz); + ApplyPrefixST(mips, s, VFPURewritePrefix(mips, VFPU_CTRL_SPREFIX, 0, sprefixAdd), sz); // T prefix forces swizzle (zwxy.) // That means negate still works, but constants are a bit weird. u32 tprefixRemove = VFPU_ANY_SWIZZLE(); u32 tprefixAdd = VFPU_SWIZZLE(2, 3, 0, 1); - ApplyPrefixST(mips, t, VFPURewritePrefix(VFPU_CTRL_TPREFIX, tprefixRemove, tprefixAdd), sz); + ApplyPrefixST(mips, t, VFPURewritePrefix(mips, VFPU_CTRL_TPREFIX, tprefixRemove, tprefixAdd), sz); // Other sizes don't seem completely predictable. if (sz != V_Quad) { @@ -1264,13 +1264,13 @@ namespace MIPSInt // vbfy1 // S prefix forces the negate flags (so y and w are negative.) u32 sprefixAdd = VFPU_NEGATE(0, 1, 0, 1); - ApplyPrefixST(mips, s, VFPURewritePrefix(VFPU_CTRL_SPREFIX, 0, sprefixAdd), sz); + ApplyPrefixST(mips, s, VFPURewritePrefix(mips, VFPU_CTRL_SPREFIX, 0, sprefixAdd), sz); // T prefix forces swizzle (yxwz.) // That means negate still works, but constants are a bit weird. u32 tprefixRemove = VFPU_ANY_SWIZZLE(); u32 tprefixAdd = VFPU_SWIZZLE(1, 0, 3, 2); - ApplyPrefixST(mips, t, VFPURewritePrefix(VFPU_CTRL_TPREFIX, tprefixRemove, tprefixAdd), sz); + ApplyPrefixST(mips, t, VFPURewritePrefix(mips, VFPU_CTRL_TPREFIX, tprefixRemove, tprefixAdd), sz); if (sz != V_Quad && sz != V_Pair) { ERROR_LOG_REPORT_ONCE(vbfy2, Log::CPU, "vfby1 with incorrect size"); @@ -1283,7 +1283,7 @@ namespace MIPSInt d[3] = s[3] + t[3]; ApplyPrefixD(mips, d, sz); - WriteVector(d, sz, vd); + WriteVector(mips, d, sz, vd); PC += 4; EatPrefixes(mips); } @@ -1293,14 +1293,14 @@ namespace MIPSInt int vd = _VD; int vs = _VS; VectorSize sz = GetVecSize(op); - ReadVector(s, sz, vs); + ReadVector(mips, s, sz, vs); ApplySwizzleS(mips, s, sz); - ReadVector(t, sz, vs); + ReadVector(mips, t, sz, vs); // T is force swizzled to yxwz from S. u32 tprefixRemove = VFPU_SWIZZLE(3, 3, 3, 3); u32 tprefixAdd = VFPU_SWIZZLE(1, 0, 3, 2); - ApplyPrefixST(mips, t, VFPURewritePrefix(VFPU_CTRL_TPREFIX, tprefixRemove, tprefixAdd), sz); + ApplyPrefixST(mips, t, VFPURewritePrefix(mips, VFPU_CTRL_TPREFIX, tprefixRemove, tprefixAdd), sz); // TODO: May mishandle NAN / negative zero / etc. d[0] = std::min(s[0], t[0]); @@ -1309,7 +1309,7 @@ namespace MIPSInt d[3] = std::max(s[3], t[3]); RetainInvalidSwizzleST(mips, d, sz); ApplyPrefixD(mips, d, sz); - WriteVector(d, sz, vd); + WriteVector(mips, d, sz, vd); PC += 4; EatPrefixes(mips); } @@ -1319,14 +1319,14 @@ namespace MIPSInt int vd = _VD; int vs = _VS; VectorSize sz = GetVecSize(op); - ReadVector(s, sz, vs); + ReadVector(mips, s, sz, vs); ApplySwizzleS(mips, s, sz); - ReadVector(t, sz, vs); + ReadVector(mips, t, sz, vs); // T is force swizzled to wzyx from S. u32 tprefixRemove = VFPU_SWIZZLE(3, 3, 3, 3); u32 tprefixAdd = VFPU_SWIZZLE(3, 2, 1, 0); - ApplyPrefixST(mips, t, VFPURewritePrefix(VFPU_CTRL_TPREFIX, tprefixRemove, tprefixAdd), sz); + ApplyPrefixST(mips, t, VFPURewritePrefix(mips, VFPU_CTRL_TPREFIX, tprefixRemove, tprefixAdd), sz); // TODO: May mishandle NAN / negative zero / etc. d[0] = std::min(s[0], t[0]); @@ -1335,7 +1335,7 @@ namespace MIPSInt d[3] = std::max(s[3], t[3]); RetainInvalidSwizzleST(mips, d, sz); ApplyPrefixD(mips, d, sz); - WriteVector(d, sz, vd); + WriteVector(mips, d, sz, vd); PC += 4; EatPrefixes(mips); } @@ -1345,14 +1345,14 @@ namespace MIPSInt int vd = _VD; int vs = _VS; VectorSize sz = GetVecSize(op); - ReadVector(s, sz, vs); + ReadVector(mips, s, sz, vs); ApplySwizzleS(mips, s, sz); - ReadVector(t, sz, vs); + ReadVector(mips, t, sz, vs); // T is force swizzled to yxwz from S. u32 tprefixRemove = VFPU_SWIZZLE(3, 3, 3, 3); u32 tprefixAdd = VFPU_SWIZZLE(1, 0, 3, 2); - ApplyPrefixST(mips, t, VFPURewritePrefix(VFPU_CTRL_TPREFIX, tprefixRemove, tprefixAdd), sz); + ApplyPrefixST(mips, t, VFPURewritePrefix(mips, VFPU_CTRL_TPREFIX, tprefixRemove, tprefixAdd), sz); // TODO: May mishandle NAN / negative zero / etc. d[0] = std::max(s[0], t[0]); @@ -1361,7 +1361,7 @@ namespace MIPSInt d[3] = std::min(s[3], t[3]); RetainInvalidSwizzleST(mips, d, sz); ApplyPrefixD(mips, d, sz); - WriteVector(d, sz, vd); + WriteVector(mips, d, sz, vd); PC += 4; EatPrefixes(mips); } @@ -1371,14 +1371,14 @@ namespace MIPSInt int vd = _VD; int vs = _VS; VectorSize sz = GetVecSize(op); - ReadVector(s, sz, vs); + ReadVector(mips, s, sz, vs); ApplySwizzleS(mips, s, sz); - ReadVector(t, sz, vs); + ReadVector(mips, t, sz, vs); // T is force swizzled to wzyx from S. u32 tprefixRemove = VFPU_SWIZZLE(3, 3, 3, 3); u32 tprefixAdd = VFPU_SWIZZLE(3, 2, 1, 0); - ApplyPrefixST(mips, t, VFPURewritePrefix(VFPU_CTRL_TPREFIX, tprefixRemove, tprefixAdd), sz); + ApplyPrefixST(mips, t, VFPURewritePrefix(mips, VFPU_CTRL_TPREFIX, tprefixRemove, tprefixAdd), sz); // TODO: May mishandle NAN / negative zero / etc. d[0] = std::max(s[0], t[0]); @@ -1387,7 +1387,7 @@ namespace MIPSInt d[3] = std::min(s[3], t[3]); RetainInvalidSwizzleST(mips, d, sz); ApplyPrefixD(mips, d, sz); - WriteVector(d, sz, vd); + WriteVector(mips, d, sz, vd); PC += 4; EatPrefixes(mips); } @@ -1399,26 +1399,26 @@ namespace MIPSInt int vs = _VS; int vt = _VT; VectorSize sz = GetVecSize(op); - ReadVector(s, sz, vs); - ReadVector(t, sz, vt); + ReadVector(mips, s, sz, vs); + ReadVector(mips, t, sz, vt); // S prefix forces swizzle (yzx?.) // That means negate still works, but constants are a bit weird. u32 sprefixRemove = VFPU_SWIZZLE(3, 3, 3, 0); u32 sprefixAdd = VFPU_SWIZZLE(1, 2, 0, 0); - ApplyPrefixST(mips, s, VFPURewritePrefix(VFPU_CTRL_SPREFIX, sprefixRemove, sprefixAdd), sz); + ApplyPrefixST(mips, s, VFPURewritePrefix(mips, VFPU_CTRL_SPREFIX, sprefixRemove, sprefixAdd), sz); // T prefix forces swizzle (zxy?.) u32 tprefixRemove = VFPU_SWIZZLE(3, 3, 3, 0); u32 tprefixAdd = VFPU_SWIZZLE(2, 0, 1, 0); - ApplyPrefixST(mips, t, VFPURewritePrefix(VFPU_CTRL_TPREFIX, tprefixRemove, tprefixAdd), sz); + ApplyPrefixST(mips, t, VFPURewritePrefix(mips, VFPU_CTRL_TPREFIX, tprefixRemove, tprefixAdd), sz); d[0] = s[0] * t[0]; d[1] = s[1] * t[1]; d[2] = s[2] * t[2]; d[3] = s[3] * t[3]; ApplyPrefixD(mips, d, sz); - WriteVector(d, sz, vd); + WriteVector(mips, d, sz, vd); PC += 4; EatPrefixes(mips); } @@ -1430,16 +1430,16 @@ namespace MIPSInt int vt = _VT; VectorSize sz = GetVecSize(op); // This is normally V_Pair. Unfilled s/t values are treated as zero. - ReadVector(s, sz, vs); + ReadVector(mips, s, sz, vs); ApplySwizzleS(mips, s, V_Quad); - ReadVector(t, sz, vt); + ReadVector(mips, t, sz, vt); // T prefix forces swizzle for x and y (yx??.) // That means negate still works, but constants are a bit weird. // Note: there is no forced negation here. u32 tprefixRemove = VFPU_SWIZZLE(3, 3, 0, 0); u32 tprefixAdd = VFPU_SWIZZLE(1, 0, 0, 0); - ApplyPrefixST(mips, t, VFPURewritePrefix(VFPU_CTRL_TPREFIX, tprefixRemove, tprefixAdd), V_Quad); + ApplyPrefixST(mips, t, VFPURewritePrefix(mips, VFPU_CTRL_TPREFIX, tprefixRemove, tprefixAdd), V_Quad); if (USE_VFPU_DOT) { s[1] = -s[1]; @@ -1450,7 +1450,7 @@ namespace MIPSInt } ApplyPrefixD(mips, d, V_Single); - WriteVector(d, V_Single, vd); + WriteVector(mips, d, V_Single, vd); PC += 4; EatPrefixes(mips); } @@ -1461,13 +1461,13 @@ namespace MIPSInt int vd = _VD; int vs = _VS; VectorSize sz = GetVecSize(op); - ReadVector(s, sz, vs); + ReadVector(mips, s, sz, vs); ApplySwizzleS(mips, s, V_Quad); // T prefix generates constants, but abs can change the constant. u32 tprefixRemove = VFPU_ANY_SWIZZLE(); u32 tprefixAdd = VFPU_MAKE_CONSTANTS(VFPUConst::ONE, VFPUConst::ONE, VFPUConst::ONE, VFPUConst::ONE); - ApplyPrefixST(mips, t, VFPURewritePrefix(VFPU_CTRL_TPREFIX, tprefixRemove, tprefixAdd), V_Quad); + ApplyPrefixST(mips, t, VFPURewritePrefix(mips, VFPU_CTRL_TPREFIX, tprefixRemove, tprefixAdd), V_Quad); if (USE_VFPU_DOT) { d = vfpu_dot(s, t); @@ -1478,7 +1478,7 @@ namespace MIPSInt } } ApplyPrefixD(mips, &d, V_Single); - WriteVector(&d, V_Single, vd); + WriteVector(mips, &d, V_Single, vd); PC += 4; EatPrefixes(mips); } @@ -1489,7 +1489,7 @@ namespace MIPSInt int vd = _VD; int vs = _VS; VectorSize sz = GetVecSize(op); - ReadVector(s, sz, vs); + ReadVector(mips, s, sz, vs); ApplySwizzleS(mips, s, V_Quad); // T prefix generates constants, but supports negate. @@ -1505,7 +1505,7 @@ namespace MIPSInt tprefixAdd = VFPU_MAKE_CONSTANTS(VFPUConst::FOURTH, VFPUConst::FOURTH, VFPUConst::FOURTH, VFPUConst::FOURTH); else tprefixAdd = 0; - ApplyPrefixST(mips, t, VFPURewritePrefix(VFPU_CTRL_TPREFIX, tprefixRemove, tprefixAdd), V_Quad); + ApplyPrefixST(mips, t, VFPURewritePrefix(mips, VFPU_CTRL_TPREFIX, tprefixRemove, tprefixAdd), V_Quad); if (USE_VFPU_DOT) { d = vfpu_dot(s, t); @@ -1516,7 +1516,7 @@ namespace MIPSInt } } ApplyPrefixD(mips, &d, V_Single); - WriteVector(&d, V_Single, vd); + WriteVector(mips, &d, V_Single, vd); PC += 4; EatPrefixes(mips); } @@ -1527,7 +1527,7 @@ namespace MIPSInt int vs = _VS; int vt = _VT; VectorSize sz = GetVecSize(op); - ReadVector(s, sz, vs); + ReadVector(mips, s, sz, vs); ApplySwizzleS(mips, s, sz); // T prefix forces swizzle (zzzz for some reason, so we force V_Quad.) @@ -1536,14 +1536,14 @@ namespace MIPSInt t[tlane] = V(vt); u32 tprefixRemove = VFPU_ANY_SWIZZLE(); u32 tprefixAdd = VFPU_SWIZZLE(tlane, tlane, tlane, tlane); - ApplyPrefixST(mips, t, VFPURewritePrefix(VFPU_CTRL_TPREFIX, tprefixRemove, tprefixAdd), V_Quad); + ApplyPrefixST(mips, t, VFPURewritePrefix(mips, VFPU_CTRL_TPREFIX, tprefixRemove, tprefixAdd), V_Quad); int n = GetNumVectorElements(sz); for (int i = 0; i < n; i++) { d[i] = s[i] * t[i]; } ApplyPrefixD(mips, d, sz); - WriteVector(d, sz, vd); + WriteVector(mips, d, sz, vd); PC += 4; EatPrefixes(mips); } @@ -1577,7 +1577,7 @@ namespace MIPSInt u32 lastsat = (mips->vfpuCtrl[VFPU_CTRL_DPREFIX] & 3) << (n + n - 2); mips->vfpuCtrl[VFPU_CTRL_DPREFIX] = lastmask | lastsat; ApplyPrefixD(mips, d.f, sz); - WriteVector(d.f, sz, vd); + WriteVector(mips, d.f, sz, vd); PC += 4; EatPrefixes(mips); } @@ -1601,11 +1601,11 @@ namespace MIPSInt } else { // Swizzle on S is a bit odd here, but generally only applies to sine. float s[4]{}; - ReadVector(s, V_Single, vs); + ReadVector(mips, s, V_Single, vs); u32 sprefixRemove = VFPU_NEGATE(1, 0, 0, 0); // We apply negSin later, not here. This handles zero a bit better. u32 sprefixAdd = VFPU_NEGATE(0, 0, 0, 0); - ApplyPrefixST(mips, s, VFPURewritePrefix(VFPU_CTRL_SPREFIX, sprefixRemove, sprefixAdd), V_Single); + ApplyPrefixST(mips, s, VFPURewritePrefix(mips, VFPU_CTRL_SPREFIX, sprefixRemove, sprefixAdd), V_Single); // Cosine ignores all prefixes, so take the original. cosine = vfpu_cos(V(vs)); @@ -1645,7 +1645,7 @@ namespace MIPSInt uint32_t dprefixRemove = (3 << cosineLane) | (1 << (8 + cosineLane)); mips->vfpuCtrl[VFPU_CTRL_DPREFIX] &= 0xFFFFF ^ dprefixRemove; ApplyPrefixD(mips, d, sz); - WriteVector(d, sz, vd); + WriteVector(mips, d, sz, vd); PC += 4; EatPrefixes(mips); } @@ -1663,8 +1663,8 @@ namespace MIPSInt int n = GetNumVectorElements(GetVecSize(op)); int tn = std::min(n, ins + 1); - ReadMatrix(s, msz, vs); - ReadVector(t, sz, vt); + ReadMatrix(mips, s, msz, vs); + ReadVector(mips, t, sz, vt); if (USE_VFPU_DOT) { float t2[4]; @@ -1717,7 +1717,7 @@ namespace MIPSInt } u32 tprefixRemove = VFPU_SWIZZLE(0, n < 2 ? 3 : 0, n < 3 ? 3 : 0, n < 4 ? 3 : 0); u32 tprefixAdd = VFPU_MAKE_CONSTANTS(constX, constY, constZ, constW); - ApplyPrefixST(mips, t, VFPURewritePrefix(VFPU_CTRL_TPREFIX, tprefixRemove, tprefixAdd), V_Quad); + ApplyPrefixST(mips, t, VFPURewritePrefix(mips, VFPU_CTRL_TPREFIX, tprefixRemove, tprefixAdd), V_Quad); // Really this is the operation all rows probably use (with constant wiring.) if (USE_VFPU_DOT) { @@ -1740,7 +1740,7 @@ namespace MIPSInt u32 lastsat = (mips->vfpuCtrl[VFPU_CTRL_DPREFIX] & 3) << (ins + ins); mips->vfpuCtrl[VFPU_CTRL_DPREFIX] = lastmask | lastsat; ApplyPrefixD(mips, d.f, sz); - WriteVector(d.f, sz, vd); + WriteVector(mips, d.f, sz, vd); PC += 4; EatPrefixes(mips); } @@ -1849,7 +1849,7 @@ namespace MIPSInt float c = cst_constants[conNum]; float temp[4] = {c,c,c,c}; ApplyPrefixD(mips, temp, sz); - WriteVector(temp, sz, vd); + WriteVector(mips, temp, sz, vd); PC += 4; EatPrefixes(mips); } @@ -1863,9 +1863,9 @@ namespace MIPSInt int n = GetNumVectorElements(sz); float s[4]; float t[4]; - ReadVector(s, sz, vs); + ReadVector(mips, s, sz, vs); ApplySwizzleS(mips, s, sz); - ReadVector(t, sz, vt); + ReadVector(mips, t, sz, vt); ApplySwizzleT(mips, t, sz); int cc = 0; int or_val = 0; @@ -1925,9 +1925,9 @@ namespace MIPSInt VectorSize sz = GetVecSize(op); int numElements = GetNumVectorElements(sz); - ReadVector(s.f, sz, vs); + ReadVector(mips, s.f, sz, vs); ApplySwizzleS(mips, s.f, sz); - ReadVector(t.f, sz, vt); + ReadVector(mips, t.f, sz, vt); ApplySwizzleT(mips, t.f, sz); // If both are zero, take t's sign. @@ -1972,7 +1972,7 @@ namespace MIPSInt } RetainInvalidSwizzleST(mips, d.f, sz); ApplyPrefixD(mips, d.f, sz); - WriteVector(d.f, sz, vd); + WriteVector(mips, d.f, sz, vd); PC += 4; EatPrefixes(mips); } @@ -1983,9 +1983,9 @@ namespace MIPSInt int vs = _VS; int vd = _VD; VectorSize sz = GetVecSize(op); - ReadVector(s.f, sz, vs); + ReadVector(mips, s.f, sz, vs); ApplySwizzleS(mips, s.f, sz); - ReadVector(t.f, sz, vt); + ReadVector(mips, t.f, sz, vt); ApplySwizzleT(mips, t.f, sz); int n = GetNumVectorElements(sz); for (int i = 0; i < n ; i++) { @@ -2002,7 +2002,7 @@ namespace MIPSInt } RetainInvalidSwizzleST(mips, d.f, sz); ApplyPrefixD(mips, d.f, sz); - WriteVector(d.f, sz, vd); + WriteVector(mips, d.f, sz, vd); PC += 4; EatPrefixes(mips); } @@ -2014,9 +2014,9 @@ namespace MIPSInt int vd = _VD; VectorSize sz = GetVecSize(op); int numElements = GetNumVectorElements(sz); - ReadVector(s, sz, vs); + ReadVector(mips, s, sz, vs); ApplySwizzleS(mips, s, sz); - ReadVector(t, sz, vt); + ReadVector(mips, t, sz, vt); ApplySwizzleT(mips, t, sz); for (int i = 0; i < numElements; i++) { if ( my_isnan(s[i]) || my_isnan(t[i]) ) @@ -2027,7 +2027,7 @@ namespace MIPSInt RetainInvalidSwizzleST(mips, d, sz); // The clamp cannot matter, so skip it. ApplyPrefixD(mips, d, sz, true); - WriteVector(d, sz, vd); + WriteVector(mips, d, sz, vd); PC += 4; EatPrefixes(mips); } @@ -2039,9 +2039,9 @@ namespace MIPSInt int vd = _VD; VectorSize sz = GetVecSize(op); int numElements = GetNumVectorElements(sz); - ReadVector(s, sz, vs); + ReadVector(mips, s, sz, vs); ApplySwizzleS(mips, s, sz); - ReadVector(t, sz, vt); + ReadVector(mips, t, sz, vt); ApplySwizzleT(mips, t, sz); for (int i = 0; i < numElements; i++) { if ( my_isnan(s[i]) || my_isnan(t[i]) ) @@ -2052,7 +2052,7 @@ namespace MIPSInt RetainInvalidSwizzleST(mips, d, sz); // The clamp cannot matter, so skip it. ApplyPrefixD(mips, d, sz, true); - WriteVector(d, sz, vd); + WriteVector(mips, d, sz, vd); PC += 4; EatPrefixes(mips); } @@ -2067,10 +2067,10 @@ namespace MIPSInt int n = GetNumVectorElements(sz); float s[4]; float d[4]; - ReadVector(s, sz, vs); + ReadVector(mips, s, sz, vs); ApplySwizzleS(mips, s, sz); // Not only is D read (as T), but the T prefix applies to it. - ReadVector(d, sz, vd); + ReadVector(mips, d, sz, vd); ApplySwizzleT(mips, d, sz); int CC = mips->vfpuCtrl[VFPU_CTRL_CC]; @@ -2089,7 +2089,7 @@ namespace MIPSInt ERROR_LOG_REPORT(Log::CPU, "Bad Imm3 in cmov: %d", imm3); } ApplyPrefixD(mips, d, sz); - WriteVector(d, sz, vd); + WriteVector(mips, d, sz, vd); PC += 4; EatPrefixes(mips); } @@ -2125,8 +2125,8 @@ namespace MIPSInt } u32 n = GetNumVectorElements(sz); - ReadVector(s, sz, vs); - ReadVector(t, sz, vt); + ReadVector(mips, s, sz, vs); + ReadVector(mips, t, sz, vt); if (optype != 7) { ApplySwizzleS(mips, s, sz); ApplySwizzleT(mips, t, sz); @@ -2165,7 +2165,7 @@ namespace MIPSInt RetainInvalidSwizzleST(mips, d.f, sz); ApplyPrefixD(mips, d.f, sz); } - WriteVector(d.f, sz, vd); + WriteVector(mips, d.f, sz, vd); PC += 4; EatPrefixes(mips); } @@ -2177,8 +2177,8 @@ namespace MIPSInt int vt = _VT; VectorSize sz = GetVecSize(op); u32 n = GetNumVectorElements(sz); - ReadVector(s, sz, vs); - ReadVector(t, sz, vt); + ReadVector(mips, s, sz, vs); + ReadVector(mips, t, sz, vt); u32 tprefixRemove = VFPU_ANY_SWIZZLE() | VFPU_NEGATE(1, 1, 1, 1); u32 tprefixAdd; @@ -2198,7 +2198,7 @@ namespace MIPSInt // T prefix forces swizzle and negate, can be used to have weird constants. tprefixAdd = VFPU_SWIZZLE(1, 0, 3, 2) | VFPU_NEGATE(0, 1, 0, 0); - ApplyPrefixST(mips, t, VFPURewritePrefix(VFPU_CTRL_TPREFIX, tprefixRemove, tprefixAdd), V_Quad); + ApplyPrefixST(mips, t, VFPURewritePrefix(mips, VFPU_CTRL_TPREFIX, tprefixRemove, tprefixAdd), V_Quad); ApplySwizzleS(mips, s, V_Quad); if (USE_VFPU_DOT) { // TODO: But flush any infs to 0? This seems sketchy. @@ -2232,7 +2232,7 @@ namespace MIPSInt // T prefix forces swizzle and negate, can be used to have weird constants. tprefixAdd = VFPU_SWIZZLE(0, 1, 2, 3) | VFPU_NEGATE(1, 1, 1, 0); - ApplyPrefixST(mips, t, VFPURewritePrefix(VFPU_CTRL_TPREFIX, tprefixRemove, tprefixAdd), V_Quad); + ApplyPrefixST(mips, t, VFPURewritePrefix(mips, VFPU_CTRL_TPREFIX, tprefixRemove, tprefixAdd), V_Quad); ApplySwizzleS(mips, s, sz); if (USE_VFPU_DOT) d[3] = vfpu_dot(s, t); @@ -2246,7 +2246,7 @@ namespace MIPSInt d[0] = 0; tprefixAdd = VFPU_SWIZZLE(0, 0, 0, 0) | VFPU_NEGATE(0, 0, 0, 0); - ApplyPrefixST(mips, t, VFPURewritePrefix(VFPU_CTRL_TPREFIX, tprefixRemove, tprefixAdd), V_Quad); + ApplyPrefixST(mips, t, VFPURewritePrefix(mips, VFPU_CTRL_TPREFIX, tprefixRemove, tprefixAdd), V_Quad); ApplySwizzleS(mips, s, V_Quad); // It's possible to populate a value by swizzling s[2]. d[1] = s[2] * t[2]; @@ -2272,7 +2272,7 @@ namespace MIPSInt // Single always seems to write out zero. mips->vfpuCtrl[VFPU_CTRL_DPREFIX] = 0; } - WriteVector(d, sz, vd); + WriteVector(mips, d, sz, vd); PC += 4; EatPrefixes(mips); } @@ -2284,7 +2284,7 @@ namespace MIPSInt int vs = _VS; VectorSize sz = GetVecSize(op); - ReadVector(s.f, sz, vs); + ReadVector(mips, s.f, sz, vs); ApplySwizzleS(mips, s.f, sz); int exp = (s.u[0] & 0x7F800000) >> 23; @@ -2303,7 +2303,7 @@ namespace MIPSInt RetainInvalidSwizzleST(mips, d.f, sz); ApplyPrefixD(mips, d.f, sz); - WriteVector(d.f, sz, vd); + WriteVector(mips, d.f, sz, vd); PC += 4; EatPrefixes(mips); } @@ -2315,7 +2315,7 @@ namespace MIPSInt VectorSize sz = GetVecSize(op); u8 exp = (u8)((op >> 16) & 0xFF); - ReadVector(s.f, sz, vs); + ReadVector(mips, s.f, sz, vs); ApplySwizzleS(mips, s.f, sz); u32 sigbit = s.u[0] & 0x80000000; @@ -2341,7 +2341,7 @@ namespace MIPSInt RetainInvalidSwizzleST(mips, d.f, sz); ApplyPrefixD(mips, d.f, sz); - WriteVector(d.f, sz, vd); + WriteVector(mips, d.f, sz, vd); PC += 4; EatPrefixes(mips); } @@ -2353,9 +2353,9 @@ namespace MIPSInt int vt = _VT; VectorSize sz = GetVecSize(op); - ReadVector(s.f, sz, vs); + ReadVector(mips, s.f, sz, vs); ApplySwizzleS(mips, s.f, sz); - ReadVector(t.f, sz, vt); + ReadVector(mips, t.f, sz, vt); ApplySwizzleT(mips, t.f, sz); // Swizzle does apply to the value read as an integer. u8 exp = (u8)(127 + t.i[0]); @@ -2374,7 +2374,7 @@ namespace MIPSInt } ApplyPrefixD(mips, d.f, sz); - WriteVector(d.f, sz, vd); + WriteVector(mips, d.f, sz, vd); PC += 4; EatPrefixes(mips); } @@ -2386,7 +2386,7 @@ namespace MIPSInt int vs = _VS; VectorSize sz = GetVecSize(op); - ReadVector(s.f, sz, vs); + ReadVector(mips, s.f, sz, vs); ApplySwizzleS(mips, s.f, sz); // NAN and denormals pass through. @@ -2402,7 +2402,7 @@ namespace MIPSInt } ApplyPrefixD(mips, d.f, sz); - WriteVector(d.f, sz, vd); + WriteVector(mips, d.f, sz, vd); PC += 4; EatPrefixes(mips); } diff --git a/Core/MIPS/MIPSAnalyst.cpp b/Core/MIPS/MIPSAnalyst.cpp index 2bce1ecf3f..c889047527 100644 --- a/Core/MIPS/MIPSAnalyst.cpp +++ b/Core/MIPS/MIPSAnalyst.cpp @@ -634,7 +634,7 @@ namespace MIPSAnalyst { return (info & DELAYSLOT) != 0; } - bool OpWouldChangeMemory(u32 pc, u32 addr, u32 size) { + bool OpWouldChangeMemory(MIPSState *mips, u32 pc, u32 addr, u32 size) { if (!Memory::IsValidRange(addr, 4)) { return false; } @@ -664,19 +664,19 @@ namespace MIPSAnalyst { if (gprMask != 0) { MIPSGPReg rt = MIPS_GET_RT(op); - writeVal = currentMIPS->r[rt] & gprMask; + writeVal = mips->r[rt] & gprMask; prevVal = Memory::ReadUnchecked_U32(addr) & gprMask; } if (IsSWC1Instr(op)) { int ft = MIPS_GET_FT(op); - writeVal = currentMIPS->fi[ft]; + writeVal = mips->fi[ft]; prevVal = Memory::ReadUnchecked_U32(addr); } if (IsSVSInstr(op)) { int vt = ((op >> 16) & 0x1f) | ((op & 3) << 5); - writeVal = currentMIPS->vi[voffset[vt]]; + writeVal = mips->vi[voffset[vt]]; prevVal = Memory::ReadUnchecked_U32(addr); } @@ -686,7 +686,7 @@ namespace MIPSAnalyst { } int vt = (((op >> 16) & 0x1f)) | ((op & 1) << 5); float rd[4]; - ReadVector(rd, V_Quad, vt); + ReadVector(mips, rd, V_Quad, vt); return memcmp(rd, Memory::GetPointerUnchecked(addr), 16) != 0; // sizeof(float) * 4 } diff --git a/Core/MIPS/MIPSAnalyst.h b/Core/MIPS/MIPSAnalyst.h index e287e2bcd6..354b4293d3 100644 --- a/Core/MIPS/MIPSAnalyst.h +++ b/Core/MIPS/MIPSAnalyst.h @@ -130,7 +130,7 @@ namespace MIPSAnalyst { bool IsDelaySlotNiceFPU(MIPSOpcode branchOp, MIPSOpcode op); bool IsSyscall(MIPSOpcode op); - bool OpWouldChangeMemory(u32 pc, u32 addr, u32 size); + bool OpWouldChangeMemory(MIPSState *mips, u32 pc, u32 addr, u32 size); int OpMemoryAccessSize(u32 pc); bool IsOpMemoryWrite(u32 pc); bool OpHasDelaySlot(u32 pc); diff --git a/Core/MIPS/MIPSVFPUUtils.cpp b/Core/MIPS/MIPSVFPUUtils.cpp index 6da405a15a..49dd87243e 100644 --- a/Core/MIPS/MIPSVFPUUtils.cpp +++ b/Core/MIPS/MIPSVFPUUtils.cpp @@ -159,11 +159,11 @@ void GetMatrixRows(int matrixReg, MatrixSize msize, u8 vecs[4]) { } } -void ReadVector(float *rd, VectorSize size, int reg) { +void ReadVector(const MIPSState *mips, float *rd, VectorSize size, int reg) { int row; int length; switch (size) { - case V_Single: rd[0] = currentMIPS->v[voffset[reg]]; return; // transpose = 0; row=(reg>>5)&3; length = 1; break; + case V_Single: rd[0] = mips->v[voffset[reg]]; return; // transpose = 0; row=(reg>>5)&3; length = 1; break; case V_Pair: row=(reg>>5)&2; length = 2; break; case V_Triple: row=(reg>>6)&1; length = 3; break; case V_Quad: row=(reg>>5)&2; length = 4; break; @@ -176,20 +176,20 @@ void ReadVector(float *rd, VectorSize size, int reg) { if (transpose) { const int base = mtx + col; for (int i = 0; i < length; i++) - rd[i] = currentMIPS->v[base + ((row + i) & 3) * 4]; + rd[i] = mips->v[base + ((row + i) & 3) * 4]; } else { const int base = mtx + col * 4; for (int i = 0; i < length; i++) - rd[i] = currentMIPS->v[base + ((row + i) & 3)]; + rd[i] = mips->v[base + ((row + i) & 3)]; } } -void WriteVector(const float *rd, VectorSize size, int reg) { +void WriteVector(MIPSState *mips, const float *rd, VectorSize size, int reg) { int row; int length; switch (size) { - case V_Single: if (!currentMIPS->VfpuWriteMask(0)) currentMIPS->v[voffset[reg]] = rd[0]; return; // transpose = 0; row=(reg>>5)&3; length = 1; break; + case V_Single: if (!mips->VfpuWriteMask(0)) mips->v[voffset[reg]] = rd[0]; return; // transpose = 0; row=(reg>>5)&3; length = 1; break; case V_Pair: row=(reg>>5)&2; length = 2; break; case V_Triple: row=(reg>>6)&1; length = 3; break; case V_Quad: row=(reg>>5)&2; length = 4; break; @@ -202,37 +202,37 @@ void WriteVector(const float *rd, VectorSize size, int reg) { // NOTE: We now skip the voffset lookups. if (transpose) { const int base = mtx + col; - if (currentMIPS->VfpuWriteMask() == 0) { + if (mips->VfpuWriteMask() == 0) { for (int i = 0; i < length; i++) - currentMIPS->v[base + ((row+i) & 3) * 4] = rd[i]; + mips->v[base + ((row+i) & 3) * 4] = rd[i]; } else { for (int i = 0; i < length; i++) { - if (!currentMIPS->VfpuWriteMask(i)) { - currentMIPS->v[base + ((row+i) & 3) * 4] = rd[i]; + if (!mips->VfpuWriteMask(i)) { + mips->v[base + ((row+i) & 3) * 4] = rd[i]; } } } } else { const int base = mtx + col * 4; - if (currentMIPS->VfpuWriteMask() == 0) { + if (mips->VfpuWriteMask() == 0) { for (int i = 0; i < length; i++) - currentMIPS->v[base + ((row + i) & 3)] = rd[i]; + mips->v[base + ((row + i) & 3)] = rd[i]; } else { for (int i = 0; i < length; i++) { - if (!currentMIPS->VfpuWriteMask(i)) { - currentMIPS->v[base + ((row + i) & 3)] = rd[i]; + if (!mips->VfpuWriteMask(i)) { + mips->v[base + ((row + i) & 3)] = rd[i]; } } } } } -u32 VFPURewritePrefix(int ctrl, u32 remove, u32 add) { - u32 prefix = currentMIPS->vfpuCtrl[ctrl]; +u32 VFPURewritePrefix(MIPSState *mips, int ctrl, u32 remove, u32 add) { + u32 prefix = mips->vfpuCtrl[ctrl]; return (prefix & ~remove) | add; } -void ReadMatrix(float *rd, MatrixSize size, int reg) { +void ReadMatrix(const MIPSState *mips, float *rd, MatrixSize size, int reg) { int row = 0; int side = 0; int transpose = (reg >> 5) & 1; @@ -250,7 +250,7 @@ void ReadMatrix(float *rd, MatrixSize size, int reg) { // The voffset ordering is now integrated in these formulas, // eliminating a table lookup. - const float *v = currentMIPS->v + (size_t)mtx * 16; + const float *v = mips->v + (size_t)mtx * 16; if (transpose) { if (side == 4 && col == 0 && row == 0) { // Fast path: Simple 4x4 transpose. TODO: Optimize. @@ -282,7 +282,7 @@ void ReadMatrix(float *rd, MatrixSize size, int reg) { } } -void WriteMatrix(const float *rd, MatrixSize size, int reg) { +void WriteMatrix(MIPSState *mips, const float *rd, MatrixSize size, int reg) { int mtx = (reg>>2)&7; int col = reg&3; @@ -304,9 +304,9 @@ void WriteMatrix(const float *rd, MatrixSize size, int reg) { // The voffset ordering is now integrated in these formulas, // eliminating a table lookup. - float *v = currentMIPS->v + (size_t)mtx * 16; + float *v = mips->v + (size_t)mtx * 16; if (transpose) { - if (side == 4 && row == 0 && col == 0 && currentMIPS->VfpuWriteMask() == 0x0) { + if (side == 4 && row == 0 && col == 0 && mips->VfpuWriteMask() == 0x0) { // Fast path: Simple 4x4 transpose. TODO: Optimize. for (int j = 0; j < side; j++) { for (int i = 0; i < side; i++) { @@ -316,7 +316,7 @@ void WriteMatrix(const float *rd, MatrixSize size, int reg) { } else { for (int j = 0; j < side; j++) { for (int i = 0; i < side; i++) { - if (j != side - 1 || !currentMIPS->VfpuWriteMask(i)) { + if (j != side - 1 || !mips->VfpuWriteMask(i)) { int index = ((row + i) & 3) * 4 + ((col + j) & 3); v[index] = rd[j * 4 + i]; } @@ -324,12 +324,12 @@ void WriteMatrix(const float *rd, MatrixSize size, int reg) { } } } else { - if (side == 4 && row == 0 && col == 0 && currentMIPS->VfpuWriteMask() == 0x0) { + if (side == 4 && row == 0 && col == 0 && mips->VfpuWriteMask() == 0x0) { memcpy(v, rd, sizeof(float) * 16); // v[j * 4 + i] = rd[j * 4 + i]; } else { for (int j = 0; j < side; j++) { for (int i = 0; i < side; i++) { - if (j != side - 1 || !currentMIPS->VfpuWriteMask(i)) { + if (j != side - 1 || !mips->VfpuWriteMask(i)) { int index = ((col + j) & 3) * 4 + ((row + i) & 3); v[index] = rd[j * 4 + i]; } diff --git a/Core/MIPS/MIPSVFPUUtils.h b/Core/MIPS/MIPSVFPUUtils.h index 045adef312..193e5da6a6 100644 --- a/Core/MIPS/MIPSVFPUUtils.h +++ b/Core/MIPS/MIPSVFPUUtils.h @@ -167,13 +167,13 @@ inline u32 VFPU_MAKE_CONSTANTS(VFPUConst x, VFPUConst y, VFPUConst z, VFPUConst return result; } -u32 VFPURewritePrefix(int ctrl, u32 remove, u32 add); +u32 VFPURewritePrefix(MIPSState *mips, int ctrl, u32 remove, u32 add); -void ReadMatrix(float *rd, MatrixSize size, int reg); -void WriteMatrix(const float *rs, MatrixSize size, int reg); +void ReadMatrix(const MIPSState *mips, float *rd, MatrixSize size, int reg); +void WriteMatrix(MIPSState *mips,const float *rs, MatrixSize size, int reg); -void WriteVector(const float *rs, VectorSize N, int reg); -void ReadVector(float *rd, VectorSize N, int reg); +void ReadVector(const MIPSState *mips, float *rd, VectorSize N, int reg); +void WriteVector(MIPSState *mips, const float *rs, VectorSize N, int reg); void GetVectorRegs(u8 regs[4], VectorSize N, int vectorReg); void GetMatrixRegs(u8 regs[16], MatrixSize N, int matrixReg); From e9a3449ededdb2a4fa3932635b2084029aafad8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Wed, 12 Aug 2026 13:59:10 +0200 Subject: [PATCH 4/7] More MIPSState * plumbing (manual) --- Core/CoreTiming.cpp | 61 +++++++++---------- Core/CoreTiming.h | 10 +-- Core/Debugger/Breakpoints.cpp | 4 +- Core/Debugger/MemBlockInfo.cpp | 4 +- Core/Debugger/WebSocket/CPUCoreSubscriber.cpp | 2 +- .../WebSocket/SteppingBroadcaster.cpp | 2 +- Core/Dialog/PSPDialog.cpp | 4 +- Core/HLE/HLE.cpp | 2 +- Core/HLE/KernelWaitHelpers.h | 4 +- Core/HLE/sceDisplay.cpp | 8 +-- Core/HLE/sceDmac.cpp | 6 +- Core/HLE/sceGe.cpp | 8 +-- Core/HLE/sceIo.cpp | 12 ++-- Core/HLE/sceKernelModule.cpp | 10 +-- Core/HLE/sceKernelModule.h | 4 +- Core/HLE/sceKernelThread.cpp | 8 +-- Core/HLE/sceUmd.cpp | 4 +- Core/HW/AsyncIOManager.h | 6 +- Core/HW/Display.cpp | 5 +- Core/HW/MemoryStick.cpp | 5 +- Core/MIPS/IR/IRInterpreter.cpp | 14 ++--- Core/MIPS/IR/IRJit.cpp | 2 +- Core/MIPS/MIPS.cpp | 2 +- Core/MIPS/MIPS.h | 3 +- Core/MIPS/MIPSDebugInterface.cpp | 2 +- Core/MIPS/MIPSDebugInterface.h | 1 + Core/MIPS/MIPSTables.cpp | 16 ++--- Core/PSPLoaders.cpp | 5 +- Core/Reporting.cpp | 3 +- Core/System.cpp | 4 +- GPU/Debugger/Playback.cpp | 2 +- GPU/GPUCommon.cpp | 8 +-- UI/ImDebugger/ImDebugger.cpp | 2 +- Windows/Debugger/Debugger_Disasm.cpp | 12 ++-- Windows/Debugger/Debugger_VFPUDlg.cpp | 4 +- libretro/libretro.cpp | 2 +- unittest/JitHarness.cpp | 2 +- 37 files changed, 130 insertions(+), 123 deletions(-) diff --git a/Core/CoreTiming.cpp b/Core/CoreTiming.cpp index 5e570d96ee..a80e919982 100644 --- a/Core/CoreTiming.cpp +++ b/Core/CoreTiming.cpp @@ -75,7 +75,7 @@ bool SetClockFrequencyHz(int cpuHz) { // When the mhz changes, we keep track of what "time" it was before hand. // This way, time always moves forward, even if mhz is changed. lastGlobalTimeUs = GetGlobalTimeUs(); - lastGlobalTimeTicks = GetTicks(); + lastGlobalTimeTicks = GetTicks(currentMIPS); CPU_HZ = cpuHz; @@ -93,13 +93,13 @@ u64 GetGlobalTimeUsScaled() { } u64 GetGlobalTimeUs() { - s64 ticksSinceLast = GetTicks() - lastGlobalTimeTicks; + s64 ticksSinceLast = GetTicks(currentMIPS) - lastGlobalTimeTicks; int freq = GetClockFrequencyHz(); s64 usSinceLast = ticksSinceLast * 1000000 / freq; if (ticksSinceLast > UINT_MAX) { // Adjust the calculated value to avoid overflow errors. lastGlobalTimeUs += usSinceLast; - lastGlobalTimeTicks = GetTicks(); + lastGlobalTimeTicks = GetTicks(currentMIPS); usSinceLast = 0; } return lastGlobalTimeUs + usSinceLast; @@ -178,9 +178,8 @@ void UnregisterAllEvents() { restoredEventTypes.clear(); } -void Init() -{ - currentMIPS->downcount = INITIAL_SLICE_LENGTH; +void Init(MIPSState *mips) { + mips->downcount = INITIAL_SLICE_LENGTH; slicelength = INITIAL_SLICE_LENGTH; globalTimer = 0; idledCycles = 0; @@ -201,18 +200,16 @@ void Shutdown() } } -u64 GetTicks() -{ - if (currentMIPS) { - return (u64)globalTimer + slicelength - currentMIPS->downcount; +u64 GetTicks(MIPSState *mips) { + if (mips) { + return (u64)globalTimer + slicelength - mips->downcount; } else { // Reporting can actually end up here during weird task switching sequences on Android return false; } } -u64 GetIdleTicks() -{ +u64 GetIdleTicks() { return (u64)idledCycles; } @@ -252,7 +249,7 @@ void ScheduleEvent(s64 cyclesIntoFuture, int event_type, u64 userdata) Event *ne = GetNewEvent(); ne->userdata = userdata; ne->type = event_type; - ne->time = GetTicks() + cyclesIntoFuture; + ne->time = GetTicks(currentMIPS) + cyclesIntoFuture; AddEventToQueue(ne); } @@ -266,7 +263,7 @@ s64 UnscheduleEvent(int event_type, u64 userdata) { if (first->type == event_type && first->userdata == userdata) { - result = first->time - GetTicks(); + result = first->time - GetTicks(currentMIPS); Event *next = first->next; FreeEvent(first); @@ -285,7 +282,7 @@ s64 UnscheduleEvent(int event_type, u64 userdata) { if (ptr->type == event_type && ptr->userdata == userdata) { - result = ptr->time - GetTicks(); + result = ptr->time - GetTicks(currentMIPS); prev->next = ptr->next; FreeEvent(ptr); @@ -352,12 +349,12 @@ void RemoveEvent(int event_type) void ProcessEvents() { while (first) { - if (first->time <= (s64)GetTicks()) { - // INFO_LOG(Log::CPU, "%s (%lld, %lld) ", first->name ? first->name : "?", (u64)GetTicks(), (u64)first->time); + if (first->time <= (s64)GetTicks(currentMIPS)) { + // INFO_LOG(Log::CPU, "%s (%lld, %lld) ", first->name ? first->name : "?", (u64)GetTicks(currentMIPS), (u64)first->time); Event *evt = first; first = first->next; if (evt->type >= 0 && evt->type < (int)event_types.size()) { - event_types[evt->type].callback(evt->userdata, (int)(GetTicks() - evt->time)); + event_types[evt->type].callback(evt->userdata, (int)(GetTicks(currentMIPS) - evt->time)); } else { _dbg_assert_msg_(false, "Bad event type %d", evt->type); } @@ -369,12 +366,11 @@ void ProcessEvents() { } } -void ForceCheck() -{ - int cyclesExecuted = slicelength - currentMIPS->downcount; +void ForceCheck(MIPSState *mips) { + int cyclesExecuted = slicelength - mips->downcount; globalTimer += cyclesExecuted; // This will cause us to check for new events immediately. - currentMIPS->downcount = -1; + mips->downcount = -1; // But let's not eat a bunch more time in Advance() because of this. slicelength = -1; @@ -384,10 +380,11 @@ void ForceCheck() } void Advance() { + MIPSState *mips = currentMIPS; // TODO: Move to parameter PROFILE_THIS_SCOPE("advance"); - int cyclesExecuted = slicelength - currentMIPS->downcount; + int cyclesExecuted = slicelength - mips->downcount; globalTimer += cyclesExecuted; - currentMIPS->downcount = slicelength; + mips->downcount = slicelength; ProcessEvents(); @@ -395,7 +392,7 @@ void Advance() { // This should never happen in PPSSPP. if (slicelength < 10000) { slicelength += 10000; - currentMIPS->downcount += 10000; + mips->downcount += 10000; } } else { // Note that events can eat cycles as well. @@ -405,7 +402,7 @@ void Advance() { const int diff = target - slicelength; slicelength += diff; - currentMIPS->downcount += diff; + mips->downcount += diff; } } @@ -417,13 +414,13 @@ void LogPendingEvents() { } } -void Idle(int maxIdle) { - int cyclesDown = currentMIPS->downcount; +void Idle(MIPSState *mips, int maxIdle) { + int cyclesDown = mips->downcount; if (maxIdle != 0 && cyclesDown > maxIdle) cyclesDown = maxIdle; if (first && cyclesDown > 0) { - int cyclesExecuted = slicelength - currentMIPS->downcount; + int cyclesExecuted = slicelength - mips->downcount; int cyclesNextEvent = (int) (first->time - globalTimer); if (cyclesNextEvent < cyclesExecuted + cyclesDown) @@ -437,9 +434,9 @@ void Idle(int maxIdle) { // VERBOSE_LOG(Log::CPU, "Idle for %i cycles! (%f ms)", cyclesDown, cyclesDown / (float)(CPU_HZ * 0.001f)); idledCycles += cyclesDown; - currentMIPS->downcount -= cyclesDown; - if (currentMIPS->downcount == 0) - currentMIPS->downcount = -1; + mips->downcount -= cyclesDown; + if (mips->downcount == 0) + mips->downcount = -1; } std::string GetScheduledEventsSummary() { diff --git a/Core/CoreTiming.h b/Core/CoreTiming.h index 11226f3b03..5a97c103ab 100644 --- a/Core/CoreTiming.h +++ b/Core/CoreTiming.h @@ -72,6 +72,8 @@ inline s64 cyclesToUs(s64 cycles) { return (cycles * 1000000) / CPU_HZ; } +class MIPSState; + namespace CoreTiming { typedef void (*TimedCallback)(u64 userdata, int cyclesLate); @@ -87,10 +89,10 @@ namespace CoreTiming { }; typedef LinkedListItem Event; - void Init(); + void Init(MIPSState *mips); void Shutdown(); - u64 GetTicks(); + u64 GetTicks(MIPSState *mips); u64 GetIdleTicks(); u64 GetGlobalTimeUs(); u64 GetGlobalTimeUsScaled(); @@ -112,10 +114,10 @@ namespace CoreTiming { void RemoveEvent(int event_type); bool IsScheduled(int event_type); void Advance(); - void ForceCheck(); + void ForceCheck(MIPSState *mips); // Pretend that the main CPU has executed enough cycles to reach the next event. - void Idle(int maxIdle = 0); + void Idle(MIPSState *mips, int maxIdle = 0); // Clear all pending events. This should ONLY be done on exit or state load. void ClearPendingEvents(); diff --git a/Core/Debugger/Breakpoints.cpp b/Core/Debugger/Breakpoints.cpp index 4674346243..34eee8c802 100644 --- a/Core/Debugger/Breakpoints.cpp +++ b/Core/Debugger/Breakpoints.cpp @@ -495,12 +495,12 @@ BreakAction BreakpointManager::ExecOpMemCheck(u32 address, u32 pc) { void BreakpointManager::SetSkipFirst(u32 pc) { breakSkipFirstAt_ = pc; - breakSkipFirstTicks_ = CoreTiming::GetTicks(); + breakSkipFirstTicks_ = CoreTiming::GetTicks(currentMIPS); } u32 BreakpointManager::CheckSkipFirst() { u32 pc = breakSkipFirstAt_; - if (breakSkipFirstTicks_ == CoreTiming::GetTicks()) + if (breakSkipFirstTicks_ == CoreTiming::GetTicks(currentMIPS)) return pc; return 0; } diff --git a/Core/Debugger/MemBlockInfo.cpp b/Core/Debugger/MemBlockInfo.cpp index 12d2857f3b..940e909d66 100644 --- a/Core/Debugger/MemBlockInfo.cpp +++ b/Core/Debugger/MemBlockInfo.cpp @@ -501,7 +501,7 @@ void NotifyMemInfoPC(MemBlockFlags flags, uint32_t start, uint32_t size, uint32_ // When the setting is off, we skip smaller info to keep things fast. if (MemBlockInfoDetailed(size) && flags != MemBlockFlags::READ) { PendingNotifyMem info{ flags, start, size }; - info.ticks = CoreTiming::GetTicks(); + info.ticks = CoreTiming::GetTicks(currentMIPS); info.pc = pc; size_t copyLength = strLength; @@ -565,7 +565,7 @@ void NotifyMemInfoCopy(uint32_t destPtr, uint32_t srcPtr, uint32_t size, const c PendingNotifyMem info{ MemBlockFlags::WRITE, destPtr, size }; info.copySrc = srcPtr; - info.ticks = CoreTiming::GetTicks(); + info.ticks = CoreTiming::GetTicks(currentMIPS); info.pc = currentMIPS->pc; // Store the prefix for now. The correct tag will be calculated on flush. diff --git a/Core/Debugger/WebSocket/CPUCoreSubscriber.cpp b/Core/Debugger/WebSocket/CPUCoreSubscriber.cpp index 708a2458a0..9c3aa3bdf1 100644 --- a/Core/Debugger/WebSocket/CPUCoreSubscriber.cpp +++ b/Core/Debugger/WebSocket/CPUCoreSubscriber.cpp @@ -126,7 +126,7 @@ void WebSocketCPUStatus(DebuggerRequest &req) { // Avoid NULL deference. json.writeUint("pc", pspInited ? currentMIPS->pc : 0); // A double ought to be good enough for a 156 day debug session. - json.writeFloat("ticks", pspInited ? CoreTiming::GetTicks() : 0); + json.writeFloat("ticks", pspInited ? CoreTiming::GetTicks(currentMIPS) : 0); } // Retrieve all regs and their values (cpu.getAllRegs) diff --git a/Core/Debugger/WebSocket/SteppingBroadcaster.cpp b/Core/Debugger/WebSocket/SteppingBroadcaster.cpp index 32176425b0..0f4fe66fa8 100644 --- a/Core/Debugger/WebSocket/SteppingBroadcaster.cpp +++ b/Core/Debugger/WebSocket/SteppingBroadcaster.cpp @@ -32,7 +32,7 @@ struct CPUSteppingEvent { j.writeString("event", "cpu.stepping"); j.writeUint("pc", currentMIPS->pc); // A double ought to be good enough for a 156 day debug session. - j.writeFloat("ticks", CoreTiming::GetTicks()); + j.writeFloat("ticks", CoreTiming::GetTicks(currentMIPS)); if (reason_.reason != BreakReason::None) { j.writeString("reason", BreakReasonToString(reason_.reason)); j.writeUint("relatedAddress", reason_.relatedAddress); diff --git a/Core/Dialog/PSPDialog.cpp b/Core/Dialog/PSPDialog.cpp index 966cad9042..2c66550b69 100644 --- a/Core/Dialog/PSPDialog.cpp +++ b/Core/Dialog/PSPDialog.cpp @@ -85,7 +85,7 @@ void PSPDialog::UpdateCommon() { } PSPDialog::DialogStatus PSPDialog::GetStatus() { - if (pendingStatusTicks != 0 && CoreTiming::GetTicks() >= pendingStatusTicks) { + if (pendingStatusTicks != 0 && CoreTiming::GetTicks(currentMIPS) >= pendingStatusTicks) { bool changeAllowed = true; if (pendingStatus == SCE_UTILITY_STATUS_NONE && status == SCE_UTILITY_STATUS_SHUTDOWN) { FinishVolatile(); @@ -126,7 +126,7 @@ void PSPDialog::ChangeStatus(DialogStatus newStatus, int delayUs) { pendingStatusTicks = 0; } else { pendingStatus = newStatus; - pendingStatusTicks = CoreTiming::GetTicks() + usToCycles(delayUs); + pendingStatusTicks = CoreTiming::GetTicks(currentMIPS) + usToCycles(delayUs); } } diff --git a/Core/HLE/HLE.cpp b/Core/HLE/HLE.cpp index 78fc5032df..19f65bd9b3 100644 --- a/Core/HLE/HLE.cpp +++ b/Core/HLE/HLE.cpp @@ -770,7 +770,7 @@ static void hleFinishSyscall(const HLEFunction *info) { } if (hleAfterSyscall & HLE_AFTER_CORETIMING_FORCE_CHECK) { - CoreTiming::ForceCheck(); + CoreTiming::ForceCheck(currentMIPS); } if ((hleAfterSyscall & HLE_AFTER_SKIP_DEADBEEF) == 0) diff --git a/Core/HLE/KernelWaitHelpers.h b/Core/HLE/KernelWaitHelpers.h index 027ede75b8..56d1fc1bb6 100644 --- a/Core/HLE/KernelWaitHelpers.h +++ b/Core/HLE/KernelWaitHelpers.h @@ -144,7 +144,7 @@ WaitBeginEndCallbackResult WaitBeginCallback(SceUID threadID, SceUID prevCallbac u64 pausedTimeout = 0; if (doTimeout && waitTimer != -1) { s64 cyclesLeft = CoreTiming::UnscheduleEvent(waitTimer, threadID); - pausedTimeout = CoreTiming::GetTicks() + cyclesLeft; + pausedTimeout = CoreTiming::GetTicks(currentMIPS) + cyclesLeft; } if (!WaitPauseHelperUpdate(pauseKey, threadID, waitingThreads, pausedWaits, pausedTimeout)) { @@ -214,7 +214,7 @@ WaitBeginEndCallbackResult WaitEndCallback(SceUID threadID, SceUID prevCallbackI } // We only check if it timed out if it couldn't unlock. - s64 cyclesLeft = waitDeadline - CoreTiming::GetTicks(); + s64 cyclesLeft = waitDeadline - CoreTiming::GetTicks(currentMIPS); if (cyclesLeft < 0 && waitDeadline != 0) { if (timeoutPtr != 0 && waitTimer != -1) { Memory::WriteOrException_U32(0, timeoutPtr); diff --git a/Core/HLE/sceDisplay.cpp b/Core/HLE/sceDisplay.cpp index ef01c2276a..20a436358e 100644 --- a/Core/HLE/sceDisplay.cpp +++ b/Core/HLE/sceDisplay.cpp @@ -284,7 +284,7 @@ void __DisplayDoState(PointerWrap &p) { } if (s < 7) { - u64 now = CoreTiming::GetTicks(); + u64 now = CoreTiming::GetTicks(currentMIPS); lastFlipCycles = now; nextFlipCycles = now; } else { @@ -796,7 +796,7 @@ static u32 sceDisplayIsVblank() { } void __DisplayWaitForVblanks(const char *reason, int vblanks, bool callbacks) { - const s64 ticksIntoFrame = CoreTiming::GetTicks() - DisplayFrameStartTicks(); + const s64 ticksIntoFrame = CoreTiming::GetTicks(currentMIPS) - DisplayFrameStartTicks(); const s64 cyclesToNextVblank = msToCycles(frameMs) - ticksIntoFrame; // These syscalls take about 115 us, so if the next vblank is before then, we're waiting extra. @@ -905,7 +905,7 @@ int sceDisplaySetFramebuf(u32 topaddr, int linesize, int pixelformat, int sync) // Otherwise it'll always be ahead if the game messes up even once. const s64 LEEWAY_CYCLES_PER_FLIP = usToCycles(10); - u64 now = CoreTiming::GetTicks(); + u64 now = CoreTiming::GetTicks(currentMIPS); s64 cyclesAhead = nextFlipCycles - now; if (cyclesAhead > FLIP_DELAY_CYCLES_MIN) { if (lastFlipsTooFrequent >= FLIP_DELAY_MIN_FLIPS) { @@ -1078,7 +1078,7 @@ static u32 sceDisplayGetMode(u32 modeAddr, u32 widthAddr, u32 heightAddr) { } static u32 sceDisplayIsVsync() { - u64 now = CoreTiming::GetTicks(); + u64 now = CoreTiming::GetTicks(currentMIPS); u64 start = DisplayFrameStartTicks() + msToCycles(vsyncStartMs); u64 end = DisplayFrameStartTicks() + msToCycles(vsyncEndMs); diff --git a/Core/HLE/sceDmac.cpp b/Core/HLE/sceDmac.cpp index 9ac66bc5ab..a6c673c39c 100644 --- a/Core/HLE/sceDmac.cpp +++ b/Core/HLE/sceDmac.cpp @@ -66,7 +66,7 @@ static int __DmacMemcpy(u32 dst, u32 src, u32 size) { if (size >= 272) { // Approx. 225 MiB/s or 235929600 B/s, so let's go with 236 B/us. int delayUs = size / 236; - dmacMemcpyDeadline = CoreTiming::GetTicks() + usToCycles(delayUs); + dmacMemcpyDeadline = CoreTiming::GetTicks(currentMIPS) + usToCycles(delayUs); return delayUs; } else { return 0; @@ -85,7 +85,7 @@ static u32 sceDmacMemcpy(u32 dst, u32 src, u32 size) { return hleLogError(Log::HLE, SCE_KERNEL_ERROR_PRIV_REQUIRED, "illegal size"); } - if (dmacMemcpyDeadline > CoreTiming::GetTicks()) { + if (dmacMemcpyDeadline > CoreTiming::GetTicks(currentMIPS)) { WARN_LOG(Log::HLE, "sceDmacMemcpy(dest=%08x, src=%08x, size=%d): overlapping read", dst, src, size); // TODO: Should block, seems like copy doesn't start until previous finishes. // Might matter for overlapping copies. @@ -107,7 +107,7 @@ static u32 sceDmacTryMemcpy(u32 dst, u32 src, u32 size) { return hleLogError(Log::HLE, SCE_KERNEL_ERROR_PRIV_REQUIRED, "illegal size"); } - if (dmacMemcpyDeadline > CoreTiming::GetTicks()) { + if (dmacMemcpyDeadline > CoreTiming::GetTicks(currentMIPS)) { return hleLogDebug(Log::HLE, SCE_KERNEL_ERROR_BUSY, "busy"); } diff --git a/Core/HLE/sceGe.cpp b/Core/HLE/sceGe.cpp index 355ca0ef71..5a6536c3ed 100644 --- a/Core/HLE/sceGe.cpp +++ b/Core/HLE/sceGe.cpp @@ -274,7 +274,7 @@ void __GeShutdown() { bool __GeTriggerSync(GPUSyncType type, int id, u64 atTicks) { u64 userdata = (u64)id << 32 | (u64)type; - s64 future = atTicks - CoreTiming::GetTicks(); + s64 future = atTicks - CoreTiming::GetTicks(currentMIPS); if (type == GPU_SYNC_DRAW) { s64 left = CoreTiming::UnscheduleEvent(geSyncEvent, userdata); if (left > future) @@ -293,7 +293,7 @@ bool __GeTriggerInterrupt(int listid, u32 pc, u64 atTicks) { ge_pending_cb.push_back(intrdata); u64 userdata = (u64)listid << 32 | (u64) pc; - CoreTiming::ScheduleEvent(atTicks - CoreTiming::GetTicks(), geInterruptEvent, userdata); + CoreTiming::ScheduleEvent(atTicks - CoreTiming::GetTicks(currentMIPS), geInterruptEvent, userdata); return true; } @@ -370,14 +370,14 @@ u32 sceGeListEnQueue(u32 listAddress, u32 stallAddress, int callbackId, u32 optP hleCoreTimingForceCheck(); DEBUG_LOG(Log::sceGe, "%08x=sceGeListEnQueue(addr=%08x, stall=%08x, cbid=%08x, param=%08x) ticks=%lld", listID, - listAddress, stallAddress, callbackId, optParamAddr, (long long)CoreTiming::GetTicks()); + listAddress, stallAddress, callbackId, optParamAddr, (long long)CoreTiming::GetTicks(currentMIPS)); return hleNoLog(listID); // We already logged above, logs get confusing if we use hleLogSuccess. } u32 sceGeListEnQueueHead(u32 listAddress, u32 stallAddress, int callbackId, u32 optParamAddr) { DEBUG_LOG(Log::sceGe, "sceGeListEnQueueHead(addr=%08x, stall=%08x, cbid=%08x, param=%08x) ticks=%lld", - listAddress, stallAddress, callbackId, optParamAddr, (long long)CoreTiming::GetTicks()); + listAddress, stallAddress, callbackId, optParamAddr, (long long)CoreTiming::GetTicks(currentMIPS)); auto optParam = PSPPointer::Create(optParamAddr); bool runList; diff --git a/Core/HLE/sceIo.cpp b/Core/HLE/sceIo.cpp index 8c83ee6cca..8b23f2daff 100644 --- a/Core/HLE/sceIo.cpp +++ b/Core/HLE/sceIo.cpp @@ -446,9 +446,9 @@ static void __IoAsyncNotify(u64 userdata, int cyclesLate) { __IoCompleteAsyncIO(f); } else if (ioTimingMethod == IOTIMING_REALISTIC) { u64 finishTicks = __IoCompleteAsyncIO(f); - if (finishTicks > CoreTiming::GetTicks()) { + if (finishTicks > CoreTiming::GetTicks(currentMIPS)) { // Reschedule for later, since we now know how long it ought to take. - CoreTiming::ScheduleEvent(finishTicks - CoreTiming::GetTicks(), asyncNotifyEvent, userdata); + CoreTiming::ScheduleEvent(finishTicks - CoreTiming::GetTicks(currentMIPS), asyncNotifyEvent, userdata); return; } } else { @@ -502,9 +502,9 @@ static void __IoSyncNotify(u64 userdata, int cyclesLate) { } } else if (ioTimingMethod == IOTIMING_REALISTIC) { u64 finishTicks = ioManager.ResultFinishTicks(f->handle); - if (finishTicks > CoreTiming::GetTicks()) { + if (finishTicks > CoreTiming::GetTicks(currentMIPS)) { // Reschedule for later when the result should finish. - CoreTiming::ScheduleEvent(finishTicks - CoreTiming::GetTicks(), syncNotifyEvent, userdata); + CoreTiming::ScheduleEvent(finishTicks - CoreTiming::GetTicks(currentMIPS), syncNotifyEvent, userdata); return; } } @@ -587,7 +587,7 @@ static void __IoManagerThread() { INFO_LOG(Log::sceIo, "Entering __IoManagerThread"); AndroidJNIThreadContext jniContext; while (ioManagerThreadEnabled) { - ioManager.RunEventsUntil(CoreTiming::GetTicks() + msToCycles(1000)); + ioManager.RunEventsUntil(CoreTiming::GetTicks(currentMIPS) + msToCycles(1000)); } INFO_LOG(Log::sceIo, "Leaving __IoManagerThread"); } @@ -887,7 +887,7 @@ u64 __IoCompleteAsyncIO(FileNode *f) { int ioTimingMethod = GetIOTimingMethod(); if (ioTimingMethod == IOTIMING_REALISTIC) { u64 finishTicks = ioManager.ResultFinishTicks(f->handle); - if (finishTicks > CoreTiming::GetTicks()) { + if (finishTicks > CoreTiming::GetTicks(currentMIPS)) { return finishTicks; } } diff --git a/Core/HLE/sceKernelModule.cpp b/Core/HLE/sceKernelModule.cpp index 5a3a12a6c7..213fc4b332 100644 --- a/Core/HLE/sceKernelModule.cpp +++ b/Core/HLE/sceKernelModule.cpp @@ -1781,7 +1781,7 @@ void __KernelLoadReset() { __KernelInit(); } -bool __KernelLoadExec(const char *filename, u32 paramPtr, std::string *error_string) { +bool __KernelLoadExec(MIPSState *mips, const char *filename, u32 paramPtr, std::string *error_string) { SceKernelLoadExecParam param{}; auto paramData = PSPPointer::Create(paramPtr); @@ -1836,9 +1836,9 @@ bool __KernelLoadExec(const char *filename, u32 paramPtr, std::string *error_str truncate_cpy(moduleName, module->nm.name); Reporting::NotifyExecModule(moduleName, moduleVersion, module->crc); - mipsr4k.pc = module->nm.entry_addr; + currentMIPS->pc = module->nm.entry_addr; - INFO_LOG(Log::Loader, "Module entry: %08x (%s %04x)", mipsr4k.pc, moduleName, moduleVersion); + INFO_LOG(Log::Loader, "Module entry: %08x (%s %04x)", currentMIPS->pc, moduleName, moduleVersion); SceKernelSMOption option; option.size = sizeof(SceKernelSMOption); @@ -1957,7 +1957,7 @@ int sceKernelLoadExec(const char *filename, u32 paramPtr) { DEBUG_LOG(Log::sceModule, "sceKernelLoadExec(name=%s,...): loading %s", filename, exec_filename.c_str()); std::string error_string; - if (!__KernelLoadExec(exec_filename.c_str(), paramPtr, &error_string)) { + if (!__KernelLoadExec(currentMIPS, exec_filename.c_str(), paramPtr, &error_string)) { Core_UpdateState(CORE_RUNTIME_ERROR); return hleLogError(Log::sceModule, -1, "failed: %s", error_string.c_str());; } @@ -2054,7 +2054,7 @@ u32 sceKernelLoadModule(const char *name, u32 flags, u32 optionAddr) { if (gpu) { gpu->Reinitialize(); } - return __KernelLoadExec(safeName.c_str(), 0, &error_string); + return __KernelLoadExec(currentMIPS, safeName.c_str(), 0, &error_string); } else { return hleDelayResult(hleLogError(Log::Loader, error, "failed to load"), "module loaded", 500); } diff --git a/Core/HLE/sceKernelModule.h b/Core/HLE/sceKernelModule.h index 2a2d39dd20..a6bf4687d5 100644 --- a/Core/HLE/sceKernelModule.h +++ b/Core/HLE/sceKernelModule.h @@ -231,10 +231,12 @@ KernelObject *__KernelModuleObject(); void __KernelModuleDoState(PointerWrap &p); void __KernelModuleShutdown(); +class MIPSState; + u32 __KernelGetModuleGP(SceUID module); bool KernelModuleIsKernelMode(SceUID module); bool __KernelLoadGEDump(std::string_view base_filename, std::string *error_string); -bool __KernelLoadExec(const char *filename, u32 paramPtr, std::string *error_string); +bool __KernelLoadExec(MIPSState *mips, const char *filename, u32 paramPtr, std::string *error_string); bool KernelFindImportByStubAddr(u32 stubAddr, std::string *importModuleName, u32 *nid, std::string *importingModuleName); // Describes which loaded module (and section within it) an address falls in, e.g. "EBOOT.BIN.text+1234". // Returns an empty string if the address isn't inside any currently loaded module. diff --git a/Core/HLE/sceKernelThread.cpp b/Core/HLE/sceKernelThread.cpp index eb02c25878..c92155a614 100644 --- a/Core/HLE/sceKernelThread.cpp +++ b/Core/HLE/sceKernelThread.cpp @@ -664,7 +664,7 @@ static void __KernelDelayEndCallback(SceUID threadID, SceUID prevCallbackId) { // TODO: Don't wake up if __KernelCurHasReadyCallbacks()? - s64 cyclesLeft = delayDeadline - CoreTiming::GetTicks(); + s64 cyclesLeft = delayDeadline - CoreTiming::GetTicks(currentMIPS); if (cyclesLeft < 0) { __KernelResumeThreadFromWait(threadID, 0); } else { @@ -884,7 +884,7 @@ void __KernelThreadingDoState(PointerWrap &p) Do(p, pausedDelays); __SetCurrentThread(kernelObjects.GetFast(currentThread), currentThread, __KernelGetThreadName(currentThread)); - lastSwitchCycles = CoreTiming::GetTicks(); + lastSwitchCycles = CoreTiming::GetTicks(currentMIPS); if (s >= 2) Do(p, threadEventHandlers); @@ -1037,7 +1037,7 @@ void __KernelIdle() // Don't skip 0xDEADBEEF here, this is called directly bypassing CallSyscall(). // That means the hle flag would stick around until the next call. - CoreTiming::Idle(); + CoreTiming::Idle(currentMIPS); // We Advance within __KernelReSchedule(), so anything that has now happened after idle // will be triggered properly upon reschedule. __KernelReSchedule("idle"); @@ -2943,7 +2943,7 @@ void __KernelSwitchContext(PSPThread *target, const char *reason) { #if DEBUG_LEVEL <= MAX_LOGLEVEL || DEBUG_LOG == NOTICE_LOG if (!(fromIdle && toIdle)) { - u64 nowCycles = CoreTiming::GetTicks(); + u64 nowCycles = CoreTiming::GetTicks(currentMIPS); s64 consumedCycles = nowCycles - lastSwitchCycles; lastSwitchCycles = nowCycles; diff --git a/Core/HLE/sceUmd.cpp b/Core/HLE/sceUmd.cpp index 2b73329eed..97e3b4ade1 100644 --- a/Core/HLE/sceUmd.cpp +++ b/Core/HLE/sceUmd.cpp @@ -207,7 +207,7 @@ static void __UmdBeginCallback(SceUID threadID, SceUID prevCallbackId) _dbg_assert_msg_(umdStatTimeoutEvent != -1, "Must have a umd timer"); s64 cyclesLeft = CoreTiming::UnscheduleEvent(umdStatTimeoutEvent, threadID); if (cyclesLeft != 0) - umdPausedWaits[pauseKey] = CoreTiming::GetTicks() + cyclesLeft; + umdPausedWaits[pauseKey] = CoreTiming::GetTicks(currentMIPS) + cyclesLeft; else umdPausedWaits[pauseKey] = 0; @@ -244,7 +244,7 @@ static void __UmdEndCallback(SceUID threadID, SceUID prevCallbackId) return; } - s64 cyclesLeft = waitDeadline - CoreTiming::GetTicks(); + s64 cyclesLeft = waitDeadline - CoreTiming::GetTicks(currentMIPS); if (cyclesLeft < 0 && waitDeadline != 0) __KernelResumeThreadFromWait(threadID, SCE_KERNEL_ERROR_WAIT_TIMEOUT); else diff --git a/Core/HW/AsyncIOManager.h b/Core/HW/AsyncIOManager.h index 00170dc4f6..830ee2f0e3 100644 --- a/Core/HW/AsyncIOManager.h +++ b/Core/HW/AsyncIOManager.h @@ -55,7 +55,7 @@ struct AsyncIOResult { explicit AsyncIOResult(s64 r) : result(r), finishTicks(0), invalidateAddr(0) {} AsyncIOResult(s64 r, int usec, u32 addr = 0) : result(r), invalidateAddr(addr) { - finishTicks = CoreTiming::GetTicks() + usToCycles(usec); + finishTicks = CoreTiming::GetTicks(currentMIPS) + usToCycles(usec); } void DoState(PointerWrap &p) { @@ -156,7 +156,7 @@ public: for (AsyncIOEvent ev = GetNextEvent(); AsyncIOEventType(ev) != IO_EVENT_INVALID; ev = GetNextEvent()) { ProcessEventIfApplicable(ev, globalticks); } - } while (CoreTiming::GetTicks() < globalticks); + } while (CoreTiming::GetTicks(currentMIPS) < globalticks); return; } @@ -177,7 +177,7 @@ public: ProcessEventIfApplicable(ev, globalticks); guard.lock(); } - } while (CoreTiming::GetTicks() < globalticks); + } while (CoreTiming::GetTicks(currentMIPS) < globalticks); // This will force the waiter to check coreState, even if we didn't actually drain. NotifyDrain(); diff --git a/Core/HW/Display.cpp b/Core/HW/Display.cpp index 162718b237..9c63e8ee98 100644 --- a/Core/HW/Display.cpp +++ b/Core/HW/Display.cpp @@ -26,6 +26,7 @@ #include "Common/Data/Text/StringWriter.h" #include "Core/Config.h" #include "Core/System.h" +#include "Core/MIPS/MIPS.h" #include "Core/CoreTiming.h" #include "Core/HLE/sceKernel.h" #include "Core/HLE/sceCtrl.h" @@ -155,7 +156,7 @@ uint64_t DisplayFrameStartTicks() { } uint32_t __DisplayGetCurrentHcount() { - const int ticksIntoFrame = (int)(CoreTiming::GetTicks() - frameStartTicks); + const int ticksIntoFrame = (int)(CoreTiming::GetTicks(currentMIPS) - frameStartTicks); const int ticksPerVblank = CoreTiming::GetClockFrequencyHz() / 60 / hCountPerVblank; // Can't seem to produce a 0 on real hardware, offsetting by 1 makes things look right. return 1 + (ticksIntoFrame / ticksPerVblank); @@ -227,7 +228,7 @@ bool DisplayIsRunningSlow() { } void DisplayFireVblankStart() { - frameStartTicks = CoreTiming::GetTicks(); + frameStartTicks = CoreTiming::GetTicks(currentMIPS); numVBlanks++; isVblank = 1; diff --git a/Core/HW/MemoryStick.cpp b/Core/HW/MemoryStick.cpp index b12a74652b..4e74526a37 100644 --- a/Core/HW/MemoryStick.cpp +++ b/Core/HW/MemoryStick.cpp @@ -31,6 +31,7 @@ #include "Core/FileSystems/MetaFileSystem.h" #include "Core/HW/MemoryStick.h" #include "Core/System.h" +#include "Core/MIPS/MIPS.h" #include "Common/CommonTypes.h" #include "Common/TimeUtil.h" #include "Common/Thread/Promise.h" @@ -85,7 +86,7 @@ MemStickState MemoryStick_State() { } MemStickFatState MemoryStick_FatState() { - if (memStickNeedsAssign && CoreTiming::GetTicks() > memStickInsertedAt + msToCycles(500)) { + if (memStickNeedsAssign && CoreTiming::GetTicks(currentMIPS) > memStickInsertedAt + msToCycles(500)) { // It's been long enough for us to be done mounting the memory stick. memStickFatState = PSP_FAT_MEMORYSTICK_STATE_ASSIGNED; memStickNeedsAssign = false; @@ -181,7 +182,7 @@ void MemoryStick_SetState(MemStickState state) { if (state == PSP_MEMORYSTICK_STATE_NOT_INSERTED) { MemoryStick_SetFatState(PSP_FAT_MEMORYSTICK_STATE_UNASSIGNED); } else { - memStickInsertedAt = CoreTiming::GetTicks(); + memStickInsertedAt = CoreTiming::GetTicks(currentMIPS); memStickNeedsAssign = true; } } diff --git a/Core/MIPS/IR/IRInterpreter.cpp b/Core/MIPS/IR/IRInterpreter.cpp index 8ec4884445..8fc7c14294 100644 --- a/Core/MIPS/IR/IRInterpreter.cpp +++ b/Core/MIPS/IR/IRInterpreter.cpp @@ -1206,7 +1206,7 @@ u32 IRInterpret(MIPSState *mips, const IRInst *inst) { MIPSOpcode op(inst->constant); CallSyscall(op); if (coreState != CORE_RUNNING_CPU) - CoreTiming::ForceCheck(); + CoreTiming::ForceCheck(mips); break; } @@ -1258,39 +1258,39 @@ u32 IRInterpret(MIPSState *mips, const IRInst *inst) { case IROp::Breakpoint: if (IRRunBreakpoint(inst->constant)) { - CoreTiming::ForceCheck(); + CoreTiming::ForceCheck(mips); return mips->pc; } break; case IROp::MemoryCheck: if (IRRunMemCheck(mips->pc + inst->dest, mips->r[inst->src1] + inst->constant)) { - CoreTiming::ForceCheck(); + CoreTiming::ForceCheck(mips); return mips->pc; } break; case IROp::ValidateAddress8: if (RunValidateAddress<1>(mips->pc, mips->r[inst->src1] + inst->constant, inst->src2)) { - CoreTiming::ForceCheck(); + CoreTiming::ForceCheck(mips); return mips->pc; } break; case IROp::ValidateAddress16: if (RunValidateAddress<2>(mips->pc, mips->r[inst->src1] + inst->constant, inst->src2)) { - CoreTiming::ForceCheck(); + CoreTiming::ForceCheck(mips); return mips->pc; } break; case IROp::ValidateAddress32: if (RunValidateAddress<4>(mips->pc, mips->r[inst->src1] + inst->constant, inst->src2)) { - CoreTiming::ForceCheck(); + CoreTiming::ForceCheck(mips); return mips->pc; } break; case IROp::ValidateAddress128: if (RunValidateAddress<16>(mips->pc, mips->r[inst->src1] + inst->constant, inst->src2)) { - CoreTiming::ForceCheck(); + CoreTiming::ForceCheck(mips); return mips->pc; } break; diff --git a/Core/MIPS/IR/IRJit.cpp b/Core/MIPS/IR/IRJit.cpp index 60fba057e5..b647ae6cb0 100644 --- a/Core/MIPS/IR/IRJit.cpp +++ b/Core/MIPS/IR/IRJit.cpp @@ -172,6 +172,7 @@ void IRJit::RunLoopUntil(u64 globalticks) { // ApplyRoundingMode(true); // IR Dispatcher + MIPSState *mips = mips_; while (true) { // RestoreRoundingMode(true); CoreTiming::Advance(); @@ -180,7 +181,6 @@ void IRJit::RunLoopUntil(u64 globalticks) { break; } - MIPSState *mips = mips_; #ifdef _DEBUG compilerEnabled_ = false; #endif diff --git a/Core/MIPS/MIPS.cpp b/Core/MIPS/MIPS.cpp index 41648a3abf..57b7aad9b5 100644 --- a/Core/MIPS/MIPS.cpp +++ b/Core/MIPS/MIPS.cpp @@ -382,7 +382,7 @@ void MIPSState::ClearJitCache() { if (coreState == CORE_RUNNING_CPU || insideJit) { pendingClears.emplace_back(0, 0); hasPendingClears = true; - CoreTiming::ForceCheck(); + CoreTiming::ForceCheck(this); } else { MIPSComp::jit->ClearCache(); } diff --git a/Core/MIPS/MIPS.h b/Core/MIPS/MIPS.h index 4b53fe2e58..c5ccbdc7b6 100644 --- a/Core/MIPS/MIPS.h +++ b/Core/MIPS/MIPS.h @@ -273,7 +273,8 @@ public: class MIPSDebugInterface; -//The one we are compiling or running currently +// The one we are compiling or running currently +// TODO: These globals should be refactored away. extern MIPSState *currentMIPS; extern MIPSDebugInterface *currentDebugMIPS; extern MIPSState mipsr4k; diff --git a/Core/MIPS/MIPSDebugInterface.cpp b/Core/MIPS/MIPSDebugInterface.cpp index c6dbcf3140..3158dde11f 100644 --- a/Core/MIPS/MIPSDebugInterface.cpp +++ b/Core/MIPS/MIPSDebugInterface.cpp @@ -159,7 +159,7 @@ public: if (referenceIndex == REF_INDEX_USEC) return (uint32_t)CoreTiming::GetGlobalTimeUs(); // Loses information if (referenceIndex == REF_INDEX_TICKS) - return (uint32_t)CoreTiming::GetTicks(); + return (uint32_t)CoreTiming::GetTicks(currentMIPS); if ((referenceIndex & ~(REF_INDEX_FPU | REF_INDEX_FPU_INT)) < 32) return cpu->GetRegValue(1, referenceIndex & ~(REF_INDEX_FPU | REF_INDEX_FPU_INT)); if ((referenceIndex & ~(REF_INDEX_VFPU | REF_INDEX_VFPU_INT)) < 128) diff --git a/Core/MIPS/MIPSDebugInterface.h b/Core/MIPS/MIPSDebugInterface.h index bf7f81380a..cef4650597 100644 --- a/Core/MIPS/MIPSDebugInterface.h +++ b/Core/MIPS/MIPSDebugInterface.h @@ -25,6 +25,7 @@ class MIPSDebugInterface : public DebugInterface { +private: MIPSState *cpu; public: MIPSDebugInterface(MIPSState *_cpu) { cpu = _cpu; } diff --git a/Core/MIPS/MIPSTables.cpp b/Core/MIPS/MIPSTables.cpp index cfd28a63db..477ebb2115 100644 --- a/Core/MIPS/MIPSTables.cpp +++ b/Core/MIPS/MIPSTables.cpp @@ -1187,25 +1187,25 @@ static void RunUntilWithChecks(MIPSState *mips, u64 globalTicks) { } } while (mips->inDelaySlot); - if (CoreTiming::GetTicks() > globalTicks) + if (CoreTiming::GetTicks(currentMIPS) > globalTicks) return; } } #undef _RS -int MIPSInterpret_RunUntil(MIPSState *curMips, u64 globalTicks) { +int MIPSInterpret_RunUntil(MIPSState *mips, u64 globalTicks) { while (coreState == CORE_RUNNING_CPU) { CoreTiming::Advance(); - uint64_t ticksLeft = globalTicks - CoreTiming::GetTicks(); - if (g_breakpoints.HasBreakPoints() || g_breakpoints.HasMemChecks() || ticksLeft <= curMips->downcount) { - RunUntilWithChecks(curMips, globalTicks); + uint64_t ticksLeft = globalTicks - CoreTiming::GetTicks(currentMIPS); + if (g_breakpoints.HasBreakPoints() || g_breakpoints.HasMemChecks() || ticksLeft <= mips->downcount) { + RunUntilWithChecks(mips, globalTicks); } else { - RunUntilFast(curMips); + RunUntilFast(mips); } - if (CoreTiming::GetTicks() > globalTicks) { - // DEBUG_LOG(Log::CPU, "Hit the max ticks, bailing 1 : %llu, %llu", globalTicks, CoreTiming::GetTicks()); + if (CoreTiming::GetTicks(mips) > globalTicks) { + // DEBUG_LOG(Log::CPU, "Hit the max ticks, bailing 1 : %llu, %llu", globalTicks, CoreTiming::GetTicks(mips)); return 1; } } diff --git a/Core/PSPLoaders.cpp b/Core/PSPLoaders.cpp index 0deffb65ba..7db4c40323 100644 --- a/Core/PSPLoaders.cpp +++ b/Core/PSPLoaders.cpp @@ -42,6 +42,7 @@ #include "Core/MemMap.h" #include "Core/HDRemaster.h" #include "Core/Util/PathUtil.h" +#include "Core/MIPS/MIPS.h" #include "Core/Config.h" #include "Core/ConfigValues.h" @@ -307,7 +308,7 @@ bool Load_PSP_ISO(FileLoader *fileLoader, std::string *error_string) { System_PostUIMessage(UIMessage::CONFIG_LOADED); INFO_LOG(Log::Loader, "Loading %s...", bootpath.c_str()); // TODO: We can't use the initial error_string pointer. - return __KernelLoadExec(bootpath.c_str(), 0, &PSP_CoreParameter().errorString); + return __KernelLoadExec(currentMIPS, bootpath.c_str(), 0, &PSP_CoreParameter().errorString); } // TODO: Move this to common. Merge with ResolvePath? @@ -451,7 +452,7 @@ bool Load_PSP_ELF_PBP(FileLoader *fileLoader, std::string_view discId, bool load g_Config.LoadGameConfig(discID); } - return __KernelLoadExec(finalName.c_str(), 0, error_string); + return __KernelLoadExec(currentMIPS, finalName.c_str(), 0, error_string); } bool Load_PSP_GE_Dump(FileLoader *fileLoader, std::string *error_string) { diff --git a/Core/Reporting.cpp b/Core/Reporting.cpp index e4ed600cf5..ed66d6beb4 100644 --- a/Core/Reporting.cpp +++ b/Core/Reporting.cpp @@ -50,6 +50,7 @@ extern "C" { #include "Core/Loaders.h" #include "Core/SaveState.h" #include "Core/System.h" +#include "Core/MIPS/MIPS.h" #include "Core/ELF/ParamSFO.h" #include "Core/FileSystems/BlockDevices.h" #include "Core/FileSystems/MetaFileSystem.h" @@ -457,7 +458,7 @@ namespace Reporting { // Just to get an idea of how long they played. if (PSP_GetBootState() == BootState::Complete) - postdata.Add("ticks", (const uint64_t)CoreTiming::GetTicks()); + postdata.Add("ticks", (const uint64_t)CoreTiming::GetTicks(currentMIPS)); float vps, fps; __DisplayGetAveragedFPS(&vps, &fps); diff --git a/Core/System.cpp b/Core/System.cpp index 9e22df9527..e33ef65b1e 100644 --- a/Core/System.cpp +++ b/Core/System.cpp @@ -437,7 +437,7 @@ static bool CPU_Init(FileLoader *fileLoader, IdentifiedFileType type, std::strin mipsr4k.Reset(); - CoreTiming::Init(); + CoreTiming::Init(&mipsr4k); DisplayHWInit(); @@ -798,7 +798,7 @@ void PSP_RunLoopWhileState() { } void PSP_RunLoopFor(int cycles) { - Core_RunLoopUntil(CoreTiming::GetTicks() + cycles); + Core_RunLoopUntil(CoreTiming::GetTicks(currentMIPS) + cycles); } const char *DumpFileTypeToString(DumpFileType type) { diff --git a/GPU/Debugger/Playback.cpp b/GPU/Debugger/Playback.cpp index b954703332..a07a4dfb42 100644 --- a/GPU/Debugger/Playback.cpp +++ b/GPU/Debugger/Playback.cpp @@ -409,7 +409,7 @@ void DumpExecute::SyncStall() { s64 listTicks = gpu->GetListTicks(execListID); if (listTicks != -1) { - s64 nowTicks = CoreTiming::GetTicks(); + s64 nowTicks = CoreTiming::GetTicks(currentMIPS); if (listTicks > nowTicks) { currentMIPS->downcount -= listTicks - nowTicks; } diff --git a/GPU/GPUCommon.cpp b/GPU/GPUCommon.cpp index d826852896..64f2533a53 100644 --- a/GPU/GPUCommon.cpp +++ b/GPU/GPUCommon.cpp @@ -186,7 +186,7 @@ u32 GPUCommon::DrawSync(int mode) { return SCE_KERNEL_ERROR_ILLEGAL_CONTEXT; } - if (drawCompleteTicks > CoreTiming::GetTicks()) { + if (drawCompleteTicks > CoreTiming::GetTicks(currentMIPS)) { __GeWaitCurrentThread(GPU_SYNC_DRAW, 1, "GeDrawSync"); } else { for (int i = 0; i < DisplayListMaxCount; ++i) { @@ -262,7 +262,7 @@ int GPUCommon::ListSync(int listid, int mode) { return SCE_KERNEL_ERROR_ILLEGAL_CONTEXT; } - if (dl.waitUntilTicks > CoreTiming::GetTicks()) { + if (dl.waitUntilTicks > CoreTiming::GetTicks(currentMIPS)) { __GeWaitCurrentThread(GPU_SYNC_LIST, listid, "GeListSync"); } @@ -367,7 +367,7 @@ u32 GPUCommon::EnqueueList(u32 listpc, u32 stall, int subIntrBase, PSPPointersize >= 16 ? (u32)args->stackAddr : 0; // Check compatibility // TODO: Figure out what games are affected by this... @@ -735,7 +735,7 @@ inline void GPUCommon::UpdateState(GPURunState state) { // This is now called when coreState == CORE_RUNNING_GE, in addition to from the various sceGe commands. DLResult GPUCommon::ProcessDLQueue() { if (!resumingFromDebugBreak_) { - startingTicks = CoreTiming::GetTicks(); + startingTicks = CoreTiming::GetTicks(currentMIPS); cyclesExecuted = 0; // ?? Seems to be correct behaviour to process the list anyway? diff --git a/UI/ImDebugger/ImDebugger.cpp b/UI/ImDebugger/ImDebugger.cpp index b3bf785ac8..bf0017c1d6 100644 --- a/UI/ImDebugger/ImDebugger.cpp +++ b/UI/ImDebugger/ImDebugger.cpp @@ -195,7 +195,7 @@ void DrawSchedulerView(ImConfig &cfg) { ImGui::End(); return; } - s64 ticks = CoreTiming::GetTicks(); + s64 ticks = CoreTiming::GetTicks(currentMIPS); if (ImGui::BeginChild("event_list", ImVec2(300.0f, 0.0))) { const CoreTiming::Event *event = CoreTiming::GetFirstEvent(); while (event) { diff --git a/Windows/Debugger/Debugger_Disasm.cpp b/Windows/Debugger/Debugger_Disasm.cpp index 04ebace40d..a4ca6b63a2 100644 --- a/Windows/Debugger/Debugger_Disasm.cpp +++ b/Windows/Debugger/Debugger_Disasm.cpp @@ -93,7 +93,7 @@ static constexpr UINT UPDATE_DELAY = 1000 / 60; CDisasm::CDisasm(HINSTANCE _hInstance, HWND _hParent, MIPSDebugInterface *_cpu) : Dialog((LPCSTR)IDD_DISASM, _hInstance, _hParent) { cpu = _cpu; - lastTicks_ = PSP_IsInited() ? CoreTiming::GetTicks() : 0; + lastTicks_ = PSP_IsInited() ? CoreTiming::GetTicks(currentMIPS) : 0; breakpoints_ = &g_breakpoints; SetWindowText(m_hDlg, L"R4"); @@ -204,7 +204,7 @@ void CDisasm::step(CPUStepType stepType) { CtrlDisAsmView *ptr = DisAsmView(); ptr->setDontRedraw(true); - lastTicks_ = CoreTiming::GetTicks(); + lastTicks_ = CoreTiming::GetTicks(currentMIPS); // Route the actual step request to the CPU thread instead of poking at it directly from this // GUI thread - see Core_RunOnCPUThread() in Core.h. @@ -219,7 +219,7 @@ void CDisasm::runToLine() { CtrlDisAsmView *ptr = DisAsmView(); u32 pos = ptr->getSelection(); - lastTicks_ = CoreTiming::GetTicks(); + lastTicks_ = CoreTiming::GetTicks(currentMIPS); ptr->setDontRedraw(true); // Route the breakpoint mutation to the CPU thread instead of poking at it directly from this // GUI thread - see Core_RunOnCPUThread() in Core.h. Core_Resume() itself is free-threaded. @@ -401,7 +401,7 @@ BOOL CDisasm::DlgProc(UINT message, WPARAM wParam, LPARAM lParam) { ptr->setDontRedraw(false); Core_Break(BreakReason::DebugBreak, 0); } else { // go - lastTicks_ = CoreTiming::GetTicks(); + lastTicks_ = CoreTiming::GetTicks(currentMIPS); Core_Resume(); } } @@ -423,7 +423,7 @@ BOOL CDisasm::DlgProc(UINT message, WPARAM wParam, LPARAM lParam) { { if (Core_IsActive()) break; - lastTicks_ = CoreTiming::GetTicks(); + lastTicks_ = CoreTiming::GetTicks(currentMIPS); // Route the actual HLE-break mutation to the CPU thread instead of poking at // it directly from this GUI thread - see Core_RunOnCPUThread() in Core.h. @@ -799,7 +799,7 @@ void CDisasm::ProcessUpdateDialog() { // Update Debug Counter if (PSP_IsInited()) { wchar_t tempTicks[24]{}; - _snwprintf(tempTicks, 23, L"%lld", CoreTiming::GetTicks() - lastTicks_); + _snwprintf(tempTicks, 23, L"%lld", CoreTiming::GetTicks(currentMIPS) - lastTicks_); SetDlgItemText(m_hDlg, IDC_DEBUG_COUNT, tempTicks); } diff --git a/Windows/Debugger/Debugger_VFPUDlg.cpp b/Windows/Debugger/Debugger_VFPUDlg.cpp index a20973c491..6057164e6e 100644 --- a/Windows/Debugger/Debugger_VFPUDlg.cpp +++ b/Windows/Debugger/Debugger_VFPUDlg.cpp @@ -164,8 +164,8 @@ BOOL CVFPUDlg::DlgProc(UINT message, WPARAM wParam, LPARAM lParam) for (int row = 0; row<4; row++) { - float val = mipsr4k.v[voffset[column*32+row+matrix*4]]; - u32 hex = mipsr4k.vi[voffset[column*32+row+matrix*4]]; + float val = currentMIPS->v[voffset[column*32+row+matrix*4]]; + u32 hex = currentMIPS->vi[voffset[column*32+row+matrix*4]]; switch (mode) { case 0: temp_len = sprintf_s(temp,"%f",val); break; diff --git a/libretro/libretro.cpp b/libretro/libretro.cpp index 2a11aa6d5c..72bc15fb8a 100644 --- a/libretro/libretro.cpp +++ b/libretro/libretro.cpp @@ -247,7 +247,7 @@ namespace Libretro } // Get elapsed time (us) for this run - s64 runTicks = CoreTiming::GetTicks(); + s64 runTicks = CoreTiming::GetTicks(currentMIPS); s64 runTimeUs = cyclesToUs(runTicks - runTicksLast); // Check if current internal frame rate is a diff --git a/unittest/JitHarness.cpp b/unittest/JitHarness.cpp index 4e56ee10b3..9d85cb495d 100644 --- a/unittest/JitHarness.cpp +++ b/unittest/JitHarness.cpp @@ -100,7 +100,7 @@ static void SetupJitHarness() { Memory::Init(Memory::MemMapSetupFlags::Default); mipsr4k.Reset(); - CoreTiming::Init(); + CoreTiming::Init(currentMIPS); InitVFPU(); } From c5e4d0d90dfa1687f15124fc5a7aa85433e30551 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Wed, 12 Aug 2026 14:06:16 +0200 Subject: [PATCH 5/7] Rename the get-memory-pointer functions to make it clear where CPU exceptions can happen. --- Core/Dialog/PSPNetconfDialog.cpp | 4 +- Core/Dialog/PSPSaveDialog.cpp | 2 +- Core/ELF/ElfReader.cpp | 2 +- Core/FileSystems/ISOFileSystem.cpp | 2 +- Core/HLE/AtracCtx.cpp | 2 +- Core/HLE/AtracCtx2.cpp | 10 ++-- Core/HLE/FunctionWrappers.h | 22 ++++----- Core/HLE/ReplaceTables.cpp | 60 ++++++++++++------------ Core/HLE/__sceAudio.cpp | 2 +- Core/HLE/proAdhoc.cpp | 2 +- Core/HLE/sceAtrac.cpp | 2 +- Core/HLE/sceAudiocodec.cpp | 4 +- Core/HLE/sceChnnlsv.cpp | 12 ++--- Core/HLE/sceDeflt.cpp | 4 +- Core/HLE/sceFont.cpp | 2 +- Core/HLE/sceGe.cpp | 4 +- Core/HLE/sceHttp.cpp | 2 +- Core/HLE/sceIo.cpp | 4 +- Core/HLE/sceJpeg.cpp | 2 +- Core/HLE/sceKernelModule.cpp | 14 +++--- Core/HLE/sceKernelMsgPipe.cpp | 4 +- Core/HLE/sceKernelTime.cpp | 2 +- Core/HLE/sceMd5.cpp | 2 +- Core/HLE/sceMpeg.cpp | 8 ++-- Core/HLE/sceMt19937.cpp | 2 +- Core/HLE/sceNet.cpp | 4 +- Core/HLE/sceNetAdhoc.cpp | 42 ++++++++--------- Core/HLE/sceNetAdhocMatching.cpp | 10 ++-- Core/HLE/sceNetInet.cpp | 62 ++++++++++++------------- Core/HLE/sceNet_lib.cpp | 2 +- Core/HLE/sceNp.cpp | 6 +-- Core/HLE/sceNp2.cpp | 4 +- Core/HLE/scePsmf.cpp | 2 +- Core/HLE/sceReg.cpp | 4 +- Core/HW/MediaEngine.cpp | 2 +- Core/HW/SasAudio.cpp | 4 +- Core/HW/SimpleAudioDec.cpp | 2 +- Core/MemMap.cpp | 2 +- Core/MemMap.h | 14 +++--- Core/MemMapFunctions.cpp | 34 +++++++------- Core/MemMapHelpers.h | 8 ++-- Core/Util/PPGeDraw.cpp | 8 ++-- GPU/Common/FramebufferManagerCommon.cpp | 2 +- GPU/Common/StencilCommon.cpp | 2 +- GPU/Common/TextureCacheCommon.cpp | 4 +- GPU/Common/TextureDecoder.h | 6 +-- GPU/Debugger/Record.cpp | 4 +- GPU/GPUCommon.cpp | 16 +++---- GPU/Software/Rasterizer.cpp | 2 +- GPU/Software/SoftGpu.cpp | 16 +++---- UI/ImDebugger/ImDebugger.cpp | 2 +- Windows/Debugger/DumpMemoryWindow.cpp | 6 +-- unittest/JitHarness.cpp | 2 +- 53 files changed, 224 insertions(+), 224 deletions(-) diff --git a/Core/Dialog/PSPNetconfDialog.cpp b/Core/Dialog/PSPNetconfDialog.cpp index fecb99e5de..43465dd84a 100644 --- a/Core/Dialog/PSPNetconfDialog.cpp +++ b/Core/Dialog/PSPNetconfDialog.cpp @@ -265,11 +265,11 @@ int PSPNetconfDialog::Update(int animSpeed) { } if (reqsz > 0) { if (hleCall(sceNetAdhocctl, int, sceNetAdhocctlGetScanInfo, scanInfosAddr, scanInfosAddr + (u32)sizeof(s32)) >= 0) { - ScanInfos* scanInfos = (ScanInfos*)Memory::GetPointer(scanInfosAddr); + ScanInfos* scanInfos = (ScanInfos*)Memory::GetPointerOrException(scanInfosAddr); int n = scanInfos->sz / sizeof(SceNetAdhocctlScanInfoEmu); // Assuming returned SceNetAdhocctlScanInfoEmu(s) are contiguous where next is pointing to current addr + sizeof(SceNetAdhocctlScanInfoEmu) while (n > 0) { - SceNetAdhocctlScanInfoEmu* si = (SceNetAdhocctlScanInfoEmu*)Memory::GetPointer(scanInfosAddr + sizeof(s32) + sizeof(SceNetAdhocctlScanInfoEmu) * (n - 1LL)); + SceNetAdhocctlScanInfoEmu* si = (SceNetAdhocctlScanInfoEmu*)Memory::GetPointerOrException(scanInfosAddr + sizeof(s32) + sizeof(SceNetAdhocctlScanInfoEmu) * (n - 1LL)); if (memcmp(si->group_name.data, request.NetconfData->groupName, ADHOCCTL_GROUPNAME_LEN) == 0) { // Moving found group info to the front so we can use it on sceNetAdhocctlJoin easily memcpy((char*)scanInfos + sizeof(s32), si, sizeof(SceNetAdhocctlScanInfoEmu)); diff --git a/Core/Dialog/PSPSaveDialog.cpp b/Core/Dialog/PSPSaveDialog.cpp index 3cd79caa14..9f2401baeb 100755 --- a/Core/Dialog/PSPSaveDialog.cpp +++ b/Core/Dialog/PSPSaveDialog.cpp @@ -678,7 +678,7 @@ int PSPSaveDialog::Update(int animSpeed) { // Check if it has changed, reload it. // TODO: Cut down on preloading? This rebuilds the list from scratch. int size = std::min((u32)sizeof(originalRequest), Memory::ReadUnchecked_U32(requestAddr)); - const u8 *updatedRequest = Memory::GetPointerRange(requestAddr, size); + const u8 *updatedRequest = Memory::GetPointerRangeOrException(requestAddr, size); if (updatedRequest && memcmp(updatedRequest, &originalRequest, size) != 0) { memset(&request, 0, sizeof(request)); Memory::Memcpy(&request, requestAddr, size); diff --git a/Core/ELF/ElfReader.cpp b/Core/ELF/ElfReader.cpp index 4f56dd89b9..bf4eea4324 100644 --- a/Core/ELF/ElfReader.cpp +++ b/Core/ELF/ElfReader.cpp @@ -544,7 +544,7 @@ int ElfReader::LoadInto(u32 loadAddress, bool fromTop) { } const u32 srcSize = p->p_filesz; const u32 dstSize = p->p_memsz; // can be bigger than size-in-file (p_filesz), we'll zero the rest below. But cannot be smaller! - u8 *dst = Memory::GetPointerWriteRange(writeAddr, dstSize); + u8 *dst = Memory::GetPointerWriteRangeOrException(writeAddr, dstSize); if (dst) { if (srcSize < dstSize) { memset(dst + srcSize, 0, dstSize - srcSize); // zero out the rest of the segment, this also applies to bss (which is all-zero) diff --git a/Core/FileSystems/ISOFileSystem.cpp b/Core/FileSystems/ISOFileSystem.cpp index ade6458594..d168a54cbb 100644 --- a/Core/FileSystems/ISOFileSystem.cpp +++ b/Core/FileSystems/ISOFileSystem.cpp @@ -455,7 +455,7 @@ int ISOFileSystem::Ioctl(u32 handle, u32 cmd, u32 indataPtr, u32 inlen, u32 outd } else { int block = (u16)desc.firstLETableSector; u32 size = Memory::ClampValidSizeAt(outdataPtr, (u32)desc.pathTableLength); - u8 *out = Memory::GetPointerWriteRange(outdataPtr, size); + u8 *out = Memory::GetPointerWriteRangeOrException(outdataPtr, size); int blocks = size / blockDevice->GetBlockSize(); blockDevice->ReadBlocks(block, blocks, out); diff --git a/Core/HLE/AtracCtx.cpp b/Core/HLE/AtracCtx.cpp index bcd730347e..a18337ea90 100644 --- a/Core/HLE/AtracCtx.cpp +++ b/Core/HLE/AtracCtx.cpp @@ -165,7 +165,7 @@ void Atrac::ResetData() { } u8 *Atrac::BufferStart() { - return ignoreDataBuf_ ? Memory::GetPointerWrite(first_.addr) : dataBuf_; + return ignoreDataBuf_ ? Memory::GetPointerWriteOrException(first_.addr) : dataBuf_; } AtracBase::~AtracBase() { diff --git a/Core/HLE/AtracCtx2.cpp b/Core/HLE/AtracCtx2.cpp index 8a6162fd27..3dccd9cb65 100644 --- a/Core/HLE/AtracCtx2.cpp +++ b/Core/HLE/AtracCtx2.cpp @@ -863,7 +863,7 @@ u32 Atrac2::DecodeInternal(u32 outbufAddr, int *SamplesNum, int *finish) { } outPtr = decodeTemp_; } else { - outPtr = outbufAddr ? (int16_t *)Memory::GetPointer(outbufAddr) : 0; // outbufAddr can be 0 during skip! + outPtr = outbufAddr ? (int16_t *)Memory::GetPointerOrException(outbufAddr) : 0; // outbufAddr can be 0 during skip! } context_->codec.inBuf = inAddr; @@ -899,7 +899,7 @@ u32 Atrac2::DecodeInternal(u32 outbufAddr, int *SamplesNum, int *finish) { } else { *finish = 0; } - u8 *outBuf = outbufAddr ? Memory::GetPointerWrite(outbufAddr) : nullptr; + u8 *outBuf = outbufAddr ? Memory::GetPointerWriteOrException(outbufAddr) : nullptr; if (samplesToDecode != info.SamplesPerFrame() && samplesToDecode != 0 && outBuf) { memcpy(outBuf, decodeTemp_, samplesToDecode * outputChannels_ * sizeof(int16_t)); } @@ -958,8 +958,8 @@ u32 Atrac2::DecodeInternal(u32 outbufAddr, int *SamplesNum, int *finish) { size_t copyLen = info.secondBufferByte % info.sampleSize; if (copyLen > info.bufferByte) copyLen = info.bufferByte; - memcpy(Memory::GetPointerWrite(info.buffer), - Memory::GetPointer(info.secondBuffer + (info.secondBufferByte - info.secondBufferByte % info.sampleSize)), + memcpy(Memory::GetPointerWriteOrException(info.buffer), + Memory::GetPointerOrException(info.secondBuffer + (info.secondBufferByte - info.secondBufferByte % info.sampleSize)), copyLen); } } @@ -1214,7 +1214,7 @@ void Atrac2::DecodeForSas(s16 *dstData, int *bytesWritten, int *finish) { // Keep decoding from the current buffer until it runs out. if (sas_.streamOffset + (int)info.sampleSize <= (int)sas_.bufSize[sas_.curBuffer]) { // Just decode. - const u8 *srcData = Memory::GetPointer(sas_.bufPtr[sas_.curBuffer] + sas_.streamOffset); + const u8 *srcData = Memory::GetPointerOrException(sas_.bufPtr[sas_.curBuffer] + sas_.streamOffset); int bytesConsumed = 0; bool decodeResult = decoder_->Decode(srcData, info.sampleSize, &bytesConsumed, 1, dstData, bytesWritten); if (!decodeResult) { diff --git a/Core/HLE/FunctionWrappers.h b/Core/HLE/FunctionWrappers.h index 099d5a9539..926ed29f72 100644 --- a/Core/HLE/FunctionWrappers.h +++ b/Core/HLE/FunctionWrappers.h @@ -106,7 +106,7 @@ template void WrapU_V() { } template void WrapU_IVI() { - u32 retval = func(PARAM(0), Memory::GetPointerWrite(PARAM(1)), PARAM(2)); + u32 retval = func(PARAM(0), Memory::GetPointerWriteOrException(PARAM(1)), PARAM(2)); RETURN(retval); } @@ -116,7 +116,7 @@ template void WrapI_CIIU() { } template void WrapI_ICUVVUI() { - u32 retval = func(PARAM(0), Memory::GetCharPointer(PARAM(1)), PARAM(2), Memory::GetPointerWrite(PARAM(3)),Memory::GetPointerWrite(PARAM(4)), PARAM(5), PARAM(6) ); + u32 retval = func(PARAM(0), Memory::GetCharPointer(PARAM(1)), PARAM(2), Memory::GetPointerWriteOrException(PARAM(3)),Memory::GetPointerWriteOrException(PARAM(4)), PARAM(5), PARAM(6) ); RETURN(retval); } @@ -147,13 +147,13 @@ template void WrapI_IIIIIIU() { // Hm, do so many params get passed in registers? template void WrapI_IIIIIIIIU() { - u32 param8 = *(const u32_le *)Memory::GetPointerWrite(currentMIPS->r[29]); //Fixed 9th parameter, thanks to Kingcom + u32 param8 = *(const u32_le *)Memory::GetPointerWriteOrException(currentMIPS->r[29]); //Fixed 9th parameter, thanks to Kingcom u32 retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4), PARAM(5), PARAM(6), PARAM(7), param8); RETURN(retval); } template void WrapU_IV() { - u32 retval = func(PARAM(0), Memory::GetPointerWrite(PARAM(1))); + u32 retval = func(PARAM(0), Memory::GetPointerWriteOrException(PARAM(1))); RETURN(retval); } @@ -881,27 +881,27 @@ template void WrapI_ICI() { } template void WrapI_IVVVVUI(){ - u32 retval = func(PARAM(0), Memory::GetPointerWrite(PARAM(1)), Memory::GetPointerWrite(PARAM(2)), Memory::GetPointerWrite(PARAM(3)), Memory::GetPointerWrite(PARAM(4)), PARAM(5), PARAM(6) ); + u32 retval = func(PARAM(0), Memory::GetPointerWriteOrException(PARAM(1)), Memory::GetPointerWriteOrException(PARAM(2)), Memory::GetPointerWriteOrException(PARAM(3)), Memory::GetPointerWriteOrException(PARAM(4)), PARAM(5), PARAM(6) ); RETURN(retval); } template void WrapI_ICUVIII(){ - u32 retval = func(PARAM(0), Memory::GetCharPointer(PARAM(1)), PARAM(2), Memory::GetPointerWrite(PARAM(3)), PARAM(4), PARAM(5), PARAM(6)); + u32 retval = func(PARAM(0), Memory::GetCharPointer(PARAM(1)), PARAM(2), Memory::GetPointerWriteOrException(PARAM(3)), PARAM(4), PARAM(5), PARAM(6)); RETURN(retval); } template void WrapI_VUI(){ - u32 retval = func(Memory::GetPointerWrite(PARAM(0)), PARAM(1), PARAM(2)); + u32 retval = func(Memory::GetPointerWriteOrException(PARAM(0)), PARAM(1), PARAM(2)); RETURN(retval); } template void WrapU_VUU() { - u32 retval = func(Memory::GetPointerWrite(PARAM(0)), PARAM(1), PARAM(2)); + u32 retval = func(Memory::GetPointerWriteOrException(PARAM(0)), PARAM(1), PARAM(2)); RETURN(retval); } template void WrapU_VC() { - u32 retval = func(Memory::GetPointerWrite(PARAM(0)), Memory::GetCharPointer(PARAM(1))); + u32 retval = func(Memory::GetPointerWriteOrException(PARAM(0)), Memory::GetCharPointer(PARAM(1))); RETURN(retval); } @@ -916,11 +916,11 @@ template void WrapI_CC() { } template void WrapU_VCU() { - u32 retval = func(Memory::GetPointerWrite(PARAM(0)), Memory::GetCharPointer(PARAM(1)), PARAM(2)); + u32 retval = func(Memory::GetPointerWriteOrException(PARAM(0)), Memory::GetCharPointer(PARAM(1)), PARAM(2)); RETURN(retval); } template void WrapU_VI() { - u32 retval = func(Memory::GetPointerWrite(PARAM(0)), PARAM(1)); + u32 retval = func(Memory::GetPointerWriteOrException(PARAM(0)), PARAM(1)); RETURN(retval); } diff --git a/Core/HLE/ReplaceTables.cpp b/Core/HLE/ReplaceTables.cpp index c98d878190..aadff67a91 100644 --- a/Core/HLE/ReplaceTables.cpp +++ b/Core/HLE/ReplaceTables.cpp @@ -133,8 +133,8 @@ static int Replace_memcpy() { } } if (!skip && bytes != 0) { - u8 *dst = Memory::GetPointerWriteRange(destPtr, bytes); - const u8 *src = Memory::GetPointerRange(srcPtr, bytes); + u8 *dst = Memory::GetPointerWriteRangeOrException(destPtr, bytes); + const u8 *src = Memory::GetPointerRangeOrException(srcPtr, bytes); if (!dst || !src) { // Already logged. @@ -200,8 +200,8 @@ static int Replace_memcpy_jak() { sliced = true; } if (!skip && bytes != 0) { - u8 *dst = Memory::GetPointerWriteRange(destPtr, bytes); - const u8 *src = Memory::GetPointerRange(srcPtr, bytes); + u8 *dst = Memory::GetPointerWriteRangeOrException(destPtr, bytes); + const u8 *src = Memory::GetPointerRangeOrException(srcPtr, bytes); if (dst && src) { // Jak style overlap. @@ -265,8 +265,8 @@ static int Replace_memcpy16() { } } if (!skip && bytes != 0) { - u8 *dst = Memory::GetPointerWriteRange(destPtr, bytes); - const u8 *src = Memory::GetPointerRange(srcPtr, bytes); + u8 *dst = Memory::GetPointerWriteRangeOrException(destPtr, bytes); + const u8 *src = Memory::GetPointerRangeOrException(srcPtr, bytes); if (dst && src) { memmove(dst, src, bytes); } @@ -290,8 +290,8 @@ static int Replace_memcpy_swizzled() { gpu->PerformReadbackToMemory(srcPtr, pitch * h); } } - u8 *dstp = Memory::GetPointerWriteRange(destPtr, pitch * h); - const u8 *srcp = Memory::GetPointerRange(srcPtr, pitch * h); + u8 *dstp = Memory::GetPointerWriteRangeOrException(destPtr, pitch * h); + const u8 *srcp = Memory::GetPointerRangeOrException(srcPtr, pitch * h); if (dstp && srcp) { const u8 *ysrcp = srcp; @@ -333,8 +333,8 @@ static int Replace_memmove() { } } if (!skip && bytes != 0) { - u8 *dst = Memory::GetPointerWriteRange(destPtr, bytes); - const u8 *src = Memory::GetPointerRange(srcPtr, bytes); + u8 *dst = Memory::GetPointerWriteRangeOrException(destPtr, bytes); + const u8 *src = Memory::GetPointerRangeOrException(srcPtr, bytes); if (dst && src) { memmove(dst, src, bytes); } @@ -357,7 +357,7 @@ static int Replace_memset() { skip = gpu->PerformMemorySet(destPtr, value, bytes); } if (!skip && bytes != 0) { - u8 *dst = Memory::GetPointerWriteRange(destPtr, bytes); + u8 *dst = Memory::GetPointerWriteRangeOrException(destPtr, bytes); if (dst) { memset(dst, value, bytes); } @@ -391,7 +391,7 @@ static int Replace_memset_jak() { sliced = true; } if (!skip && bytes != 0) { - u8 *dst = Memory::GetPointerWriteRange(destPtr, bytes); + u8 *dst = Memory::GetPointerWriteRangeOrException(destPtr, bytes); if (dst) { memset(dst, value, bytes); } @@ -419,7 +419,7 @@ static int Replace_memset_jak() { static uint32_t SafeStringLen(const uint32_t ptr, uint32_t maxLen = 0x07FFFFFF) { maxLen = Memory::ClampValidSizeAt(ptr, 0x07FFFFFF); - const uint8_t *p = Memory::GetPointerRange(ptr, maxLen); + const uint8_t *p = Memory::GetPointerRangeOrException(ptr, maxLen); if (!p) return 0; const uint8_t *end = (const uint8_t *)memchr(p, '\0', maxLen); @@ -439,8 +439,8 @@ static int Replace_strcpy() { u32 destPtr = PARAM(0); u32 srcPtr = PARAM(1); u32 len = SafeStringLen(srcPtr); - char *dst = (char *)Memory::GetPointerWriteRange(destPtr, len); - const char *src = (const char *)Memory::GetPointerRange(srcPtr, len); + char *dst = (char *)Memory::GetPointerWriteRangeOrException(destPtr, len); + const char *src = (const char *)Memory::GetPointerRangeOrException(srcPtr, len); if (dst && src && len != 0) { strcpy(dst, src); } @@ -452,9 +452,9 @@ static int Replace_strncpy() { u32 destPtr = PARAM(0); u32 srcPtr = PARAM(1); u32 bytes = PARAM(2); - char *dst = (char *)Memory::GetPointerRange(destPtr, bytes); + char *dst = (char *)Memory::GetPointerRangeOrException(destPtr, bytes); u32 srcLen = SafeStringLen(srcPtr, bytes); - const char *src = (const char *)Memory::GetPointerRange(srcPtr, srcLen == 0 ? bytes : srcLen); + const char *src = (const char *)Memory::GetPointerRangeOrException(srcPtr, srcLen == 0 ? bytes : srcLen); if (dst && src && bytes != 0) { strncpy(dst, src, bytes); } @@ -464,9 +464,9 @@ static int Replace_strncpy() { static int Replace_strcmp() { u32 aLen = SafeStringLen(PARAM(0)); - const char *a = (const char *)Memory::GetPointerRange(PARAM(0), aLen); + const char *a = (const char *)Memory::GetPointerRangeOrException(PARAM(0), aLen); u32 bLen = SafeStringLen(PARAM(1)); - const char *b = (const char *)Memory::GetPointerRange(PARAM(1), bLen); + const char *b = (const char *)Memory::GetPointerRangeOrException(PARAM(1), bLen); if (a && b && aLen != 0 && bLen != 0) { RETURN(strcmp(a, b)); } else { @@ -478,9 +478,9 @@ static int Replace_strcmp() { static int Replace_strncmp() { u32 bytes = PARAM(2); u32 aLen = SafeStringLen(PARAM(0), bytes); - const char *a = (const char *)Memory::GetPointerRange(PARAM(0), aLen == 0 ? bytes : aLen); + const char *a = (const char *)Memory::GetPointerRangeOrException(PARAM(0), aLen == 0 ? bytes : aLen); u32 bLen = SafeStringLen(PARAM(1), bytes); - const char *b = (const char *)Memory::GetPointerRange(PARAM(1), bLen == 0 ? bytes : bLen); + const char *b = (const char *)Memory::GetPointerRangeOrException(PARAM(1), bLen == 0 ? bytes : bLen); if (a && b && bytes != 0) { RETURN(strncmp(a, b, bytes)); } else { @@ -495,9 +495,9 @@ static int Replace_fabsf() { } static int Replace_vmmul_q_transp() { - float_le *out = (float_le *)Memory::GetPointerRange(PARAM(0), 16 * 4); - const float_le *a = (const float_le *)Memory::GetPointerRange(PARAM(1), 16 * 4); - const float_le *b = (const float_le *)Memory::GetPointerRange(PARAM(2), 16 * 4); + float_le *out = (float_le *)Memory::GetPointerRangeOrException(PARAM(0), 16 * 4); + const float_le *a = (const float_le *)Memory::GetPointerRangeOrException(PARAM(1), 16 * 4); + const float_le *b = (const float_le *)Memory::GetPointerRangeOrException(PARAM(2), 16 * 4); // TODO: Actually use an optimized matrix multiply here... if (out && b && a) { @@ -522,8 +522,8 @@ static int Replace_vmmul_q_transp() { // a1 = matrix // a2 = source address static int Replace_gta_dl_write_matrix() { - u32_le *ptr = (u32_le *)Memory::GetPointerWriteRange(PARAM(0), 4); - const u32_le *src = (const u32_le *)Memory::GetPointerRange(PARAM(2), 16); + u32_le *ptr = (u32_le *)Memory::GetPointerWriteRangeOrException(PARAM(0), 4); + const u32_le *src = (const u32_le *)Memory::GetPointerRangeOrException(PARAM(2), 16); u32 matrix = PARAM(1) << 24; if (!ptr || !src) { @@ -531,7 +531,7 @@ static int Replace_gta_dl_write_matrix() { return 38; } - u32_le *dest = (u32_le *)Memory::GetPointerWriteRange(ptr[0], 12 * 4); + u32_le *dest = (u32_le *)Memory::GetPointerWriteRangeOrException(ptr[0], 12 * 4); if (!dest) { RETURN(0); return 38; @@ -581,8 +581,8 @@ static int Replace_gta_dl_write_matrix() { // TODO: Inline into a few NEON or SSE instructions - especially if a1 is a known immediate! // Anyway, not sure if worth it. There's not that many matrices written per frame normally. static int Replace_dl_write_matrix() { - u32_le *dlStruct = (u32_le *)Memory::GetPointerWriteRange(PARAM(0), 3 * 4); - const u32_le *src = (const u32_le *)Memory::GetPointerRange(PARAM(2), 16 * 4); + u32_le *dlStruct = (u32_le *)Memory::GetPointerWriteRangeOrException(PARAM(0), 3 * 4); + const u32_le *src = (const u32_le *)Memory::GetPointerRangeOrException(PARAM(2), 16 * 4); if (!dlStruct || !src) { RETURN(0); @@ -607,7 +607,7 @@ static int Replace_dl_write_matrix() { break; } - u32_le *dest = (u32_le *)Memory::GetPointerWriteRange(dlStruct[2], 4 + count * 4); + u32_le *dest = (u32_le *)Memory::GetPointerWriteRangeOrException(dlStruct[2], 4 + count * 4); if (!dest) { RETURN(0); return 60; diff --git a/Core/HLE/__sceAudio.cpp b/Core/HLE/__sceAudio.cpp index e13b99d804..a6fe3b22e8 100644 --- a/Core/HLE/__sceAudio.cpp +++ b/Core/HLE/__sceAudio.cpp @@ -259,7 +259,7 @@ u32 __AudioEnqueue(AudioChannel &chan, int chanNum, bool blocking) { if (chan.format == PSP_AUDIO_FORMAT_STEREO) { const u32 totalSamples = chan.sampleCount * 2; - s16_le *sampleData = (s16_le *) Memory::GetPointer(chan.sampleAddress); + s16_le *sampleData = (s16_le *) Memory::GetPointerOrException(chan.sampleAddress); // Walking a pointer for speed. But let's make sure we wouldn't trip on an invalid ptr. if (Memory::IsValidAddress(chan.sampleAddress + (totalSamples - 1) * sizeof(s16_le))) { diff --git a/Core/HLE/proAdhoc.cpp b/Core/HLE/proAdhoc.cpp index 8189abec88..3c40adf583 100644 --- a/Core/HLE/proAdhoc.cpp +++ b/Core/HLE/proAdhoc.cpp @@ -1202,7 +1202,7 @@ void AfterMatchingMipsCall::run(MipsCall &call) { u32 v0 = currentMIPS->r[MIPS_REG_V0]; if (__IsInInterrupt()) ERROR_LOG(Log::sceNet, "AfterMatchingMipsCall::run [ID=%i][Event=%d] is Returning Inside an Interrupt!", contextID, EventID); //SetMatchingInCallback(context, false); - DEBUG_LOG(Log::sceNet, "AfterMatchingMipsCall::run [ID=%i][Event=%d][%s] [cbId: %u][retV0: %08x]", contextID, EventID, mac2str((SceNetEtherAddr*)Memory::GetPointer(bufAddr)).c_str(), call.cbId, v0); + DEBUG_LOG(Log::sceNet, "AfterMatchingMipsCall::run [ID=%i][Event=%d][%s] [cbId: %u][retV0: %08x]", contextID, EventID, mac2str((SceNetEtherAddr*)Memory::GetPointerOrException(bufAddr)).c_str(), call.cbId, v0); if (Memory::IsValidAddress(bufAddr)) userMemory.Free(bufAddr); //call.setReturnValue(v0); } diff --git a/Core/HLE/sceAtrac.cpp b/Core/HLE/sceAtrac.cpp index 10becfdb35..170a9b4b16 100644 --- a/Core/HLE/sceAtrac.cpp +++ b/Core/HLE/sceAtrac.cpp @@ -333,7 +333,7 @@ static u32 sceAtracDecodeData(int atracID, u32 outAddr, u32 numSamplesAddr, u32 return hleLogError(Log::Atrac, SCE_ERROR_ATRAC_SIZE_TOO_SMALL); } - u8 *outPtr = outAddr ? Memory::GetPointerWrite(outAddr) : nullptr; + u8 *outPtr = outAddr ? Memory::GetPointerWriteOrException(outAddr) : nullptr; int ret = atrac->DecodeData(outPtr, outAddr, &numSamplesWritten, &finish, &remains); if (ret != (int)SCE_ERROR_ATRAC_BAD_ATRACID && ret != (int)SCE_ERROR_ATRAC_NO_DATA) { diff --git a/Core/HLE/sceAudiocodec.cpp b/Core/HLE/sceAudiocodec.cpp index bf513beb3c..9bcd2f2363 100644 --- a/Core/HLE/sceAudiocodec.cpp +++ b/Core/HLE/sceAudiocodec.cpp @@ -256,9 +256,9 @@ static int sceAudiocodecDecode(u32 ctxPtr, int codec) { DEBUG_LOG(Log::ME, "decoder. in: %08x out: %08x unk40: %02x unk41: %02x", ctx->inBuf, ctx->outBuf, ctx->unk40, ctx->unk41); - int16_t *outBuf = (int16_t *)Memory::GetPointerWrite(ctx->outBuf); + int16_t *outBuf = (int16_t *)Memory::GetPointerWriteOrException(ctx->outBuf); - bool result = decoder->Decode(Memory::GetPointer(ctx->inBuf), bytesPerFrame, &inDataConsumed, 2, outBuf, &outSamples); + bool result = decoder->Decode(Memory::GetPointerOrException(ctx->inBuf), bytesPerFrame, &inDataConsumed, 2, outBuf, &outSamples); if (!result) { ctx->err = 0x20b; ERROR_LOG(Log::ME, "AudioCodec decode failed. Setting error to %08x", ctx->err); diff --git a/Core/HLE/sceChnnlsv.cpp b/Core/HLE/sceChnnlsv.cpp index 89530b5ff4..1ca310015b 100644 --- a/Core/HLE/sceChnnlsv.cpp +++ b/Core/HLE/sceChnnlsv.cpp @@ -218,10 +218,10 @@ static int sub_17A8(KirkState *kirk, u8* data) static int sceSdGetLastIndex(u32 addressCtx, u32 addressHash, u32 addressKey) { auto ctx = PSPPointer::Create(addressCtx); - u8 *hash = Memory::GetPointerWrite(addressHash); + u8 *hash = Memory::GetPointerWriteOrException(addressHash); if (!ctx.IsValid() || !hash) return hleLogError(Log::sceMisc, 0, "Invalid pointer"); - return hleLogDebug(Log::sceMisc, sceSdMacFinal(*ctx, hash, Memory::GetPointerWrite(addressKey))); + return hleLogDebug(Log::sceMisc, sceSdMacFinal(*ctx, hash, Memory::GetPointerWriteOrException(addressKey))); } int sceSdMacFinal(pspChnnlsvContext1& ctx, u8* in_hash, const u8* in_key) @@ -347,7 +347,7 @@ static int sceSdRemoveValue(u32 addressCtx, u32 addressData, int length) { auto ctx = PSPPointer::Create(addressCtx); if (!ctx.IsValid() || !Memory::IsValidAddress(addressData)) return hleLogError(Log::sceMisc, 0, "Invalid pointer"); - return hleLogDebug(Log::sceMisc, sceSdMacUpdate(*ctx, Memory::GetPointerWrite(addressData), length)); + return hleLogDebug(Log::sceMisc, sceSdMacUpdate(*ctx, Memory::GetPointerWriteOrException(addressData), length)); } int sceSdMacUpdate(pspChnnlsvContext1& ctx, const u8* data, int length) @@ -394,8 +394,8 @@ int sceSdMacUpdate(pspChnnlsvContext1& ctx, const u8* data, int length) static int sceSdCreateList(u32 ctx2Addr, int mode, int unkwn, u32 dataAddr, u32 cryptkeyAddr) { auto ctx2 = PSPPointer::Create(ctx2Addr); - u8* data = Memory::GetPointerWrite(dataAddr); - u8* cryptkey = Memory::GetPointerWrite(cryptkeyAddr); + u8* data = Memory::GetPointerWriteOrException(dataAddr); + u8* cryptkey = Memory::GetPointerWriteOrException(cryptkeyAddr); if (!ctx2.IsValid() || !data) return hleLogError(Log::sceMisc, 0, "Invalid pointer"); @@ -458,7 +458,7 @@ int sceSdCipherInit(pspChnnlsvContext2& ctx2, int mode, int uknw, u8* data, cons static int sceSdSetMember(u32 ctxAddr, u32 dataAddr, int alignedLen) { auto ctx = PSPPointer::Create(ctxAddr); - u8 *data = Memory::GetPointerWrite(dataAddr); + u8 *data = Memory::GetPointerWriteOrException(dataAddr); if (!ctx.IsValid() || !data) return hleLogError(Log::sceMisc, 0, "Invalid pointer"); diff --git a/Core/HLE/sceDeflt.cpp b/Core/HLE/sceDeflt.cpp index 529f4f7126..4f1aa57769 100644 --- a/Core/HLE/sceDeflt.cpp +++ b/Core/HLE/sceDeflt.cpp @@ -36,8 +36,8 @@ static int CommonDecompress(int windowBits, u32 OutBuffer, int OutBufferLength, } z_stream stream{}; - u8 *outBufferPtr = Memory::GetPointerWrite(OutBuffer); - stream.next_in = (Bytef*)Memory::GetPointer(InBuffer); + u8 *outBufferPtr = Memory::GetPointerWriteOrException(OutBuffer); + stream.next_in = (Bytef*)Memory::GetPointerOrException(InBuffer); // We don't know the available length, just let it use as much as it wants. stream.avail_in = (uInt)Memory::ClampValidSizeAt(InBuffer, Memory::g_MemorySize); stream.next_out = outBufferPtr; diff --git a/Core/HLE/sceFont.cpp b/Core/HLE/sceFont.cpp index 51c023423a..ec0d8eb2ef 100644 --- a/Core/HLE/sceFont.cpp +++ b/Core/HLE/sceFont.cpp @@ -1096,7 +1096,7 @@ static u32 sceFontOpenUserMemory(u32 libHandle, u32 memoryFontPtr, u32 memoryFon return hleReportError(Log::sceFont, 0, "invalid size"); } - const u8 *fontData = Memory::GetPointer(memoryFontPtr); + const u8 *fontData = Memory::GetPointerOrException(memoryFontPtr); // Games are able to overstate the size of a font. Let's avoid crashing when we memcpy() it. // Unsigned 0xFFFFFFFF is treated as max, but that's impossible, so let's clamp to 64MB. if (memoryFontLength > 0x03FFFFFF) diff --git a/Core/HLE/sceGe.cpp b/Core/HLE/sceGe.cpp index 5a6536c3ed..3e8af46d94 100644 --- a/Core/HLE/sceGe.cpp +++ b/Core/HLE/sceGe.cpp @@ -540,7 +540,7 @@ u32 sceGeSaveContext(u32 ctxAddr) { // Let's just dump gstate. if (Memory::IsValidAddress(ctxAddr)) { - gstate.Save((u32_le *)Memory::GetPointer(ctxAddr)); + gstate.Save((u32_le *)Memory::GetPointerOrException(ctxAddr)); } // This action should probably be pushed to the end of the queue of the display thread - @@ -554,7 +554,7 @@ u32 sceGeRestoreContext(u32 ctxAddr) { } if (Memory::IsValidAddress(ctxAddr)) { - gstate.Restore((u32_le *)Memory::GetPointer(ctxAddr)); + gstate.Restore((u32_le *)Memory::GetPointerOrException(ctxAddr)); } gpu->ReapplyGfxState(); diff --git a/Core/HLE/sceHttp.cpp b/Core/HLE/sceHttp.cpp index 8047386c59..954f6775aa 100644 --- a/Core/HLE/sceHttp.cpp +++ b/Core/HLE/sceHttp.cpp @@ -158,7 +158,7 @@ int HTTPRequest::getAllResponseHeaders(u32 headerAddrPtr, u32 headerSizePtr) { headerSize_ = sz; } - u8* header = Memory::GetPointerWrite(headerAddr_); + u8* header = Memory::GetPointerWriteOrException(headerAddr_); DEBUG_LOG(Log::sceNet, "headerAddr: %08x => %08x", headerAddr.IsValid() ? *headerAddr : 0, headerAddr_); DEBUG_LOG(Log::sceNet, "headerSize: %d => %d", headerSize.IsValid() ? *headerSize : 0, sz); if (!header && sz > 0) { diff --git a/Core/HLE/sceIo.cpp b/Core/HLE/sceIo.cpp index 8b23f2daff..b1b3f5f7a5 100644 --- a/Core/HLE/sceIo.cpp +++ b/Core/HLE/sceIo.cpp @@ -1196,7 +1196,7 @@ static bool __IoWrite(int &result, int id, u32 data_addr, int size, int &us) { us = 100; } - const void *data_ptr = Memory::GetPointer(data_addr); + const void *data_ptr = Memory::GetPointerOrException(data_addr); const u32 validSize = Memory::ClampValidSizeAt(data_addr, size); // Let's handle stdout/stderr specially. if (id == PSP_STDOUT || id == PSP_STDERR) { @@ -2522,7 +2522,7 @@ static u32 sceIoDread(int id, u32 dirent_addr) { Core_MemoryException(dirent_addr, sizeof(SceIoDirEnt), currentMIPS->pc, MemoryExceptionType::WRITE_BLOCK, "sceIoDread"); return hleLogError(Log::sceIo, SCE_KERNEL_ERROR_ILLEGAL_ADDR, "invalid address"); } - SceIoDirEnt *entry = (SceIoDirEnt*) Memory::GetPointer(dirent_addr); + SceIoDirEnt *entry = (SceIoDirEnt*) Memory::GetPointerOrException(dirent_addr); if (dir->index == (int) dir->listing.size()) { entry->d_name[0] = '\0'; diff --git a/Core/HLE/sceJpeg.cpp b/Core/HLE/sceJpeg.cpp index 3ea7f3b89b..ac0f941b7d 100644 --- a/Core/HLE/sceJpeg.cpp +++ b/Core/HLE/sceJpeg.cpp @@ -396,7 +396,7 @@ static int JpegGetOutputInfo(u32 jpegAddr, int jpegSize, u32 colourInfoAddr) { } #ifdef JPEG_DEBUG - const u8 *jpegDumpBuf = Memory::GetPointer(jpegAddr); + const u8 *jpegDumpBuf = Memory::GetPointerOrException(jpegAddr); u32 jpeg_xxhash = XXH32((const char *)jpegDumpBuf, jpegSize, 0xC0108888); Path jpegDir("Jpeg"); Path jpegFile = jpegDir / StringFromFormat("%X.jpg", jpeg_xxhash); diff --git a/Core/HLE/sceKernelModule.cpp b/Core/HLE/sceKernelModule.cpp index 213fc4b332..938c0f5891 100644 --- a/Core/HLE/sceKernelModule.cpp +++ b/Core/HLE/sceKernelModule.cpp @@ -927,7 +927,7 @@ static bool KernelImportModuleFuncs(PSPModule *module, u32 *firstImportStubAddr, if (needReport) { std::string debugInfo; - entryPos = (const u32_le *)Memory::GetPointer(module->libstub); + entryPos = (const u32_le *)Memory::GetPointerOrException(module->libstub); while (entryPos < entryEnd) { const PspLibStubEntry *entry = (const PspLibStubEntry *)entryPos; entryPos += entry->size; @@ -1453,8 +1453,8 @@ static PSPModule *__KernelLoadELFFromPtr(const u8 *ptr, size_t elfSize, u32 load module->nm.stub_top = modinfo->libstub; module->nm.stub_size = modinfo->libstubend - modinfo->libstub; - const u32_le *entPos = (u32_le *)Memory::GetPointer(modinfo->libent); - const u32_le *entEnd = (u32_le *)Memory::GetPointer(modinfo->libentend); + const u32_le *entPos = (u32_le *)Memory::GetPointerOrException(modinfo->libent); + const u32_le *entEnd = (u32_le *)Memory::GetPointerOrException(modinfo->libentend); for (int m = 0; entPos < entEnd; ++m) { const PspLibEntEntry *ent = (const PspLibEntEntry *)entPos; @@ -2017,7 +2017,7 @@ u32 sceKernelLoadModule(const char *name, u32 flags, u32 optionAddr) { } const SceKernelLMOption *lmoption = 0; if (optionAddr) { - lmoption = (const SceKernelLMOption *)Memory::GetPointer(optionAddr); + lmoption = (const SceKernelLMOption *)Memory::GetPointerOrException(optionAddr); if (lmoption->position < PSP_SMEM_Low || lmoption->position > PSP_SMEM_HighAligned) { ERROR_LOG_REPORT(Log::Loader, "sceKernelLoadModule(%s): invalid position (%i)", name, (int)lmoption->position); return hleDelayResult(SCE_KERNEL_ERROR_ILLEGAL_MEMBLOCKTYPE, "module loaded", 500); @@ -2486,7 +2486,7 @@ static u32 sceKernelLoadModuleByID(u32 id, u32 flags, u32 lmoptionPtr) { } const SceKernelLMOption *lmoption = 0; if (lmoptionPtr) { - lmoption = (const SceKernelLMOption *)Memory::GetPointer(lmoptionPtr); + lmoption = (const SceKernelLMOption *)Memory::GetPointerOrException(lmoptionPtr); WARN_LOG_REPORT(Log::Loader, "sceKernelLoadModuleByID: unsupported options size=%08x, flags=%08x, pos=%d, access=%d, data=%d, text=%d", lmoption->size, lmoption->flags, lmoption->position, lmoption->access, lmoption->mpiddata, lmoption->mpidtext); } u32 pos = (u32)pspFileSystem.SeekFile(handle, 0, FILEMOVE_CURRENT); @@ -2547,7 +2547,7 @@ SceUID sceKernelLoadModuleBufferUsbWlan(u32 size, u32 bufPtr, u32 flags, u32 lmo } const SceKernelLMOption *lmoption = 0; if (lmoptionPtr) { - lmoption = (const SceKernelLMOption *)Memory::GetPointer(lmoptionPtr); + lmoption = (const SceKernelLMOption *)Memory::GetPointerOrException(lmoptionPtr); WARN_LOG_REPORT(Log::Loader, "sceKernelLoadModuleBufferUsbWlan: unsupported options size=%08x, flags=%08x, pos=%d, access=%d, data=%d, text=%d", lmoption->size, lmoption->flags, lmoption->position, lmoption->access, lmoption->mpiddata, lmoption->mpidtext); } std::string error_string; @@ -2559,7 +2559,7 @@ SceUID sceKernelLoadModuleBufferUsbWlan(u32 size, u32 bufPtr, u32 flags, u32 lmo char fakeDebugFilename[512]; snprintf(fakeDebugFilename, sizeof(fakeDebugFilename), "moduleByPtr_%08x_%d", bufPtr, (int)size); - module = __KernelLoadELFFromPtr(Memory::GetPointer(bufPtr), size, 0, lmoption ? lmoption->position == PSP_SMEM_High : false, &error_string, &magic, fakeDebugFilename, error); + module = __KernelLoadELFFromPtr(Memory::GetPointerOrException(bufPtr), size, 0, lmoption ? lmoption->position == PSP_SMEM_High : false, &error_string, &magic, fakeDebugFilename, error); if (!module) { // Some games try to load strange stuff as PARAM.SFO as modules and expect it to fail. diff --git a/Core/HLE/sceKernelMsgPipe.cpp b/Core/HLE/sceKernelMsgPipe.cpp index c78f4fa341..e2d7e1cf50 100644 --- a/Core/HLE/sceKernelMsgPipe.cpp +++ b/Core/HLE/sceKernelMsgPipe.cpp @@ -222,7 +222,7 @@ struct MsgPipe : public KernelObject // Receive as much as possible, even if it's not enough to wake up. u32 bytesToSend = std::min(thread->freeSize, GetUsedSize()); - u8* ptr = Memory::GetPointerWrite(buffer); + u8* ptr = Memory::GetPointerWriteOrException(buffer); thread->WriteBuffer(buffer, bytesToSend); // Put the unused data at the start of the buffer. nmp.freeSize += bytesToSend; @@ -496,7 +496,7 @@ static int __KernelReceiveMsgPipe(MsgPipe *m, u32 receiveBufAddr, u32 receiveSiz { Memory::Memcpy(curReceiveAddr, m->buffer, bytesToReceive, "MsgPipeReceive"); m->nmp.freeSize += bytesToReceive; - memmove(Memory::GetPointerWrite(m->buffer), Memory::GetPointer(m->buffer) + bytesToReceive, m->GetUsedSize()); + memmove(Memory::GetPointerWriteOrException(m->buffer), Memory::GetPointerOrException(m->buffer) + bytesToReceive, m->GetUsedSize()); curReceiveAddr += bytesToReceive; receiveSize -= bytesToReceive; diff --git a/Core/HLE/sceKernelTime.cpp b/Core/HLE/sceKernelTime.cpp index 4e344f63d8..b0f8c6e4eb 100644 --- a/Core/HLE/sceKernelTime.cpp +++ b/Core/HLE/sceKernelTime.cpp @@ -178,7 +178,7 @@ u32 sceKernelLibcGettimeofday(u32 timeAddr, u32 tzAddr) // TODO: tzAddr? if (Memory::IsValidAddress(timeAddr)) { - PSPTimeval *tv = (PSPTimeval *)Memory::GetPointer(timeAddr); + PSPTimeval *tv = (PSPTimeval *)Memory::GetPointerOrException(timeAddr); __RtcTimeOfDay(tv); } diff --git a/Core/HLE/sceMd5.cpp b/Core/HLE/sceMd5.cpp index 8ac8d02c61..6653ae9e92 100644 --- a/Core/HLE/sceMd5.cpp +++ b/Core/HLE/sceMd5.cpp @@ -33,7 +33,7 @@ u32 sceKernelUtilsMt19937Init(u32 ctx, u32 seed) { DEBUG_LOG(Log::HLE, "sceKernelUtilsMt19937Init(%08x, %08x)", ctx, seed); if (!Memory::IsValidAddress(ctx)) return -1; - void *ptr = Memory::GetPointerWrite(ctx); + void *ptr = Memory::GetPointerWriteOrException(ctx); // This is made to match the memory layout of a PSP MT structure exactly. // Let's just construct it in place with placement new. Elite C++ hackery FTW. new (ptr) MersenneTwister(seed); diff --git a/Core/HLE/sceMpeg.cpp b/Core/HLE/sceMpeg.cpp index fc45897771..3418883434 100644 --- a/Core/HLE/sceMpeg.cpp +++ b/Core/HLE/sceMpeg.cpp @@ -923,7 +923,7 @@ static bool decodePmpVideo(PSPPointer ringbuffer, u32 pmpctxA for (int i = 0; i < pmp_nBlocks; i++){ auto lli = PSPPointer::Create(pmp_videoSource); // add source block into pmpframes - const uint8_t *ptr = Memory::GetPointerRange(lli->pSrc, lli->iSize); + const uint8_t *ptr = Memory::GetPointerRangeOrException(lli->pSrc, lli->iSize); if (ptr) pmpframes->add(ptr, lli->iSize); // get next block @@ -1449,7 +1449,7 @@ void PostPutAction::run(MipsCall &call) { auto demuxer = std::make_unique(packetsAddedThisRound * 2048, 0); int readOffset = ringbuffer->packetsRead % (s32)ringbuffer->packets; uint32_t bufSize = Memory::ClampValidSizeAt(ringbuffer->data + readOffset * 2048, packetsAddedThisRound * 2048); - const u8 *buf = Memory::GetPointer(ringbuffer->data + readOffset * 2048); + const u8 *buf = Memory::GetPointerOrException(ringbuffer->data + readOffset * 2048); bool invalid = false; for (uint32_t i = 0; i < bufSize / 2048; ++i) { demuxer->addStreamData(buf, 2048); @@ -1484,7 +1484,7 @@ void PostPutAction::run(MipsCall &call) { WARN_LOG(Log::Mpeg, "sceMpegRingbufferPut clamping packetsAdded old=%i new=%i", packetsAddedThisRound, ringbuffer->packets - ringbuffer->packetsAvail); packetsAddedThisRound = ringbuffer->packets - ringbuffer->packetsAvail; } - const u8 *data = Memory::GetPointer(ringbuffer->data + writeOffset * 2048); + const u8 *data = Memory::GetPointerOrException(ringbuffer->data + writeOffset * 2048); uint32_t dataSize = Memory::ClampValidSizeAt(ringbuffer->data + writeOffset * 2048, packetsAddedThisRound * 2048); int actuallyAdded = ctx->mediaengine == NULL ? 8 : ctx->mediaengine->addStreamData(data, dataSize) / 2048; if (actuallyAdded != packetsAddedThisRound) { @@ -2102,7 +2102,7 @@ static int __MpegAvcConvertToYuv420(const void *data, u32 bufferOutputAddr, int u32 *imageBuffer = (u32*)data; int sizeY = width * height; int sizeCb = sizeY >> 2; - u8 *Y = Memory::GetPointerWriteRange(bufferOutputAddr, sizeY + sizeCb + sizeCb); + u8 *Y = Memory::GetPointerWriteRangeOrException(bufferOutputAddr, sizeY + sizeCb + sizeCb); u8 *Cb = Y + sizeY; u8 *Cr = Cb + sizeCb; diff --git a/Core/HLE/sceMt19937.cpp b/Core/HLE/sceMt19937.cpp index 198ec25555..70a50f1b5a 100644 --- a/Core/HLE/sceMt19937.cpp +++ b/Core/HLE/sceMt19937.cpp @@ -44,7 +44,7 @@ static u32 sceMt19937UInt(u32 mt19937Addr) { if (!Memory::IsValidAddress(mt19937Addr)) return hleLogError(Log::HLE, -1); - MersenneTwister *mt = (MersenneTwister *)Memory::GetPointer(mt19937Addr); + MersenneTwister *mt = (MersenneTwister *)Memory::GetPointerOrException(mt19937Addr); return hleLogVerbose(Log::HLE, mt->R32()); } diff --git a/Core/HLE/sceNet.cpp b/Core/HLE/sceNet.cpp index 11b9ed20af..cfa63699cb 100644 --- a/Core/HLE/sceNet.cpp +++ b/Core/HLE/sceNet.cpp @@ -1098,7 +1098,7 @@ static void sceNetEtherStrton(u32 bufferPtr, u32 macPtr) { if (Memory::IsValidAddress(bufferPtr) && Memory::IsValidAddress(macPtr)) { const char *buffer = (const char *)Memory::GetPointerUnchecked(bufferPtr); - u8 *mac = Memory::GetPointerWrite(macPtr); + u8 *mac = Memory::GetPointerWriteOrException(macPtr); // MAC address is always 6 pairs of hex digits. // TODO: Funny stuff happens if it's too short. @@ -1124,7 +1124,7 @@ static void sceNetEtherStrton(u32 bufferPtr, u32 macPtr) { } } - VERBOSE_LOG(Log::sceNet, "sceNetEtherStrton - [%s]", mac2str((SceNetEtherAddr*)Memory::GetPointer(macPtr)).c_str()); + VERBOSE_LOG(Log::sceNet, "sceNetEtherStrton - [%s]", mac2str((SceNetEtherAddr*)Memory::GetPointerOrException(macPtr)).c_str()); // Seems to maybe kinda return the last value. Probably returns void. //return value; } diff --git a/Core/HLE/sceNetAdhoc.cpp b/Core/HLE/sceNetAdhoc.cpp index ddef583492..9434ffbb6d 100644 --- a/Core/HLE/sceNetAdhoc.cpp +++ b/Core/HLE/sceNetAdhoc.cpp @@ -2986,7 +2986,7 @@ int sceNetAdhocPollSocket(u32 socketStructAddr, int count, int timeout, int nonb if (netAdhocInited) { SceNetAdhocPollSd * sds = NULL; - if (Memory::IsValidAddress(socketStructAddr)) sds = (SceNetAdhocPollSd *)Memory::GetPointer(socketStructAddr); + if (Memory::IsValidAddress(socketStructAddr)) sds = (SceNetAdhocPollSd *)Memory::GetPointerOrException(socketStructAddr); // Valid Arguments if (sds != NULL && count > 0) @@ -3201,11 +3201,11 @@ int sceNetAdhocctlScan() { int sceNetAdhocctlGetScanInfo(u32 sizeAddr, u32 bufAddr) { s32_le *buflen = NULL; if (Memory::IsValidAddress(sizeAddr)) { - buflen = (s32_le *)Memory::GetPointer(sizeAddr); + buflen = (s32_le *)Memory::GetPointerOrException(sizeAddr); } SceNetAdhocctlScanInfoEmu *buf = NULL; if (Memory::IsValidAddress(bufAddr)) { - buf = (SceNetAdhocctlScanInfoEmu *)Memory::GetPointer(bufAddr); + buf = (SceNetAdhocctlScanInfoEmu *)Memory::GetPointerOrException(bufAddr); } INFO_LOG(Log::sceNet, "sceNetAdhocctlGetScanInfo([%08x]=%i, %08x) at %08x", sizeAddr, Memory::ReadUnchecked_U32(sizeAddr), bufAddr, currentMIPS->pc); @@ -3518,7 +3518,7 @@ static int sceNetAdhocctlGetNameByAddr(const char *mac, u32 nameAddr) { // Valid Arguments if (mac != NULL && Memory::IsValidAddress(nameAddr)) { - SceNetAdhocctlNickname * nickname = (SceNetAdhocctlNickname *)Memory::GetPointer(nameAddr); + SceNetAdhocctlNickname * nickname = (SceNetAdhocctlNickname *)Memory::GetPointerOrException(nameAddr); // Get Local MAC Address SceNetEtherAddr localmac; getLocalMac(&localmac); @@ -3584,7 +3584,7 @@ int sceNetAdhocctlGetPeerInfo(const char *mac, int size, u32 peerInfoAddr) { SceNetEtherAddr * maddr = (SceNetEtherAddr *)mac; SceNetAdhocctlPeerInfoEmu * buf = NULL; if (Memory::IsValidAddress(peerInfoAddr)) { - buf = (SceNetAdhocctlPeerInfoEmu *)Memory::GetPointer(peerInfoAddr); + buf = (SceNetAdhocctlPeerInfoEmu *)Memory::GetPointerOrException(peerInfoAddr); } // Library initialized if (netAdhocctlInited) { @@ -3755,7 +3755,7 @@ int sceNetAdhocctlJoin(u32 scanInfoAddr) { // Valid Argument if (Memory::IsValidAddress(scanInfoAddr)) { - SceNetAdhocctlScanInfoEmu* sinfo = (SceNetAdhocctlScanInfoEmu*)Memory::GetPointer(scanInfoAddr); + SceNetAdhocctlScanInfoEmu* sinfo = (SceNetAdhocctlScanInfoEmu*)Memory::GetPointerOrException(scanInfoAddr); char grpName[ADHOCCTL_GROUPNAME_LEN + 1] = { 0 }; memcpy(grpName, sinfo->group_name.data, ADHOCCTL_GROUPNAME_LEN); // For logging purpose, must not be truncated DEBUG_LOG(Log::sceNet, "sceNetAdhocctlJoin - Group: %s", grpName); @@ -3943,9 +3943,9 @@ static int sceNetAdhocGetPdpStat(u32 structSize, u32 structAddr) { if (netAdhocInited) { s32_le *buflen = NULL; - if (Memory::IsValidAddress(structSize)) buflen = (s32_le *)Memory::GetPointer(structSize); + if (Memory::IsValidAddress(structSize)) buflen = (s32_le *)Memory::GetPointerOrException(structSize); SceNetAdhocPdpStat *buf = NULL; - if (Memory::IsValidAddress(structAddr)) buf = (SceNetAdhocPdpStat *)Memory::GetPointer(structAddr); + if (Memory::IsValidAddress(structAddr)) buf = (SceNetAdhocPdpStat *)Memory::GetPointerOrException(structAddr); // Socket Count int socketcount = getPDPSocketCount(); @@ -4049,9 +4049,9 @@ static int sceNetAdhocGetPtpStat(u32 structSize, u32 structAddr) { VERBOSE_LOG(Log::sceNet,"sceNetAdhocGetPtpStat(%08x, %08x) at %08x",structSize,structAddr,currentMIPS->pc); s32_le *buflen = NULL; - if (Memory::IsValidAddress(structSize)) buflen = (s32_le *)Memory::GetPointer(structSize); + if (Memory::IsValidAddress(structSize)) buflen = (s32_le *)Memory::GetPointerOrException(structSize); SceNetAdhocPtpStat *buf = NULL; - if (Memory::IsValidAddress(structAddr)) buf = (SceNetAdhocPtpStat *)Memory::GetPointer(structAddr); + if (Memory::IsValidAddress(structAddr)) buf = (SceNetAdhocPtpStat *)Memory::GetPointerOrException(structAddr); // Library is initialized if (netAdhocInited) { @@ -4637,7 +4637,7 @@ static int sceNetAdhocPtpAccept(int id, u32 peerMacAddrPtr, u32 peerPortPtr, int } uint16_t * port = NULL; // if (Memory::IsValidAddress(peerPortPtr)) { - port = (uint16_t *)Memory::GetPointer(peerPortPtr); + port = (uint16_t *)Memory::GetPointerOrException(peerPortPtr); } if (flag == 0) { // Prevent spamming Debug Log with retries of non-bocking socket DEBUG_LOG(Log::sceNet, "sceNetAdhocPtpAccept(%d, [%08x]=%s, [%08x]=%u, %d, %u) at %08x", id, peerMacAddrPtr, mac2str(addr).c_str(), peerPortPtr, port ? *port : -1, timeout, flag, currentMIPS->pc); @@ -5211,7 +5211,7 @@ static int sceNetAdhocPtpListen(const char *srcmac, int sport, int bufsize, int static int sceNetAdhocPtpSend(int id, u32 dataAddr, u32 dataSizeAddr, int timeout, int flag) { DEBUG_LOG(Log::sceNet, "sceNetAdhocPtpSend(%d,%08x,%08x,%d,%d) at %08x", id, dataAddr, dataSizeAddr, timeout, flag, currentMIPS->pc); - int * len = (int *)Memory::GetPointer(dataSizeAddr); + int * len = (int *)Memory::GetPointerOrException(dataSizeAddr); const char * data = Memory::GetCharPointer(dataAddr); // Library is initialized if (netAdhocInited) { @@ -5331,8 +5331,8 @@ static int sceNetAdhocPtpSend(int id, u32 dataAddr, u32 dataSizeAddr, int timeou static int sceNetAdhocPtpRecv(int id, u32 dataAddr, u32 dataSizeAddr, int timeout, int flag) { DEBUG_LOG(Log::sceNet, "sceNetAdhocPtpRecv(%d,%08x,%08x,%d,%d) at %08x", id, dataAddr, dataSizeAddr, timeout, flag, currentMIPS->pc); - void * buf = (void *)Memory::GetPointer(dataAddr); - int * len = (int *)Memory::GetPointer(dataSizeAddr); + void * buf = (void *)Memory::GetPointerOrException(dataAddr); + int * len = (int *)Memory::GetPointerOrException(dataSizeAddr); // Library is initialized if (netAdhocInited) { // Valid Arguments @@ -5726,7 +5726,7 @@ static int sceNetAdhocGameModeUpdateReplica(int id, u32 infoAddr) { // Bomberman Panic Bomber is using 0/null on infoAddr, so i guess it's optional. GameModeUpdateInfo* gmuinfo = NULL; if (Memory::IsValidAddress(infoAddr)) { - gmuinfo = (GameModeUpdateInfo*)Memory::GetPointer(infoAddr); + gmuinfo = (GameModeUpdateInfo*)Memory::GetPointerOrException(infoAddr); } for (auto& gma : replicaGameModeAreas) { @@ -5943,7 +5943,7 @@ static int sceNetAdhocctlGetGameModeInfo(u32 infoAddr) { if (!Memory::IsValidAddress(infoAddr)) return hleLogError(Log::sceNet, SCE_NET_ADHOCCTL_ERROR_INVALID_ARG, "invalid arg"); - SceNetAdhocctlGameModeInfo* gmInfo = (SceNetAdhocctlGameModeInfo*)Memory::GetPointer(infoAddr); + SceNetAdhocctlGameModeInfo* gmInfo = (SceNetAdhocctlGameModeInfo*)Memory::GetPointerOrException(infoAddr); // Writes number of participants and each participating MAC address into infoAddr/gmInfo gmInfo->num = static_cast(gameModeMacs.size()); int i = 0; @@ -5961,11 +5961,11 @@ static int sceNetAdhocctlGetGameModeInfo(u32 infoAddr) { static int sceNetAdhocctlGetPeerList(u32 sizeAddr, u32 bufAddr) { s32_le *buflen = NULL; if (Memory::IsValidAddress(sizeAddr)) { - buflen = (s32_le *)Memory::GetPointer(sizeAddr); + buflen = (s32_le *)Memory::GetPointerOrException(sizeAddr); } SceNetAdhocctlPeerInfoEmu *buf = NULL; if (Memory::IsValidAddress(bufAddr)) { - buf = (SceNetAdhocctlPeerInfoEmu *)Memory::GetPointer(bufAddr); + buf = (SceNetAdhocctlPeerInfoEmu *)Memory::GetPointerOrException(bufAddr); } DEBUG_LOG(Log::sceNet, "sceNetAdhocctlGetPeerList([%08x]=%i, %08x) at %08x", sizeAddr, /*buflen ? *buflen : -1*/Memory::ReadUnchecked_U32(sizeAddr), bufAddr, currentMIPS->pc); @@ -6058,7 +6058,7 @@ static int sceNetAdhocctlGetPeerList(u32 sizeAddr, u32 bufAddr) { static int sceNetAdhocctlGetAddrByName(const char *nickName, u32 sizeAddr, u32 bufAddr) { s32_le *buflen = NULL; //int32_t - if (Memory::IsValidAddress(sizeAddr)) buflen = (s32_le *)Memory::GetPointer(sizeAddr); + if (Memory::IsValidAddress(sizeAddr)) buflen = (s32_le *)Memory::GetPointerOrException(sizeAddr); if (!nickName || !buflen) { return hleLogError(Log::sceNet, SCE_NET_ADHOCCTL_ERROR_INVALID_ARG); @@ -6075,7 +6075,7 @@ static int sceNetAdhocctlGetAddrByName(const char *nickName, u32 sizeAddr, u32 b { { SceNetAdhocctlPeerInfoEmu *buf = NULL; - if (Memory::IsValidAddress(bufAddr)) buf = (SceNetAdhocctlPeerInfoEmu *)Memory::GetPointer(bufAddr); + if (Memory::IsValidAddress(bufAddr)) buf = (SceNetAdhocctlPeerInfoEmu *)Memory::GetPointerOrException(bufAddr); // Multithreading Lock peerlock.lock(); @@ -6219,7 +6219,7 @@ int sceNetAdhocDiscoverInitStart(u32 paramAddr) { //if (Memory::ReadOrException_U32(netAdhocDiscoverBufAddr + 0x80) != 0) //if (*((int*)Memory::GetPointer(0x000010B0)) != 0) // return 0x80411301; // Already Initialized/Started? // TODO: Need to findout whether using invalid params or param address will return an error code or not - netAdhocDiscoverParam = (SceNetAdhocDiscoverParam*)Memory::GetPointer(paramAddr); + netAdhocDiscoverParam = (SceNetAdhocDiscoverParam*)Memory::GetPointerOrException(paramAddr); if (!netAdhocDiscoverParam) return hleLogError(Log::sceNet, -1, "invalid param?"); // FIXME: paramAddr seems to be stored at 0x000010D8 without validating the value first diff --git a/Core/HLE/sceNetAdhocMatching.cpp b/Core/HLE/sceNetAdhocMatching.cpp index 287edf7f94..1c2d90c809 100644 --- a/Core/HLE/sceNetAdhocMatching.cpp +++ b/Core/HLE/sceNetAdhocMatching.cpp @@ -86,7 +86,7 @@ void notifyMatchingHandler(SceNetAdhocMatchingContext * context, ThreadMessage * MatchingArgs argsNew = { 0 }; u32_le dataBufLen = msg->optlen + 8; //max(bufLen, msg->optlen + 8); u32_le dataBufAddr = userMemory.Alloc(dataBufLen); // We will free this memory after returning from mipscall. FIXME: Are these buffers supposed to be taken/pre-allocated from the memory pool during sceNetAdhocMatchingInit? - uint8_t *dataPtr = Memory::GetPointerWriteRange(dataBufAddr, dataBufLen); + uint8_t *dataPtr = Memory::GetPointerWriteRangeOrException(dataBufAddr, dataBufLen); if (dataPtr) { memcpy(dataPtr, &msg->mac, sizeof(msg->mac)); if (msg->optlen > 0) @@ -2594,7 +2594,7 @@ int sceNetAdhocMatchingGetPoolStat(u32 poolstatPtr) { } SceNetMallocStat * poolstat = NULL; - if (Memory::IsValidAddress(poolstatPtr)) poolstat = (SceNetMallocStat *)Memory::GetPointer(poolstatPtr); + if (Memory::IsValidAddress(poolstatPtr)) poolstat = (SceNetMallocStat *)Memory::GetPointerOrException(poolstatPtr); if (poolstat == NULL) { // Invalid Argument @@ -2628,10 +2628,10 @@ void __NetMatchingCallbacks() { //(int matchingId) actionAfterMatchingMipsCall = __KernelRegisterActionType(AfterMatchingMipsCall::Create); } DEBUG_LOG(Log::sceNet, "AdhocMatching - Remaining Events: %zu", matchingEvents.size()); - auto peer = findPeer(context, (SceNetEtherAddr*)Memory::GetPointer(args[2])); + auto peer = findPeer(context, (SceNetEtherAddr*)Memory::GetPointerOrException(args[2])); // Discard HELLO Events when in the middle of joining, as some games (ie. Super Pocket Tennis) might tried to join again (TODO: Need to confirm whether sceNetAdhocMatchingSelectTarget supposed to be blocking the current thread or not) if (peer == NULL || (args[1] != PSP_ADHOC_MATCHING_EVENT_HELLO || (peer->state != PSP_ADHOC_MATCHING_PEER_OUTGOING_REQUEST && peer->state != PSP_ADHOC_MATCHING_PEER_INCOMING_REQUEST && peer->state != PSP_ADHOC_MATCHING_PEER_CANCEL_IN_PROGRESS))) { - DEBUG_LOG(Log::sceNet, "AdhocMatchingCallback: [ID=%i][EVENT=%i][%s]", args[0], args[1], mac2str((SceNetEtherAddr *)Memory::GetPointer(args[2])).c_str()); + DEBUG_LOG(Log::sceNet, "AdhocMatchingCallback: [ID=%i][EVENT=%i][%s]", args[0], args[1], mac2str((SceNetEtherAddr *)Memory::GetPointerOrException(args[2])).c_str()); AfterMatchingMipsCall* after = (AfterMatchingMipsCall*)__KernelCreateAction(actionAfterMatchingMipsCall); after->SetData(args[0], args[1], args[2]); @@ -2639,7 +2639,7 @@ void __NetMatchingCallbacks() { //(int matchingId) matchingEvents.pop_front(); } else { - DEBUG_LOG(Log::sceNet, "AdhocMatching - Discarding Callback: [ID=%i][EVENT=%i][%s]", args[0], args[1], mac2str((SceNetEtherAddr*)Memory::GetPointer(args[2])).c_str()); + DEBUG_LOG(Log::sceNet, "AdhocMatching - Discarding Callback: [ID=%i][EVENT=%i][%s]", args[0], args[1], mac2str((SceNetEtherAddr*)Memory::GetPointerOrException(args[2])).c_str()); matchingEvents.pop_front(); } } diff --git a/Core/HLE/sceNetInet.cpp b/Core/HLE/sceNetInet.cpp index 86c2035460..4ef836fc52 100644 --- a/Core/HLE/sceNetInet.cpp +++ b/Core/HLE/sceNetInet.cpp @@ -106,7 +106,7 @@ static int sceNetInetInetPton(int af, const char* hostname, u32 inAddrPtr) { return hleLogError(Log::sceNet, 0, "invalid arg"); //-1 } - int retval = inet_pton(convertSocketDomainPSP2Host(af), hostname, (void*)Memory::GetPointer(inAddrPtr)); + int retval = inet_pton(convertSocketDomainPSP2Host(af), hostname, (void*)Memory::GetPointerOrException(inAddrPtr)); // Note that inet_pton can set errno! if (retval < 0) { UpdateErrnoFromHost(__KernelGetCurThread(), socket_errno, __FUNCTION__); @@ -121,7 +121,7 @@ static int sceNetInetInetAton(const char* hostname, u32 inAddrPtr) { } // TODO: Wait what, we're calling pton in aton? - int retval = inet_pton(AF_INET, hostname, (void*)Memory::GetPointer(inAddrPtr)); + int retval = inet_pton(AF_INET, hostname, (void*)Memory::GetPointerOrException(inAddrPtr)); // inet_aton() returns nonzero if the address is valid, zero if not. return hleLogDebug(Log::sceNet, retval); } @@ -165,8 +165,8 @@ static int sceNetInetGetpeername(int socket, u32 namePtr, u32 namelenPtr) { return hleLogError(Log::sceNet, ERROR_INET_EBADF, "Bad socket #%d", socket); } - SceNetInetSockaddr* name = (SceNetInetSockaddr*)Memory::GetPointer(namePtr); - int* namelen = (int*)Memory::GetPointer(namelenPtr); + SceNetInetSockaddr* name = (SceNetInetSockaddr*)Memory::GetPointerOrException(namePtr); + int* namelen = (int*)Memory::GetPointerOrException(namelenPtr); SockAddrIN4 saddr{}; // TODO: Should've created convertSockaddrPSP2Host (and Host2PSP too) function as it's being used pretty often, thus fixing a bug on it will be tedious when scattered all over the places saddr.addr.sa_family = name->sa_family; @@ -199,8 +199,8 @@ static int sceNetInetGetsockname(int socket, u32 namePtr, u32 namelenPtr) { return hleLogError(Log::sceNet, ERROR_INET_EBADF, "Bad socket #%d", socket); } - SceNetInetSockaddr* name = (SceNetInetSockaddr*)Memory::GetPointer(namePtr); - int* namelen = (int*)Memory::GetPointer(namelenPtr); + SceNetInetSockaddr* name = (SceNetInetSockaddr*)Memory::GetPointerOrException(namePtr); + int* namelen = (int*)Memory::GetPointerOrException(namelenPtr); SockAddrIN4 saddr{}; saddr.addr.sa_family = name->sa_family; int len = std::min(*namelen > 0 ? *namelen : 0, static_cast(sizeof(saddr))); @@ -223,10 +223,10 @@ static int sceNetInetGetsockname(int socket, u32 namePtr, u32 namelenPtr) { // FIXME: nfds is number of fd(s) as in posix poll, or was it maximum fd value as in posix select? Star Wars Battlefront Renegade seems to set the nfds to 64, while Coded Arms Contagion is using 256 int sceNetInetSelect(int nfds, u32 readfdsPtr, u32 writefdsPtr, u32 exceptfdsPtr, u32 timeoutPtr) { - SceNetInetFdSet *readfds = readfdsPtr ? (SceNetInetFdSet*)Memory::GetPointerWrite(readfdsPtr) : nullptr; - SceNetInetFdSet *writefds = writefdsPtr ? (SceNetInetFdSet*)Memory::GetPointerWrite(writefdsPtr) : nullptr; - SceNetInetFdSet *exceptfds = exceptfdsPtr ? (SceNetInetFdSet*)Memory::GetPointerWrite(exceptfdsPtr) : nullptr; - SceNetInetTimeval *timeout = timeoutPtr ? (SceNetInetTimeval*)Memory::GetPointerWrite(timeoutPtr) : nullptr; + SceNetInetFdSet *readfds = readfdsPtr ? (SceNetInetFdSet*)Memory::GetPointerWriteOrException(readfdsPtr) : nullptr; + SceNetInetFdSet *writefds = writefdsPtr ? (SceNetInetFdSet*)Memory::GetPointerWriteOrException(writefdsPtr) : nullptr; + SceNetInetFdSet *exceptfds = exceptfdsPtr ? (SceNetInetFdSet*)Memory::GetPointerWriteOrException(exceptfdsPtr) : nullptr; + SceNetInetTimeval *timeout = timeoutPtr ? (SceNetInetTimeval*)Memory::GetPointerWriteOrException(timeoutPtr) : nullptr; // First, translate the specified fd_sets to host sockets. @@ -357,7 +357,7 @@ int sceNetInetPoll(u32 fdsPtr, u32 nfds, int timeout) { // timeout in milisecond DEBUG_LOG(Log::sceNet, "UNTESTED sceNetInetPoll(%08x, %d, %i) at %08x", fdsPtr, nfds, timeout, currentMIPS->pc); int retval = -1; int maxHostFd = 0; - SceNetInetPollfd *fdarray = (SceNetInetPollfd*)Memory::GetPointer(fdsPtr); // SceNetInetPollfd/pollfd, sceNetInetPoll() have similarity to BSD poll() but pollfd have different size on 64bit + SceNetInetPollfd *fdarray = (SceNetInetPollfd*)Memory::GetPointerOrException(fdsPtr); // SceNetInetPollfd/pollfd, sceNetInetPoll() have similarity to BSD poll() but pollfd have different size on 64bit if (nfds > FD_SETSIZE) nfds = FD_SETSIZE; @@ -419,7 +419,7 @@ static int sceNetInetRecv(int socket, u32 bufPtr, u32 bufLen, u32 flags) { int flgs = flags & ~PSP_NET_INET_MSG_DONTWAIT; // removing non-POSIX flag, which is an alternative way to use non-blocking mode flgs = convertMSGFlagsPSP2Host(flgs); - int retval = recv(inetSock->sock, (char*)Memory::GetPointer(bufPtr), bufLen, flgs | MSG_NOSIGNAL); + int retval = recv(inetSock->sock, (char*)Memory::GetPointerOrException(bufPtr), bufLen, flgs | MSG_NOSIGNAL); if (retval < 0) { if (UpdateErrnoFromHost(__KernelGetCurThread(), socket_errno, __FUNCTION__) == ERROR_INET_EAGAIN) { retval = hleLogDebug(Log::sceNet, retval, "EAGAIN"); @@ -430,7 +430,7 @@ static int sceNetInetRecv(int socket, u32 bufPtr, u32 bufLen, u32 flags) { } std::string datahex; - DataToHexString(10, 0, Memory::GetPointer(bufPtr), retval, &datahex); + DataToHexString(10, 0, Memory::GetPointerOrException(bufPtr), retval, &datahex); VERBOSE_LOG(Log::sceNet, "Data Dump (%d bytes):\n%s", retval, datahex.c_str()); return hleDelayResult(hleLogInfo(Log::sceNet, retval), "workaround until blocking-socket", 500); // Using hleDelayResult as a workaround for games that need blocking-socket to be implemented @@ -443,12 +443,12 @@ static int sceNetInetSend(int socket, u32 bufPtr, u32 bufLen, u32 flags) { } std::string datahex; - DataToHexString(10, 0, Memory::GetPointer(bufPtr), bufLen, &datahex); + DataToHexString(10, 0, Memory::GetPointerOrException(bufPtr), bufLen, &datahex); VERBOSE_LOG(Log::sceNet, "Data Dump (%d bytes):\n%s", bufLen, datahex.c_str()); int flgs = flags & ~PSP_NET_INET_MSG_DONTWAIT; // removing non-POSIX flag, which is an alternative way to use non-blocking mode flgs = convertMSGFlagsPSP2Host(flgs); - int retval = send(inetSock->sock, (char*)Memory::GetPointer(bufPtr), bufLen, flgs | MSG_NOSIGNAL); + int retval = send(inetSock->sock, (char*)Memory::GetPointerOrException(bufPtr), bufLen, flgs | MSG_NOSIGNAL); if (retval < 0) { UpdateErrnoFromHost(__KernelGetCurThread(), socket_errno, __FUNCTION__); return hleLogError(Log::sceNet, retval); @@ -561,8 +561,8 @@ static int sceNetInetGetsockopt(int socket, int level, int optname, u32 optvalPt return hleLogError(Log::sceNet, ERROR_INET_EBADF, "Bad socket #%d", socket); } - u32_le* optval = (u32_le*)Memory::GetPointer(optvalPtr); - socklen_t* optlen = (socklen_t*)Memory::GetPointer(optlenPtr); + u32_le* optval = (u32_le*)Memory::GetPointerOrException(optvalPtr); + socklen_t* optlen = (socklen_t*)Memory::GetPointerOrException(optlenPtr); DEBUG_LOG(Log::sceNet, "SockOpt: Level = %s, OptName = %s", inetSockoptLevel2str(level).c_str(), inetSockoptName2str(optname, level).c_str()); timeval tval{}; // TODO: Ignoring SO_NBIO/SO_NONBLOCK flag if we always use non-bloking mode (ie. simulated blocking mode) @@ -626,7 +626,7 @@ static int sceNetInetBind(int socket, u32 namePtr, int namelen) { return hleLogError(Log::sceNet, ERROR_INET_EBADF, "Bad socket #%d", socket); } - SceNetInetSockaddr* name = (SceNetInetSockaddr*)Memory::GetPointer(namePtr); + SceNetInetSockaddr* name = (SceNetInetSockaddr*)Memory::GetPointerOrException(namePtr); SockAddrIN4 saddr{}; // TODO: Should've created convertSockaddrPSP2Host (and Host2PSP too) function as it's being used pretty often, thus fixing a bug on it will be tedious when scattered all over the places saddr.addr.sa_family = name->sa_family; @@ -687,7 +687,7 @@ static int sceNetInetConnect(int socket, u32 sockAddrPtr, int sockAddrLen) { // Still using warn log here so it stands out in the log - SceNetInetSockaddr* dst = (SceNetInetSockaddr*)Memory::GetPointer(sockAddrPtr); + SceNetInetSockaddr* dst = (SceNetInetSockaddr*)Memory::GetPointerOrException(sockAddrPtr); SockAddrIN4 saddr{}; int dstlen = std::min(sockAddrLen > 0 ? sockAddrLen : 0, static_cast(sizeof(saddr))); saddr.addr.sa_family = dst->sa_family; @@ -852,7 +852,7 @@ static int sceNetInetRecvfrom(int socket, u32 bufferPtr, int len, int flags, u32 *srclen = std::min((*srclen) > 0 ? *srclen : 0, static_cast(sizeof(saddr))); int flgs = flags & ~PSP_NET_INET_MSG_DONTWAIT; // removing non-POSIX flag, which is an alternative way to use non-blocking mode flgs = convertMSGFlagsPSP2Host(flgs); - int retval = recvfrom(inetSock->sock, (char*)Memory::GetPointer(bufferPtr), len, flgs | MSG_NOSIGNAL, (struct sockaddr*)&saddr.addr, srclen); + int retval = recvfrom(inetSock->sock, (char*)Memory::GetPointerOrException(bufferPtr), len, flgs | MSG_NOSIGNAL, (struct sockaddr*)&saddr.addr, srclen); if (retval < 0) { if (UpdateErrnoFromHost(__KernelGetCurThread(), socket_errno, __FUNCTION__) == ERROR_INET_EAGAIN) { retval = hleLogDebug(Log::sceNet, retval, "EAGAIN"); @@ -879,7 +879,7 @@ static int sceNetInetRecvfrom(int socket, u32 bufferPtr, int len, int flags, u32 }*/ std::string datahex; - DataToHexString(0, 0, Memory::GetPointer(bufferPtr), retval, &datahex); + DataToHexString(0, 0, Memory::GetPointerOrException(bufferPtr), retval, &datahex); VERBOSE_LOG(Log::sceNet, "Data Dump (%d bytes):\n%s", retval, datahex.c_str()); // Using hleDelayResult as a workaround for games that need blocking-socket to be implemented (ie. Coded Arms Contagion) @@ -904,7 +904,7 @@ static int sceNetInetSendto(int socket, u32 bufferPtr, int len, int flags, u32 t } std::string datahex; - DataToHexString(0, 0, Memory::GetPointer(bufferPtr), len, &datahex); + DataToHexString(0, 0, Memory::GetPointerOrException(bufferPtr), len, &datahex); VERBOSE_LOG(Log::sceNet, "Data Dump (%d bytes):\n%s", len, datahex.c_str()); int retval; @@ -920,7 +920,7 @@ static int sceNetInetSendto(int socket, u32 bufferPtr, int len, int flags, u32 t continue; saddr.in.sin_addr.s_addr = peer->ip_addr; - retval = sendto(inetSock->sock, (char*)Memory::GetPointer(bufferPtr), len, flgs | MSG_NOSIGNAL, (struct sockaddr*)&saddr.addr, dstlen); + retval = sendto(inetSock->sock, (char*)Memory::GetPointerOrException(bufferPtr), len, flgs | MSG_NOSIGNAL, (struct sockaddr*)&saddr.addr, dstlen); if (retval < 0) { DEBUG_LOG(Log::sceNet, "SendTo(BC): Socket error %d", socket_errno); } else { @@ -946,7 +946,7 @@ static int sceNetInetSendto(int socket, u32 bufferPtr, int len, int flags, u32 t saddr.in.sin_addr.s_addr = sockAddr.sin_addr.s_addr; DEBUG_LOG(Log::sceNet, "SendTo(BC): Address Replacement = %s", ip2str(saddr.in.sin_addr).c_str()); }*/ - retval = sendto(inetSock->sock, (char*)Memory::GetPointer(bufferPtr), len, flgs | MSG_NOSIGNAL, (struct sockaddr*)&saddr.addr, dstlen); + retval = sendto(inetSock->sock, (char*)Memory::GetPointerOrException(bufferPtr), len, flgs | MSG_NOSIGNAL, (struct sockaddr*)&saddr.addr, dstlen); } if (retval < 0) { if (UpdateErrnoFromHost(__KernelGetCurThread(), socket_errno, __FUNCTION__) == ERROR_INET_EAGAIN) { @@ -974,7 +974,7 @@ static int sceNetInetSendmsg(int socket, u32 msghdrPtr, int flags) { return hleLogError(Log::sceNet, ERROR_INET_EBADF, "Bad socket #%d", socket); } - InetMsghdr* pspMsghdr = (InetMsghdr*)Memory::GetPointer(msghdrPtr); + InetMsghdr* pspMsghdr = (InetMsghdr*)Memory::GetPointerOrException(msghdrPtr); int flgs = flags & ~PSP_NET_INET_MSG_DONTWAIT; // removing non-POSIX flag, which is an alternative way to use non-blocking mode flgs = convertMSGFlagsPSP2Host(flgs); SockAddrIN4 saddr{}; @@ -996,7 +996,7 @@ static int sceNetInetSendmsg(int socket, u32 msghdrPtr, int flags) { memset(iov, 0, pspMsghdr->msg_iovlen * iovecsize); memset(&hdr, 0, sizeof(hdr)); if (pspMsghdr->msg_name != 0) { - SceNetInetSockaddr* pspSaddr = (SceNetInetSockaddr*)Memory::GetPointer(pspMsghdr->msg_name); + SceNetInetSockaddr* pspSaddr = (SceNetInetSockaddr*)Memory::GetPointerOrException(pspMsghdr->msg_name); saddr.addr.sa_family = pspSaddr->sa_family; size_t datalen = std::min(pspMsghdr->msg_namelen - (sizeof(pspSaddr->sa_len) + sizeof(pspSaddr->sa_family)), sizeof(saddr.addr.sa_data)); memcpy(saddr.addr.sa_data, pspSaddr->sa_data, datalen); @@ -1017,14 +1017,14 @@ static int sceNetInetSendmsg(int socket, u32 msghdrPtr, int flags) { hdr.msg_iovlen = pspMsghdr->msg_iovlen; #endif if (pspMsghdr->msg_iov != 0) { - SceNetIovec* pspIov = (SceNetIovec*)Memory::GetPointer(pspMsghdr->msg_iov); + SceNetIovec* pspIov = (SceNetIovec*)Memory::GetPointerOrException(pspMsghdr->msg_iov); for (int i = 0; i < pspMsghdr->msg_iovlen; i++) { if (pspIov[i].iov_base != 0) { #if defined(_WIN32) - iov[i].buf = (char*)Memory::GetPointer(pspIov[i].iov_base); + iov[i].buf = (char*)Memory::GetPointerOrException(pspIov[i].iov_base); iov[i].len = pspIov[i].iov_len; #else - iov[i].iov_base = (char*)Memory::GetPointer(pspIov[i].iov_base); + iov[i].iov_base = (char*)Memory::GetPointerOrException(pspIov[i].iov_base); iov[i].iov_len = pspIov[i].iov_len; #endif } @@ -1042,7 +1042,7 @@ static int sceNetInetSendmsg(int socket, u32 msghdrPtr, int flags) { free(iov); return hleLogError(Log::sceNet, retval); } - InetCmsghdr* pspCmsghdr = (InetCmsghdr*)Memory::GetPointer(pspMsghdr->msg_control); + InetCmsghdr* pspCmsghdr = (InetCmsghdr*)Memory::GetPointerOrException(pspMsghdr->msg_control); // TODO: Convert InetCmsghdr into platform-specific struct as they're affected by 32/64bit memcpy(chdr, pspCmsghdr, pspMsghdr->msg_controllen); #if defined(_WIN32) @@ -1173,7 +1173,7 @@ static int sceNetInetRecvmsg(int socket, u32 msghdrPtr, int flags) { UpdateErrnoFromHost(__KernelGetCurThread(), EFAULT, __FUNCTION__); return hleLogError(Log::sceNet, retval); } - InetMsghdr* pspMsghdr = (InetMsghdr*)Memory::GetPointer(msghdrPtr); + InetMsghdr* pspMsghdr = (InetMsghdr*)Memory::GetPointerOrException(msghdrPtr); int flgs = flags & ~PSP_NET_INET_MSG_DONTWAIT; // removing non-POSIX flag, which is an alternative way to use non-blocking mode flgs = convertMSGFlagsPSP2Host(flgs); SockAddrIN4 saddr{}; diff --git a/Core/HLE/sceNet_lib.cpp b/Core/HLE/sceNet_lib.cpp index 80de698a9d..d0f95f7028 100644 --- a/Core/HLE/sceNet_lib.cpp +++ b/Core/HLE/sceNet_lib.cpp @@ -117,7 +117,7 @@ u32 sceNetStrlen(const char* str) { s32 sceNetMemcmp(u32 lhsPtr, u32 rhsPtr, u32 count) { // Redirect that to libc - s32 res = std::memcmp(Memory::GetPointer(lhsPtr), Memory::GetPointer(rhsPtr), count); + s32 res = std::memcmp(Memory::GetPointerOrException(lhsPtr), Memory::GetPointerOrException(rhsPtr), count); return hleLogDebug(Log::sceNet, res); } diff --git a/Core/HLE/sceNp.cpp b/Core/HLE/sceNp.cpp index 80e931b2dc..fc174bc697 100644 --- a/Core/HLE/sceNp.cpp +++ b/Core/HLE/sceNp.cpp @@ -432,7 +432,7 @@ int sceNpAuthGetTicket(u32 requestId, u32 bufferAddr, u32 length) { // Dummy Login ticket returned as Login response. Dummy ticket contents were taken from https://www.psdevwiki.com/ps3/X-I-5-Ticket ticket.header.version = TICKET_VER_2_1; ticket.header.size = 0xF0; // size excluding the header - u8* buf = Memory::GetPointerWrite(bufferAddr + sizeof(ticket)); + u8* buf = Memory::GetPointerWriteOrException(bufferAddr + sizeof(ticket)); int ofs = 0; ofs += writeTicketParam(buf, PARAM_TYPE_STRING_ASCII, "\x4c\x47\x56\x3b\x81\x39\x4a\x22\xd8\x6b\xc1\x57\x71\x6e\xfd\xb8\xab\x63\xcc\x51", 20); // 20 random letters, token key or SceNpSignature? ofs += writeTicketU32Param(buf + ofs, PARAM_TYPE_INT, 0x0100); // a flags? @@ -516,13 +516,13 @@ int sceNpAuthGetTicketParam(u32 ticketBufPtr, int ticketLen, int paramNum, u32 b return hleLogError(Log::sceNet, SCE_NP_MANAGER_ERROR_INVALID_ARGUMENT); } - SceNpTicket* ticket = (SceNpTicket*)Memory::GetPointer(ticketBufPtr); + SceNpTicket* ticket = (SceNpTicket*)Memory::GetPointerOrException(ticketBufPtr); u32 inbuf = ticketBufPtr; inbuf += sizeof(ticket->header); inbuf += ticket->section.size + sizeof(ticket->section); u32 outbuf = bufferPtr; for (int i = 0; i < paramNum; i++) { - SceNpTicketParamData* ticketParam = (SceNpTicketParamData*)Memory::GetPointer(inbuf); + SceNpTicketParamData* ticketParam = (SceNpTicketParamData*)Memory::GetPointerOrException(inbuf); u32 sz = (u32)sizeof(SceNpTicketParamData) + ticketParam->length; Memory::Memcpy(outbuf, inbuf, sz); DEBUG_LOG(Log::sceNet, "%s - Param #%d: Type = %04x, Length = %u", __FUNCTION__, i, static_cast(ticketParam->type), static_cast(ticketParam->length)); diff --git a/Core/HLE/sceNp2.cpp b/Core/HLE/sceNp2.cpp index e88b8abb40..48cc7d851e 100644 --- a/Core/HLE/sceNp2.cpp +++ b/Core/HLE/sceNp2.cpp @@ -72,9 +72,9 @@ bool NpMatching2ProcessEvents() { } // Per npMatching2 function callback - u32* inStruct = (u32*)Memory::GetPointer(inStructPtr); + u32* inStruct = (u32*)Memory::GetPointerOrException(inStructPtr); if (Memory::IsValidAddress(inStruct[0])) { - DEBUG_LOG(Log::sceNet, "NpMatching2Callback [ServerID=%i][EventID=%04x][State=%04x][FuncAddr=%08x][ArgsPtr=%08x]", *(u32*)Memory::GetPointer(serverIdPtr), event, stat, inStruct[0], inStruct[1]); + DEBUG_LOG(Log::sceNet, "NpMatching2Callback [ServerID=%i][EventID=%04x][State=%04x][FuncAddr=%08x][ArgsPtr=%08x]", *(u32*)Memory::GetPointerOrException(serverIdPtr), event, stat, inStruct[0], inStruct[1]); hleEnqueueCall(inStruct[0], 7, args.data); } return true; diff --git a/Core/HLE/scePsmf.cpp b/Core/HLE/scePsmf.cpp index 1c9f7fb2f1..762b6ea992 100644 --- a/Core/HLE/scePsmf.cpp +++ b/Core/HLE/scePsmf.cpp @@ -770,7 +770,7 @@ static u32 scePsmfSetPsmf(u32 psmfStruct, u32 psmfData) { return hleReportError(Log::ME, SCE_KERNEL_ERROR_ILLEGAL_ADDRESS, "bad address"); } - Psmf *psmf = new Psmf(Memory::GetPointer(psmfData), psmfData); + Psmf *psmf = new Psmf(Memory::GetPointerOrException(psmfData), psmfData); if (psmf->magic != PSMF_MAGIC) { delete psmf; return hleLogError(Log::ME, SCE_PSMF_ERROR_INVALID_PSMF, "invalid psmf data"); diff --git a/Core/HLE/sceReg.cpp b/Core/HLE/sceReg.cpp index a0a13eaef3..49c013b0a1 100644 --- a/Core/HLE/sceReg.cpp +++ b/Core/HLE/sceReg.cpp @@ -1145,7 +1145,7 @@ int sceRegGetKeys(int catHandle, u32 bufAddr, int num) { count = std::min(count, num); for (int i = 0; i < num; i++) { - char *dest = (char *)Memory::GetPointerWrite(bufAddr + i * keyLen); + char *dest = (char *)Memory::GetPointerWriteOrException(bufAddr + i * keyLen); strncpy(dest, keyvals[i].name.c_str(), keyLen); } @@ -1366,7 +1366,7 @@ int sceRegGetCategoryListAtRoot(int regHandle, u32 bufPtr, int numCategories) { for (int i = 0; i < numCategories; i++) { const KeyValue &kv = ROOT[i]; _dbg_assert_msg_(kv.type == ValueType::DIR, "Unexpected non-dir in ROOT"); - char *dest = (char *)Memory::GetPointerWrite(bufPtr + i * 27); + char *dest = (char *)Memory::GetPointerWriteOrException(bufPtr + i * 27); if (dest) { strncpy(dest, kv.name.c_str(), 27); } diff --git a/Core/HW/MediaEngine.cpp b/Core/HW/MediaEngine.cpp index 32f94d4d7d..5782f905f4 100644 --- a/Core/HW/MediaEngine.cpp +++ b/Core/HW/MediaEngine.cpp @@ -1077,7 +1077,7 @@ int MediaEngine::getNextAudioFrame(u8 **buf, int *headerCode1, int *headerCode2) } int MediaEngine::getAudioSamples(u32 bufferPtr) { - int16_t *buffer = (int16_t *)Memory::GetPointerWriteRange(bufferPtr, 8192); + int16_t *buffer = (int16_t *)Memory::GetPointerWriteRangeOrException(bufferPtr, 8192); if (buffer == nullptr) { ERROR_LOG_REPORT(Log::ME, "Ignoring bad audio decode address %08x during video playback", bufferPtr); } diff --git a/Core/HW/SasAudio.cpp b/Core/HW/SasAudio.cpp index 461f1ae0f0..d12c6e1949 100644 --- a/Core/HW/SasAudio.cpp +++ b/Core/HW/SasAudio.cpp @@ -641,8 +641,8 @@ void SasInstance::Mix(u32 outAddr, u32 inAddr, int leftVol, int rightVol, bool m // Then mix the send buffer in with the rest. // Alright, all voices mixed. Let's convert and clip, and at the same time, wipe mixBuffer for next time. Could also dither. - s16 *outp = (s16 *)Memory::GetPointerWriteRange(outAddr, 4 * grainSize); - const s16 *inp = inAddr ? (const s16 *)Memory::GetPointerRange(inAddr, 4 * grainSize) : 0; + s16 *outp = (s16 *)Memory::GetPointerWriteRangeOrException(outAddr, 4 * grainSize); + const s16 *inp = inAddr ? (const s16 *)Memory::GetPointerRangeOrException(inAddr, 4 * grainSize) : 0; if (!outp) { WARN_LOG_REPORT(Log::sceSas, "Bad SAS Mix output address: %08x, grain=%d", outAddr, grainSize); } else if (outputMode == PSP_SAS_OUTPUTMODE_MIXED) { diff --git a/Core/HW/SimpleAudioDec.cpp b/Core/HW/SimpleAudioDec.cpp index 1fee3ceafd..d778ab5504 100644 --- a/Core/HW/SimpleAudioDec.cpp +++ b/Core/HW/SimpleAudioDec.cpp @@ -497,7 +497,7 @@ size_t AuCtx::FindNextMp3Sync() { // return output pcm size, <0 error u32 AuCtx::AuDecode(u32 pcmAddr) { u32 outptr = PCMBuf + nextOutputHalf * PCMBufSize / 2; - auto outbuf = Memory::GetPointerWriteRange(outptr, PCMBufSize / 2); + auto outbuf = Memory::GetPointerWriteRangeOrException(outptr, PCMBufSize / 2); int outpcmbufsize = 0; if (pcmAddr) diff --git a/Core/MemMap.cpp b/Core/MemMap.cpp index 3cac1f45d8..dff978cf75 100644 --- a/Core/MemMap.cpp +++ b/Core/MemMap.cpp @@ -337,7 +337,7 @@ void Reinit() { } static void DoMemoryVoid(PointerWrap &p, uint32_t start, uint32_t size) { - uint8_t *d = GetPointerWrite(start); + uint8_t *d = GetPointerWriteOrException(start); uint8_t *&storage = *p.ptr; // We only handle aligned data and sizes. diff --git a/Core/MemMap.h b/Core/MemMap.h index 76c421f659..2b55b7924d 100644 --- a/Core/MemMap.h +++ b/Core/MemMap.h @@ -242,19 +242,19 @@ void WriteOrException_U16(const u16 data, const u32 address); void WriteOrException_U32(const u32 data, const u32 address); void WriteOrException_U64(const u64 data, const u32 address); -u8* GetPointerWrite(const u32 address); -const u8* GetPointer(const u32 address); +u8* GetPointerWriteOrException(const u32 address); +const u8* GetPointerOrException(const u32 address); -u8 *GetPointerWriteRange(const u32 address, const u32 size); +u8 *GetPointerWriteRangeOrException(const u32 address, const u32 size); template T* GetTypedPointerWriteRange(const u32 address, const u32 size) { - return reinterpret_cast(GetPointerWriteRange(address, size)); + return reinterpret_cast(GetPointerWriteRangeOrException(address, size)); } -const u8 *GetPointerRange(const u32 address, const u32 size); +const u8 *GetPointerRangeOrException(const u32 address, const u32 size); template const T* GetTypedPointerRange(const u32 address, const u32 size) { - return reinterpret_cast(GetPointerRange(address, size)); + return reinterpret_cast(GetPointerRangeOrException(address, size)); } bool IsRAMAddress(const u32 address); @@ -568,7 +568,7 @@ struct PSPPointer } void FillWithZero() { - memset(Memory::GetPointerWrite(ptr), 0, sizeof(T)); + memset(Memory::GetPointerWriteOrException(ptr), 0, sizeof(T)); } bool Equals(u32 addr) const { diff --git a/Core/MemMapFunctions.cpp b/Core/MemMapFunctions.cpp index 363a997f6d..61301affae 100644 --- a/Core/MemMapFunctions.cpp +++ b/Core/MemMapFunctions.cpp @@ -27,7 +27,7 @@ namespace Memory { -u8 *GetPointerWrite(const u32 address) { +u8 *GetPointerWriteOrException(const u32 address) { if ((address & 0x3E000000) == 0x08000000 || // RAM (address & 0xBF800000) == 0x04000000 || // VRAM (address & 0xBFFFC000) == 0x00010000 || // Scratchpad @@ -40,7 +40,7 @@ u8 *GetPointerWrite(const u32 address) { } } -const u8 *GetPointer(const u32 address) { +const u8 *GetPointerOrException(const u32 address) { if ((address & 0x3E000000) == 0x08000000 || // RAM (address & 0xBF800000) == 0x04000000 || // VRAM (address & 0xBFFFC000) == 0x00010000 || // Scratchpad @@ -53,8 +53,8 @@ const u8 *GetPointer(const u32 address) { } } -u8 *GetPointerWriteRange(const u32 address, const u32 size) { - u8 *ptr = GetPointerWrite(address); +u8 *GetPointerWriteRangeOrException(const u32 address, const u32 size) { + u8 *ptr = GetPointerWriteOrException(address); if (ptr) { if (ClampValidSizeAt(address, size) != size) { // That's a memory exception! TODO: Adjust reported address to the end of the range? @@ -69,8 +69,8 @@ u8 *GetPointerWriteRange(const u32 address, const u32 size) { } } -const u8 *GetPointerRange(const u32 address, const u32 size) { - const u8 *ptr = GetPointer(address); +const u8 *GetPointerRangeOrException(const u32 address, const u32 size) { + const u8 *ptr = GetPointerOrException(address); if (ptr) { if (ClampValidSizeAt(address, size) != size) { // That's a memory exception! TODO: Adjust reported address to the end of the range? @@ -86,7 +86,7 @@ const u8 *GetPointerRange(const u32 address, const u32 size) { } template -inline void ReadMemoryOrRaiseException(T &var, const u32 address) { +inline void ReadMemoryOrException(T &var, const u32 address) { if ((address & 0x3E000000) == 0x08000000 || // RAM (address & 0xBF800000) == 0x04000000 || // VRAM (address & 0xBFFFC000) == 0x00010000 || // Scratchpad @@ -99,7 +99,7 @@ inline void ReadMemoryOrRaiseException(T &var, const u32 address) { } template -inline void WriteMemoryOrRaiseException(u32 address, const T data) { +inline void WriteMemoryOrException(u32 address, const T data) { if ((address & 0x3E000000) == 0x08000000 || // RAM (address & 0xBF800000) == 0x04000000 || // VRAM (address & 0xBFFFC000) == 0x00010000 || // Scratchpad @@ -126,42 +126,42 @@ bool IsScratchpadAddress(const u32 address) { u8 ReadOrException_U8(const u32 address) { u8 value = 0; - ReadMemoryOrRaiseException(value, address); + ReadMemoryOrException(value, address); return (u8)value; } u16 ReadOrException_U16(const u32 address) { u16_le value = 0; - ReadMemoryOrRaiseException(value, address); + ReadMemoryOrException(value, address); return (u16)value; } u32 ReadOrException_U32(const u32 address) { u32_le value = 0; - ReadMemoryOrRaiseException(value, address); + ReadMemoryOrException(value, address); return value; } -u64 Read_U64(const u32 address) { +u64 ReadOrException_U64(const u32 address) { u64_le value = 0; - ReadMemoryOrRaiseException(value, address); + ReadMemoryOrException(value, address); return value; } void WriteOrException_U8(const u8 _Data, const u32 address) { - WriteMemoryOrRaiseException(address, _Data); + WriteMemoryOrException(address, _Data); } void WriteOrException_U16(const u16 _Data, const u32 address) { - WriteMemoryOrRaiseException(address, _Data); + WriteMemoryOrException(address, _Data); } void WriteOrException_U32(const u32 _Data, const u32 address) { - WriteMemoryOrRaiseException(address, _Data); + WriteMemoryOrException(address, _Data); } void WriteOrException_U64(const u64 _Data, const u32 address) { - WriteMemoryOrRaiseException(address, _Data); + WriteMemoryOrException(address, _Data); } } // namespace Memory diff --git a/Core/MemMapHelpers.h b/Core/MemMapHelpers.h index d01b2ca5f4..35b08aec0d 100644 --- a/Core/MemMapHelpers.h +++ b/Core/MemMapHelpers.h @@ -32,7 +32,7 @@ namespace Memory { inline void Memcpy(const u32 to_address, const void *from_data, const u32 len, const char *tag, size_t tagLen) { - u8 *to = GetPointerWriteRange(to_address, len); + u8 *to = GetPointerWriteRangeOrException(to_address, len); if (to) { memcpy(to, from_data, len); if (!tag) { @@ -45,7 +45,7 @@ inline void Memcpy(const u32 to_address, const void *from_data, const u32 len, c } inline void Memcpy(void *to_data, const u32 from_address, const u32 len, const char *tag, size_t tagLen) { - const u8 *from = GetPointerRange(from_address, len); + const u8 *from = GetPointerRangeOrException(from_address, len); if (from) { memcpy(to_data, from, len); if (!tag) { @@ -58,11 +58,11 @@ inline void Memcpy(void *to_data, const u32 from_address, const u32 len, const c } inline void Memcpy(const u32 to_address, const u32 from_address, const u32 len, const char *tag, size_t tagLen) { - u8 *to = GetPointerWriteRange(to_address, len); + u8 *to = GetPointerWriteRangeOrException(to_address, len); // If not, GetPointer will log. if (!to) return; - const u8 *from = GetPointerRange(from_address, len); + const u8 *from = GetPointerRangeOrException(from_address, len); if (!from) return; diff --git a/Core/Util/PPGeDraw.cpp b/Core/Util/PPGeDraw.cpp index 6fb7dd7e0a..b52c98095f 100644 --- a/Core/Util/PPGeDraw.cpp +++ b/Core/Util/PPGeDraw.cpp @@ -285,7 +285,7 @@ void __PPGeInit() { NotifyMemInfo(MemBlockFlags::WRITE, palette.ptr, 16 * sizeof(u16_le), "PPGe Palette"); const u32_le *imagePtr = (u32_le *)imageData[0]; - u8 *ramPtr = atlasPtr == 0 ? nullptr : (u8 *)Memory::GetPointerRange(atlasPtr, atlasSize); + u8 *ramPtr = atlasPtr == 0 ? nullptr : (u8 *)Memory::GetPointerRangeOrException(atlasPtr, atlasSize); // Palettize to 4-bit, the easy way. for (int i = 0; i < width[0] * height[0] / 2; i++) { @@ -334,7 +334,7 @@ void __PPGeDoState(PointerWrap &p) } else { // Memory was already updated by this point, so check directly. if (atlasPtr != 0) { - savedHash = XXH3_64bits(Memory::GetPointerRange(atlasPtr, atlasWidth * atlasHeight / 2), atlasWidth * atlasHeight / 2); + savedHash = XXH3_64bits(Memory::GetPointerRangeOrException(atlasPtr, atlasWidth * atlasHeight / 2), atlasWidth * atlasHeight / 2); } else { savedHash ^= 1; } @@ -929,7 +929,7 @@ static PPGeTextDrawerImage PPGeGetTextImage(std::string_view text, const PPGeSty if (im.ptr) { int wBytes = (im.entry.bmWidth + 1) / 2; - u8 *ramPtr = Memory::GetPointerWriteRange(im.ptr, sz); + u8 *ramPtr = Memory::GetPointerWriteRangeOrException(im.ptr, sz); for (int y = 0; y < im.entry.bmHeight; ++y) { for (int x = 0; x < wBytes; ++x) { uint8_t c1 = bitmapData[y * im.entry.bmWidth + x * 2]; @@ -1373,7 +1373,7 @@ bool PPGeImage::Load() { int success; if (filename_.empty()) { _dbg_assert_(size_ < MAX_VALID_IMAGE_SIZE); - const u8 *srcPtr = Memory::GetPointerRange(png_, (u32)size_); + const u8 *srcPtr = Memory::GetPointerRangeOrException(png_, (u32)size_); if (!srcPtr) { ERROR_LOG(Log::sceGe, "Trying to load PPGeImage from invalid range: %08x, %08x bytes", png_, (int)size_); return false; diff --git a/GPU/Common/FramebufferManagerCommon.cpp b/GPU/Common/FramebufferManagerCommon.cpp index 0a194de4a7..d68c428a07 100644 --- a/GPU/Common/FramebufferManagerCommon.cpp +++ b/GPU/Common/FramebufferManagerCommon.cpp @@ -3144,7 +3144,7 @@ bool FramebufferManagerCommon::GetStencilbuffer(u32 fb_address, int fb_stride, G return false; // If there's no vfb and we're drawing there, must be memory? // TODO: Actually get the stencil. - buffer = GPUDebugBuffer(Memory::GetPointerWrite(fb_address), fb_stride, 512, GPU_DBG_FORMAT_8888); + buffer = GPUDebugBuffer(Memory::GetPointerWriteOrException(fb_address), fb_stride, 512, GPU_DBG_FORMAT_8888); return true; } diff --git a/GPU/Common/StencilCommon.cpp b/GPU/Common/StencilCommon.cpp index c0c99258fe..47ea8fe0c3 100644 --- a/GPU/Common/StencilCommon.cpp +++ b/GPU/Common/StencilCommon.cpp @@ -186,7 +186,7 @@ bool FramebufferManagerCommon::PerformWriteStencilFromMemory(u32 addr, int size, u8 usedBits = 0; bool useExportShader = draw_->GetDeviceCaps().fragmentShaderStencilWriteSupported; - const u8 *src = Memory::GetPointer(addr); + const u8 *src = Memory::GetPointerOrException(addr); if (!src) return false; diff --git a/GPU/Common/TextureCacheCommon.cpp b/GPU/Common/TextureCacheCommon.cpp index f9f359a561..3c3f60e30a 100644 --- a/GPU/Common/TextureCacheCommon.cpp +++ b/GPU/Common/TextureCacheCommon.cpp @@ -407,7 +407,7 @@ static u32 ComputeTextureHash(TextureReplacer &replacer, u32 addr, int bufw, int } else { sizeInRAM = (textureBitsPerPixel[format] * bufw * h) >> 3; } - const u32 *checkp = (const u32 *)Memory::GetPointer(addr); + const u32 *checkp = (const u32 *)Memory::GetPointerOrException(addr); if (Memory::IsValidAddress(addr + sizeInRAM)) { gpuStats.perFrame.numTextureDataBytesHashed += sizeInRAM; @@ -1956,7 +1956,7 @@ TextureAlpha TextureCacheCommon::DecodeTextureLevel(u8 *out, int outPitch, GETex int w = gstate.getTextureWidth(level); int h = gstate.getTextureHeight(level); - const u8 *texptr = Memory::GetPointer(texaddr); + const u8 *texptr = Memory::GetPointerOrException(texaddr); const uint32_t byteSize = (textureBitsPerPixel[format] * bufw * h) / 8; // Validate the texture data fits in mapped RAM, like the DXT path does. diff --git a/GPU/Common/TextureDecoder.h b/GPU/Common/TextureDecoder.h index 7f48b1888b..e8160989e3 100644 --- a/GPU/Common/TextureDecoder.h +++ b/GPU/Common/TextureDecoder.h @@ -135,7 +135,7 @@ inline void DeIndexTexture(/*WRITEONLY*/ ClutT *dest, const IndexT *indexed, int template inline void DeIndexTexture(/*WRITEONLY*/ ClutT *dest, const u32 texaddr, int length, const ClutT *clut, u32 *outAlphaSum) { - const IndexT *indexed = (const IndexT *) Memory::GetPointer(texaddr); + const IndexT *indexed = (const IndexT *) Memory::GetPointerOrException(texaddr); DeIndexTexture(dest, indexed, length, clut, outAlphaSum); } @@ -221,12 +221,12 @@ inline void DeIndexTexture4OptimalRev(u16 *dest, const u8 *indexed, int length, template inline void DeIndexTexture4(ClutT *dest, const u32 texaddr, int length, const ClutT *clut) { - const u8 *indexed = (const u8 *) Memory::GetPointer(texaddr); + const u8 *indexed = (const u8 *) Memory::GetPointerOrException(texaddr); DeIndexTexture4(dest, indexed, length, clut); } template inline void DeIndexTexture4Optimal(ClutT *dest, const u32 texaddr, int length, ClutT color) { - const u8 *indexed = (const u8 *) Memory::GetPointer(texaddr); + const u8 *indexed = (const u8 *) Memory::GetPointerOrException(texaddr); DeIndexTexture4Optimal(dest, indexed, length, color); } diff --git a/GPU/Debugger/Record.cpp b/GPU/Debugger/Record.cpp index 0cc3eb881d..38330805c3 100644 --- a/GPU/Debugger/Record.cpp +++ b/GPU/Debugger/Record.cpp @@ -466,10 +466,10 @@ void Recorder::FlushPrimState(int vcount) { } } - const void *verts = Memory::GetPointer(gstate_c.vertexAddr); + const void *verts = Memory::GetPointerOrException(gstate_c.vertexAddr); const void *indices = nullptr; if ((gstate.vertType & GE_VTYPE_IDX_MASK) != GE_VTYPE_IDX_NONE) { - indices = Memory::GetPointer(gstate_c.indexAddr); + indices = Memory::GetPointerOrException(gstate_c.indexAddr); } u32 ibytes = 0; diff --git a/GPU/GPUCommon.cpp b/GPU/GPUCommon.cpp index 64f2533a53..be6157e334 100644 --- a/GPU/GPUCommon.cpp +++ b/GPU/GPUCommon.cpp @@ -1768,8 +1768,8 @@ void GPUCommon::DoBlockTransfer(u32 skipDrawReason) { u32 dstLineStartAddr = dstBasePtr + (dstY * dstStride + dstX) * bpp; u32 bytesToCopy = width * height * bpp; - const u8 *srcp = Memory::GetPointer(srcLineStartAddr); - u8 *dstp = Memory::GetPointerWrite(dstLineStartAddr); + const u8 *srcp = Memory::GetPointerOrException(srcLineStartAddr); + u8 *dstp = Memory::GetPointerWriteOrException(dstLineStartAddr); memcpy(dstp, srcp, bytesToCopy); if (MemBlockInfoDetailed(bytesToCopy)) { @@ -1786,8 +1786,8 @@ void GPUCommon::DoBlockTransfer(u32 skipDrawReason) { } auto notifyingMemmove = [&](u32 d, u32 s, u32 sz) { - const u8 *srcp = Memory::GetPointer(s); - u8 *dstp = Memory::GetPointerWrite(d); + const u8 *srcp = Memory::GetPointerOrException(s); + u8 *dstp = Memory::GetPointerWriteOrException(d); memmove(dstp, srcp, sz); if (notifyDetail) { @@ -1809,8 +1809,8 @@ void GPUCommon::DoBlockTransfer(u32 skipDrawReason) { bool dstLineWrap = !Memory::IsValidRange(dstLineStartAddr, bytesToCopy); if (!srcLineWrap && !dstLineWrap) { - const u8 *srcp = Memory::GetPointer(srcLineStartAddr); - u8 *dstp = Memory::GetPointerWrite(dstLineStartAddr); + const u8 *srcp = Memory::GetPointerOrException(srcLineStartAddr); + u8 *dstp = Memory::GetPointerWriteOrException(dstLineStartAddr); for (u32 i = 0; i < bytesToCopy; i += 64) { u32 chunk = i + 64 > bytesToCopy ? bytesToCopy - i : 64; memmove(dstp + i, srcp + i, chunk); @@ -1890,8 +1890,8 @@ void GPUCommon::DoBlockTransfer(u32 skipDrawReason) { u32 srcLineStartAddr = srcBasePtr + ((y + srcY) * srcStride + srcX) * bpp; u32 dstLineStartAddr = dstBasePtr + ((y + dstY) * dstStride + dstX) * bpp; - const u8 *srcp = Memory::GetPointer(srcLineStartAddr); - u8 *dstp = Memory::GetPointerWrite(dstLineStartAddr); + const u8 *srcp = Memory::GetPointerOrException(srcLineStartAddr); + u8 *dstp = Memory::GetPointerWriteOrException(dstLineStartAddr); memcpy(dstp, srcp, bytesToCopy); // If we're tracking detail, it's useful to have the gaps illustrated properly. diff --git a/GPU/Software/Rasterizer.cpp b/GPU/Software/Rasterizer.cpp index e82fd5af68..1fe93a32d8 100644 --- a/GPU/Software/Rasterizer.cpp +++ b/GPU/Software/Rasterizer.cpp @@ -1850,7 +1850,7 @@ bool GetCurrentTexture(GPUDebugBuffer &buffer, int level) return false; } - u8 *texptr = Memory::GetPointerWrite(texaddr); + u8 *texptr = Memory::GetPointerWriteOrException(texaddr); u32 *row = (u32 *)buffer.GetData(); for (int y = 0; y < h; ++y) { for (int x = 0; x < w; ++x) { diff --git a/GPU/Software/SoftGpu.cpp b/GPU/Software/SoftGpu.cpp index c367d7fb42..aff9d47ad9 100644 --- a/GPU/Software/SoftGpu.cpp +++ b/GPU/Software/SoftGpu.cpp @@ -395,8 +395,8 @@ const SoftwareCommandTableEntry softgpuCommandTable[] = { SoftGPU::SoftGPU(GraphicsContext *gfxCtx, Draw::DrawContext *draw) : GPUCommon(gfxCtx, draw) { - fb.data = Memory::GetPointerWrite(0x44000000); // TODO: correct default address? - depthbuf.data = Memory::GetPointerWrite(0x44000000); // TODO: correct default address? + fb.data = Memory::GetPointerWriteOrException(0x44000000); // TODO: correct default address? + depthbuf.data = Memory::GetPointerWriteOrException(0x44000000); // TODO: correct default address? memset(softgpuCmdInfo, 0, sizeof(softgpuCmdInfo)); @@ -500,7 +500,7 @@ void SoftGPU::ConvertTextureDescFrom16(Draw::TextureDesc &desc, int srcwidth, in fbTexBuffer_.resize(srcwidth * srcheight); const uint16_t *displayBuffer = overrideData; if (!displayBuffer) - displayBuffer = (const uint16_t *)Memory::GetPointer(displayFramebuf_); + displayBuffer = (const uint16_t *)Memory::GetPointerOrException(displayFramebuf_); for (int y = 0; y < srcheight; ++y) { u32 *buf_line = &fbTexBuffer_[y * srcwidth]; @@ -564,7 +564,7 @@ void SoftGPU::CopyToCurrentFboFromDisplayRam(const DisplayLayoutConfig &config, bool hasPostShader = presentation_ && presentation_->HasPostShader(); if (PSP_CoreParameter().compat.flags().DarkStalkersPresentHack && displayFormat_ == GE_FORMAT_5551 && g_DarkStalkerStretch != DSStretch::Off) { - const u8 *data = Memory::GetPointerWrite(0x04088000); + const u8 *data = Memory::GetPointerWriteOrException(0x04088000); bool fillDesc = true; if (draw_->GetDataFormatSupport(Draw::DataFormat::A1B5G5R5_UNORM_PACK16) & Draw::FMT_TEXTURE) { // The perfect one. @@ -593,13 +593,13 @@ void SoftGPU::CopyToCurrentFboFromDisplayRam(const DisplayLayoutConfig &config, hasImage = false; u1 = 1.0f; } else if (displayFormat_ == GE_FORMAT_8888) { - const u8 *data = Memory::GetPointer(displayFramebuf_); + const u8 *data = Memory::GetPointerOrException(displayFramebuf_); desc.width = displayStride_ == 0 ? srcwidth : displayStride_; desc.height = srcheight; desc.initData.push_back(data); desc.format = Draw::DataFormat::R8G8B8A8_UNORM; } else if (displayFormat_ == GE_FORMAT_5551) { - const u8 *data = Memory::GetPointer(displayFramebuf_); + const u8 *data = Memory::GetPointerOrException(displayFramebuf_); bool fillDesc = true; if (draw_->GetDataFormatSupport(Draw::DataFormat::A1B5G5R5_UNORM_PACK16) & Draw::FMT_TEXTURE) { // The perfect one. @@ -1037,7 +1037,7 @@ void SoftGPU::Execute_ZbufPtr(u32 op, u32 diff) { drawEngine_->transformUnit.Flush(this, "depthbuf"); // For the pointer, ignore memory mirrors. This also gives some buffer for draws that go outside. // TODO: Confirm how wrapping is handled in drawing. Adjust if we ever handle VRAM mirrors more accurately. - depthbuf.data = Memory::GetPointerWrite(gstate.getDepthBufAddress() & 0x041FFFF0); + depthbuf.data = Memory::GetPointerWriteOrException(gstate.getDepthBufAddress() & 0x041FFFF0); } } @@ -1365,7 +1365,7 @@ bool SoftGPU::GetCurrentFramebuffer(GPUDebugBuffer &buffer, GPUDebugFramebufferT size.y = 272; stride = displayStride_; fmt = displayFormat_; - src = Memory::GetPointer(displayFramebuf_); + src = Memory::GetPointerOrException(displayFramebuf_); } buffer.Allocate(size.x, size.y, fmt); diff --git a/UI/ImDebugger/ImDebugger.cpp b/UI/ImDebugger/ImDebugger.cpp index bf0017c1d6..a2bae971d4 100644 --- a/UI/ImDebugger/ImDebugger.cpp +++ b/UI/ImDebugger/ImDebugger.cpp @@ -1381,7 +1381,7 @@ void DrawMediaDecodersView(ImConfig &cfg, ImControl &control) { if (!Memory::IsValidRange(info.buffer, info.bufferByte)) { return; } - const u8 *data = Memory::GetPointerRange(info.buffer, info.bufferByte); + const u8 *data = Memory::GetPointerRangeOrException(info.buffer, info.bufferByte); if (!data) { return; } diff --git a/Windows/Debugger/DumpMemoryWindow.cpp b/Windows/Debugger/DumpMemoryWindow.cpp index 3456ff7a63..aecfb09ee4 100644 --- a/Windows/Debugger/DumpMemoryWindow.cpp +++ b/Windows/Debugger/DumpMemoryWindow.cpp @@ -99,16 +99,16 @@ INT_PTR CALLBACK DumpMemoryWindow::dlgFunc(HWND hwnd, UINT iMsg, WPARAM wParam, } if (includeReplacements) { - fwrite(Memory::GetPointer(bp->start), 1, bp->size, output); + fwrite(Memory::GetPointerOrException(bp->start), 1, bp->size, output); } else { auto savedReplacements = SaveAndClearReplacements(); std::lock_guard guard(MIPSComp::jitLock); if (MIPSComp::jit) { auto savedBlocks = MIPSComp::jit->SaveAndClearEmuHackOps(); - fwrite(Memory::GetPointer(bp->start), 1, bp->size, output); + fwrite(Memory::GetPointerOrException(bp->start), 1, bp->size, output); MIPSComp::jit->RestoreSavedEmuHackOps(savedBlocks); } else { - fwrite(Memory::GetPointer(bp->start), 1, bp->size, output); + fwrite(Memory::GetPointerOrException(bp->start), 1, bp->size, output); } RestoreSavedReplacements(savedReplacements); } diff --git a/unittest/JitHarness.cpp b/unittest/JitHarness.cpp index 9d85cb495d..a73ed48d18 100644 --- a/unittest/JitHarness.cpp +++ b/unittest/JitHarness.cpp @@ -120,7 +120,7 @@ bool TestJit() { g_Config.bFastMemory = true; currentMIPS->pc = PSP_GetUserMemoryBase(); - u32 *p = (u32 *)Memory::GetPointer(currentMIPS->pc); + u32 *p = (u32 *)Memory::GetPointerOrException(currentMIPS->pc); // TODO: Smarter way of seeding in the code sequence. static const char *lines[] = { From 6836a2bd4ef256d37ccb9ce6e98d1e3da74c3fad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Wed, 12 Aug 2026 14:26:10 +0200 Subject: [PATCH 6/7] Libretro buildfix, add a comment --- Core/MemMap.cpp | 5 +++++ libretro/libretro.cpp | 1 + 2 files changed, 6 insertions(+) diff --git a/Core/MemMap.cpp b/Core/MemMap.cpp index dff978cf75..815b4c1f0e 100644 --- a/Core/MemMap.cpp +++ b/Core/MemMap.cpp @@ -71,6 +71,11 @@ u8 *m_pUncachedKernelRAM[3]; static u8 *m_pPhysicalVRAM[4]; static u8 *m_pUncachedVRAM[4]; +// Hardware registers are mapped at 0xbc000000 and forwards (physical address 0x1C000000, but we need +// the 0x80000000 kernel flag and 0x40000000 uncached flag for these). Exception vectors are at 0xbfc00000. +// Since we do HLE emulation, we currently don't bother with any of that. +// Some limited documentation here: https://www.psdevwiki.com/psp/Hardware_Registers#Introduction + // Holds the ending address of the PSP's user space. // Required for HD Remasters to work properly. // This replaces RAM_NORMAL_SIZE at runtime. diff --git a/libretro/libretro.cpp b/libretro/libretro.cpp index 72bc15fb8a..974f78d50c 100644 --- a/libretro/libretro.cpp +++ b/libretro/libretro.cpp @@ -27,6 +27,7 @@ #include "Core/Config.h" #include "Core/ConfigValues.h" #include "Core/Core.h" +#include "Core/MIPS/MIPS.h" #include "Core/HLE/sceCtrl.h" #include "Core/HLE/sceUtility.h" #include "Core/HLE/__sceAudio.h" From 5a8e24f58318fed2e24578902f9607af2c07a053 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Wed, 12 Aug 2026 14:48:06 +0200 Subject: [PATCH 7/7] Interpreter: Hook up dummy MMIO handlers for future experiments --- Core/MIPS/Interpreter.cpp | 67 ++++++++++++++++++++++++++++++++++++++- Core/MIPS/MIPSTables.cpp | 16 ++++++---- Core/MemMap.h | 6 ++++ 3 files changed, 81 insertions(+), 8 deletions(-) diff --git a/Core/MIPS/Interpreter.cpp b/Core/MIPS/Interpreter.cpp index a16c9e6856..ef9d7bc184 100644 --- a/Core/MIPS/Interpreter.cpp +++ b/Core/MIPS/Interpreter.cpp @@ -92,6 +92,32 @@ int MIPS_SingleStep(MIPSState *mips) { return 1; } +// Dummy functions, for any future MMIO support. +static u8 ReadMMIO_U8(MIPSState *mips, u32 addr) { + WARN_LOG(Log::CPU, "MMIO Read8 at %08x", addr); + return 0; +} + +static u16 ReadMMIO_U16(MIPSState *mips, u32 addr) { + WARN_LOG(Log::CPU, "MMIO Read16 at %08x", addr); + return 0; +} + +static u32 ReadMMIO_U32(MIPSState *mips, u32 addr) { + WARN_LOG(Log::CPU, "MMIO Read32 at %08x", addr); + return 0; +} + +void WriteMMIO_U8(MIPSState *mips, u32 addr, u8 value) { + WARN_LOG(Log::CPU, "MMIO Write8 at %08x = %02x", addr, value); +} +void WriteMMIO_U16(MIPSState *mips, u32 addr, u16 value) { + WARN_LOG(Log::CPU, "MMIO Write16 at %08x = %04x", addr, value); +} +void WriteMMIO_U32(MIPSState *mips, u32 addr, u32 value) { + WARN_LOG(Log::CPU, "MMIO Write32 at %08x = %08x", addr, value); +} + namespace MIPSInt { void Int_Cache(MIPSState *mips, MIPSOpcode op) { int imm = SignExtend16ToS32(op); @@ -400,7 +426,6 @@ namespace MIPSInt { PC += 4; } - void Int_ITypeMem(MIPSState *mips, MIPSOpcode op) { int imm = (signed short)(op&0xFFFF); int rt = _RT; @@ -416,6 +441,11 @@ namespace MIPSInt { switch (op >> 26) { case 32: if (!Memory::IsValidAddress(addr)) { + if (Memory::IsMMIOAccess(addr)) { + // This is a read from MMIO, so we can handle it. + R(rt) = SignExtend8ToU32(ReadMMIO_U8(mips, addr)); + break; + } Core_MemoryException(addr, 1, PC, MemoryExceptionType::READ_WORD, "lb"); return; } @@ -423,6 +453,11 @@ namespace MIPSInt { break; //lb case 33: if (!Memory::IsValid2AlignedAddress(addr)) { + if (Memory::IsMMIOAccess(addr)) { + // This is a read from MMIO, so we can handle it. + R(rt) = SignExtend16ToU32(ReadMMIO_U16(mips, addr)); + break; + } Core_MemoryException(addr, 2, PC, MemoryExceptionType::READ_WORD, "lh"); return; } @@ -430,6 +465,11 @@ namespace MIPSInt { break; //lh case 35: if (!Memory::IsValid4AlignedAddress(addr)) { + if (Memory::IsMMIOAccess(addr)) { + // This is a read from MMIO, so we can handle it. + R(rt) = ReadMMIO_U32(mips, addr); + break; + } Core_MemoryException(addr, 4, PC, MemoryExceptionType::READ_WORD, "lw"); return; } @@ -437,6 +477,11 @@ namespace MIPSInt { break; //lw case 36: if (!Memory::IsValidAddress(addr)) { + if (Memory::IsMMIOAccess(addr)) { + // This is a read from MMIO, so we can handle it. + R(rt) = ReadMMIO_U8(mips, addr); + break; + } Core_MemoryException(addr, 1, PC, MemoryExceptionType::READ_WORD, "lbu"); return; } @@ -444,6 +489,11 @@ namespace MIPSInt { break; //lbu case 37: if (!Memory::IsValid2AlignedAddress(addr)) { + if (Memory::IsMMIOAccess(addr)) { + // This is a read from MMIO, so we can handle it. + R(rt) = ReadMMIO_U16(mips, addr); + break; + } Core_MemoryException(addr, 2, PC, MemoryExceptionType::READ_WORD, "lhu"); return; } @@ -451,6 +501,11 @@ namespace MIPSInt { break; //lhu case 40: if (!Memory::IsValidAddress(addr)) { + if (Memory::IsMMIOAccess(addr)) { + // This is a write to MMIO, so we can handle it. + WriteMMIO_U8(mips, addr, (u8)(R(rt))); + break; + } Core_MemoryException(addr, 1, PC, MemoryExceptionType::WRITE_WORD, "sb"); return; } @@ -458,6 +513,11 @@ namespace MIPSInt { break; //sb case 41: if (!Memory::IsValid2AlignedAddress(addr)) { + if (Memory::IsMMIOAccess(addr)) { + // This is a write to MMIO, so we can handle it. + WriteMMIO_U16(mips, addr, (u16)(R(rt))); + break; + } Core_MemoryException(addr, 2, PC, MemoryExceptionType::WRITE_WORD, "sh"); return; } @@ -465,6 +525,11 @@ namespace MIPSInt { break; //sh case 43: if (!Memory::IsValid4AlignedAddress(addr)) { + if (Memory::IsMMIOAccess(addr)) { + // This is a write to MMIO, so we can handle it. + WriteMMIO_U32(mips, addr, R(rt)); + break; + } Core_MemoryException(addr, 4, PC, MemoryExceptionType::WRITE_WORD, "sw"); return; } diff --git a/Core/MIPS/MIPSTables.cpp b/Core/MIPS/MIPSTables.cpp index 477ebb2115..75f4c937eb 100644 --- a/Core/MIPS/MIPSTables.cpp +++ b/Core/MIPS/MIPSTables.cpp @@ -1106,9 +1106,10 @@ void CDECL MIPSInterpretTrampoline(MIPSOpcode op) { MIPSInterpret(currentMIPS, op); } -static inline void RunUntilFast(MIPSState *mips) { - // NEVER stop in a delay slot! +static void RunUntilDowncountZeroFast(MIPSState *mips) { while (mips->downcount >= 0 && coreState == CORE_RUNNING_CPU) { + // Don't stop in a delay slot! + int cycleCount = 0; do { if (!Memory::IsValid4AlignedAddress(mips->pc)) { Core_ExecException(mips->pc, mips->pc, ExecExceptionType::JUMP); @@ -1124,7 +1125,7 @@ static inline void RunUntilFast(MIPSState *mips) { Core_ExecException(mips->pc, mips->pc, ExecExceptionType::ILLEGAL); break; } - mips->downcount -= cycles; + cycleCount += cycles; // The reason we have to check this is the delay slot hack in Int_Syscall. if (mips->inDelaySlot && wasInDelaySlot) { @@ -1132,15 +1133,16 @@ static inline void RunUntilFast(MIPSState *mips) { mips->inDelaySlot = false; } } while (mips->inDelaySlot); + mips->downcount -= cycleCount; } } #define _RS(op) ((op>>21) & 0x1F) -static void RunUntilWithChecks(MIPSState *mips, u64 globalTicks) { - // NEVER stop in a delay slot! +static void RunUntilDowncountZeroWithChecks(MIPSState *mips, u64 globalTicks) { bool hasBPs = g_breakpoints.HasBreakPoints(); bool hasMCs = g_breakpoints.HasMemChecks(); while (mips->downcount >= 0 && coreState == CORE_RUNNING_CPU) { + // Don't stop in a delay slot! Well, unless we hit a memcheck in one, of course. do { if (!Memory::IsValid4AlignedAddress(mips->pc)) { Core_ExecException(mips->pc, mips->pc, ExecExceptionType::JUMP); @@ -1199,9 +1201,9 @@ int MIPSInterpret_RunUntil(MIPSState *mips, u64 globalTicks) { uint64_t ticksLeft = globalTicks - CoreTiming::GetTicks(currentMIPS); if (g_breakpoints.HasBreakPoints() || g_breakpoints.HasMemChecks() || ticksLeft <= mips->downcount) { - RunUntilWithChecks(mips, globalTicks); + RunUntilDowncountZeroWithChecks(mips, globalTicks); } else { - RunUntilFast(mips); + RunUntilDowncountZeroFast(mips); } if (CoreTiming::GetTicks(mips) > globalTicks) { diff --git a/Core/MemMap.h b/Core/MemMap.h index 2b55b7924d..18738ac6cb 100644 --- a/Core/MemMap.h +++ b/Core/MemMap.h @@ -267,6 +267,11 @@ inline bool IsDepthTexVRAMAddress(const u32 address) { return ((address & 0xBFE00000) == 0x04200000) || ((address & 0xBFE00000) == 0x04600000); } +// TODO: To re-evaluate. +inline bool IsMMIOAccess(const u32 address) { + return ((address & 0xFC000000) == 0xBC000000); +} + // 0x08000000 -> 0x08800000 inline bool IsKernelAddress(const u32 address) { return ((address & 0x3F800000) == 0x08000000); @@ -291,6 +296,7 @@ inline void MemcpyUnchecked(const u32 to_address, const u32 from_address, const MemcpyUnchecked(GetPointerWriteUnchecked(to_address), from_address, len); } +// Applies to user mode. // Without a length, IsValidAddress is generally semi-meaningless, unless it's about a single byte access. For larger accesses, use IsValid4AlignedAddress // etc when appropriate, or for longer sizes, use IsValidRange or IsValid4AlignedRange for example. Checking aligned-ness helps avoid the problem // of reading past the last byte, say reading 4 bytes at offset 5 of a memory sized 8.