From 17df17805dad914fb13b58b80c2d2230906178af Mon Sep 17 00:00:00 2001 From: zilmar Date: Thu, 18 May 2023 10:49:58 +0930 Subject: [PATCH] Core: convert DoTrapException to TriggerException --- .../N64System/Interpreter/InterpreterOps.cpp | 24 +++++------ .../N64System/Mips/Register.cpp | 41 +++++++++++-------- .../Project64-core/N64System/Mips/Register.h | 1 + 3 files changed, 37 insertions(+), 29 deletions(-) diff --git a/Source/Project64-core/N64System/Interpreter/InterpreterOps.cpp b/Source/Project64-core/N64System/Interpreter/InterpreterOps.cpp index 01bec8ba1..39c41cb02 100644 --- a/Source/Project64-core/N64System/Interpreter/InterpreterOps.cpp +++ b/Source/Project64-core/N64System/Interpreter/InterpreterOps.cpp @@ -1602,7 +1602,7 @@ void R4300iOp::SPECIAL_TEQ() { if (_GPR[m_Opcode.rs].DW == _GPR[m_Opcode.rt].DW) { - g_Reg->DoTrapException(g_System->m_PipelineStage == PIPELINE_STAGE_JUMP); + g_Reg->TriggerException(EXC_TRAP); } } @@ -1610,7 +1610,7 @@ void R4300iOp::SPECIAL_TGE() { if (_GPR[m_Opcode.rs].DW >= _GPR[m_Opcode.rt].DW) { - g_Reg->DoTrapException(g_System->m_PipelineStage == PIPELINE_STAGE_JUMP); + g_Reg->TriggerException(EXC_TRAP); } } @@ -1618,7 +1618,7 @@ void R4300iOp::SPECIAL_TGEU() { if (_GPR[m_Opcode.rs].UDW >= _GPR[m_Opcode.rt].UDW) { - g_Reg->DoTrapException(g_System->m_PipelineStage == PIPELINE_STAGE_JUMP); + g_Reg->TriggerException(EXC_TRAP); } } @@ -1626,7 +1626,7 @@ void R4300iOp::SPECIAL_TLT() { if (_GPR[m_Opcode.rs].DW < _GPR[m_Opcode.rt].DW) { - g_Reg->DoTrapException(g_System->m_PipelineStage == PIPELINE_STAGE_JUMP); + g_Reg->TriggerException(EXC_TRAP); } } @@ -1634,7 +1634,7 @@ void R4300iOp::SPECIAL_TLTU() { if (_GPR[m_Opcode.rs].UDW < _GPR[m_Opcode.rt].UDW) { - g_Reg->DoTrapException(g_System->m_PipelineStage == PIPELINE_STAGE_JUMP); + g_Reg->TriggerException(EXC_TRAP); } } @@ -1642,7 +1642,7 @@ void R4300iOp::SPECIAL_TNE() { if (_GPR[m_Opcode.rs].DW != _GPR[m_Opcode.rt].DW) { - g_Reg->DoTrapException(g_System->m_PipelineStage == PIPELINE_STAGE_JUMP); + g_Reg->TriggerException(EXC_TRAP); } } @@ -1772,7 +1772,7 @@ void R4300iOp::REGIMM_TEQI() { if (_GPR[m_Opcode.rs].DW == (int64_t)((int16_t)m_Opcode.immediate)) { - g_Reg->DoTrapException(g_System->m_PipelineStage == PIPELINE_STAGE_JUMP); + g_Reg->TriggerException(EXC_TRAP); } } @@ -1780,7 +1780,7 @@ void R4300iOp::REGIMM_TGEI() { if (_GPR[m_Opcode.rs].DW >= (int64_t)((int16_t)m_Opcode.immediate)) { - g_Reg->DoTrapException(g_System->m_PipelineStage == PIPELINE_STAGE_JUMP); + g_Reg->TriggerException(EXC_TRAP); } } @@ -1792,7 +1792,7 @@ void R4300iOp::REGIMM_TGEIU() imm64 = imm32; if (_GPR[m_Opcode.rs].UDW >= (uint64_t)imm64) { - g_Reg->DoTrapException(g_System->m_PipelineStage == PIPELINE_STAGE_JUMP); + g_Reg->TriggerException(EXC_TRAP); } } @@ -1800,7 +1800,7 @@ void R4300iOp::REGIMM_TLTI() { if (_GPR[m_Opcode.rs].DW < (int64_t)((int16_t)m_Opcode.immediate)) { - g_Reg->DoTrapException(g_System->m_PipelineStage == PIPELINE_STAGE_JUMP); + g_Reg->TriggerException(EXC_TRAP); } } @@ -1812,7 +1812,7 @@ void R4300iOp::REGIMM_TLTIU() imm64 = imm32; if (_GPR[m_Opcode.rs].UDW < (uint64_t)imm64) { - g_Reg->DoTrapException(g_System->m_PipelineStage == PIPELINE_STAGE_JUMP); + g_Reg->TriggerException(EXC_TRAP); } } @@ -1820,7 +1820,7 @@ void R4300iOp::REGIMM_TNEI() { if (_GPR[m_Opcode.rs].DW != (int64_t)((int16_t)m_Opcode.immediate)) { - g_Reg->DoTrapException(g_System->m_PipelineStage == PIPELINE_STAGE_JUMP); + g_Reg->TriggerException(EXC_TRAP); } } diff --git a/Source/Project64-core/N64System/Mips/Register.cpp b/Source/Project64-core/N64System/Mips/Register.cpp index 1c82fa055..7e0afce54 100644 --- a/Source/Project64-core/N64System/Mips/Register.cpp +++ b/Source/Project64-core/N64System/Mips/Register.cpp @@ -641,23 +641,6 @@ void CRegisters::DoFloatingPointException(bool DelaySlot) m_PROGRAM_COUNTER = 0x80000180; } -void CRegisters::DoTrapException(bool DelaySlot) -{ - CAUSE_REGISTER.ExceptionCode = EXC_TRAP; - CAUSE_REGISTER.CoprocessorUnitNumber = 0; - if (DelaySlot) - { - EPC_REGISTER = (int64_t)((int32_t)m_PROGRAM_COUNTER - 4); - CAUSE_REGISTER.BranchDelay = 1; - } - else - { - EPC_REGISTER = (int64_t)((int32_t)m_PROGRAM_COUNTER); - CAUSE_REGISTER.BranchDelay = 0; - } - m_PROGRAM_COUNTER = 0x80000180; -} - void CRegisters::DoCopUnusableException(bool DelaySlot, int32_t Coprocessor) { if (HaveDebugger()) @@ -872,3 +855,27 @@ void CRegisters::DoSysCallException(bool DelaySlot) STATUS_REGISTER |= STATUS_EXL; m_PROGRAM_COUNTER = 0x80000180; } + +void CRegisters::TriggerException(uint32_t ExceptionCode, uint32_t Coprocessor) +{ + if (GenerateLog() && LogExceptions()) + { + if (ExceptionCode != EXC_INT) + { + LogMessage("%08X: Exception %d", m_PROGRAM_COUNTER, ExceptionCode); + } + else if (!LogNoInterrupts()) + { + LogMessage("%08X: Interrupt generated", m_PROGRAM_COUNTER); + } + } + + CAUSE_REGISTER.ExceptionCode = ExceptionCode; + CAUSE_REGISTER.CoprocessorUnitNumber = Coprocessor; + CAUSE_REGISTER.BranchDelay = m_System->m_PipelineStage == PIPELINE_STAGE_JUMP; + EPC_REGISTER = (int64_t)((int32_t)m_PROGRAM_COUNTER - (CAUSE_REGISTER.BranchDelay ? 4 : 0)); + STATUS_REGISTER |= STATUS_EXL; + m_PROGRAM_COUNTER = 0x80000180; + m_System->m_PipelineStage = PIPELINE_STAGE_JUMP; + m_System->m_JumpToLocation = (*_PROGRAM_COUNTER); +} diff --git a/Source/Project64-core/N64System/Mips/Register.h b/Source/Project64-core/N64System/Mips/Register.h index a5cae61c4..af0a23378 100644 --- a/Source/Project64-core/N64System/Mips/Register.h +++ b/Source/Project64-core/N64System/Mips/Register.h @@ -417,6 +417,7 @@ public: void FixFpuLocations(); void Reset(); void SetAsCurrentSystem(); + void TriggerException(uint32_t ExceptionCode, uint32_t Coprocessor = 0); uint64_t Cop0_MF(COP0Reg Reg); void Cop0_MT(COP0Reg Reg, uint64_t Value);