From 3006c23c85b4028cb63143f095f8017342b1cbce Mon Sep 17 00:00:00 2001 From: "Admiral H. Curtiss" Date: Sun, 12 Mar 2023 18:48:23 +0100 Subject: [PATCH] Core/CPUThreadGuard: Fetch System from Guard. --- Source/Core/Common/Debug/CodeTrace.cpp | 11 +++++----- Source/Core/Common/Debug/CodeTrace.h | 2 +- Source/Core/Core/Core.h | 2 ++ Source/Core/Core/HW/AddressSpace.cpp | 7 ++++--- Source/Core/Core/PowerPC/MMU.cpp | 29 +++++++++++++------------- 5 files changed, 28 insertions(+), 23 deletions(-) diff --git a/Source/Core/Common/Debug/CodeTrace.cpp b/Source/Core/Common/Debug/CodeTrace.cpp index 3023923fbb..49ad967382 100644 --- a/Source/Core/Common/Debug/CodeTrace.cpp +++ b/Source/Core/Common/Debug/CodeTrace.cpp @@ -8,6 +8,7 @@ #include #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 && diff --git a/Source/Core/Common/Debug/CodeTrace.h b/Source/Core/Common/Debug/CodeTrace.h index c47ae8e961..ae99b6d9a2 100644 --- a/Source/Core/Common/Debug/CodeTrace.h +++ b/Source/Core/Common/Debug/CodeTrace.h @@ -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; diff --git a/Source/Core/Core/Core.h b/Source/Core/Core/Core.h index 4dd0f7e32e..e237e25711 100644 --- a/Source/Core/Core/Core.h +++ b/Source/Core/Core/Core.h @@ -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; diff --git a/Source/Core/Core/HW/AddressSpace.cpp b/Source/Core/Core/HW/AddressSpace.cpp index b620f2ee7e..0bacf52c2d 100644 --- a/Source/Core/Core/HW/AddressSpace.cpp +++ b/Source/Core/Core/HW/AddressSpace.cpp @@ -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; } diff --git a/Source/Core/Core/PowerPC/MMU.cpp b/Source/Core/Core/PowerPC/MMU.cpp index 0a03195138..2b3706ae27 100644 --- a/Source/Core/Core/PowerPC/MMU.cpp +++ b/Source/Core/Core/PowerPC/MMU.cpp @@ -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(system, memory, address); } @@ -536,7 +537,7 @@ std::optional> 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> 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(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(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(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(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(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(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(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(system, memory, address, static_cast(var >> 32), 4); @@ -887,7 +888,7 @@ static std::optional 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)