Core: Update how exceptions are handled with the recompiler

This commit is contained in:
zilmar 2023-06-08 16:25:05 +09:30
parent 18a712ce6a
commit 187bd64915
5 changed files with 22 additions and 15 deletions

View File

@ -14,18 +14,6 @@
#include <float.h> #include <float.h>
#include <math.h> #include <math.h>
#if (defined(_MSC_VER) && (_MSC_VER < 1800))
double trunc(double num)
{
return (num < 0) ? ceil(num) : floor(num);
}
float truncf(float num)
{
return (num < 0) ? ceilf(num) : floorf(num);
}
#endif
bool R4300iOp::m_TestTimer = false; bool R4300iOp::m_TestTimer = false;
R4300iOpcode R4300iOp::m_Opcode; R4300iOpcode R4300iOp::m_Opcode;

View File

@ -709,7 +709,6 @@ void CRegisters::TriggerException(uint32_t ExceptionCode, uint32_t Coprocessor)
CAUSE_REGISTER.BranchDelay = m_System->m_PipelineStage == PIPELINE_STAGE_JUMP; CAUSE_REGISTER.BranchDelay = m_System->m_PipelineStage == PIPELINE_STAGE_JUMP;
EPC_REGISTER = (int64_t)((int32_t)m_PROGRAM_COUNTER - (CAUSE_REGISTER.BranchDelay ? 4 : 0)); EPC_REGISTER = (int64_t)((int32_t)m_PROGRAM_COUNTER - (CAUSE_REGISTER.BranchDelay ? 4 : 0));
STATUS_REGISTER |= STATUS_EXL; STATUS_REGISTER |= STATUS_EXL;
m_PROGRAM_COUNTER = 0x80000180;
m_System->m_PipelineStage = PIPELINE_STAGE_JUMP; m_System->m_PipelineStage = PIPELINE_STAGE_JUMP;
m_System->m_JumpToLocation = (*_PROGRAM_COUNTER); m_System->m_JumpToLocation = 0x80000180;
} }

View File

@ -114,7 +114,11 @@ void CSystemEvents::ExecuteEvents()
m_System->Reset(true, true); m_System->Reset(true, true);
break; break;
case SysEvent_ExecuteInterrupt: case SysEvent_ExecuteInterrupt:
g_Reg->DoIntrException(); if (g_Reg->DoIntrException())
{
g_Reg->m_PROGRAM_COUNTER = m_System->JumpToLocation();
m_System->m_PipelineStage = PIPELINE_STAGE_NORMAL;
}
break; break;
case SysEvent_Interrupt_SP: case SysEvent_Interrupt_SP:
g_Reg->MI_INTR_REG |= MI_INTR_SP; g_Reg->MI_INTR_REG |= MI_INTR_SP;

View File

@ -146,6 +146,7 @@ private:
friend class CInterpreterCPU; friend class CInterpreterCPU;
friend class R4300iOp32; friend class R4300iOp32;
friend class R4300iOp; friend class R4300iOp;
friend class CSystemEvents;
friend class VideoInterfaceHandler; friend class VideoInterfaceHandler;
friend class PifRamHandler; friend class PifRamHandler;

View File

@ -9476,6 +9476,9 @@ void CX86RecompilerOps::CompileExit(uint32_t JumpPC, uint32_t TargetPC, CRegInfo
m_Assembler.push(0); m_Assembler.push(0);
m_Assembler.PushImm32("EXC_SYSCALL", EXC_SYSCALL); m_Assembler.PushImm32("EXC_SYSCALL", EXC_SYSCALL);
m_Assembler.CallThis((uint32_t)g_Reg, AddressOf(&CRegisters::TriggerException), "CRegisters::TriggerException", 12); m_Assembler.CallThis((uint32_t)g_Reg, AddressOf(&CRegisters::TriggerException), "CRegisters::TriggerException", 12);
m_Assembler.MoveVariableToX86reg(asmjit::x86::edx, &g_System->m_JumpToLocation, "System->m_JumpToLocation");
m_Assembler.MoveX86regToVariable(&g_Reg->m_PROGRAM_COUNTER, "PROGRAM_COUNTER", asmjit::x86::edx);
m_Assembler.MoveConstToVariable(&g_System->m_PipelineStage, "g_System->m_PipelineStage", PIPELINE_STAGE_NORMAL);
ExitCodeBlock(); ExitCodeBlock();
break; break;
case ExitReason_Break: case ExitReason_Break:
@ -9483,6 +9486,9 @@ void CX86RecompilerOps::CompileExit(uint32_t JumpPC, uint32_t TargetPC, CRegInfo
m_Assembler.push(0); m_Assembler.push(0);
m_Assembler.PushImm32("EXC_BREAK", EXC_BREAK); m_Assembler.PushImm32("EXC_BREAK", EXC_BREAK);
m_Assembler.CallThis((uint32_t)g_Reg, AddressOf(&CRegisters::TriggerException), "CRegisters::TriggerException", 12); m_Assembler.CallThis((uint32_t)g_Reg, AddressOf(&CRegisters::TriggerException), "CRegisters::TriggerException", 12);
m_Assembler.MoveVariableToX86reg(asmjit::x86::edx, &g_System->m_JumpToLocation, "System->m_JumpToLocation");
m_Assembler.MoveX86regToVariable(&g_Reg->m_PROGRAM_COUNTER, "PROGRAM_COUNTER", asmjit::x86::edx);
m_Assembler.MoveConstToVariable(&g_System->m_PipelineStage, "g_System->m_PipelineStage", PIPELINE_STAGE_NORMAL);
ExitCodeBlock(); ExitCodeBlock();
break; break;
case ExitReason_COP1Unuseable: case ExitReason_COP1Unuseable:
@ -9490,6 +9496,9 @@ void CX86RecompilerOps::CompileExit(uint32_t JumpPC, uint32_t TargetPC, CRegInfo
m_Assembler.push(1); m_Assembler.push(1);
m_Assembler.PushImm32("EXC_CPU", EXC_CPU); m_Assembler.PushImm32("EXC_CPU", EXC_CPU);
m_Assembler.CallThis((uint32_t)g_Reg, AddressOf(&CRegisters::TriggerException), "CRegisters::TriggerException", 12); m_Assembler.CallThis((uint32_t)g_Reg, AddressOf(&CRegisters::TriggerException), "CRegisters::TriggerException", 12);
m_Assembler.MoveVariableToX86reg(asmjit::x86::edx, &g_System->m_JumpToLocation, "System->m_JumpToLocation");
m_Assembler.MoveX86regToVariable(&g_Reg->m_PROGRAM_COUNTER, "PROGRAM_COUNTER", asmjit::x86::edx);
m_Assembler.MoveConstToVariable(&g_System->m_PipelineStage, "g_System->m_PipelineStage", PIPELINE_STAGE_NORMAL);
ExitCodeBlock(); ExitCodeBlock();
break; break;
case ExitReason_ResetRecompCode: case ExitReason_ResetRecompCode:
@ -9512,6 +9521,9 @@ void CX86RecompilerOps::CompileExit(uint32_t JumpPC, uint32_t TargetPC, CRegInfo
m_Assembler.push(0); m_Assembler.push(0);
m_Assembler.PushImm32("EXC_OV", EXC_OV); m_Assembler.PushImm32("EXC_OV", EXC_OV);
m_Assembler.CallThis((uint32_t)g_Reg, AddressOf(&CRegisters::TriggerException), "CRegisters::TriggerException", 12); m_Assembler.CallThis((uint32_t)g_Reg, AddressOf(&CRegisters::TriggerException), "CRegisters::TriggerException", 12);
m_Assembler.MoveVariableToX86reg(asmjit::x86::edx, &g_System->m_JumpToLocation, "System->m_JumpToLocation");
m_Assembler.MoveX86regToVariable(&g_Reg->m_PROGRAM_COUNTER, "PROGRAM_COUNTER", asmjit::x86::edx);
m_Assembler.MoveConstToVariable(&g_System->m_PipelineStage, "g_System->m_PipelineStage", PIPELINE_STAGE_NORMAL);
ExitCodeBlock(); ExitCodeBlock();
break; break;
case ExitReason_AddressErrorExceptionRead32: case ExitReason_AddressErrorExceptionRead32:
@ -9540,6 +9552,9 @@ void CX86RecompilerOps::CompileExit(uint32_t JumpPC, uint32_t TargetPC, CRegInfo
m_Assembler.push(0); m_Assembler.push(0);
m_Assembler.PushImm32("EXC_II", EXC_II); m_Assembler.PushImm32("EXC_II", EXC_II);
m_Assembler.CallThis((uint32_t)g_Reg, AddressOf(&CRegisters::TriggerException), "CRegisters::TriggerException", 12); m_Assembler.CallThis((uint32_t)g_Reg, AddressOf(&CRegisters::TriggerException), "CRegisters::TriggerException", 12);
m_Assembler.MoveVariableToX86reg(asmjit::x86::edx, &g_System->m_JumpToLocation, "System->m_JumpToLocation");
m_Assembler.MoveX86regToVariable(&g_Reg->m_PROGRAM_COUNTER, "PROGRAM_COUNTER", asmjit::x86::edx);
m_Assembler.MoveConstToVariable(&g_System->m_PipelineStage, "g_System->m_PipelineStage", PIPELINE_STAGE_NORMAL);
ExitCodeBlock(); ExitCodeBlock();
break; break;
default: default: