From a636f4dc60c3529f115f760e4f5571dd54160e97 Mon Sep 17 00:00:00 2001 From: irisz64 Date: Mon, 1 Sep 2025 12:06:01 +0200 Subject: [PATCH] Apparently ERET will throw a COP unusable exception when non-kernel mode. --- src/backend/core/interpreter/cop0instructions.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/backend/core/interpreter/cop0instructions.cpp b/src/backend/core/interpreter/cop0instructions.cpp index 1a6ef6e7..484316fb 100644 --- a/src/backend/core/interpreter/cop0instructions.cpp +++ b/src/backend/core/interpreter/cop0instructions.cpp @@ -25,6 +25,10 @@ void Cop0::dmfc0(const Instruction instr) const { void Cop0::eret() { Registers& regs = Core::GetRegs(); + if (!regs.cop0.kernelMode) { + FireException(ExceptionCode::CoprocessorUnusable, 0, regs.oldPC); + return; + } if (status.erl) { regs.SetPC64(ErrorEPC); status.erl = false; @@ -76,12 +80,14 @@ void Cop0::tlbw(const int index_) { void Cop0::tlbp() { int match = -1; - if (const TLBEntry *entry = TLBTryMatch(entryHi.raw, match); match >= 0) { + const TLBEntry *entry = TLBTryMatch(entryHi.raw, match); + if (match >= 0) { index.raw = match; - } else { - index.raw = 0; - index.p = 1; + return; } + + index.raw = 0; + index.p = 1; } } // namespace n64