Core/CPUThreadGuard: Fetch System from Guard.

This commit is contained in:
Admiral H. Curtiss 2023-03-12 18:48:23 +01:00
parent 31d33d0efd
commit 3006c23c85
No known key found for this signature in database
GPG Key ID: F051B4C4044F33FB
5 changed files with 28 additions and 23 deletions

View File

@ -8,6 +8,7 @@
#include <regex>
#include "Common/Event.h"
#include "Core/Core.h"
#include "Core/Debugger/PPCDebugInterface.h"
#include "Core/HW/CPU.h"
#include "Core/PowerPC/PowerPC.h"
@ -122,14 +123,14 @@ InstructionAttributes CodeTrace::GetInstructionAttributes(const TraceOutput& ins
return tmp_attributes;
}
TraceOutput CodeTrace::SaveCurrentInstruction(const Core::CPUThreadGuard* guard) const
TraceOutput CodeTrace::SaveCurrentInstruction(const Core::CPUThreadGuard& guard) const
{
auto& system = Core::System::GetInstance();
auto& system = guard.GetSystem();
auto& ppc_state = system.GetPPCState();
// Quickly save instruction and memory target for fast logging.
TraceOutput output;
const std::string instr = PowerPC::debug_interface.Disassemble(guard, ppc_state.pc);
const std::string instr = PowerPC::debug_interface.Disassemble(&guard, ppc_state.pc);
output.instruction = instr;
output.address = ppc_state.pc;
@ -147,7 +148,7 @@ AutoStepResults CodeTrace::AutoStepping(const Core::CPUThreadGuard& guard, bool
if (m_recording)
return results;
TraceOutput pc_instr = SaveCurrentInstruction(&guard);
TraceOutput pc_instr = SaveCurrentInstruction(guard);
const InstructionAttributes instr = GetInstructionAttributes(pc_instr);
// Not an instruction we should start autostepping from (ie branches).
@ -199,7 +200,7 @@ AutoStepResults CodeTrace::AutoStepping(const Core::CPUThreadGuard& guard, bool
{
PowerPC::SingleStep();
pc_instr = SaveCurrentInstruction(&guard);
pc_instr = SaveCurrentInstruction(guard);
hit = TraceLogic(pc_instr);
results.count += 1;
} while (clock::now() < timeout && hit < stop_condition &&

View File

@ -73,7 +73,7 @@ public:
private:
InstructionAttributes GetInstructionAttributes(const TraceOutput& line) const;
TraceOutput SaveCurrentInstruction(const Core::CPUThreadGuard* guard) const;
TraceOutput SaveCurrentInstruction(const Core::CPUThreadGuard& guard) const;
HitType TraceLogic(const TraceOutput& current_instr, bool first_hit = false);
bool m_recording = false;

View File

@ -116,6 +116,8 @@ public:
CPUThreadGuard& operator=(const CPUThreadGuard&) = delete;
CPUThreadGuard& operator=(CPUThreadGuard&&) = delete;
Core::System& GetSystem() const { return m_system; }
private:
Core::System& m_system;
const bool m_was_cpu_thread;

View File

@ -7,6 +7,7 @@
#include "Common/BitUtils.h"
#include "Core/ConfigManager.h"
#include "Core/Core.h"
#include "Core/HW/DSP.h"
#include "Core/HW/Memmap.h"
#include "Core/PowerPC/MMU.h"
@ -125,7 +126,7 @@ struct EffectiveAddressSpaceAccessors : Accessors
bool Matches(const Core::CPUThreadGuard& guard, u32 haystack_start, const u8* needle_start,
std::size_t needle_size) const
{
auto& system = Core::System::GetInstance();
auto& system = guard.GetSystem();
auto& memory = system.GetMemory();
u32 page_base = haystack_start & 0xfffff000;
@ -212,13 +213,13 @@ struct AuxiliaryAddressSpaceAccessors : Accessors
}
u8 ReadU8(const Core::CPUThreadGuard& guard, u32 address) const override
{
const u8* base = Core::System::GetInstance().GetDSP().GetARAMPtr();
const u8* base = guard.GetSystem().GetDSP().GetARAMPtr();
return base[address];
}
void WriteU8(const Core::CPUThreadGuard& guard, u32 address, u8 value) override
{
u8* base = Core::System::GetInstance().GetDSP().GetARAMPtr();
u8* base = guard.GetSystem().GetDSP().GetARAMPtr();
base[address] = value;
}

View File

@ -15,6 +15,7 @@
#include "Common/Logging/Log.h"
#include "Core/ConfigManager.h"
#include "Core/Core.h"
#include "Core/HW/CPU.h"
#include "Core/HW/GPFifo.h"
#include "Core/HW/MMIO.h"
@ -524,7 +525,7 @@ TryReadInstResult TryReadInstruction(u32 address)
u32 HostRead_Instruction(const Core::CPUThreadGuard& guard, const u32 address)
{
auto& system = Core::System::GetInstance();
auto& system = guard.GetSystem();
auto& memory = system.GetMemory();
return ReadFromHardware<XCheckTLBFlag::OpcodeNoException, u32>(system, memory, address);
}
@ -536,7 +537,7 @@ std::optional<ReadResult<u32>> HostTryReadInstruction(const Core::CPUThreadGuard
if (!HostIsInstructionRAMAddress(guard, address, space))
return std::nullopt;
auto& system = Core::System::GetInstance();
auto& system = guard.GetSystem();
auto& memory = system.GetMemory();
switch (space)
@ -660,7 +661,7 @@ static std::optional<ReadResult<T>> HostTryReadUX(const Core::CPUThreadGuard& gu
if (!HostIsRAMAddress(guard, address, space))
return std::nullopt;
auto& system = Core::System::GetInstance();
auto& system = guard.GetSystem();
auto& memory = system.GetMemory();
switch (space)
@ -795,28 +796,28 @@ void Write_F64(const double var, const u32 address)
u8 HostRead_U8(const Core::CPUThreadGuard& guard, const u32 address)
{
auto& system = Core::System::GetInstance();
auto& system = guard.GetSystem();
auto& memory = system.GetMemory();
return ReadFromHardware<XCheckTLBFlag::NoException, u8>(system, memory, address);
}
u16 HostRead_U16(const Core::CPUThreadGuard& guard, const u32 address)
{
auto& system = Core::System::GetInstance();
auto& system = guard.GetSystem();
auto& memory = system.GetMemory();
return ReadFromHardware<XCheckTLBFlag::NoException, u16>(system, memory, address);
}
u32 HostRead_U32(const Core::CPUThreadGuard& guard, const u32 address)
{
auto& system = Core::System::GetInstance();
auto& system = guard.GetSystem();
auto& memory = system.GetMemory();
return ReadFromHardware<XCheckTLBFlag::NoException, u32>(system, memory, address);
}
u64 HostRead_U64(const Core::CPUThreadGuard& guard, const u32 address)
{
auto& system = Core::System::GetInstance();
auto& system = guard.GetSystem();
auto& memory = system.GetMemory();
return ReadFromHardware<XCheckTLBFlag::NoException, u64>(system, memory, address);
}
@ -837,28 +838,28 @@ double HostRead_F64(const Core::CPUThreadGuard& guard, const u32 address)
void HostWrite_U8(const Core::CPUThreadGuard& guard, const u32 var, const u32 address)
{
auto& system = Core::System::GetInstance();
auto& system = guard.GetSystem();
auto& memory = system.GetMemory();
WriteToHardware<XCheckTLBFlag::NoException>(system, memory, address, var, 1);
}
void HostWrite_U16(const Core::CPUThreadGuard& guard, const u32 var, const u32 address)
{
auto& system = Core::System::GetInstance();
auto& system = guard.GetSystem();
auto& memory = system.GetMemory();
WriteToHardware<XCheckTLBFlag::NoException>(system, memory, address, var, 2);
}
void HostWrite_U32(const Core::CPUThreadGuard& guard, const u32 var, const u32 address)
{
auto& system = Core::System::GetInstance();
auto& system = guard.GetSystem();
auto& memory = system.GetMemory();
WriteToHardware<XCheckTLBFlag::NoException>(system, memory, address, var, 4);
}
void HostWrite_U64(const Core::CPUThreadGuard& guard, const u64 var, const u32 address)
{
auto& system = Core::System::GetInstance();
auto& system = guard.GetSystem();
auto& memory = system.GetMemory();
WriteToHardware<XCheckTLBFlag::NoException>(system, memory, address, static_cast<u32>(var >> 32),
4);
@ -887,7 +888,7 @@ static std::optional<WriteResult> HostTryWriteUX(const Core::CPUThreadGuard& gua
if (!HostIsRAMAddress(guard, address, space))
return std::nullopt;
auto& system = Core::System::GetInstance();
auto& system = guard.GetSystem();
auto& memory = system.GetMemory();
switch (space)
@ -1041,7 +1042,7 @@ static bool IsRAMAddress(Memory::MemoryManager& memory, u32 address, bool transl
bool HostIsRAMAddress(const Core::CPUThreadGuard& guard, u32 address, RequestedAddressSpace space)
{
auto& system = Core::System::GetInstance();
auto& system = guard.GetSystem();
auto& memory = system.GetMemory();
switch (space)
@ -1067,7 +1068,7 @@ bool HostIsInstructionRAMAddress(const Core::CPUThreadGuard& guard, u32 address,
if (address & 3)
return false;
auto& system = Core::System::GetInstance();
auto& system = guard.GetSystem();
auto& memory = system.GetMemory();
switch (space)