2010-05-25 09:15:19 +00:00
|
|
|
#include "stdafx.h"
|
2022-09-26 02:31:54 +00:00
|
|
|
|
2015-12-06 09:59:58 +00:00
|
|
|
#include "InterpreterCPU.h"
|
2017-08-18 05:08:22 +00:00
|
|
|
|
2022-09-26 02:31:54 +00:00
|
|
|
#include <Project64-core/Debugger.h>
|
|
|
|
#include <Project64-core/ExceptionHandler.h>
|
2015-12-06 09:59:58 +00:00
|
|
|
#include <Project64-core/N64System/Interpreter/InterpreterOps32.h>
|
2022-09-26 02:31:54 +00:00
|
|
|
#include <Project64-core/N64System/Mips/MemoryVirtualMem.h>
|
2022-07-18 08:31:00 +00:00
|
|
|
#include <Project64-core/N64System/Mips/R4300iInstruction.h>
|
2022-09-26 02:31:54 +00:00
|
|
|
#include <Project64-core/N64System/N64System.h>
|
|
|
|
#include <Project64-core/N64System/SystemGlobals.h>
|
2015-12-19 23:50:17 +00:00
|
|
|
#include <Project64-core/Plugins/GFXPlugin.h>
|
2022-09-26 02:31:54 +00:00
|
|
|
#include <Project64-core/Plugins/Plugin.h>
|
2010-05-25 09:15:19 +00:00
|
|
|
|
2021-04-12 11:35:39 +00:00
|
|
|
R4300iOp::Func * CInterpreterCPU::m_R4300i_Opcode = nullptr;
|
2010-05-31 00:21:08 +00:00
|
|
|
|
2015-11-08 20:55:32 +00:00
|
|
|
void ExecuteInterpreterOps(uint32_t /*Cycles*/)
|
2010-05-25 09:15:19 +00:00
|
|
|
{
|
2015-12-09 11:37:58 +00:00
|
|
|
g_Notify->BreakPoint(__FILE__, __LINE__);
|
2010-05-25 09:15:19 +00:00
|
|
|
}
|
|
|
|
|
2015-04-28 22:19:02 +00:00
|
|
|
void CInterpreterCPU::BuildCPU()
|
2015-11-08 20:55:32 +00:00
|
|
|
{
|
|
|
|
R4300iOp::m_TestTimer = false;
|
|
|
|
|
|
|
|
if (g_Settings->LoadBool(Game_32Bit))
|
|
|
|
{
|
|
|
|
m_R4300i_Opcode = R4300iOp32::BuildInterpreter();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_R4300i_Opcode = R4300iOp::BuildInterpreter();
|
|
|
|
}
|
2012-09-30 12:24:07 +00:00
|
|
|
}
|
|
|
|
|
2015-04-28 22:19:02 +00:00
|
|
|
void CInterpreterCPU::InPermLoop()
|
2015-03-29 15:02:27 +00:00
|
|
|
{
|
2022-08-01 01:29:16 +00:00
|
|
|
if (EndOnPermLoop() &&
|
|
|
|
((g_Reg->STATUS_REGISTER & STATUS_IE) == 0 ||
|
2022-09-26 02:31:54 +00:00
|
|
|
(g_Reg->STATUS_REGISTER & STATUS_EXL) != 0 ||
|
|
|
|
(g_Reg->STATUS_REGISTER & STATUS_ERL) != 0 ||
|
|
|
|
(g_Reg->STATUS_REGISTER & 0xFF00) == 0))
|
2015-11-08 20:55:32 +00:00
|
|
|
{
|
2021-04-12 11:35:39 +00:00
|
|
|
if (g_Plugins->Gfx()->UpdateScreen != nullptr)
|
2015-11-08 20:55:32 +00:00
|
|
|
{
|
|
|
|
g_Plugins->Gfx()->UpdateScreen();
|
|
|
|
}
|
|
|
|
g_Notify->DisplayError(GS(MSG_PERM_LOOP));
|
|
|
|
g_System->CloseCpu();
|
|
|
|
}
|
2022-08-01 01:29:16 +00:00
|
|
|
else if (*g_NextTimer > 0)
|
2015-11-08 20:55:32 +00:00
|
|
|
{
|
2022-08-01 01:29:16 +00:00
|
|
|
g_SystemTimer->UpdateTimers();
|
|
|
|
*g_NextTimer = 0 - g_System->CountPerOp();
|
|
|
|
g_SystemTimer->UpdateTimers();
|
2015-11-08 20:55:32 +00:00
|
|
|
}
|
2010-05-25 09:15:19 +00:00
|
|
|
}
|
|
|
|
|
2015-04-28 22:19:02 +00:00
|
|
|
void CInterpreterCPU::ExecuteCPU()
|
2015-11-08 20:55:32 +00:00
|
|
|
{
|
2016-08-07 06:18:34 +00:00
|
|
|
WriteTrace(TraceN64System, TraceDebug, "Start");
|
|
|
|
|
2015-11-08 20:55:32 +00:00
|
|
|
bool & Done = g_System->m_EndEmulation;
|
2022-01-18 07:47:21 +00:00
|
|
|
PIPELINE_STAGE & PipelineStage = g_System->m_PipelineStage;
|
2015-11-08 20:45:41 +00:00
|
|
|
uint32_t & PROGRAM_COUNTER = *_PROGRAM_COUNTER;
|
2022-07-18 08:31:00 +00:00
|
|
|
R4300iOpcode & Opcode = R4300iOp::m_Opcode;
|
2022-01-18 07:47:21 +00:00
|
|
|
uint32_t & JumpToLocation = g_System->m_JumpToLocation;
|
2015-11-08 20:55:32 +00:00
|
|
|
bool & TestTimer = R4300iOp::m_TestTimer;
|
|
|
|
const int32_t & bDoSomething = g_SystemEvents->DoSomething();
|
|
|
|
uint32_t CountPerOp = g_System->CountPerOp();
|
|
|
|
int32_t & NextTimer = *g_NextTimer;
|
2016-08-07 06:18:34 +00:00
|
|
|
bool CheckTimer = false;
|
2015-11-14 22:08:30 +00:00
|
|
|
|
2016-01-13 09:33:17 +00:00
|
|
|
__except_try()
|
2015-11-08 20:55:32 +00:00
|
|
|
{
|
|
|
|
while (!Done)
|
|
|
|
{
|
2022-07-18 08:31:00 +00:00
|
|
|
if (!g_MMU->MemoryValue32(PROGRAM_COUNTER, Opcode.Value))
|
2015-12-04 01:10:26 +00:00
|
|
|
{
|
2022-01-18 07:47:21 +00:00
|
|
|
g_Reg->DoTLBReadMiss(PipelineStage == PIPELINE_STAGE_JUMP, PROGRAM_COUNTER);
|
|
|
|
PipelineStage = PIPELINE_STAGE_NORMAL;
|
2015-12-04 01:10:26 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2022-01-03 23:56:14 +00:00
|
|
|
if (HaveDebugger())
|
2018-01-16 21:26:54 +00:00
|
|
|
{
|
|
|
|
if (HaveExecutionBP() && g_Debugger->ExecutionBP(PROGRAM_COUNTER))
|
|
|
|
{
|
|
|
|
g_Settings->SaveBool(Debugger_SteppingOps, true);
|
|
|
|
}
|
2019-01-14 09:18:43 +00:00
|
|
|
|
2021-05-18 11:51:36 +00:00
|
|
|
g_Debugger->CPUStepStarted(); // May set stepping ops/skip op
|
2019-01-17 09:34:24 +00:00
|
|
|
|
2018-01-16 21:26:54 +00:00
|
|
|
if (isStepping())
|
|
|
|
{
|
|
|
|
g_Debugger->WaitForStep();
|
|
|
|
}
|
|
|
|
|
2019-01-17 09:34:24 +00:00
|
|
|
if (SkipOp())
|
2018-03-18 01:14:52 +00:00
|
|
|
{
|
2019-01-14 09:18:43 +00:00
|
|
|
// Skip command if instructed by the debugger
|
2018-03-18 01:14:52 +00:00
|
|
|
g_Settings->SaveBool(Debugger_SkipOp, false);
|
|
|
|
PROGRAM_COUNTER += 4;
|
|
|
|
continue;
|
|
|
|
}
|
2019-01-17 09:34:24 +00:00
|
|
|
|
|
|
|
g_Debugger->CPUStep();
|
2017-08-20 22:48:31 +00:00
|
|
|
}
|
|
|
|
|
2015-12-21 07:35:22 +00:00
|
|
|
/* if (PROGRAM_COUNTER > 0x80000300 && PROGRAM_COUNTER < 0x80380000)
|
2016-01-13 09:33:17 +00:00
|
|
|
{
|
2022-07-18 08:31:00 +00:00
|
|
|
WriteTraceF((TraceType)(TraceError | TraceNoHeader),"%X: %s",*_PROGRAM_COUNTER,R4300iInstruction(*_PROGRAM_COUNTER, Opcode.Value).NameAndParam().c_str());
|
|
|
|
// WriteTraceF((TraceType)(TraceError | TraceNoHeader),"%X: %s t9: %08X v1: %08X",*_PROGRAM_COUNTER,R4300iInstruction(*_PROGRAM_COUNTER, Opcode.Value).NameAndParam().c_str(),_GPR[0x19].UW[0],_GPR[0x03].UW[0]);
|
2016-01-13 09:33:17 +00:00
|
|
|
// WriteTraceF((TraceType)(TraceError | TraceNoHeader),"%X: %d %d",*_PROGRAM_COUNTER,*g_NextTimer,g_SystemTimer->CurrentType());
|
|
|
|
} */
|
2017-08-18 05:08:22 +00:00
|
|
|
|
2015-12-04 01:10:26 +00:00
|
|
|
m_R4300i_Opcode[Opcode.op]();
|
2021-05-18 11:51:36 +00:00
|
|
|
_GPR[0].DW = 0; // MIPS $zero hard-wired to 0
|
2015-12-04 01:10:26 +00:00
|
|
|
NextTimer -= CountPerOp;
|
2017-08-20 22:48:31 +00:00
|
|
|
|
2022-09-26 02:31:54 +00:00
|
|
|
if (CDebugSettings::HaveDebugger())
|
|
|
|
{
|
|
|
|
g_Debugger->CPUStepEnded();
|
|
|
|
}
|
2017-08-30 04:54:06 +00:00
|
|
|
|
2015-12-19 02:20:10 +00:00
|
|
|
PROGRAM_COUNTER += 4;
|
2022-01-18 07:47:21 +00:00
|
|
|
switch (PipelineStage)
|
2015-12-04 01:10:26 +00:00
|
|
|
{
|
2022-01-18 07:47:21 +00:00
|
|
|
case PIPELINE_STAGE_NORMAL:
|
2015-12-04 01:10:26 +00:00
|
|
|
break;
|
2022-01-18 07:47:21 +00:00
|
|
|
case PIPELINE_STAGE_DELAY_SLOT:
|
|
|
|
PipelineStage = PIPELINE_STAGE_JUMP;
|
2015-12-04 01:10:26 +00:00
|
|
|
break;
|
2022-09-26 02:31:54 +00:00
|
|
|
case PIPELINE_STAGE_PERMLOOP_DO_DELAY:
|
2022-01-18 07:47:21 +00:00
|
|
|
PipelineStage = PIPELINE_STAGE_PERMLOOP_DELAY_DONE;
|
2015-12-04 01:10:26 +00:00
|
|
|
break;
|
2022-09-26 02:31:54 +00:00
|
|
|
case PIPELINE_STAGE_JUMP:
|
2016-08-07 06:18:34 +00:00
|
|
|
CheckTimer = (JumpToLocation < PROGRAM_COUNTER - 4 || TestTimer);
|
2015-12-04 01:10:26 +00:00
|
|
|
PROGRAM_COUNTER = JumpToLocation;
|
2022-01-18 07:47:21 +00:00
|
|
|
PipelineStage = PIPELINE_STAGE_NORMAL;
|
2015-12-04 01:10:26 +00:00
|
|
|
if (CheckTimer)
|
2015-11-14 22:08:30 +00:00
|
|
|
{
|
2015-12-04 01:10:26 +00:00
|
|
|
TestTimer = false;
|
|
|
|
if (NextTimer < 0)
|
2015-11-08 20:55:32 +00:00
|
|
|
{
|
2015-12-04 01:10:26 +00:00
|
|
|
g_SystemTimer->TimerDone();
|
2015-11-08 20:55:32 +00:00
|
|
|
}
|
|
|
|
if (bDoSomething)
|
|
|
|
{
|
|
|
|
g_SystemEvents->ExecuteEvents();
|
|
|
|
}
|
|
|
|
}
|
2016-08-07 06:18:34 +00:00
|
|
|
break;
|
2022-01-18 07:47:21 +00:00
|
|
|
case PIPELINE_STAGE_PERMLOOP_DELAY_DONE:
|
2015-12-04 01:10:26 +00:00
|
|
|
PROGRAM_COUNTER = JumpToLocation;
|
2022-01-18 07:47:21 +00:00
|
|
|
PipelineStage = PIPELINE_STAGE_NORMAL;
|
2015-12-04 01:10:26 +00:00
|
|
|
CInterpreterCPU::InPermLoop();
|
|
|
|
g_SystemTimer->TimerDone();
|
|
|
|
if (bDoSomething)
|
|
|
|
{
|
|
|
|
g_SystemEvents->ExecuteEvents();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2015-12-09 11:37:58 +00:00
|
|
|
g_Notify->BreakPoint(__FILE__, __LINE__);
|
2015-11-08 20:55:32 +00:00
|
|
|
}
|
|
|
|
}
|
2015-11-14 22:08:30 +00:00
|
|
|
}
|
2016-01-13 09:33:17 +00:00
|
|
|
__except_catch()
|
2015-11-08 20:55:32 +00:00
|
|
|
{
|
|
|
|
g_Notify->FatalError(GS(MSG_UNKNOWN_MEM_ACTION));
|
|
|
|
}
|
2016-08-07 06:18:34 +00:00
|
|
|
WriteTrace(TraceN64System, TraceDebug, "Done");
|
2010-05-25 09:15:19 +00:00
|
|
|
}
|
|
|
|
|
2015-11-08 20:55:32 +00:00
|
|
|
void CInterpreterCPU::ExecuteOps(int32_t Cycles)
|
2010-05-31 00:21:08 +00:00
|
|
|
{
|
2022-01-18 07:47:21 +00:00
|
|
|
bool & Done = g_System->m_EndEmulation;
|
2022-09-26 02:31:54 +00:00
|
|
|
uint32_t & PROGRAM_COUNTER = *_PROGRAM_COUNTER;
|
2022-07-18 08:31:00 +00:00
|
|
|
R4300iOpcode & Opcode = R4300iOp::m_Opcode;
|
2022-01-18 07:47:21 +00:00
|
|
|
PIPELINE_STAGE & PipelineStage = g_System->m_PipelineStage;
|
|
|
|
uint32_t & JumpToLocation = g_System->m_JumpToLocation;
|
2022-09-26 02:31:54 +00:00
|
|
|
bool & TestTimer = R4300iOp::m_TestTimer;
|
2015-11-08 20:55:32 +00:00
|
|
|
const int32_t & DoSomething = g_SystemEvents->DoSomething();
|
|
|
|
uint32_t CountPerOp = g_System->CountPerOp();
|
2016-08-07 06:18:34 +00:00
|
|
|
bool CheckTimer = false;
|
2015-11-08 20:55:32 +00:00
|
|
|
|
2016-01-13 09:33:17 +00:00
|
|
|
__except_try()
|
2015-11-08 20:55:32 +00:00
|
|
|
{
|
|
|
|
while (!Done)
|
|
|
|
{
|
|
|
|
if (Cycles <= 0)
|
|
|
|
{
|
|
|
|
g_SystemTimer->UpdateTimers();
|
|
|
|
return;
|
|
|
|
}
|
2010-07-05 11:29:46 +00:00
|
|
|
|
2022-07-18 08:31:00 +00:00
|
|
|
if (g_MMU->MemoryValue32(PROGRAM_COUNTER, Opcode.Value))
|
2015-11-08 20:55:32 +00:00
|
|
|
{
|
|
|
|
/*if (PROGRAM_COUNTER > 0x80000300 && PROGRAM_COUNTER< 0x80380000)
|
|
|
|
{
|
2022-07-18 08:31:00 +00:00
|
|
|
WriteTraceF((TraceType)(TraceError | TraceNoHeader),"%X: %s",*_PROGRAM_COUNTER,R4300iInstruction(*_PROGRAM_COUNTER, Opcode.Value).NameAndParam().c_str());
|
|
|
|
//WriteTraceF((TraceType)(TraceError | TraceNoHeader),"%X: %s t9: %08X v1: %08X",*_PROGRAM_COUNTER,R4300iInstruction(*_PROGRAM_COUNTER, Opcode.Value).NameAndParam().c_str(),_GPR[0x19].UW[0],_GPR[0x03].UW[0]);
|
2015-11-08 20:55:32 +00:00
|
|
|
//WriteTraceF((TraceType)(TraceError | TraceNoHeader),"%X: %d %d",*_PROGRAM_COUNTER,*g_NextTimer,g_SystemTimer->CurrentType());
|
|
|
|
}*/
|
|
|
|
/*if (PROGRAM_COUNTER > 0x80323000 && PROGRAM_COUNTER< 0x80380000)
|
|
|
|
{
|
2022-07-18 08:31:00 +00:00
|
|
|
WriteTraceF((TraceType)(TraceError | TraceNoHeader),"%X: %s",*_PROGRAM_COUNTER,R4300iInstruction(*_PROGRAM_COUNTER, Opcode.Value).NameAndParam().c_str());
|
|
|
|
//WriteTraceF((TraceType)(TraceError | TraceNoHeader),"%X: %s t9: %08X v1: %08X",*_PROGRAM_COUNTER,R4300iInstruction(*_PROGRAM_COUNTER, Opcode.Value).NameAndParam().c_str(),_GPR[0x19].UW[0],_GPR[0x03].UW[0]);
|
2015-11-08 20:55:32 +00:00
|
|
|
//WriteTraceF((TraceType)(TraceError | TraceNoHeader),"%X: %d %d",*_PROGRAM_COUNTER,*g_NextTimer,g_SystemTimer->CurrentType());
|
|
|
|
}*/
|
|
|
|
m_R4300i_Opcode[Opcode.op]();
|
|
|
|
_GPR[0].DW = 0; /* MIPS $zero hard-wired to 0 */
|
|
|
|
|
|
|
|
Cycles -= CountPerOp;
|
|
|
|
*g_NextTimer -= CountPerOp;
|
|
|
|
|
|
|
|
/*static uint32_t TestAddress = 0x80077B0C, TestValue = 0, CurrentValue = 0;
|
2022-05-02 10:52:31 +00:00
|
|
|
if (g_MMU->MemoryValue32(TestAddress, TestValue))
|
2015-11-08 20:55:32 +00:00
|
|
|
{
|
|
|
|
if (TestValue != CurrentValue)
|
|
|
|
{
|
2022-07-18 08:31:00 +00:00
|
|
|
WriteTraceF(TraceError,"%X: %X changed (%s)",PROGRAM_COUNTER,TestAddress,R4300iInstruction(PROGRAM_COUNTER, m_Opcode.Value).NameAndParam().c_str());
|
2015-11-08 20:55:32 +00:00
|
|
|
CurrentValue = TestValue;
|
|
|
|
}
|
|
|
|
}*/
|
|
|
|
|
2022-01-18 07:47:21 +00:00
|
|
|
switch (PipelineStage)
|
2015-11-08 20:55:32 +00:00
|
|
|
{
|
2022-01-18 07:47:21 +00:00
|
|
|
case PIPELINE_STAGE_NORMAL:
|
2015-11-08 20:55:32 +00:00
|
|
|
PROGRAM_COUNTER += 4;
|
|
|
|
break;
|
2022-01-18 07:47:21 +00:00
|
|
|
case PIPELINE_STAGE_DELAY_SLOT:
|
|
|
|
PipelineStage = PIPELINE_STAGE_JUMP;
|
2015-11-08 20:55:32 +00:00
|
|
|
PROGRAM_COUNTER += 4;
|
|
|
|
break;
|
2022-01-18 07:47:21 +00:00
|
|
|
case PIPELINE_STAGE_PERMLOOP_DO_DELAY:
|
|
|
|
PipelineStage = PIPELINE_STAGE_PERMLOOP_DELAY_DONE;
|
2015-11-08 20:55:32 +00:00
|
|
|
PROGRAM_COUNTER += 4;
|
|
|
|
break;
|
2022-01-18 07:47:21 +00:00
|
|
|
case PIPELINE_STAGE_JUMP:
|
2016-08-07 06:18:34 +00:00
|
|
|
CheckTimer = (JumpToLocation < PROGRAM_COUNTER || TestTimer);
|
|
|
|
PROGRAM_COUNTER = JumpToLocation;
|
2022-01-18 07:47:21 +00:00
|
|
|
PipelineStage = PIPELINE_STAGE_NORMAL;
|
2016-08-07 06:18:34 +00:00
|
|
|
if (CheckTimer)
|
2015-11-08 20:55:32 +00:00
|
|
|
{
|
2016-08-07 06:18:34 +00:00
|
|
|
TestTimer = false;
|
|
|
|
if (*g_NextTimer < 0)
|
|
|
|
{
|
|
|
|
g_SystemTimer->TimerDone();
|
|
|
|
}
|
|
|
|
if (DoSomething)
|
2015-11-14 22:08:30 +00:00
|
|
|
{
|
2016-08-07 06:18:34 +00:00
|
|
|
g_SystemEvents->ExecuteEvents();
|
2015-11-08 20:55:32 +00:00
|
|
|
}
|
|
|
|
}
|
2016-01-13 09:33:17 +00:00
|
|
|
break;
|
2022-01-18 07:47:21 +00:00
|
|
|
case PIPELINE_STAGE_PERMLOOP_DELAY_DONE:
|
2015-11-08 20:55:32 +00:00
|
|
|
PROGRAM_COUNTER = JumpToLocation;
|
2022-01-18 07:47:21 +00:00
|
|
|
PipelineStage = PIPELINE_STAGE_NORMAL;
|
2015-11-08 20:55:32 +00:00
|
|
|
CInterpreterCPU::InPermLoop();
|
|
|
|
g_SystemTimer->TimerDone();
|
|
|
|
if (DoSomething)
|
|
|
|
{
|
|
|
|
g_SystemEvents->ExecuteEvents();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2015-12-09 11:37:58 +00:00
|
|
|
g_Notify->BreakPoint(__FILE__, __LINE__);
|
2015-11-08 20:55:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-01-18 07:47:21 +00:00
|
|
|
g_Reg->DoTLBReadMiss(PipelineStage == PIPELINE_STAGE_JUMP, PROGRAM_COUNTER);
|
|
|
|
PipelineStage = PIPELINE_STAGE_NORMAL;
|
2015-11-08 20:55:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-01-13 09:33:17 +00:00
|
|
|
__except_catch()
|
2015-11-08 20:55:32 +00:00
|
|
|
{
|
|
|
|
g_Notify->FatalError(GS(MSG_UNKNOWN_MEM_ACTION));
|
|
|
|
}
|
2015-11-14 22:08:30 +00:00
|
|
|
}
|