Skip to content

Commit

Permalink
Core: Update how exceptions are handled with the recompiler
Browse files Browse the repository at this point in the history
  • Loading branch information
project64 committed Jun 8, 2023
1 parent 18a712c commit 187bd64
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 15 deletions.
12 changes: 0 additions & 12 deletions Source/Project64-core/N64System/Interpreter/InterpreterOps.cpp
Expand Up @@ -14,18 +14,6 @@
#include <float.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;
R4300iOpcode R4300iOp::m_Opcode;

Expand Down
3 changes: 1 addition & 2 deletions Source/Project64-core/N64System/Mips/Register.cpp
Expand Up @@ -709,7 +709,6 @@ void CRegisters::TriggerException(uint32_t ExceptionCode, uint32_t 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);
m_System->m_JumpToLocation = 0x80000180;
}
6 changes: 5 additions & 1 deletion Source/Project64-core/N64System/Mips/SystemEvents.cpp
Expand Up @@ -114,7 +114,11 @@ void CSystemEvents::ExecuteEvents()
m_System->Reset(true, true);
break;
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;
case SysEvent_Interrupt_SP:
g_Reg->MI_INTR_REG |= MI_INTR_SP;
Expand Down
1 change: 1 addition & 0 deletions Source/Project64-core/N64System/N64System.h
Expand Up @@ -146,6 +146,7 @@ class CN64System :
friend class CInterpreterCPU;
friend class R4300iOp32;
friend class R4300iOp;
friend class CSystemEvents;

friend class VideoInterfaceHandler;
friend class PifRamHandler;
Expand Down
Expand Up @@ -9476,20 +9476,29 @@ void CX86RecompilerOps::CompileExit(uint32_t JumpPC, uint32_t TargetPC, CRegInfo
m_Assembler.push(0);
m_Assembler.PushImm32("EXC_SYSCALL", EXC_SYSCALL);
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();
break;
case ExitReason_Break:
m_Assembler.MoveConstToVariable(&g_System->m_PipelineStage, "System->m_PipelineStage", m_PipelineStage == PIPELINE_STAGE_JUMP || m_PipelineStage == PIPELINE_STAGE_DELAY_SLOT ? PIPELINE_STAGE_JUMP : PIPELINE_STAGE_NORMAL);
m_Assembler.push(0);
m_Assembler.PushImm32("EXC_BREAK", EXC_BREAK);
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();
break;
case ExitReason_COP1Unuseable:
m_Assembler.MoveConstToVariable(&g_System->m_PipelineStage, "System->m_PipelineStage", m_PipelineStage == PIPELINE_STAGE_JUMP || m_PipelineStage == PIPELINE_STAGE_DELAY_SLOT ? PIPELINE_STAGE_JUMP : PIPELINE_STAGE_NORMAL);
m_Assembler.push(1);
m_Assembler.PushImm32("EXC_CPU", EXC_CPU);
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();
break;
case ExitReason_ResetRecompCode:
Expand All @@ -9512,6 +9521,9 @@ void CX86RecompilerOps::CompileExit(uint32_t JumpPC, uint32_t TargetPC, CRegInfo
m_Assembler.push(0);
m_Assembler.PushImm32("EXC_OV", EXC_OV);
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();
break;
case ExitReason_AddressErrorExceptionRead32:
Expand Down Expand Up @@ -9540,6 +9552,9 @@ void CX86RecompilerOps::CompileExit(uint32_t JumpPC, uint32_t TargetPC, CRegInfo
m_Assembler.push(0);
m_Assembler.PushImm32("EXC_II", EXC_II);
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();
break;
default:
Expand Down

0 comments on commit 187bd64

Please sign in to comment.