37 changes: 20 additions & 17 deletions Source/Core/Core/HW/EXI/EXI_Device.cpp
Expand Up @@ -19,6 +19,10 @@

namespace ExpansionInterface
{
IEXIDevice::IEXIDevice(Core::System& system) : m_system(system)
{
}

void IEXIDevice::ImmWrite(u32 data, u32 size)
{
while (size--)
Expand Down Expand Up @@ -48,8 +52,7 @@ void IEXIDevice::ImmReadWrite(u32& data, u32 size)

void IEXIDevice::DMAWrite(u32 address, u32 size)
{
auto& system = Core::System::GetInstance();
auto& memory = system.GetMemory();
auto& memory = m_system.GetMemory();
while (size--)
{
u8 byte = memory.Read_U8(address++);
Expand All @@ -59,8 +62,7 @@ void IEXIDevice::DMAWrite(u32 address, u32 size)

void IEXIDevice::DMARead(u32 address, u32 size)
{
auto& system = Core::System::GetInstance();
auto& memory = system.GetMemory();
auto& memory = m_system.GetMemory();
while (size--)
{
u8 byte = 0;
Expand Down Expand Up @@ -101,7 +103,8 @@ void IEXIDevice::TransferByte(u8& byte)
}

// F A C T O R Y
std::unique_ptr<IEXIDevice> EXIDevice_Create(const EXIDeviceType device_type, const int channel_num,
std::unique_ptr<IEXIDevice> EXIDevice_Create(Core::System& system, const EXIDeviceType device_type,
const int channel_num,
const Memcard::HeaderData& memcard_header_data)
{
std::unique_ptr<IEXIDevice> result;
Expand All @@ -112,58 +115,58 @@ std::unique_ptr<IEXIDevice> EXIDevice_Create(const EXIDeviceType device_type, co
switch (device_type)
{
case EXIDeviceType::Dummy:
result = std::make_unique<CEXIDummy>("Dummy");
result = std::make_unique<CEXIDummy>(system, "Dummy");
break;

case EXIDeviceType::MemoryCard:
case EXIDeviceType::MemoryCardFolder:
{
bool gci_folder = (device_type == EXIDeviceType::MemoryCardFolder);
result = std::make_unique<CEXIMemoryCard>(slot, gci_folder, memcard_header_data);
result = std::make_unique<CEXIMemoryCard>(system, slot, gci_folder, memcard_header_data);
break;
}
case EXIDeviceType::MaskROM:
result = std::make_unique<CEXIIPL>();
result = std::make_unique<CEXIIPL>(system);
break;

case EXIDeviceType::AD16:
result = std::make_unique<CEXIAD16>();
result = std::make_unique<CEXIAD16>(system);
break;

case EXIDeviceType::Microphone:
result = std::make_unique<CEXIMic>(channel_num);
result = std::make_unique<CEXIMic>(system, channel_num);
break;

case EXIDeviceType::Ethernet:
result = std::make_unique<CEXIETHERNET>(BBADeviceType::TAP);
result = std::make_unique<CEXIETHERNET>(system, BBADeviceType::TAP);
break;

#if defined(__APPLE__)
case EXIDeviceType::EthernetTapServer:
result = std::make_unique<CEXIETHERNET>(BBADeviceType::TAPSERVER);
result = std::make_unique<CEXIETHERNET>(system, BBADeviceType::TAPSERVER);
break;
#endif

case EXIDeviceType::EthernetXLink:
result = std::make_unique<CEXIETHERNET>(BBADeviceType::XLINK);
result = std::make_unique<CEXIETHERNET>(system, BBADeviceType::XLINK);
break;

case EXIDeviceType::EthernetBuiltIn:
result = std::make_unique<CEXIETHERNET>(BBADeviceType::BuiltIn);
result = std::make_unique<CEXIETHERNET>(system, BBADeviceType::BuiltIn);
break;

case EXIDeviceType::Gecko:
result = std::make_unique<CEXIGecko>();
result = std::make_unique<CEXIGecko>(system);
break;

case EXIDeviceType::AGP:
result = std::make_unique<CEXIAgp>(slot);
result = std::make_unique<CEXIAgp>(system, slot);
break;

case EXIDeviceType::AMBaseboard:
case EXIDeviceType::None:
default:
result = std::make_unique<IEXIDevice>();
result = std::make_unique<IEXIDevice>(system);
break;
}

Expand Down
11 changes: 10 additions & 1 deletion Source/Core/Core/HW/EXI/EXI_Device.h
Expand Up @@ -11,6 +11,10 @@

class PointerWrap;

namespace Core
{
class System;
}
namespace Memcard
{
struct HeaderData;
Expand Down Expand Up @@ -44,6 +48,7 @@ enum class EXIDeviceType : int
class IEXIDevice
{
public:
explicit IEXIDevice(Core::System& system);
virtual ~IEXIDevice() = default;

// Immediate copy functions
Expand All @@ -69,12 +74,16 @@ class IEXIDevice
// such.
EXIDeviceType m_device_type = EXIDeviceType::None;

protected:
Core::System& m_system;

private:
// Byte transfer function for this device
virtual void TransferByte(u8& byte);
};

std::unique_ptr<IEXIDevice> EXIDevice_Create(EXIDeviceType device_type, int channel_num,
std::unique_ptr<IEXIDevice> EXIDevice_Create(Core::System& system, EXIDeviceType device_type,
int channel_num,
const Memcard::HeaderData& memcard_header_data);
} // namespace ExpansionInterface

Expand Down
4 changes: 3 additions & 1 deletion Source/Core/Core/HW/EXI/EXI_DeviceAD16.cpp
Expand Up @@ -9,7 +9,9 @@

namespace ExpansionInterface
{
CEXIAD16::CEXIAD16() = default;
CEXIAD16::CEXIAD16(Core::System& system) : IEXIDevice(system)
{
}

void CEXIAD16::SetCS(int cs)
{
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/Core/HW/EXI/EXI_DeviceAD16.h
Expand Up @@ -12,7 +12,7 @@ namespace ExpansionInterface
class CEXIAD16 : public IEXIDevice
{
public:
CEXIAD16();
explicit CEXIAD16(Core::System& system);
void SetCS(int cs) override;
bool IsPresent() const override;
void DoState(PointerWrap& p) override;
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/Core/HW/EXI/EXI_DeviceAGP.cpp
Expand Up @@ -19,7 +19,7 @@

namespace ExpansionInterface
{
CEXIAgp::CEXIAgp(Slot slot)
CEXIAgp::CEXIAgp(Core::System& system, Slot slot) : IEXIDevice(system)
{
ASSERT(IsMemcardSlot(slot));
m_slot = slot;
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/Core/HW/EXI/EXI_DeviceAGP.h
Expand Up @@ -17,7 +17,7 @@ enum class Slot : int;
class CEXIAgp : public IEXIDevice
{
public:
CEXIAgp(const Slot slot);
CEXIAgp(Core::System& system, const Slot slot);
virtual ~CEXIAgp() override;
bool IsPresent() const override { return true; }
void ImmWrite(u32 _uData, u32 _uSize) override;
Expand Down
3 changes: 2 additions & 1 deletion Source/Core/Core/HW/EXI/EXI_DeviceDummy.cpp
Expand Up @@ -10,7 +10,8 @@

namespace ExpansionInterface
{
CEXIDummy::CEXIDummy(const std::string& name) : m_name{name}
CEXIDummy::CEXIDummy(Core::System& system, const std::string& name)
: IEXIDevice(system), m_name{name}
{
}

Expand Down
2 changes: 1 addition & 1 deletion Source/Core/Core/HW/EXI/EXI_DeviceDummy.h
Expand Up @@ -16,7 +16,7 @@ namespace ExpansionInterface
class CEXIDummy final : public IEXIDevice
{
public:
explicit CEXIDummy(const std::string& name);
CEXIDummy(Core::System& system, const std::string& name);

void ImmWrite(u32 data, u32 size) override;
u32 ImmRead(u32 size) override;
Expand Down
8 changes: 3 additions & 5 deletions Source/Core/Core/HW/EXI/EXI_DeviceEthernet.cpp
Expand Up @@ -27,7 +27,7 @@ namespace ExpansionInterface
// Multiple parts of this implementation depend on Dolphin
// being compiled for a little endian host.

CEXIETHERNET::CEXIETHERNET(BBADeviceType type)
CEXIETHERNET::CEXIETHERNET(Core::System& system, BBADeviceType type) : IEXIDevice(system)
{
// Parse MAC address from config, and generate a new one if it doesn't
// exist or can't be parsed.
Expand Down Expand Up @@ -233,8 +233,7 @@ void CEXIETHERNET::DMAWrite(u32 addr, u32 size)
if (transfer.region == transfer.MX && transfer.direction == transfer.WRITE &&
transfer.address == BBA_WRTXFIFOD)
{
auto& system = Core::System::GetInstance();
auto& memory = system.GetMemory();
auto& memory = m_system.GetMemory();
DirectFIFOWrite(memory.GetPointer(addr), size);
}
else
Expand All @@ -248,8 +247,7 @@ void CEXIETHERNET::DMAWrite(u32 addr, u32 size)
void CEXIETHERNET::DMARead(u32 addr, u32 size)
{
DEBUG_LOG_FMT(SP1, "DMA read: {:08x} {:x}", addr, size);
auto& system = Core::System::GetInstance();
auto& memory = system.GetMemory();
auto& memory = m_system.GetMemory();
memory.CopyToEmu(addr, &mBbaMem[transfer.address], size);
transfer.address += size;
}
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/Core/HW/EXI/EXI_DeviceEthernet.h
Expand Up @@ -214,7 +214,7 @@ enum class BBADeviceType
class CEXIETHERNET : public IEXIDevice
{
public:
explicit CEXIETHERNET(BBADeviceType type);
CEXIETHERNET(Core::System& system, BBADeviceType type);
virtual ~CEXIETHERNET();
void SetCS(int cs) override;
bool IsPresent() const override;
Expand Down
4 changes: 4 additions & 0 deletions Source/Core/Core/HW/EXI/EXI_DeviceGecko.cpp
Expand Up @@ -159,6 +159,10 @@ void GeckoSockServer::ClientThread()
client->disconnect();
}

CEXIGecko::CEXIGecko(Core::System& system) : IEXIDevice(system)
{
}

void CEXIGecko::ImmReadWrite(u32& _uData, u32 _uSize)
{
// We don't really care about _uSize
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/Core/HW/EXI/EXI_DeviceGecko.h
Expand Up @@ -49,7 +49,7 @@ class GeckoSockServer
class CEXIGecko : public IEXIDevice, private GeckoSockServer
{
public:
CEXIGecko() {}
explicit CEXIGecko(Core::System& system);
bool IsPresent() const override { return true; }
void ImmReadWrite(u32& _uData, u32 _uSize) override;

Expand Down
20 changes: 9 additions & 11 deletions Source/Core/Core/HW/EXI/EXI_DeviceIPL.cpp
Expand Up @@ -99,7 +99,7 @@ void CEXIIPL::Descrambler(u8* data, u32 size)
}
}

CEXIIPL::CEXIIPL()
CEXIIPL::CEXIIPL(Core::System& system) : IEXIDevice(system)
{
// Fill the ROM
m_rom = std::make_unique<u8[]>(ROM_SIZE);
Expand Down Expand Up @@ -130,7 +130,7 @@ CEXIIPL::CEXIIPL()
LoadFontFile((File::GetSysDirectory() + GC_SYS_DIR + DIR_SEP + FONT_WINDOWS_1252), 0x1fcf00);
}

auto& sram = Core::System::GetInstance().GetSRAM();
auto& sram = system.GetSRAM();

// Clear RTC
sram.rtc = 0;
Expand All @@ -146,7 +146,7 @@ CEXIIPL::~CEXIIPL() = default;

void CEXIIPL::DoState(PointerWrap& p)
{
auto& sram = Core::System::GetInstance().GetSRAM();
auto& sram = m_system.GetSRAM();

p.Do(sram);
p.Do(g_rtc_flags);
Expand Down Expand Up @@ -251,8 +251,8 @@ void CEXIIPL::SetCS(int cs)

void CEXIIPL::UpdateRTC()
{
auto& sram = Core::System::GetInstance().GetSRAM();
sram.rtc = GetEmulatedTime(GC_EPOCH);
auto& sram = m_system.GetSRAM();
sram.rtc = GetEmulatedTime(m_system, GC_EPOCH);
}

bool CEXIIPL::IsPresent() const
Expand Down Expand Up @@ -342,7 +342,7 @@ void CEXIIPL::TransferByte(u8& data)
}
else if (IN_RANGE(SRAM))
{
auto& sram = Core::System::GetInstance().GetSRAM();
auto& sram = m_system.GetSRAM();
u32 dev_addr = DEV_ADDR_CURSOR(SRAM);
if (m_command.is_write())
sram[dev_addr] = data;
Expand Down Expand Up @@ -396,7 +396,7 @@ void CEXIIPL::TransferByte(u8& data)
}
}

u32 CEXIIPL::GetEmulatedTime(u32 epoch)
u32 CEXIIPL::GetEmulatedTime(Core::System& system, u32 epoch)
{
u64 ltime = 0;

Expand All @@ -405,16 +405,14 @@ u32 CEXIIPL::GetEmulatedTime(u32 epoch)
ltime = Movie::GetRecordingStartTime();

// let's keep time moving forward, regardless of what it starts at
ltime +=
Core::System::GetInstance().GetCoreTiming().GetTicks() / SystemTimers::GetTicksPerSecond();
ltime += system.GetCoreTiming().GetTicks() / SystemTimers::GetTicksPerSecond();
}
else if (NetPlay::IsNetPlayRunning())
{
ltime = NetPlay_GetEmulatedTime();

// let's keep time moving forward, regardless of what it starts at
ltime +=
Core::System::GetInstance().GetCoreTiming().GetTicks() / SystemTimers::GetTicksPerSecond();
ltime += system.GetCoreTiming().GetTicks() / SystemTimers::GetTicksPerSecond();
}
else
{
Expand Down
4 changes: 2 additions & 2 deletions Source/Core/Core/HW/EXI/EXI_DeviceIPL.h
Expand Up @@ -16,7 +16,7 @@ namespace ExpansionInterface
class CEXIIPL : public IEXIDevice
{
public:
CEXIIPL();
explicit CEXIIPL(Core::System& system);
~CEXIIPL() override;

void SetCS(int cs) override;
Expand All @@ -26,7 +26,7 @@ class CEXIIPL : public IEXIDevice
static constexpr u32 UNIX_EPOCH = 0; // 1970-01-01 00:00:00
static constexpr u32 GC_EPOCH = 0x386D4380; // 2000-01-01 00:00:00

static u32 GetEmulatedTime(u32 epoch);
static u32 GetEmulatedTime(Core::System& system, u32 epoch);
static u64 NetPlay_GetEmulatedTime();

static void Descrambler(u8* data, u32 size);
Expand Down
22 changes: 9 additions & 13 deletions Source/Core/Core/HW/EXI/EXI_DeviceMemoryCard.cpp
Expand Up @@ -104,9 +104,9 @@ void CEXIMemoryCard::Shutdown()
s_et_transfer_complete.fill(nullptr);
}

CEXIMemoryCard::CEXIMemoryCard(const Slot slot, bool gci_folder,
CEXIMemoryCard::CEXIMemoryCard(Core::System& system, const Slot slot, bool gci_folder,
const Memcard::HeaderData& header_data)
: m_card_slot(slot)
: IEXIDevice(system), m_card_slot(slot)
{
ASSERT_MSG(EXPANSIONINTERFACE, IsMemcardSlot(slot), "Trying to create invalid memory card in {}.",
slot);
Expand Down Expand Up @@ -144,7 +144,7 @@ CEXIMemoryCard::CEXIMemoryCard(const Slot slot, bool gci_folder,
m_memory_card_size = m_memory_card->GetCardId() * SIZE_TO_Mb;
std::array<u8, 20> header{};
m_memory_card->Read(0, static_cast<s32>(header.size()), header.data());
auto& sram = Core::System::GetInstance().GetSRAM();
auto& sram = system.GetSRAM();
SetCardFlashID(&sram, header.data(), m_card_slot);
}

Expand Down Expand Up @@ -235,8 +235,7 @@ void CEXIMemoryCard::SetupRawMemcard(u16 size_mb)

CEXIMemoryCard::~CEXIMemoryCard()
{
auto& system = Core::System::GetInstance();
auto& core_timing = system.GetCoreTiming();
auto& core_timing = m_system.GetCoreTiming();
core_timing.RemoveEvent(s_et_cmd_done[m_card_slot]);
core_timing.RemoveEvent(s_et_transfer_complete[m_card_slot]);
}
Expand Down Expand Up @@ -269,8 +268,7 @@ void CEXIMemoryCard::TransferComplete()

void CEXIMemoryCard::CmdDoneLater(u64 cycles)
{
auto& system = Core::System::GetInstance();
auto& core_timing = system.GetCoreTiming();
auto& core_timing = m_system.GetCoreTiming();
core_timing.RemoveEvent(s_et_cmd_done[m_card_slot]);
core_timing.ScheduleEvent(cycles, s_et_cmd_done[m_card_slot], static_cast<u64>(m_card_slot));
}
Expand Down Expand Up @@ -523,8 +521,7 @@ void CEXIMemoryCard::DoState(PointerWrap& p)
// read all at once instead of single byte at a time as done by IEXIDevice::DMARead
void CEXIMemoryCard::DMARead(u32 addr, u32 size)
{
auto& system = Core::System::GetInstance();
auto& memory = system.GetMemory();
auto& memory = m_system.GetMemory();
m_memory_card->Read(m_address, size, memory.GetPointer(addr));

if ((m_address + size) % Memcard::BLOCK_SIZE == 0)
Expand All @@ -533,7 +530,7 @@ void CEXIMemoryCard::DMARead(u32 addr, u32 size)
}

// Schedule transfer complete later based on read speed
system.GetCoreTiming().ScheduleEvent(
m_system.GetCoreTiming().ScheduleEvent(
size * (SystemTimers::GetTicksPerSecond() / MC_TRANSFER_RATE_READ),
s_et_transfer_complete[m_card_slot], static_cast<u64>(m_card_slot));
}
Expand All @@ -542,8 +539,7 @@ void CEXIMemoryCard::DMARead(u32 addr, u32 size)
// write all at once instead of single byte at a time as done by IEXIDevice::DMAWrite
void CEXIMemoryCard::DMAWrite(u32 addr, u32 size)
{
auto& system = Core::System::GetInstance();
auto& memory = system.GetMemory();
auto& memory = m_system.GetMemory();
m_memory_card->Write(m_address, size, memory.GetPointer(addr));

if (((m_address + size) % Memcard::BLOCK_SIZE) == 0)
Expand All @@ -552,7 +548,7 @@ void CEXIMemoryCard::DMAWrite(u32 addr, u32 size)
}

// Schedule transfer complete later based on write speed
system.GetCoreTiming().ScheduleEvent(
m_system.GetCoreTiming().ScheduleEvent(
size * (SystemTimers::GetTicksPerSecond() / MC_TRANSFER_RATE_WRITE),
s_et_transfer_complete[m_card_slot], static_cast<u64>(m_card_slot));
}
Expand Down
3 changes: 2 additions & 1 deletion Source/Core/Core/HW/EXI/EXI_DeviceMemoryCard.h
Expand Up @@ -36,7 +36,8 @@ enum class AllowMovieFolder
class CEXIMemoryCard : public IEXIDevice
{
public:
CEXIMemoryCard(Slot slot, bool gci_folder, const Memcard::HeaderData& header_data);
CEXIMemoryCard(Core::System& system, Slot slot, bool gci_folder,
const Memcard::HeaderData& header_data);
~CEXIMemoryCard() override;
void SetCS(int cs) override;
bool IsInterruptSet() override;
Expand Down
8 changes: 4 additions & 4 deletions Source/Core/Core/HW/EXI/EXI_DeviceMic.cpp
Expand Up @@ -196,8 +196,8 @@ void CEXIMic::StreamReadOne()

u8 const CEXIMic::exi_id[] = {0, 0x0a, 0, 0, 0};

CEXIMic::CEXIMic(int index)
: slot(index)
CEXIMic::CEXIMic(Core::System& system, int index)
: IEXIDevice(system), slot(index)
#ifdef _WIN32
,
m_work_queue("Mic Worker", [](const std::function<void()>& func) { func(); })
Expand Down Expand Up @@ -265,13 +265,13 @@ void CEXIMic::SetCS(int cs)
void CEXIMic::UpdateNextInterruptTicks()
{
int diff = (SystemTimers::GetTicksPerSecond() / sample_rate) * buff_size_samples;
next_int_ticks = Core::System::GetInstance().GetCoreTiming().GetTicks() + diff;
next_int_ticks = m_system.GetCoreTiming().GetTicks() + diff;
ExpansionInterface::ScheduleUpdateInterrupts(CoreTiming::FromThread::CPU, diff);
}

bool CEXIMic::IsInterruptSet()
{
if (next_int_ticks && Core::System::GetInstance().GetCoreTiming().GetTicks() >= next_int_ticks)
if (next_int_ticks && m_system.GetCoreTiming().GetTicks() >= next_int_ticks)
{
if (status.is_active)
UpdateNextInterruptTicks();
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/Core/HW/EXI/EXI_DeviceMic.h
Expand Up @@ -17,7 +17,7 @@ namespace ExpansionInterface
class CEXIMic : public IEXIDevice
{
public:
CEXIMic(const int index);
CEXIMic(Core::System& system, const int index);
virtual ~CEXIMic();
void SetCS(int cs) override;
bool IsInterruptSet() override;
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/Core/HW/SystemTimers.cpp
Expand Up @@ -284,7 +284,7 @@ void Init()

core_timing.SetFakeTBStartValue(static_cast<u64>(s_cpu_core_clock / TIMER_RATIO) *
static_cast<u64>(ExpansionInterface::CEXIIPL::GetEmulatedTime(
ExpansionInterface::CEXIIPL::GC_EPOCH)));
system, ExpansionInterface::CEXIIPL::GC_EPOCH)));

core_timing.SetFakeTBStartTicks(core_timing.GetTicks());

Expand Down
8 changes: 5 additions & 3 deletions Source/Core/Core/IOS/ES/ES.cpp
Expand Up @@ -362,7 +362,8 @@ bool ESDevice::LaunchIOS(u64 ios_title_id, HangPPC hang_ppc)
const ES::TicketReader ticket = FindSignedTicket(ios_title_id);
ES::Content content;
if (!tmd.IsValid() || !ticket.IsValid() || !tmd.GetContent(tmd.GetBootIndex(), &content) ||
!m_ios.BootIOS(ios_title_id, hang_ppc, GetContentPath(ios_title_id, content)))
!m_ios.BootIOS(Core::System::GetInstance(), ios_title_id, hang_ppc,
GetContentPath(ios_title_id, content)))
{
PanicAlertFmtT("Could not launch IOS {0:016x} because it is missing from the NAND.\n"
"The emulated software will likely hang now.",
Expand All @@ -372,7 +373,7 @@ bool ESDevice::LaunchIOS(u64 ios_title_id, HangPPC hang_ppc)
return true;
}

return m_ios.BootIOS(ios_title_id, hang_ppc);
return m_ios.BootIOS(Core::System::GetInstance(), ios_title_id, hang_ppc);
}

s32 ESDevice::WriteLaunchFile(const ES::TMDReader& tmd, Ticks ticks)
Expand Down Expand Up @@ -471,7 +472,8 @@ bool ESDevice::LaunchPPCTitle(u64 title_id)

bool ESDevice::BootstrapPPC()
{
const bool result = m_ios.BootstrapPPC(m_pending_ppc_boot_content_path);
const bool result =
m_ios.BootstrapPPC(Core::System::GetInstance(), m_pending_ppc_boot_content_path);
m_pending_ppc_boot_content_path = {};
return result;
}
Expand Down
18 changes: 9 additions & 9 deletions Source/Core/Core/IOS/IOS.cpp
Expand Up @@ -403,7 +403,7 @@ static std::vector<u8> ReadBootContent(FSDevice* fs, const std::string& path, si

// This corresponds to syscall 0x41, which loads a binary from the NAND and bootstraps the PPC.
// Unlike 0x42, IOS will set up some constants in memory before booting the PPC.
bool Kernel::BootstrapPPC(const std::string& boot_content_path)
bool Kernel::BootstrapPPC(Core::System& system, const std::string& boot_content_path)
{
// Seeking and processing overhead is ignored as most time is spent reading from the NAND.
u64 ticks = 0;
Expand All @@ -422,12 +422,11 @@ bool Kernel::BootstrapPPC(const std::string& boot_content_path)
if (dol.IsAncast())
INFO_LOG_FMT(IOS, "BootstrapPPC: Loading ancast image");

if (!dol.LoadIntoMemory())
if (!dol.LoadIntoMemory(system))
return false;

INFO_LOG_FMT(IOS, "BootstrapPPC: {}", boot_content_path);
Core::System::GetInstance().GetCoreTiming().ScheduleEvent(ticks, s_event_finish_ppc_bootstrap,
dol.IsAncast());
system.GetCoreTiming().ScheduleEvent(ticks, s_event_finish_ppc_bootstrap, dol.IsAncast());
return true;
}

Expand Down Expand Up @@ -478,7 +477,8 @@ static constexpr SystemTimers::TimeBaseTick GetIOSBootTicks(u32 version)
// Passing a boot content path is optional because we do not require IOSes
// to be installed at the moment. If one is passed, the boot binary must exist
// on the NAND, or the call will fail like on a Wii.
bool Kernel::BootIOS(const u64 ios_title_id, HangPPC hang_ppc, const std::string& boot_content_path)
bool Kernel::BootIOS(Core::System& system, const u64 ios_title_id, HangPPC hang_ppc,
const std::string& boot_content_path)
{
// IOS suspends regular PPC<->ARM IPC before loading a new IOS.
// IPC is not resumed if the boot fails for any reason.
Expand All @@ -494,7 +494,7 @@ bool Kernel::BootIOS(const u64 ios_title_id, HangPPC hang_ppc, const std::string
return false;

ElfReader elf{binary.GetElf()};
if (!elf.LoadIntoMemory(true))
if (!elf.LoadIntoMemory(system, true))
return false;
}

Expand All @@ -503,8 +503,8 @@ bool Kernel::BootIOS(const u64 ios_title_id, HangPPC hang_ppc, const std::string

if (Core::IsRunningAndStarted())
{
Core::System::GetInstance().GetCoreTiming().ScheduleEvent(
GetIOSBootTicks(GetVersion()), s_event_finish_ios_boot, ios_title_id);
system.GetCoreTiming().ScheduleEvent(GetIOSBootTicks(GetVersion()), s_event_finish_ios_boot,
ios_title_id);
}
else
{
Expand Down Expand Up @@ -914,7 +914,7 @@ static void FinishPPCBootstrap(Core::System& system, u64 userdata, s64 cycles_la
ReleasePPC();

ASSERT(Core::IsCPUThread());
Core::CPUThreadGuard guard;
Core::CPUThreadGuard guard(system);
SConfig::OnNewTitleLoad(guard);

INFO_LOG_FMT(IOS, "Bootstrapping done.");
Expand Down
9 changes: 7 additions & 2 deletions Source/Core/Core/IOS/IOS.h
Expand Up @@ -20,6 +20,11 @@

class PointerWrap;

namespace Core
{
class System;
}

namespace IOS::HLE
{
namespace FS
Expand Down Expand Up @@ -134,8 +139,8 @@ class Kernel
void SetGidForPPC(u16 gid);
u16 GetGidForPPC() const;

bool BootstrapPPC(const std::string& boot_content_path);
bool BootIOS(u64 ios_title_id, HangPPC hang_ppc = HangPPC::No,
bool BootstrapPPC(Core::System& system, const std::string& boot_content_path);
bool BootIOS(Core::System& system, u64 ios_title_id, HangPPC hang_ppc = HangPPC::No,
const std::string& boot_content_path = {});
void InitIPC();
u32 GetVersion() const;
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/Core/IOS/MIOS.cpp
Expand Up @@ -61,7 +61,7 @@ bool Load()
auto& memory = system.GetMemory();

ASSERT(Core::IsCPUThread());
Core::CPUThreadGuard guard;
Core::CPUThreadGuard guard(system);

memory.Write_U32(0x00000000, ADDRESS_INIT_SEMAPHORE);
memory.Write_U32(0x09142001, 0x3180);
Expand Down
6 changes: 4 additions & 2 deletions Source/Core/Core/IOS/Network/KD/NetKDTime.cpp
Expand Up @@ -91,7 +91,8 @@ u64 NetKDTimeDevice::GetAdjustedUTC() const
{
using namespace ExpansionInterface;

const time_t current_time = CEXIIPL::GetEmulatedTime(CEXIIPL::UNIX_EPOCH);
const time_t current_time =
CEXIIPL::GetEmulatedTime(Core::System::GetInstance(), CEXIIPL::UNIX_EPOCH);
tm* const gm_time = gmtime(&current_time);
const u32 emulated_time = mktime(gm_time);
return u64(s64(emulated_time) + utcdiff);
Expand All @@ -101,7 +102,8 @@ void NetKDTimeDevice::SetAdjustedUTC(u64 wii_utc)
{
using namespace ExpansionInterface;

const time_t current_time = CEXIIPL::GetEmulatedTime(CEXIIPL::UNIX_EPOCH);
const time_t current_time =
CEXIIPL::GetEmulatedTime(Core::System::GetInstance(), CEXIIPL::UNIX_EPOCH);
tm* const gm_time = gmtime(&current_time);
const u32 emulated_time = mktime(gm_time);
utcdiff = s64(emulated_time - wii_utc);
Expand Down
3 changes: 2 additions & 1 deletion Source/Core/Core/Movie.cpp
Expand Up @@ -201,7 +201,8 @@ std::string GetRTCDisplay()
{
using ExpansionInterface::CEXIIPL;

const time_t current_time = CEXIIPL::GetEmulatedTime(CEXIIPL::UNIX_EPOCH);
const time_t current_time =
CEXIIPL::GetEmulatedTime(Core::System::GetInstance(), CEXIIPL::UNIX_EPOCH);
const tm* const gm_time = gmtime(&current_time);

std::ostringstream format_time;
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/Core/PatchEngine.cpp
Expand Up @@ -322,7 +322,7 @@ bool ApplyFramePatches()
auto& ppc_state = system.GetPPCState();

ASSERT(Core::IsCPUThread());
Core::CPUThreadGuard guard;
Core::CPUThreadGuard guard(system);

// Because we're using the VI Interrupt to time this instead of patching the game with a
// callback hook we can end up catching the game in an exception vector.
Expand Down
11 changes: 6 additions & 5 deletions Source/Core/Core/PowerPC/Expression.cpp
Expand Up @@ -83,7 +83,7 @@ static double HostReadFunc(expr_func* f, vec_expr_t* args, void* c)
return 0;
const u32 address = static_cast<u32>(expr_eval(&vec_nth(args, 0)));

Core::CPUThreadGuard guard;
Core::CPUThreadGuard guard(Core::System::GetInstance());
return Common::BitCast<T>(HostRead<U>(guard, address));
}

Expand All @@ -95,7 +95,7 @@ static double HostWriteFunc(expr_func* f, vec_expr_t* args, void* c)
const T var = static_cast<T>(expr_eval(&vec_nth(args, 0)));
const u32 address = static_cast<u32>(expr_eval(&vec_nth(args, 1)));

Core::CPUThreadGuard guard;
Core::CPUThreadGuard guard(Core::System::GetInstance());
HostWrite<U>(guard, Common::BitCast<U>(var), address);
return var;
}
Expand All @@ -115,8 +115,9 @@ static double CallstackFunc(expr_func* f, vec_expr_t* args, void* c)

std::vector<Dolphin_Debugger::CallstackEntry> stack;
{
Core::CPUThreadGuard guard;
bool success = Dolphin_Debugger::GetCallstack(Core::System::GetInstance(), guard, stack);
auto& system = Core::System::GetInstance();
Core::CPUThreadGuard guard(system);
bool success = Dolphin_Debugger::GetCallstack(system, guard, stack);
if (!success)
return 0;
}
Expand Down Expand Up @@ -163,7 +164,7 @@ static double StreqFunc(expr_func* f, vec_expr_t* args, void* c)
return 0;

std::array<std::string, 2> strs;
Core::CPUThreadGuard guard;
Core::CPUThreadGuard guard(Core::System::GetInstance());
for (int i = 0; i < 2; i++)
{
std::optional<std::string> arg = ReadStringArg(guard, &vec_nth(args, i));
Expand Down
4 changes: 2 additions & 2 deletions Source/Core/Core/PowerPC/GDBStub.cpp
Expand Up @@ -997,15 +997,15 @@ void ProcessCommands(bool loop_until_continue)
case 'm':
{
ASSERT(Core::IsCPUThread());
Core::CPUThreadGuard guard;
Core::CPUThreadGuard guard(system);

ReadMemory(guard);
break;
}
case 'M':
{
ASSERT(Core::IsCPUThread());
Core::CPUThreadGuard guard;
Core::CPUThreadGuard guard(system);

WriteMemory(guard);
auto& ppc_state = system.GetPPCState();
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/Core/PowerPC/Interpreter/Interpreter.cpp
Expand Up @@ -343,7 +343,7 @@ void Interpreter::unknown_instruction(UGeckoInstruction inst)
{
ASSERT(Core::IsCPUThread());
auto& system = Core::System::GetInstance();
Core::CPUThreadGuard guard;
Core::CPUThreadGuard guard(system);

const u32 opcode = PowerPC::HostRead_U32(guard, last_pc);
const std::string disasm = Common::GekkoDisassembler::Disassemble(opcode, last_pc);
Expand Down
3 changes: 2 additions & 1 deletion Source/Core/Core/PowerPC/Interpreter/Interpreter_Branch.cpp
Expand Up @@ -10,6 +10,7 @@
#include "Core/HLE/HLE.h"
#include "Core/PowerPC/Interpreter/ExceptionUtils.h"
#include "Core/PowerPC/PowerPC.h"
#include "Core/System.h"

void Interpreter::bx(UGeckoInstruction inst)
{
Expand Down Expand Up @@ -98,7 +99,7 @@ void Interpreter::HLEFunction(UGeckoInstruction inst)
m_end_block = true;

ASSERT(Core::IsCPUThread());
Core::CPUThreadGuard guard;
Core::CPUThreadGuard guard(Core::System::GetInstance());

HLE::Execute(guard, PowerPC::ppcState.pc, inst.hex);
}
Expand Down
3 changes: 2 additions & 1 deletion Source/Core/Core/PowerPC/JitInterface.cpp
Expand Up @@ -30,6 +30,7 @@
#include "Core/PowerPC/PPCSymbolDB.h"
#include "Core/PowerPC/PowerPC.h"
#include "Core/PowerPC/Profiler.h"
#include "Core/System.h"

#if _M_X86
#include "Core/PowerPC/Jit64/Jit.h"
Expand Down Expand Up @@ -273,7 +274,7 @@ void CompileExceptionCheck(ExceptionType type)
if (type == ExceptionType::FIFOWrite)
{
ASSERT(Core::IsCPUThread());
Core::CPUThreadGuard guard;
Core::CPUThreadGuard guard(Core::System::GetInstance());

// Check in case the code has been replaced since: do we need to do this?
const OpType optype =
Expand Down
5 changes: 3 additions & 2 deletions Source/Core/DolphinQt/CheatSearchWidget.cpp
Expand Up @@ -37,6 +37,7 @@
#include "Core/ConfigManager.h"
#include "Core/Core.h"
#include "Core/PowerPC/PowerPC.h"
#include "Core/System.h"

#include "DolphinQt/Config/CheatCodeEditor.h"
#include "DolphinQt/Config/CheatWarningWidget.h"
Expand Down Expand Up @@ -288,7 +289,7 @@ void CheatSearchWidget::OnNextScanClicked()
}

const Cheats::SearchErrorCode error_code = [this] {
Core::CPUThreadGuard guard;
Core::CPUThreadGuard guard(Core::System::GetInstance());
return m_session->RunSearch(guard);
}();

Expand Down Expand Up @@ -397,7 +398,7 @@ bool CheatSearchWidget::RefreshValues()
tmp->SetFilterType(Cheats::FilterType::DoNotFilter);

const Cheats::SearchErrorCode error_code = [&tmp] {
Core::CPUThreadGuard guard;
Core::CPUThreadGuard guard(Core::System::GetInstance());
return tmp->RunSearch(guard);
}();

Expand Down
3 changes: 2 additions & 1 deletion Source/Core/DolphinQt/Debugger/CodeDiffDialog.cpp
Expand Up @@ -23,6 +23,7 @@
#include "Core/PowerPC/PPCSymbolDB.h"
#include "Core/PowerPC/PowerPC.h"
#include "Core/PowerPC/Profiler.h"
#include "Core/System.h"

#include "DolphinQt/Debugger/CodeWidget.h"
#include "DolphinQt/Host.h"
Expand Down Expand Up @@ -485,7 +486,7 @@ void CodeDiffDialog::OnSetBLR()
return;

{
Core::CPUThreadGuard guard;
Core::CPUThreadGuard guard(Core::System::GetInstance());
PowerPC::debug_interface.SetPatch(guard, symbol->address, 0x4E800020);
}

Expand Down
31 changes: 16 additions & 15 deletions Source/Core/DolphinQt/Debugger/CodeViewWidget.cpp
Expand Up @@ -33,6 +33,7 @@
#include "Core/PowerPC/PPCAnalyst.h"
#include "Core/PowerPC/PPCSymbolDB.h"
#include "Core/PowerPC/PowerPC.h"
#include "Core/System.h"
#include "DolphinQt/Debugger/PatchInstructionDialog.h"
#include "DolphinQt/Host.h"
#include "DolphinQt/Resources.h"
Expand Down Expand Up @@ -258,7 +259,7 @@ void CodeViewWidget::Update()

if (Core::GetState() == Core::State::Paused)
{
Core::CPUThreadGuard guard;
Core::CPUThreadGuard guard(Core::System::GetInstance());
Update(&guard);
}
else
Expand Down Expand Up @@ -532,7 +533,7 @@ void CodeViewWidget::SetAddress(u32 address, SetAddressUpdate update)

void CodeViewWidget::ReplaceAddress(u32 address, ReplaceWith replace)
{
Core::CPUThreadGuard guard;
Core::CPUThreadGuard guard(Core::System::GetInstance());

PowerPC::debug_interface.SetPatch(guard, address,
replace == ReplaceWith::BLR ? 0x4e800020 : 0x60000000);
Expand Down Expand Up @@ -594,7 +595,7 @@ void CodeViewWidget::OnContextMenu()
bool follow_branch_enabled = false;
if (paused)
{
Core::CPUThreadGuard guard;
Core::CPUThreadGuard guard(Core::System::GetInstance());
const std::string disasm = PowerPC::debug_interface.Disassemble(&guard, PowerPC::ppcState.pc);

if (addr == PowerPC::ppcState.pc)
Expand Down Expand Up @@ -650,7 +651,7 @@ void CodeViewWidget::AutoStep(CodeTrace::AutoStop option)
// Autosteps and follows value in the target (left-most) register. The Used and Changed options
// silently follows target through reshuffles in memory and registers and stops on use or update.

Core::CPUThreadGuard guard;
Core::CPUThreadGuard guard(Core::System::GetInstance());

CodeTrace code_trace;
bool repeat = false;
Expand Down Expand Up @@ -741,7 +742,7 @@ void CodeViewWidget::OnCopyTargetAddress()
const u32 addr = GetContextAddress();

const std::string code_line = [addr] {
Core::CPUThreadGuard guard;
Core::CPUThreadGuard guard(Core::System::GetInstance());
return PowerPC::debug_interface.Disassemble(&guard, addr);
}();

Expand Down Expand Up @@ -771,7 +772,7 @@ void CodeViewWidget::OnShowTargetInMemory()
const u32 addr = GetContextAddress();

const std::string code_line = [addr] {
Core::CPUThreadGuard guard;
Core::CPUThreadGuard guard(Core::System::GetInstance());
return PowerPC::debug_interface.Disassemble(&guard, addr);
}();

Expand All @@ -790,7 +791,7 @@ void CodeViewWidget::OnCopyCode()
const u32 addr = GetContextAddress();

const std::string text = [addr] {
Core::CPUThreadGuard guard;
Core::CPUThreadGuard guard(Core::System::GetInstance());
return PowerPC::debug_interface.Disassemble(&guard, addr);
}();

Expand All @@ -808,7 +809,7 @@ void CodeViewWidget::OnCopyFunction()
std::string text = symbol->name + "\r\n";

{
Core::CPUThreadGuard guard;
Core::CPUThreadGuard guard(Core::System::GetInstance());

// we got a function
const u32 start = symbol->address;
Expand All @@ -828,7 +829,7 @@ void CodeViewWidget::OnCopyHex()
const u32 addr = GetContextAddress();

const u32 instruction = [addr] {
Core::CPUThreadGuard guard;
Core::CPUThreadGuard guard(Core::System::GetInstance());
return PowerPC::debug_interface.ReadInstruction(guard, addr);
}();

Expand Down Expand Up @@ -856,7 +857,7 @@ void CodeViewWidget::OnAddFunction()
{
const u32 addr = GetContextAddress();

Core::CPUThreadGuard guard;
Core::CPUThreadGuard guard(Core::System::GetInstance());

g_symbolDB.AddFunction(guard, addr);
emit SymbolsChanged();
Expand All @@ -882,7 +883,7 @@ void CodeViewWidget::OnFollowBranch()
const u32 addr = GetContextAddress();

const u32 branch_addr = [addr] {
Core::CPUThreadGuard guard;
Core::CPUThreadGuard guard(Core::System::GetInstance());
return GetBranchFromAddress(guard, addr);
}();

Expand Down Expand Up @@ -945,7 +946,7 @@ void CodeViewWidget::OnSetSymbolSize()
if (!good)
return;

Core::CPUThreadGuard guard;
Core::CPUThreadGuard guard(Core::System::GetInstance());

PPCAnalyst::ReanalyzeFunction(guard, symbol->address, *symbol, size);
emit SymbolsChanged();
Expand Down Expand Up @@ -973,7 +974,7 @@ void CodeViewWidget::OnSetSymbolEndAddress()
if (!good)
return;

Core::CPUThreadGuard guard;
Core::CPUThreadGuard guard(Core::System::GetInstance());

PPCAnalyst::ReanalyzeFunction(guard, symbol->address, *symbol, address - symbol->address);
emit SymbolsChanged();
Expand All @@ -982,7 +983,7 @@ void CodeViewWidget::OnSetSymbolEndAddress()

void CodeViewWidget::OnReplaceInstruction()
{
Core::CPUThreadGuard guard;
Core::CPUThreadGuard guard(Core::System::GetInstance());

const u32 addr = GetContextAddress();

Expand All @@ -1004,7 +1005,7 @@ void CodeViewWidget::OnReplaceInstruction()

void CodeViewWidget::OnRestoreInstruction()
{
Core::CPUThreadGuard guard;
Core::CPUThreadGuard guard(Core::System::GetInstance());

const u32 addr = GetContextAddress();

Expand Down
8 changes: 4 additions & 4 deletions Source/Core/DolphinQt/Debugger/CodeWidget.cpp
Expand Up @@ -330,7 +330,7 @@ void CodeWidget::UpdateCallstack()
std::vector<Dolphin_Debugger::CallstackEntry> stack;

const bool success = [&stack] {
Core::CPUThreadGuard guard;
Core::CPUThreadGuard guard(Core::System::GetInstance());
return Dolphin_Debugger::GetCallstack(Core::System::GetInstance(), guard, stack);
}();

Expand Down Expand Up @@ -461,8 +461,8 @@ void CodeWidget::StepOver()
if (!cpu.IsStepping())
return;

const UGeckoInstruction inst = [] {
Core::CPUThreadGuard guard;
const UGeckoInstruction inst = [&] {
Core::CPUThreadGuard guard(system);
return PowerPC::HostRead_Instruction(guard, PowerPC::ppcState.pc);
}();

Expand Down Expand Up @@ -506,7 +506,7 @@ void CodeWidget::StepOut()
clock::time_point timeout = clock::now() + std::chrono::seconds(5);

{
Core::CPUThreadGuard guard;
Core::CPUThreadGuard guard(system);

PowerPC::breakpoints.ClearAllTemporary();

Expand Down
9 changes: 5 additions & 4 deletions Source/Core/DolphinQt/Debugger/MemoryViewWidget.cpp
Expand Up @@ -25,6 +25,7 @@
#include "Core/HW/AddressSpace.h"
#include "Core/PowerPC/BreakPoints.h"
#include "Core/PowerPC/PowerPC.h"
#include "Core/System.h"
#include "DolphinQt/Host.h"
#include "DolphinQt/Resources.h"
#include "DolphinQt/Settings.h"
Expand Down Expand Up @@ -153,7 +154,7 @@ class MemoryViewTable final : public QTableWidget
u32 end_address = address + static_cast<u32>(bytes.size()) - 1;
AddressSpace::Accessors* accessors = AddressSpace::GetAccessors(m_view->GetAddressSpace());

Core::CPUThreadGuard guard;
Core::CPUThreadGuard guard(Core::System::GetInstance());

if (!bytes.empty() && accessors->IsValidAddress(guard, address) &&
accessors->IsValidAddress(guard, end_address))
Expand Down Expand Up @@ -442,7 +443,7 @@ void MemoryViewWidget::UpdateColumns()

if (Core::GetState() == Core::State::Paused)
{
Core::CPUThreadGuard guard;
Core::CPUThreadGuard guard(Core::System::GetInstance());
UpdateColumns(&guard);
}
else
Expand Down Expand Up @@ -850,7 +851,7 @@ void MemoryViewWidget::OnCopyHex(u32 addr)
const AddressSpace::Accessors* accessors = AddressSpace::GetAccessors(m_address_space);

const u64 value = [addr, accessors] {
Core::CPUThreadGuard guard;
Core::CPUThreadGuard guard(Core::System::GetInstance());
return accessors->ReadU64(guard, addr);
}();

Expand All @@ -873,7 +874,7 @@ void MemoryViewWidget::OnContextMenu(const QPoint& pos)
[this, addr] {
const AddressSpace::Accessors* accessors = AddressSpace::GetAccessors(m_address_space);

Core::CPUThreadGuard guard;
Core::CPUThreadGuard guard(Core::System::GetInstance());
return accessors->IsValidAddress(guard, addr);
}();

Expand Down
9 changes: 5 additions & 4 deletions Source/Core/DolphinQt/Debugger/MemoryWidget.cpp
Expand Up @@ -32,6 +32,7 @@
#include "Core/ConfigManager.h"
#include "Core/Core.h"
#include "Core/HW/AddressSpace.h"
#include "Core/System.h"
#include "DolphinQt/Debugger/MemoryViewWidget.h"
#include "DolphinQt/Host.h"
#include "DolphinQt/QtUtils/ModalMessageBox.h"
Expand Down Expand Up @@ -496,7 +497,7 @@ void MemoryWidget::SetAddress(u32 address)
AddressSpace::Accessors* accessors =
AddressSpace::GetAccessors(m_memory_view->GetAddressSpace());

Core::CPUThreadGuard guard;
Core::CPUThreadGuard guard(Core::System::GetInstance());
good = accessors->IsValidAddress(guard, current_addr);
}

Expand Down Expand Up @@ -653,7 +654,7 @@ void MemoryWidget::OnSetValue()
return;
}

Core::CPUThreadGuard guard;
Core::CPUThreadGuard guard(Core::System::GetInstance());

AddressSpace::Accessors* accessors = AddressSpace::GetAccessors(m_memory_view->GetAddressSpace());
u32 end_address = target_addr.address + static_cast<u32>(bytes.size()) - 1;
Expand Down Expand Up @@ -715,7 +716,7 @@ void MemoryWidget::OnSetValueFromFile()

AddressSpace::Accessors* accessors = AddressSpace::GetAccessors(m_memory_view->GetAddressSpace());

Core::CPUThreadGuard guard;
Core::CPUThreadGuard guard(Core::System::GetInstance());

for (u8 b : file_contents)
accessors->WriteU8(guard, target_addr.address++, b);
Expand Down Expand Up @@ -833,7 +834,7 @@ void MemoryWidget::FindValue(bool next)
AddressSpace::Accessors* accessors =
AddressSpace::GetAccessors(m_memory_view->GetAddressSpace());

Core::CPUThreadGuard guard;
Core::CPUThreadGuard guard(Core::System::GetInstance());
return accessors->Search(guard, target_addr.address,
reinterpret_cast<const u8*>(search_for.data()),
static_cast<u32>(search_for.size()), next);
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/DolphinQt/Debugger/RegisterWidget.cpp
Expand Up @@ -296,7 +296,7 @@ void RegisterWidget::AutoStep(const std::string& reg) const
while (true)
{
const AutoStepResults results = [&trace] {
Core::CPUThreadGuard guard;
Core::CPUThreadGuard guard(Core::System::GetInstance());
return trace.AutoStepping(guard, true);
}();

Expand Down
7 changes: 4 additions & 3 deletions Source/Core/DolphinQt/Debugger/ThreadWidget.cpp
Expand Up @@ -15,6 +15,7 @@
#include "Core/Core.h"
#include "Core/PowerPC/MMU.h"
#include "Core/PowerPC/PowerPC.h"
#include "Core/System.h"
#include "DolphinQt/Host.h"
#include "DolphinQt/Settings.h"

Expand Down Expand Up @@ -257,7 +258,7 @@ void ThreadWidget::Update()
m_thread_table->setRowCount(0);
UpdateThreadContext({});

Core::CPUThreadGuard guard;
Core::CPUThreadGuard guard(Core::System::GetInstance());
UpdateThreadCallstack(guard, {});
}
if (emu_state != Core::State::Paused)
Expand Down Expand Up @@ -301,7 +302,7 @@ void ThreadWidget::Update()
};

{
Core::CPUThreadGuard guard;
Core::CPUThreadGuard guard(Core::System::GetInstance());

// YAGCD - Section 4.2.1.4 Dolphin OS Globals
m_current_context->setText(format_hex_from(guard, 0x800000D4));
Expand Down Expand Up @@ -471,7 +472,7 @@ void ThreadWidget::UpdateThreadCallstack(const Core::CPUThreadGuard& guard,

void ThreadWidget::OnSelectionChanged(int row)
{
Core::CPUThreadGuard guard;
Core::CPUThreadGuard guard(Core::System::GetInstance());
Common::Debug::PartialContext context;

if (row >= 0 && size_t(row) < m_threads.size())
Expand Down
17 changes: 9 additions & 8 deletions Source/Core/DolphinQt/Debugger/WatchWidget.cpp
Expand Up @@ -16,6 +16,7 @@
#include "Core/Core.h"
#include "Core/PowerPC/MMU.h"
#include "Core/PowerPC/PowerPC.h"
#include "Core/System.h"

#include "DolphinQt/Host.h"
#include "DolphinQt/QtUtils/ModalMessageBox.h"
Expand Down Expand Up @@ -166,7 +167,7 @@ void WatchWidget::Update()
m_table->setDisabled(false);
m_table->clearContents();

Core::CPUThreadGuard guard;
Core::CPUThreadGuard guard(Core::System::GetInstance());

int size = static_cast<int>(PowerPC::debug_interface.GetWatches().size());

Expand Down Expand Up @@ -295,7 +296,7 @@ void WatchWidget::OnLoad()
return;
}

Core::CPUThreadGuard guard;
Core::CPUThreadGuard guard(Core::System::GetInstance());

if (ini.GetLines("Watches", &watches, false))
{
Expand Down Expand Up @@ -405,7 +406,7 @@ void WatchWidget::OnItemChanged(QTableWidgetItem* item)

if (good)
{
Core::CPUThreadGuard guard;
Core::CPUThreadGuard guard(Core::System::GetInstance());

if (column == COLUMN_INDEX_ADDRESS)
{
Expand All @@ -430,7 +431,7 @@ void WatchWidget::OnItemChanged(QTableWidgetItem* item)
{
PowerPC::debug_interface.UpdateWatchLockedState(row, item->checkState() == Qt::Checked);
const auto& watch = PowerPC::debug_interface.GetWatch(row);
Core::CPUThreadGuard guard;
Core::CPUThreadGuard guard(Core::System::GetInstance());
if (watch.locked)
LockWatchAddress(guard, watch.address);
else
Expand Down Expand Up @@ -459,7 +460,7 @@ void WatchWidget::LockWatchAddress(const Core::CPUThreadGuard& guard, u32 addres
void WatchWidget::DeleteSelectedWatches()
{
{
Core::CPUThreadGuard guard;
Core::CPUThreadGuard guard(Core::System::GetInstance());
std::vector<int> row_indices;
for (const auto& index : m_table->selectionModel()->selectedRows())
{
Expand Down Expand Up @@ -491,7 +492,7 @@ void WatchWidget::DeleteWatch(const Core::CPUThreadGuard& guard, int row)
void WatchWidget::DeleteWatchAndUpdate(int row)
{
{
Core::CPUThreadGuard guard;
Core::CPUThreadGuard guard(Core::System::GetInstance());
DeleteWatch(guard, row);
}

Expand All @@ -517,7 +518,7 @@ void WatchWidget::AddWatch(QString name, u32 addr)
void WatchWidget::LockSelectedWatches()
{
{
Core::CPUThreadGuard guard;
Core::CPUThreadGuard guard(Core::System::GetInstance());
for (const auto& index : m_table->selectionModel()->selectedRows())
{
const auto* item = m_table->item(index.row(), index.column());
Expand All @@ -539,7 +540,7 @@ void WatchWidget::LockSelectedWatches()
void WatchWidget::UnlockSelectedWatches()
{
{
Core::CPUThreadGuard guard;
Core::CPUThreadGuard guard(Core::System::GetInstance());
for (const auto& index : m_table->selectionModel()->selectedRows())
{
const auto* item = m_table->item(index.row(), index.column());
Expand Down
20 changes: 10 additions & 10 deletions Source/Core/DolphinQt/MenuBar.cpp
Expand Up @@ -1186,7 +1186,7 @@ void MenuBar::ClearSymbols()

void MenuBar::GenerateSymbolsFromAddress()
{
Core::CPUThreadGuard guard;
Core::CPUThreadGuard guard(Core::System::GetInstance());

auto& system = Core::System::GetInstance();
auto& memory = system.GetMemory();
Expand All @@ -1198,7 +1198,7 @@ void MenuBar::GenerateSymbolsFromAddress()

void MenuBar::GenerateSymbolsFromSignatureDB()
{
Core::CPUThreadGuard guard;
Core::CPUThreadGuard guard(Core::System::GetInstance());

auto& system = Core::System::GetInstance();
auto& memory = system.GetMemory();
Expand Down Expand Up @@ -1244,7 +1244,7 @@ void MenuBar::GenerateSymbolsFromRSO()
return;
}

Core::CPUThreadGuard guard;
Core::CPUThreadGuard guard(Core::System::GetInstance());

RSOChainView rso_chain;
if (rso_chain.Load(guard, static_cast<u32>(address)))
Expand Down Expand Up @@ -1300,7 +1300,7 @@ void MenuBar::GenerateSymbolsFromRSOAuto()
RSOChainView rso_chain;
const u32 address = item.mid(0, item.indexOf(QLatin1Char(' '))).toUInt(nullptr, 16);

Core::CPUThreadGuard guard;
Core::CPUThreadGuard guard(Core::System::GetInstance());

if (rso_chain.Load(guard, address))
{
Expand All @@ -1315,7 +1315,7 @@ void MenuBar::GenerateSymbolsFromRSOAuto()

RSOVector MenuBar::DetectRSOModules(ParallelProgressDialog& progress)
{
Core::CPUThreadGuard guard;
Core::CPUThreadGuard guard(Core::System::GetInstance());

constexpr std::array<std::string_view, 2> search_for = {".elf", ".plf"};

Expand Down Expand Up @@ -1429,7 +1429,7 @@ void MenuBar::LoadSymbolMap()
g_symbolDB.Clear();

{
Core::CPUThreadGuard guard;
Core::CPUThreadGuard guard(Core::System::GetInstance());

PPCAnalyst::FindFunctions(guard, Memory::MEM1_BASE_ADDR + 0x1300000,
Memory::MEM1_BASE_ADDR + memory.GetRamSizeReal(), &g_symbolDB);
Expand Down Expand Up @@ -1523,7 +1523,7 @@ void MenuBar::SaveCode()

bool success;
{
Core::CPUThreadGuard guard;
Core::CPUThreadGuard guard(Core::System::GetInstance());
success = g_symbolDB.SaveCodeMap(guard, path);
}

Expand All @@ -1537,7 +1537,7 @@ void MenuBar::SaveCode()

bool MenuBar::TryLoadMapFile(const QString& path, const bool bad)
{
Core::CPUThreadGuard guard;
Core::CPUThreadGuard guard(Core::System::GetInstance());

if (!g_symbolDB.LoadMap(guard, path.toStdString(), bad))
{
Expand Down Expand Up @@ -1621,7 +1621,7 @@ void MenuBar::ApplySignatureFile()
SignatureDB db(load_path);
db.Load(load_path);
{
Core::CPUThreadGuard guard;
Core::CPUThreadGuard guard(Core::System::GetInstance());
db.Apply(guard, &g_symbolDB);
}
db.List();
Expand Down Expand Up @@ -1692,7 +1692,7 @@ void MenuBar::SearchInstruction()
auto& system = Core::System::GetInstance();
auto& memory = system.GetMemory();

Core::CPUThreadGuard guard;
Core::CPUThreadGuard guard(system);

bool found = false;
for (u32 addr = Memory::MEM1_BASE_ADDR; addr < Memory::MEM1_BASE_ADDR + memory.GetRamSizeReal();
Expand Down