Interpreter: Move global state into class, move instance to System.
This commit is contained in:
11 files changed
+80
-53
No files matched your search
@@ -27,13 +27,6 @@
|
||||
#include "Core/PowerPC/PowerPC.h"
|
||||
#include "Core/System.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
u32 last_pc;
|
||||
}
|
||||
|
||||
bool Interpreter::m_end_block;
|
||||
|
||||
namespace
|
||||
{
|
||||
// Determines whether or not the given instruction is one where its execution
|
||||
@@ -63,13 +56,20 @@ bool IsInvalidPairedSingleExecution(UGeckoInstruction inst)
|
||||
return HID2(PowerPC::ppcState).PSE && !HID2(PowerPC::ppcState).LSQE &&
|
||||
IsPairedSingleQuantizedNonIndexedInstruction(inst);
|
||||
}
|
||||
} // namespace
|
||||
|
||||
void UpdatePC()
|
||||
void Interpreter::UpdatePC()
|
||||
{
|
||||
last_pc = PowerPC::ppcState.pc;
|
||||
m_last_pc = PowerPC::ppcState.pc;
|
||||
PowerPC::ppcState.pc = PowerPC::ppcState.npc;
|
||||
}
|
||||
} // Anonymous namespace
|
||||
|
||||
Interpreter::Interpreter(Core::System& system, PowerPC::PowerPCState& ppc_state)
|
||||
: m_system(system), m_ppc_state(ppc_state)
|
||||
{
|
||||
}
|
||||
|
||||
Interpreter::~Interpreter() = default;
|
||||
|
||||
void Interpreter::Init()
|
||||
{
|
||||
@@ -80,9 +80,7 @@ void Interpreter::Shutdown()
|
||||
{
|
||||
}
|
||||
|
||||
static bool s_start_trace = false;
|
||||
|
||||
static void Trace(const UGeckoInstruction& inst)
|
||||
void Interpreter::Trace(const UGeckoInstruction& inst)
|
||||
{
|
||||
std::string regs;
|
||||
for (size_t i = 0; i < std::size(PowerPC::ppcState.gpr); i++)
|
||||
@@ -109,8 +107,8 @@ static void Trace(const UGeckoInstruction& inst)
|
||||
|
||||
bool Interpreter::HandleFunctionHooking(u32 address)
|
||||
{
|
||||
return HLE::ReplaceFunctionIfPossible(address, [](u32 hook_index, HLE::HookType type) {
|
||||
HLEFunction(*Interpreter::getInstance(), hook_index);
|
||||
return HLE::ReplaceFunctionIfPossible(address, [this](u32 hook_index, HLE::HookType type) {
|
||||
HLEFunction(*this, hook_index);
|
||||
return type != HLE::HookType::Start;
|
||||
});
|
||||
}
|
||||
@@ -135,14 +133,14 @@ int Interpreter::SingleStepInner()
|
||||
// if ((PowerPC::ppcState.pc & 0x00FFFFFF) >= 0x000AB54C &&
|
||||
// (PowerPC::ppcState.pc & 0x00FFFFFF) <= 0x000AB624)
|
||||
// {
|
||||
// s_start_trace = true;
|
||||
// m_start_trace = true;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// s_start_trace = false;
|
||||
// m_start_trace = false;
|
||||
// }
|
||||
|
||||
if (s_start_trace)
|
||||
if (m_start_trace)
|
||||
{
|
||||
Trace(m_prev_inst);
|
||||
}
|
||||
@@ -156,7 +154,7 @@ int Interpreter::SingleStepInner()
|
||||
}
|
||||
else if (PowerPC::ppcState.msr.FP)
|
||||
{
|
||||
RunInterpreterOp(*Interpreter::getInstance(), m_prev_inst);
|
||||
RunInterpreterOp(*this, m_prev_inst);
|
||||
if ((PowerPC::ppcState.Exceptions & EXCEPTION_DSI) != 0)
|
||||
{
|
||||
CheckExceptions();
|
||||
@@ -172,7 +170,7 @@ int Interpreter::SingleStepInner()
|
||||
}
|
||||
else
|
||||
{
|
||||
RunInterpreterOp(*Interpreter::getInstance(), m_prev_inst);
|
||||
RunInterpreterOp(*this, m_prev_inst);
|
||||
if ((PowerPC::ppcState.Exceptions & EXCEPTION_DSI) != 0)
|
||||
{
|
||||
CheckExceptions();
|
||||
@@ -319,6 +317,7 @@ void Interpreter::unknown_instruction(Interpreter& interpreter, UGeckoInstructio
|
||||
auto& system = Core::System::GetInstance();
|
||||
Core::CPUThreadGuard guard(system);
|
||||
|
||||
const u32 last_pc = interpreter.m_last_pc;
|
||||
const u32 opcode = PowerPC::HostRead_U32(guard, last_pc);
|
||||
const std::string disasm = Common::GekkoDisassembler::Disassemble(opcode, last_pc);
|
||||
NOTICE_LOG_FMT(POWERPC, "Last PC = {:08x} : {}", last_pc, disasm);
|
||||
@@ -360,9 +359,3 @@ const char* Interpreter::GetName() const
|
||||
return "Interpreter32";
|
||||
#endif
|
||||
}
|
||||
|
||||
Interpreter* Interpreter::getInstance()
|
||||
{
|
||||
static Interpreter instance;
|
||||
return &instance;
|
||||
}
|
||||
@@ -9,9 +9,25 @@
|
||||
#include "Core/PowerPC/CPUCoreBase.h"
|
||||
#include "Core/PowerPC/Gekko.h"
|
||||
|
||||
namespace Core
|
||||
{
|
||||
class System;
|
||||
}
|
||||
namespace PowerPC
|
||||
{
|
||||
struct PowerPCState;
|
||||
}
|
||||
|
||||
class Interpreter : public CPUCoreBase
|
||||
{
|
||||
public:
|
||||
Interpreter(Core::System& system, PowerPC::PowerPCState& ppc_state);
|
||||
Interpreter(const Interpreter&) = delete;
|
||||
Interpreter(Interpreter&&) = delete;
|
||||
Interpreter& operator=(const Interpreter&) = delete;
|
||||
Interpreter& operator=(Interpreter&&) = delete;
|
||||
~Interpreter();
|
||||
|
||||
void Init() override;
|
||||
void Shutdown() override;
|
||||
void SingleStep() override;
|
||||
@@ -266,9 +282,6 @@ public:
|
||||
static Instruction GetInterpreterOp(UGeckoInstruction inst);
|
||||
static void RunInterpreterOp(Interpreter& interpreter, UGeckoInstruction inst);
|
||||
|
||||
// singleton
|
||||
static Interpreter* getInstance();
|
||||
|
||||
static void RunTable4(Interpreter& interpreter, UGeckoInstruction inst);
|
||||
static void RunTable19(Interpreter& interpreter, UGeckoInstruction inst);
|
||||
static void RunTable31(Interpreter& interpreter, UGeckoInstruction inst);
|
||||
@@ -280,7 +293,7 @@ public:
|
||||
private:
|
||||
void CheckExceptions();
|
||||
|
||||
static bool HandleFunctionHooking(u32 address);
|
||||
bool HandleFunctionHooking(u32 address);
|
||||
|
||||
// flag helper
|
||||
static void Helper_UpdateCR0(u32 value);
|
||||
@@ -290,7 +303,15 @@ private:
|
||||
static void Helper_FloatCompareOrdered(UGeckoInstruction inst, double a, double b);
|
||||
static void Helper_FloatCompareUnordered(UGeckoInstruction inst, double a, double b);
|
||||
|
||||
UGeckoInstruction m_prev_inst{};
|
||||
void UpdatePC();
|
||||
|
||||
static bool m_end_block;
|
||||
void Trace(const UGeckoInstruction& inst);
|
||||
|
||||
Core::System& m_system;
|
||||
PowerPC::PowerPCState& m_ppc_state;
|
||||
|
||||
UGeckoInstruction m_prev_inst{};
|
||||
u32 m_last_pc = 0;
|
||||
bool m_end_block = false;
|
||||
bool m_start_trace = false;
|
||||
};
|
||||
@@ -24,7 +24,7 @@ void Interpreter::bx(Interpreter& interpreter, UGeckoInstruction inst)
|
||||
else
|
||||
PowerPC::ppcState.npc = PowerPC::ppcState.pc + address;
|
||||
|
||||
m_end_block = true;
|
||||
interpreter.m_end_block = true;
|
||||
}
|
||||
|
||||
// bcx - ugly, straight from PPC manual equations :)
|
||||
@@ -54,7 +54,7 @@ void Interpreter::bcx(Interpreter& interpreter, UGeckoInstruction inst)
|
||||
PowerPC::ppcState.npc = PowerPC::ppcState.pc + address;
|
||||
}
|
||||
|
||||
m_end_block = true;
|
||||
interpreter.m_end_block = true;
|
||||
}
|
||||
|
||||
void Interpreter::bcctrx(Interpreter& interpreter, UGeckoInstruction inst)
|
||||
@@ -72,7 +72,7 @@ void Interpreter::bcctrx(Interpreter& interpreter, UGeckoInstruction inst)
|
||||
LR(PowerPC::ppcState) = PowerPC::ppcState.pc + 4;
|
||||
}
|
||||
|
||||
m_end_block = true;
|
||||
interpreter.m_end_block = true;
|
||||
}
|
||||
|
||||
void Interpreter::bclrx(Interpreter& interpreter, UGeckoInstruction inst)
|
||||
@@ -91,12 +91,12 @@ void Interpreter::bclrx(Interpreter& interpreter, UGeckoInstruction inst)
|
||||
LR(PowerPC::ppcState) = PowerPC::ppcState.pc + 4;
|
||||
}
|
||||
|
||||
m_end_block = true;
|
||||
interpreter.m_end_block = true;
|
||||
}
|
||||
|
||||
void Interpreter::HLEFunction(Interpreter& interpreter, UGeckoInstruction inst)
|
||||
{
|
||||
m_end_block = true;
|
||||
interpreter.m_end_block = true;
|
||||
|
||||
ASSERT(Core::IsCPUThread());
|
||||
Core::CPUThreadGuard guard(Core::System::GetInstance());
|
||||
@@ -126,7 +126,7 @@ void Interpreter::rfi(Interpreter& interpreter, UGeckoInstruction inst)
|
||||
// else
|
||||
// set NPC to saved offset and resume
|
||||
PowerPC::ppcState.npc = SRR0(PowerPC::ppcState);
|
||||
m_end_block = true;
|
||||
interpreter.m_end_block = true;
|
||||
}
|
||||
|
||||
// sc isn't really used for anything important in GameCube games (just for a write barrier) so we
|
||||
@@ -136,5 +136,5 @@ void Interpreter::sc(Interpreter& interpreter, UGeckoInstruction inst)
|
||||
{
|
||||
PowerPC::ppcState.Exceptions |= EXCEPTION_SYSCALL;
|
||||
PowerPC::CheckExceptions();
|
||||
m_end_block = true;
|
||||
interpreter.m_end_block = true;
|
||||
}
|
||||
@@ -137,7 +137,7 @@ void Interpreter::twi(Interpreter& interpreter, UGeckoInstruction inst)
|
||||
{
|
||||
GenerateProgramException(ProgramExceptionCause::Trap);
|
||||
PowerPC::CheckExceptions();
|
||||
m_end_block = true; // Dunno about this
|
||||
interpreter.m_end_block = true; // Dunno about this
|
||||
}
|
||||
}
|
||||
|
||||
@@ -353,7 +353,7 @@ void Interpreter::tw(Interpreter& interpreter, UGeckoInstruction inst)
|
||||
{
|
||||
GenerateProgramException(ProgramExceptionCause::Trap);
|
||||
PowerPC::CheckExceptions();
|
||||
m_end_block = true; // Dunno about this
|
||||
interpreter.m_end_block = true; // Dunno about this
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -175,7 +175,7 @@ void Interpreter::mtmsr(Interpreter& interpreter, UGeckoInstruction inst)
|
||||
CheckFPExceptions(PowerPC::ppcState.fpscr);
|
||||
|
||||
PowerPC::CheckExceptions();
|
||||
m_end_block = true;
|
||||
interpreter.m_end_block = true;
|
||||
}
|
||||
|
||||
// Segment registers. MMU control.
|
||||
|
||||
Reference in new issue
Block a user