RSP: Have NextInstruction and JumpTo members of RSP System instead of a global variable

This commit is contained in:
zilmar 2024-08-22 19:44:07 +09:30
parent 29c49a2063
commit 2b7975280e
14 changed files with 1267 additions and 1288 deletions

View File

@ -43,7 +43,6 @@
<ClCompile Include="cpu\RspClamp.cpp" />
<ClCompile Include="cpu\RSPCpu.cpp" />
<ClCompile Include="cpu\RSPiInstruction.cpp" />
<ClCompile Include="cpu\RSPInterpreterCPU.cpp" />
<ClCompile Include="cpu\RSPInterpreterOps.cpp" />
<ClCompile Include="cpu\RspLog.cpp" />
<ClCompile Include="cpu\RspMemory.cpp" />
@ -79,11 +78,11 @@
<ClInclude Include="cpu\RspClamp.h" />
<ClInclude Include="cpu\RSPCpu.h" />
<ClInclude Include="cpu\RSPInstruction.h" />
<ClInclude Include="cpu\RSPInterpreterCPU.h" />
<ClInclude Include="cpu\RSPInterpreterOps.h" />
<ClInclude Include="cpu\RspLog.h" />
<ClInclude Include="cpu\RspMemory.h" />
<ClInclude Include="cpu\RSPOpcode.h" />
<ClInclude Include="cpu\RspPipelineStage.h" />
<ClInclude Include="cpu\RSPRegisterHandler.h" />
<ClInclude Include="cpu\RSPRegisterHandlerPlugin.h" />
<ClInclude Include="cpu\RSPRegisters.h" />

View File

@ -48,9 +48,6 @@
<ClCompile Include="cpu\RSPRegister.cpp">
<Filter>Source Files\cpu</Filter>
</ClCompile>
<ClCompile Include="cpu\RSPInterpreterCPU.cpp">
<Filter>Source Files\cpu</Filter>
</ClCompile>
<ClCompile Include="cpu\RSPInterpreterOps.cpp">
<Filter>Source Files\cpu</Filter>
</ClCompile>
@ -155,9 +152,6 @@
<ClInclude Include="cpu\RSPRegisters.h">
<Filter>Header Files\cpu</Filter>
</ClInclude>
<ClInclude Include="cpu\RSPInterpreterCPU.h">
<Filter>Header Files\cpu</Filter>
</ClInclude>
<ClInclude Include="cpu\RSPInterpreterOps.h">
<Filter>Header Files\cpu</Filter>
</ClInclude>
@ -224,5 +218,8 @@
<ClInclude Include="cpu\RspSystem.h">
<Filter>Header Files\cpu</Filter>
</ClInclude>
<ClInclude Include="cpu\RspPipelineStage.h">
<Filter>Header Files\cpu</Filter>
</ClInclude>
</ItemGroup>
</Project>

File diff suppressed because it is too large Load Diff

View File

@ -6,7 +6,6 @@
#include <Project64-rsp-core/RSPInfo.h>
#include <Project64-rsp-core/cpu/RSPCpu.h>
#include <Project64-rsp-core/cpu/RSPInstruction.h>
#include <Project64-rsp-core/cpu/RSPInterpreterCPU.h>
#include <Project64-rsp-core/cpu/RSPOpcode.h>
#include <Project64-rsp-core/cpu/RSPRegisters.h>
#include <Project64-rsp-core/cpu/RspLog.h>
@ -45,6 +44,7 @@ CRSPRecompiler::CRSPRecompiler(CRSPSystem & System) :
m_System(System),
m_RSPRegisterHandler(System.m_RSPRegisterHandler),
m_OpCode(System.m_OpCode),
m_NextInstruction(RSPPIPELINE_NORMAL),
m_IMEM(System.m_IMEM)
{
}
@ -794,12 +794,12 @@ bool IsJumpLabel(uint32_t PC)
return false;
}
void CompilerLinkBlocks(void)
void CRSPRecompiler::CompilerLinkBlocks(void)
{
uint8_t * KnownCode = (uint8_t *)*(JumpTable + (CompilePC >> 2));
CPU_Message("***** Linking block to X86: %08X *****", KnownCode);
NextInstruction = RSPPIPELINE_FINISH_BLOCK;
m_NextInstruction = RSPPIPELINE_FINISH_BLOCK;
// Block linking scenario
JmpLabel32("Linked block", 0);
@ -812,7 +812,7 @@ void CRSPRecompiler::CompilerRSPBlock(void)
uint8_t * IMEM_SAVE = (uint8_t *)malloc(0x1000);
const size_t X86BaseAddress = (size_t)RecompPos;
NextInstruction = RSPPIPELINE_NORMAL;
m_NextInstruction = RSPPIPELINE_NORMAL;
CompilePC = *m_System.m_SP_PC_REG;
memset(&m_CurrentBlock, 0, sizeof(m_CurrentBlock));
@ -853,7 +853,7 @@ void CRSPRecompiler::CompilerRSPBlock(void)
// Reordering is setup to allow us to have loop labels
// so here we see if this is one and put it in the jump table
if (NextInstruction == RSPPIPELINE_NORMAL && IsJumpLabel(CompilePC))
if (m_NextInstruction == RSPPIPELINE_NORMAL && IsJumpLabel(CompilePC))
{
// Jumps come around twice
if (NULL == *(JumpTable + (CompilePC >> 2)))
@ -866,7 +866,7 @@ void CRSPRecompiler::CompilerRSPBlock(void)
m_CurrentBlock.CurrPC = CompilePC;
ReOrderSubBlock(&m_CurrentBlock);
}
else if (NextInstruction != RSPPIPELINE_DELAY_SLOT_DONE)
else if (m_NextInstruction != RSPPIPELINE_DELAY_SLOT_DONE)
{
// We could link the blocks here, but performance-wise it might be better to just let it run
@ -892,36 +892,36 @@ void CRSPRecompiler::CompilerRSPBlock(void)
if (m_OpCode.Value == 0xFFFFFFFF)
{
// I think this pops up an unknown OP dialog
// NextInstruction = RSPPIPELINE_FINISH_BLOCK;
// m_NextInstruction = RSPPIPELINE_FINISH_BLOCK;
}
else
{
(RecompilerOps.*RSP_Recomp_Opcode[m_OpCode.op])();
}
switch (NextInstruction)
switch (m_NextInstruction)
{
case RSPPIPELINE_NORMAL:
CompilePC += 4;
break;
case RSPPIPELINE_DO_DELAY_SLOT:
NextInstruction = RSPPIPELINE_DELAY_SLOT;
m_NextInstruction = RSPPIPELINE_DELAY_SLOT;
CompilePC += 4;
break;
case RSPPIPELINE_DELAY_SLOT:
NextInstruction = RSPPIPELINE_DELAY_SLOT_DONE;
m_NextInstruction = RSPPIPELINE_DELAY_SLOT_DONE;
CompilePC = (CompilePC - 4 & 0xFFC);
break;
case RSPPIPELINE_DELAY_SLOT_EXIT:
NextInstruction = RSPPIPELINE_DELAY_SLOT_EXIT_DONE;
m_NextInstruction = RSPPIPELINE_DELAY_SLOT_EXIT_DONE;
CompilePC = (CompilePC - 4 & 0xFFC);
break;
case RSPPIPELINE_FINISH_SUB_BLOCK:
NextInstruction = RSPPIPELINE_NORMAL;
m_NextInstruction = RSPPIPELINE_NORMAL;
CompilePC += 8;
if (CompilePC >= 0x1000)
{
NextInstruction = RSPPIPELINE_FINISH_BLOCK;
m_NextInstruction = RSPPIPELINE_FINISH_BLOCK;
}
else if (NULL == *(JumpTable + (CompilePC >> 2)))
{
@ -941,7 +941,7 @@ void CRSPRecompiler::CompilerRSPBlock(void)
case RSPPIPELINE_FINISH_BLOCK: break;
default:
g_Notify->DisplayError(stdstr_f("RSP main loop\n\nWTF NextInstruction = %d", NextInstruction).c_str());
g_Notify->DisplayError(stdstr_f("RSP main loop\n\nWTF m_NextInstruction = %d", m_NextInstruction).c_str());
CompilePC += 4;
break;
}
@ -951,7 +951,7 @@ void CRSPRecompiler::CompilerRSPBlock(void)
CompilePC = 0;
EndPC = *m_System.m_SP_PC_REG;
}
} while (NextInstruction != RSPPIPELINE_FINISH_BLOCK && (CompilePC < EndPC || NextInstruction == RSPPIPELINE_DELAY_SLOT || NextInstruction == RSPPIPELINE_DELAY_SLOT_DONE));
} while (m_NextInstruction != RSPPIPELINE_FINISH_BLOCK && (CompilePC < EndPC || m_NextInstruction == RSPPIPELINE_DELAY_SLOT || m_NextInstruction == RSPPIPELINE_DELAY_SLOT_DONE));
if (CompilePC >= EndPC)
{
MoveConstToVariable((CompilePC & 0xFFC), m_System.m_SP_PC_REG, "RSP PC");
@ -1041,7 +1041,7 @@ void CRSPRecompiler::RunCPU(void)
{
StopTimer();
}
if (RSP_NextInstruction == RSPPIPELINE_SINGLE_STEP)
if (m_System.m_NextInstruction == RSPPIPELINE_SINGLE_STEP)
{
RSP_Running = false;
}

View File

@ -2,6 +2,7 @@
#include <Project64-rsp-core/Settings/RspSettings.h>
#include <Project64-rsp-core/cpu/RSPOpcode.h>
#include <Project64-rsp-core/cpu/RspPipelineStage.h>
#include <Project64-rsp-core/cpu/RspTypes.h>
#include <Settings/Settings.h>
@ -37,6 +38,7 @@ private:
CRSPRecompiler(const CRSPRecompiler &);
CRSPRecompiler & operator=(const CRSPRecompiler &);
void CompilerLinkBlocks(void);
void CompilerRSPBlock(void);
void LinkBranches(RSP_BLOCK * Block);
void ReOrderSubBlock(RSP_BLOCK * Block);
@ -47,10 +49,11 @@ private:
RSPRegisterHandlerPlugin *& m_RSPRegisterHandler;
RSPOpcode & m_OpCode;
RSP_BLOCK m_CurrentBlock;
RSPPIPELINE_STAGE m_NextInstruction;
uint8_t *& m_IMEM;
};
extern uint32_t CompilePC, NextInstruction, JumpTableSize;
extern uint32_t CompilePC, JumpTableSize;
extern bool ChangedPC;
#define CompilerWarning \

File diff suppressed because it is too large Load Diff

View File

@ -6,6 +6,11 @@ class CRSPRegisters;
class CRSPRecompilerOps
{
enum
{
HIT_BRANCH = 0x2,
};
public:
CRSPRecompilerOps(CRSPSystem & System, CRSPRecompiler & Recompiler);
@ -166,6 +171,12 @@ private:
void Cheat_r4300iOpcode(RSPOp::Func FunctAddress, const char * FunctName);
void Cheat_r4300iOpcodeNoMessage(RSPOp::Func FunctAddress, const char * FunctName);
bool IsNextInstructionMmx(uint32_t PC);
bool UseRspFlags(int PC);
bool WriteToAccum(int Location, int PC);
uint32_t WriteToAccum2(int Location, int PC, bool RecursiveCall);
bool WriteToVectorDest(uint32_t DestReg, int PC);
bool WriteToVectorDest2(uint32_t DestReg, int PC, bool RecursiveCall);
void RSP_Element2Mmx(int MmxReg);
void RSP_MultiElement2Mmx(int MmxReg1, int MmxReg2);
void CompileBranchExit(uint32_t TargetPC, uint32_t ContinuePC);
@ -206,6 +217,7 @@ private:
RSPRegisterHandlerPlugin *& m_RSPRegisterHandler;
CRSPRegisters & m_Reg;
CRSPRecompiler & m_Recompiler;
RSPPIPELINE_STAGE & m_NextInstruction;
RSPOpcode & m_OpCode;
UWORD32 * m_GPR;
UDWORD * m_ACCUM;

View File

@ -12,7 +12,7 @@
class RSPRegisterHandler;
UDWORD EleSpec[16], Indx[16];
uint32_t NextInstruction, RSP_Running;
uint32_t RSP_Running;
void BuildRecompilerCPU(void);

View File

@ -1,11 +0,0 @@
#include "RSPInterpreterCPU.h"
#include "RSPCpu.h"
#include "RSPInterpreterOps.h"
#include "RSPRegisters.h"
#include <Project64-rsp-core/RSPDebugger.h>
#include <Project64-rsp-core/RSPInfo.h>
#include <Project64-rsp-core/cpu/RspSystem.h>
#include <Settings/Settings.h>
RSPPIPELINE_STAGE RSP_NextInstruction;
uint32_t RSP_JumpTo;

View File

@ -1,5 +1,4 @@
#include "RSPCpu.h"
#include "RSPInterpreterCPU.h"
#include "RSPRegisters.h"
#include "RspLog.h"
#include <Common/StdString.h>
@ -61,6 +60,8 @@ RSPOp::RSPOp(CRSPSystem & System) :
m_RSPRegisterHandler(System.m_RSPRegisterHandler),
m_OpCode(System.m_OpCode),
m_Reg(System.m_Reg),
m_NextInstruction(System.m_NextInstruction),
m_JumpTo(System.m_JumpTo),
m_MI_INTR_REG(System.m_MI_INTR_REG),
m_SP_PC_REG(System.m_SP_PC_REG),
m_SP_STATUS_REG(System.m_SP_STATUS_REG),
@ -469,39 +470,39 @@ void RSPOp::REGIMM(void)
void RSPOp::J(void)
{
RSP_NextInstruction = RSPPIPELINE_DELAY_SLOT;
RSP_JumpTo = (m_OpCode.target << 2) & 0xFFC;
m_NextInstruction = RSPPIPELINE_DELAY_SLOT;
m_JumpTo = (m_OpCode.target << 2) & 0xFFC;
}
void RSPOp::JAL(void)
{
RSP_NextInstruction = RSPPIPELINE_DELAY_SLOT;
m_NextInstruction = RSPPIPELINE_DELAY_SLOT;
m_GPR[31].UW = (*m_SP_PC_REG + 8) & 0xFFC;
RSP_JumpTo = (m_OpCode.target << 2) & 0xFFC;
m_JumpTo = (m_OpCode.target << 2) & 0xFFC;
}
void RSPOp::BEQ(void)
{
RSP_NextInstruction = RSPPIPELINE_DELAY_SLOT;
RSP_JumpTo = BranchIf(m_GPR[m_OpCode.rs].W == m_GPR[m_OpCode.rt].W);
m_NextInstruction = RSPPIPELINE_DELAY_SLOT;
m_JumpTo = BranchIf(m_GPR[m_OpCode.rs].W == m_GPR[m_OpCode.rt].W);
}
void RSPOp::BNE(void)
{
RSP_NextInstruction = RSPPIPELINE_DELAY_SLOT;
RSP_JumpTo = BranchIf(m_GPR[m_OpCode.rs].W != m_GPR[m_OpCode.rt].W);
m_NextInstruction = RSPPIPELINE_DELAY_SLOT;
m_JumpTo = BranchIf(m_GPR[m_OpCode.rs].W != m_GPR[m_OpCode.rt].W);
}
void RSPOp::BLEZ(void)
{
RSP_NextInstruction = RSPPIPELINE_DELAY_SLOT;
RSP_JumpTo = BranchIf(m_GPR[m_OpCode.rs].W <= 0);
m_NextInstruction = RSPPIPELINE_DELAY_SLOT;
m_JumpTo = BranchIf(m_GPR[m_OpCode.rs].W <= 0);
}
void RSPOp::BGTZ(void)
{
RSP_NextInstruction = RSPPIPELINE_DELAY_SLOT;
RSP_JumpTo = BranchIf(m_GPR[m_OpCode.rs].W > 0);
m_NextInstruction = RSPPIPELINE_DELAY_SLOT;
m_JumpTo = BranchIf(m_GPR[m_OpCode.rs].W > 0);
}
void RSPOp::ADDI(void)
@ -708,14 +709,14 @@ void RSPOp::Special_SRAV(void)
void RSPOp::Special_JR(void)
{
RSP_NextInstruction = RSPPIPELINE_DELAY_SLOT;
RSP_JumpTo = (m_GPR[m_OpCode.rs].W & 0xFFC);
m_NextInstruction = RSPPIPELINE_DELAY_SLOT;
m_JumpTo = (m_GPR[m_OpCode.rs].W & 0xFFC);
}
void RSPOp::Special_JALR(void)
{
RSP_NextInstruction = RSPPIPELINE_DELAY_SLOT;
RSP_JumpTo = (m_GPR[m_OpCode.rs].W & 0xFFC);
m_NextInstruction = RSPPIPELINE_DELAY_SLOT;
m_JumpTo = (m_GPR[m_OpCode.rs].W & 0xFFC);
m_GPR[m_OpCode.rd].W = (*m_SP_PC_REG + 8) & 0xFFC;
}
@ -784,27 +785,27 @@ void RSPOp::Special_SLTU(void)
void RSPOp::BLTZ(void)
{
RSP_NextInstruction = RSPPIPELINE_DELAY_SLOT;
RSP_JumpTo = BranchIf(m_GPR[m_OpCode.rs].W < 0);
m_NextInstruction = RSPPIPELINE_DELAY_SLOT;
m_JumpTo = BranchIf(m_GPR[m_OpCode.rs].W < 0);
}
void RSPOp::BGEZ(void)
{
RSP_NextInstruction = RSPPIPELINE_DELAY_SLOT;
RSP_JumpTo = BranchIf(m_GPR[m_OpCode.rs].W >= 0);
m_NextInstruction = RSPPIPELINE_DELAY_SLOT;
m_JumpTo = BranchIf(m_GPR[m_OpCode.rs].W >= 0);
}
void RSPOp::BLTZAL(void)
{
RSP_NextInstruction = RSPPIPELINE_DELAY_SLOT;
RSP_JumpTo = BranchIf(m_GPR[m_OpCode.rs].W < 0);
m_NextInstruction = RSPPIPELINE_DELAY_SLOT;
m_JumpTo = BranchIf(m_GPR[m_OpCode.rs].W < 0);
m_GPR[31].UW = (*m_SP_PC_REG + 8) & 0xFFC;
}
void RSPOp::BGEZAL(void)
{
RSP_NextInstruction = RSPPIPELINE_DELAY_SLOT;
RSP_JumpTo = BranchIf(m_GPR[m_OpCode.rs].W >= 0);
m_NextInstruction = RSPPIPELINE_DELAY_SLOT;
m_JumpTo = BranchIf(m_GPR[m_OpCode.rs].W >= 0);
m_GPR[31].UW = (*m_SP_PC_REG + 8) & 0xFFC;
}

View File

@ -1,5 +1,6 @@
#pragma once
#include <Project64-rsp-core/cpu/RSPOpcode.h>
#include <Project64-rsp-core/cpu/RspPipelineStage.h>
#include <Project64-rsp-core/cpu/RspTypes.h>
class CRSPSystem;
@ -186,6 +187,8 @@ private:
RSPRegisterHandlerPlugin *& m_RSPRegisterHandler;
RSPOpcode & m_OpCode;
CRSPRegisters & m_Reg;
RSPPIPELINE_STAGE & m_NextInstruction;
uint32_t & m_JumpTo;
uint32_t *& m_MI_INTR_REG;
uint32_t *& m_SP_PC_REG;
uint32_t *& m_SP_STATUS_REG;

View File

@ -1,4 +1,4 @@
#include <stdint.h>
#pragma once
enum RSPPIPELINE_STAGE
{
@ -14,6 +14,3 @@ enum RSPPIPELINE_STAGE
RSPPIPELINE_FINISH_BLOCK = 9,
RSPPIPELINE_FINISH_SUB_BLOCK = 10,
};
extern RSPPIPELINE_STAGE RSP_NextInstruction;
extern uint32_t RSP_JumpTo;

View File

@ -3,7 +3,6 @@
#include <Project64-rsp-core/Recompiler/RspRecompilerCPU.h>
#include <Project64-rsp-core/Settings/RspSettings.h>
#include <Project64-rsp-core/cpu/RSPCpu.h>
#include <Project64-rsp-core/cpu/RSPInterpreterCPU.h>
#include <Project64-rsp-core/cpu/RSPRegisters.h>
#include <Project64-rsp-core/cpu/RspSystem.h>
#include <Settings/Settings.h>
@ -14,6 +13,8 @@ CRSPSystem::CRSPSystem() :
m_Recompiler(nullptr),
m_RSPRegisterHandler(nullptr),
m_Op(*this),
m_NextInstruction(RSPPIPELINE_NORMAL),
m_JumpTo(0),
m_HEADER(nullptr),
m_RDRAM(nullptr),
m_DMEM(nullptr),
@ -127,22 +128,22 @@ uint32_t CRSPSystem::RunInterpreterCPU(uint32_t Cycles)
(m_Op.*(m_Op.Jump_Opcode[m_OpCode.op]))();
GprR0 = 0x00000000; // MIPS $zero hard-wired to 0
switch (RSP_NextInstruction)
switch (m_NextInstruction)
{
case RSPPIPELINE_NORMAL:
ProgramCounter = (ProgramCounter + 4) & 0xFFC;
break;
case RSPPIPELINE_DELAY_SLOT:
RSP_NextInstruction = RSPPIPELINE_JUMP;
m_NextInstruction = RSPPIPELINE_JUMP;
ProgramCounter = (ProgramCounter + 4) & 0xFFC;
break;
case RSPPIPELINE_JUMP:
RSP_NextInstruction = RSPPIPELINE_NORMAL;
ProgramCounter = RSP_JumpTo;
m_NextInstruction = RSPPIPELINE_NORMAL;
ProgramCounter = m_JumpTo;
break;
case RSPPIPELINE_SINGLE_STEP:
ProgramCounter = (ProgramCounter + 4) & 0xFFC;
RSP_NextInstruction = RSPPIPELINE_SINGLE_STEP_DONE;
m_NextInstruction = RSPPIPELINE_SINGLE_STEP_DONE;
break;
case RSPPIPELINE_SINGLE_STEP_DONE:
ProgramCounter = (ProgramCounter + 4) & 0xFFC;

View File

@ -2,6 +2,7 @@
#include <Project64-rsp-core/RSPInfo.h>
#include <Project64-rsp-core/cpu/RSPInterpreterOps.h>
#include <Project64-rsp-core/cpu/RSPRegisters.h>
#include <Project64-rsp-core/cpu/RspPipelineStage.h>
#include <Project64-rsp-core/cpu/RspTypes.h>
#include <stdint.h>
@ -38,6 +39,8 @@ private:
CRSPRegisters m_Reg;
RSPOp m_Op;
RSPOpcode m_OpCode;
RSPPIPELINE_STAGE m_NextInstruction;
uint32_t m_JumpTo;
uint8_t * m_HEADER;
uint8_t * m_RDRAM;
uint8_t * m_DMEM;