Merge pull request #11632 from AdmiralCurtiss/pass-more-system

Pass System to Boot functions, CPUThreadGuard, IEXIDevice.
This commit is contained in:
Mai 2023-03-08 17:38:40 -05:00 committed by GitHub
commit 2856723bc1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
54 changed files with 226 additions and 191 deletions

View File

@ -321,26 +321,24 @@ static const DiscIO::VolumeDisc* SetDisc(std::unique_ptr<DiscIO::VolumeDisc> dis
return pointer; return pointer;
} }
bool CBoot::DVDRead(const DiscIO::VolumeDisc& disc, u64 dvd_offset, u32 output_address, u32 length, bool CBoot::DVDRead(Core::System& system, const DiscIO::VolumeDisc& disc, u64 dvd_offset,
const DiscIO::Partition& partition) u32 output_address, u32 length, const DiscIO::Partition& partition)
{ {
std::vector<u8> buffer(length); std::vector<u8> buffer(length);
if (!disc.Read(dvd_offset, length, buffer.data(), partition)) if (!disc.Read(dvd_offset, length, buffer.data(), partition))
return false; return false;
auto& system = Core::System::GetInstance();
auto& memory = system.GetMemory(); auto& memory = system.GetMemory();
memory.CopyToEmu(output_address, buffer.data(), length); memory.CopyToEmu(output_address, buffer.data(), length);
return true; return true;
} }
bool CBoot::DVDReadDiscID(const DiscIO::VolumeDisc& disc, u32 output_address) bool CBoot::DVDReadDiscID(Core::System& system, const DiscIO::VolumeDisc& disc, u32 output_address)
{ {
std::array<u8, 0x20> buffer; std::array<u8, 0x20> buffer;
if (!disc.Read(0, buffer.size(), buffer.data(), DiscIO::PARTITION_NONE)) if (!disc.Read(0, buffer.size(), buffer.data(), DiscIO::PARTITION_NONE))
return false; return false;
auto& system = Core::System::GetInstance();
auto& memory = system.GetMemory(); auto& memory = system.GetMemory();
memory.CopyToEmu(output_address, buffer.data(), buffer.size()); memory.CopyToEmu(output_address, buffer.data(), buffer.size());
@ -550,14 +548,14 @@ bool CBoot::BootUp(Core::System& system, const Core::CPUThreadGuard& guard,
// Because there is no TMD to get the requested system (IOS) version from, // Because there is no TMD to get the requested system (IOS) version from,
// we default to IOS58, which is the version used by the Homebrew Channel. // we default to IOS58, which is the version used by the Homebrew Channel.
SetupWiiMemory(system, IOS::HLE::IOSC::ConsoleType::Retail); SetupWiiMemory(system, IOS::HLE::IOSC::ConsoleType::Retail);
IOS::HLE::GetIOS()->BootIOS(Titles::IOS(58)); IOS::HLE::GetIOS()->BootIOS(system, Titles::IOS(58));
} }
else else
{ {
SetupGCMemory(system, guard); SetupGCMemory(system, guard);
} }
if (!executable.reader->LoadIntoMemory()) if (!executable.reader->LoadIntoMemory(system))
{ {
PanicAlertFmtT("Failed to load the executable to memory."); PanicAlertFmtT("Failed to load the executable to memory.");
return false; return false;

View File

@ -171,9 +171,10 @@ public:
static bool LoadMapFromFilename(const Core::CPUThreadGuard& guard); static bool LoadMapFromFilename(const Core::CPUThreadGuard& guard);
private: private:
static bool DVDRead(const DiscIO::VolumeDisc& disc, u64 dvd_offset, u32 output_address, static bool DVDRead(Core::System& system, const DiscIO::VolumeDisc& disc, u64 dvd_offset,
u32 length, const DiscIO::Partition& partition); u32 output_address, u32 length, const DiscIO::Partition& partition);
static bool DVDReadDiscID(const DiscIO::VolumeDisc& disc, u32 output_address); static bool DVDReadDiscID(Core::System& system, const DiscIO::VolumeDisc& disc,
u32 output_address);
static void RunFunction(Core::System& system, u32 address); static void RunFunction(Core::System& system, u32 address);
static void UpdateDebugger_MapLoaded(); static void UpdateDebugger_MapLoaded();
@ -213,7 +214,7 @@ public:
virtual u32 GetEntryPoint() const = 0; virtual u32 GetEntryPoint() const = 0;
virtual bool IsValid() const = 0; virtual bool IsValid() const = 0;
virtual bool IsWii() const = 0; virtual bool IsWii() const = 0;
virtual bool LoadIntoMemory(bool only_in_mem1 = false) const = 0; virtual bool LoadIntoMemory(Core::System& system, bool only_in_mem1 = false) const = 0;
virtual bool LoadSymbols(const Core::CPUThreadGuard& guard) const = 0; virtual bool LoadSymbols(const Core::CPUThreadGuard& guard) const = 0;
protected: protected:

View File

@ -44,10 +44,10 @@
namespace namespace
{ {
void PresetTimeBaseTicks(const Core::CPUThreadGuard& guard) void PresetTimeBaseTicks(Core::System& system, const Core::CPUThreadGuard& guard)
{ {
const u64 emulated_time = const u64 emulated_time =
ExpansionInterface::CEXIIPL::GetEmulatedTime(ExpansionInterface::CEXIIPL::GC_EPOCH); ExpansionInterface::CEXIIPL::GetEmulatedTime(system, ExpansionInterface::CEXIIPL::GC_EPOCH);
const u64 time_base_ticks = emulated_time * 40500000ULL; const u64 time_base_ticks = emulated_time * 40500000ULL;
@ -148,7 +148,7 @@ bool CBoot::RunApploader(Core::System& system, const Core::CPUThreadGuard& guard
INFO_LOG_FMT(BOOT, "Invalid apploader. Your disc image is probably corrupted."); INFO_LOG_FMT(BOOT, "Invalid apploader. Your disc image is probably corrupted.");
return false; return false;
} }
DVDRead(volume, offset + 0x20, 0x01200000, *size + *trailer, partition); DVDRead(system, volume, offset + 0x20, 0x01200000, *size + *trailer, partition);
// TODO - Make Apploader(or just RunFunction()) debuggable!!! // TODO - Make Apploader(or just RunFunction()) debuggable!!!
@ -195,7 +195,7 @@ bool CBoot::RunApploader(Core::System& system, const Core::CPUThreadGuard& guard
INFO_LOG_FMT(BOOT, "DVDRead: offset: {:08x} memOffset: {:08x} length: {}", dvd_offset, INFO_LOG_FMT(BOOT, "DVDRead: offset: {:08x} memOffset: {:08x} length: {}", dvd_offset,
ram_address, length); ram_address, length);
DVDRead(volume, dvd_offset, ram_address, length, partition); DVDRead(system, volume, dvd_offset, ram_address, length, partition);
DiscIO::Riivolution::ApplyApploaderMemoryPatches(guard, riivolution_patches, ram_address, DiscIO::Riivolution::ApplyApploaderMemoryPatches(guard, riivolution_patches, ram_address,
length); length);
@ -248,7 +248,7 @@ void CBoot::SetupGCMemory(Core::System& system, const Core::CPUThreadGuard& guar
PowerPC::HostWrite_U32(guard, 0x4c000064, 0x80000800); // Write default FPU Handler: rfi PowerPC::HostWrite_U32(guard, 0x4c000064, 0x80000800); // Write default FPU Handler: rfi
PowerPC::HostWrite_U32(guard, 0x4c000064, 0x80000C00); // Write default Syscall Handler: rfi PowerPC::HostWrite_U32(guard, 0x4c000064, 0x80000C00); // Write default Syscall Handler: rfi
PresetTimeBaseTicks(guard); PresetTimeBaseTicks(system, guard);
// HIO checks this // HIO checks this
// PowerPC::HostWrite_U16(0x8200, 0x000030e6); // Console type // PowerPC::HostWrite_U16(0x8200, 0x000030e6); // Console type
@ -284,7 +284,7 @@ bool CBoot::EmulatedBS2_GC(Core::System& system, const Core::CPUThreadGuard& gua
auto& vertex_shader_manager = system.GetVertexShaderManager(); auto& vertex_shader_manager = system.GetVertexShaderManager();
vertex_shader_manager.InvalidateXFRange(XFMEM_POSTMATRICES + 0x3d * 4, XFMEM_POSTMATRICES_END); vertex_shader_manager.InvalidateXFRange(XFMEM_POSTMATRICES + 0x3d * 4, XFMEM_POSTMATRICES_END);
DVDReadDiscID(volume, 0x00000000); DVDReadDiscID(system, volume, 0x00000000);
auto& memory = system.GetMemory(); auto& memory = system.GetMemory();
bool streaming = memory.Read_U8(0x80000008); bool streaming = memory.Read_U8(0x80000008);
@ -554,7 +554,7 @@ bool CBoot::EmulatedBS2_Wii(Core::System& system, const Core::CPUThreadGuard& gu
const u64 ios = ios_override >= 0 ? Titles::IOS(static_cast<u32>(ios_override)) : tmd.GetIOSId(); const u64 ios = ios_override >= 0 ? Titles::IOS(static_cast<u32>(ios_override)) : tmd.GetIOSId();
const auto console_type = volume.GetTicket(data_partition).GetConsoleType(); const auto console_type = volume.GetTicket(data_partition).GetConsoleType();
if (!SetupWiiMemory(system, console_type) || !IOS::HLE::GetIOS()->BootIOS(ios)) if (!SetupWiiMemory(system, console_type) || !IOS::HLE::GetIOS()->BootIOS(system, ios))
return false; return false;
auto di = auto di =
@ -563,13 +563,13 @@ bool CBoot::EmulatedBS2_Wii(Core::System& system, const Core::CPUThreadGuard& gu
di->InitializeIfFirstTime(); di->InitializeIfFirstTime();
di->ChangePartition(data_partition); di->ChangePartition(data_partition);
DVDReadDiscID(volume, 0x00000000); DVDReadDiscID(system, volume, 0x00000000);
// This is some kind of consistency check that is compared to the 0x00 // This is some kind of consistency check that is compared to the 0x00
// values as the game boots. This location keeps the 4 byte ID for as long // values as the game boots. This location keeps the 4 byte ID for as long
// as the game is running. The 6 byte ID at 0x00 is overwritten sometime // as the game is running. The 6 byte ID at 0x00 is overwritten sometime
// after this check during booting. // after this check during booting.
DVDRead(volume, 0, 0x3180, 4, partition); DVDRead(system, volume, 0, 0x3180, 4, partition);
auto& ppc_state = system.GetPPCState(); auto& ppc_state = system.GetPPCState();

View File

@ -110,15 +110,14 @@ bool DolReader::Initialize(const std::vector<u8>& buffer)
return true; return true;
} }
bool DolReader::LoadIntoMemory(bool only_in_mem1) const bool DolReader::LoadIntoMemory(Core::System& system, bool only_in_mem1) const
{ {
if (!m_is_valid) if (!m_is_valid)
return false; return false;
if (m_is_ancast) if (m_is_ancast)
return LoadAncastIntoMemory(); return LoadAncastIntoMemory(system);
auto& system = Core::System::GetInstance();
auto& memory = system.GetMemory(); auto& memory = system.GetMemory();
// load all text (code) sections // load all text (code) sections
@ -149,7 +148,7 @@ bool DolReader::LoadIntoMemory(bool only_in_mem1) const
} }
// On a real console this would be done in the Espresso bootrom // On a real console this would be done in the Espresso bootrom
bool DolReader::LoadAncastIntoMemory() const bool DolReader::LoadAncastIntoMemory(Core::System& system) const
{ {
// The ancast image will always be in data section 0 // The ancast image will always be in data section 0
const auto& section = m_data_sections[0]; const auto& section = m_data_sections[0];
@ -227,7 +226,6 @@ bool DolReader::LoadAncastIntoMemory() const
body_size)) body_size))
return false; return false;
auto& system = Core::System::GetInstance();
auto& memory = system.GetMemory(); auto& memory = system.GetMemory();
// Copy the Ancast header to the emu // Copy the Ancast header to the emu

View File

@ -26,7 +26,7 @@ public:
bool IsWii() const override { return m_is_wii; } bool IsWii() const override { return m_is_wii; }
bool IsAncast() const { return m_is_ancast; }; bool IsAncast() const { return m_is_ancast; };
u32 GetEntryPoint() const override { return m_dolheader.entryPoint; } u32 GetEntryPoint() const override { return m_dolheader.entryPoint; }
bool LoadIntoMemory(bool only_in_mem1 = false) const override; bool LoadIntoMemory(Core::System& system, bool only_in_mem1 = false) const override;
bool LoadSymbols(const Core::CPUThreadGuard& guard) const override { return false; } bool LoadSymbols(const Core::CPUThreadGuard& guard) const override { return false; }
private: private:
@ -63,5 +63,5 @@ private:
// Copy sections to internal buffers // Copy sections to internal buffers
bool Initialize(const std::vector<u8>& buffer); bool Initialize(const std::vector<u8>& buffer);
bool LoadAncastIntoMemory() const; bool LoadAncastIntoMemory(Core::System& system) const;
}; };

View File

@ -124,7 +124,7 @@ const char* ElfReader::GetSectionName(int section) const
} }
// This is just a simple elf loader, good enough to load elfs generated by devkitPPC // This is just a simple elf loader, good enough to load elfs generated by devkitPPC
bool ElfReader::LoadIntoMemory(bool only_in_mem1) const bool ElfReader::LoadIntoMemory(Core::System& system, bool only_in_mem1) const
{ {
INFO_LOG_FMT(BOOT, "String section: {}", header->e_shstrndx); INFO_LOG_FMT(BOOT, "String section: {}", header->e_shstrndx);
@ -136,7 +136,6 @@ bool ElfReader::LoadIntoMemory(bool only_in_mem1) const
INFO_LOG_FMT(BOOT, "{} segments:", header->e_phnum); INFO_LOG_FMT(BOOT, "{} segments:", header->e_phnum);
auto& system = Core::System::GetInstance();
auto& memory = system.GetMemory(); auto& memory = system.GetMemory();
// Copy segments into ram. // Copy segments into ram.

View File

@ -35,7 +35,7 @@ public:
ElfMachine GetMachine() const { return (ElfMachine)(header->e_machine); } ElfMachine GetMachine() const { return (ElfMachine)(header->e_machine); }
u32 GetEntryPoint() const override { return entryPoint; } u32 GetEntryPoint() const override { return entryPoint; }
u32 GetFlags() const { return (u32)(header->e_flags); } u32 GetFlags() const { return (u32)(header->e_flags); }
bool LoadIntoMemory(bool only_in_mem1 = false) const override; bool LoadIntoMemory(Core::System& system, bool only_in_mem1 = false) const override;
bool LoadSymbols(const Core::CPUThreadGuard& guard) const override; bool LoadSymbols(const Core::CPUThreadGuard& guard) const override;
// TODO: actually check for validity. // TODO: actually check for validity.
bool IsValid() const override { return true; } bool IsValid() const override { return true; }

View File

@ -170,7 +170,7 @@ void OnFrameEnd()
if (s_memory_watcher) if (s_memory_watcher)
{ {
ASSERT(IsCPUThread()); ASSERT(IsCPUThread());
CPUThreadGuard guard; CPUThreadGuard guard(Core::System::GetInstance());
s_memory_watcher->Step(guard); s_memory_watcher->Step(guard);
} }
@ -533,7 +533,7 @@ static void EmuThread(std::unique_ptr<BootParameters> boot, WindowSystemInfo wsi
HW::Init(NetPlay::IsNetPlayRunning() ? &(boot_session_data.GetNetplaySettings()->sram) : nullptr); HW::Init(NetPlay::IsNetPlayRunning() ? &(boot_session_data.GetNetplaySettings()->sram) : nullptr);
Common::ScopeGuard hw_guard{[] { Common::ScopeGuard hw_guard{[&system] {
// We must set up this flag before executing HW::Shutdown() // We must set up this flag before executing HW::Shutdown()
s_hardware_initialized = false; s_hardware_initialized = false;
INFO_LOG_FMT(CONSOLE, "{}", StopMessage(false, "Shutting down HW")); INFO_LOG_FMT(CONSOLE, "{}", StopMessage(false, "Shutting down HW"));
@ -550,7 +550,7 @@ static void EmuThread(std::unique_ptr<BootParameters> boot, WindowSystemInfo wsi
PatchEngine::Shutdown(); PatchEngine::Shutdown();
HLE::Clear(); HLE::Clear();
CPUThreadGuard guard; CPUThreadGuard guard(system);
PowerPC::debug_interface.Clear(guard); PowerPC::debug_interface.Clear(guard);
}}; }};
@ -603,7 +603,7 @@ static void EmuThread(std::unique_ptr<BootParameters> boot, WindowSystemInfo wsi
{ {
ASSERT(IsCPUThread()); ASSERT(IsCPUThread());
CPUThreadGuard guard; CPUThreadGuard guard(system);
if (!CBoot::BootUp(system, guard, std::move(boot))) if (!CBoot::BootUp(system, guard, std::move(boot)))
return; return;
} }
@ -1058,16 +1058,17 @@ void UpdateInputGate(bool require_focus, bool require_full_focus)
ControlReference::SetInputGate(focus_passes && full_focus_passes); ControlReference::SetInputGate(focus_passes && full_focus_passes);
} }
CPUThreadGuard::CPUThreadGuard() : m_was_cpu_thread(IsCPUThread()) CPUThreadGuard::CPUThreadGuard(Core::System& system)
: m_system(system), m_was_cpu_thread(IsCPUThread())
{ {
if (!m_was_cpu_thread) if (!m_was_cpu_thread)
m_was_unpaused = PauseAndLock(Core::System::GetInstance(), true, true); m_was_unpaused = PauseAndLock(system, true, true);
} }
CPUThreadGuard::~CPUThreadGuard() CPUThreadGuard::~CPUThreadGuard()
{ {
if (!m_was_cpu_thread) if (!m_was_cpu_thread)
PauseAndLock(Core::System::GetInstance(), false, m_was_unpaused); PauseAndLock(m_system, false, m_was_unpaused);
} }
} // namespace Core } // namespace Core

View File

@ -108,7 +108,7 @@ enum class ConsoleType : u32
class CPUThreadGuard final class CPUThreadGuard final
{ {
public: public:
CPUThreadGuard(); explicit CPUThreadGuard(Core::System& system);
~CPUThreadGuard(); ~CPUThreadGuard();
CPUThreadGuard(const CPUThreadGuard&) = delete; CPUThreadGuard(const CPUThreadGuard&) = delete;
@ -117,6 +117,7 @@ public:
CPUThreadGuard& operator=(CPUThreadGuard&&) = delete; CPUThreadGuard& operator=(CPUThreadGuard&&) = delete;
private: private:
Core::System& m_system;
const bool m_was_cpu_thread; const bool m_was_cpu_thread;
bool m_was_unpaused = false; bool m_was_unpaused = false;
}; };

View File

@ -169,7 +169,7 @@ void Execute(const Core::CPUThreadGuard& guard, u32 current_pc, u32 hook_index)
void ExecuteFromJIT(u32 current_pc, u32 hook_index) void ExecuteFromJIT(u32 current_pc, u32 hook_index)
{ {
ASSERT(Core::IsCPUThread()); ASSERT(Core::IsCPUThread());
Core::CPUThreadGuard guard; Core::CPUThreadGuard guard(Core::System::GetInstance());
Execute(guard, current_pc, hook_index); Execute(guard, current_pc, hook_index);
} }

View File

@ -149,7 +149,7 @@ void Init(const Sram* override_sram)
Memcard::HeaderData header_data; Memcard::HeaderData header_data;
Memcard::InitializeHeaderData(&header_data, flash_id, size_mbits, shift_jis, rtc_bias, Memcard::InitializeHeaderData(&header_data, flash_id, size_mbits, shift_jis, rtc_bias,
sram_language, format_time + i); sram_language, format_time + i);
state.channels[i] = std::make_unique<CEXIChannel>(i, header_data); state.channels[i] = std::make_unique<CEXIChannel>(system, i, header_data);
} }
} }

View File

@ -25,8 +25,9 @@ enum
EXI_READWRITE EXI_READWRITE
}; };
CEXIChannel::CEXIChannel(u32 channel_id, const Memcard::HeaderData& memcard_header_data) CEXIChannel::CEXIChannel(Core::System& system, u32 channel_id,
: m_channel_id(channel_id), m_memcard_header_data(memcard_header_data) const Memcard::HeaderData& memcard_header_data)
: m_system(system), m_channel_id(channel_id), m_memcard_header_data(memcard_header_data)
{ {
if (m_channel_id == 0 || m_channel_id == 1) if (m_channel_id == 0 || m_channel_id == 1)
m_status.EXTINT = 1; m_status.EXTINT = 1;
@ -34,7 +35,7 @@ CEXIChannel::CEXIChannel(u32 channel_id, const Memcard::HeaderData& memcard_head
m_status.CHIP_SELECT = 1; m_status.CHIP_SELECT = 1;
for (auto& device : m_devices) for (auto& device : m_devices)
device = EXIDevice_Create(EXIDeviceType::None, m_channel_id, m_memcard_header_data); device = EXIDevice_Create(system, EXIDeviceType::None, m_channel_id, m_memcard_header_data);
} }
CEXIChannel::~CEXIChannel() CEXIChannel::~CEXIChannel()
@ -170,7 +171,8 @@ void CEXIChannel::RemoveDevices()
void CEXIChannel::AddDevice(const EXIDeviceType device_type, const int device_num) void CEXIChannel::AddDevice(const EXIDeviceType device_type, const int device_num)
{ {
AddDevice(EXIDevice_Create(device_type, m_channel_id, m_memcard_header_data), device_num); AddDevice(EXIDevice_Create(m_system, device_type, m_channel_id, m_memcard_header_data),
device_num);
} }
void CEXIChannel::AddDevice(std::unique_ptr<IEXIDevice> device, const int device_num, void CEXIChannel::AddDevice(std::unique_ptr<IEXIDevice> device, const int device_num,
@ -255,7 +257,7 @@ void CEXIChannel::DoState(PointerWrap& p)
else else
{ {
std::unique_ptr<IEXIDevice> save_device = std::unique_ptr<IEXIDevice> save_device =
EXIDevice_Create(type, m_channel_id, m_memcard_header_data); EXIDevice_Create(m_system, type, m_channel_id, m_memcard_header_data);
save_device->DoState(p); save_device->DoState(p);
AddDevice(std::move(save_device), device_index, false); AddDevice(std::move(save_device), device_index, false);
} }

View File

@ -25,7 +25,8 @@ enum class EXIDeviceType : int;
class CEXIChannel class CEXIChannel
{ {
public: public:
explicit CEXIChannel(u32 channel_id, const Memcard::HeaderData& memcard_header_data); explicit CEXIChannel(Core::System& system, u32 channel_id,
const Memcard::HeaderData& memcard_header_data);
~CEXIChannel(); ~CEXIChannel();
// get device // get device
@ -100,6 +101,8 @@ private:
}; };
}; };
Core::System& m_system;
// STATE_TO_SAVE // STATE_TO_SAVE
UEXI_STATUS m_status; UEXI_STATUS m_status;
u32 m_dma_memory_address = 0; u32 m_dma_memory_address = 0;

View File

@ -19,6 +19,10 @@
namespace ExpansionInterface namespace ExpansionInterface
{ {
IEXIDevice::IEXIDevice(Core::System& system) : m_system(system)
{
}
void IEXIDevice::ImmWrite(u32 data, u32 size) void IEXIDevice::ImmWrite(u32 data, u32 size)
{ {
while (size--) while (size--)
@ -48,8 +52,7 @@ void IEXIDevice::ImmReadWrite(u32& data, u32 size)
void IEXIDevice::DMAWrite(u32 address, u32 size) void IEXIDevice::DMAWrite(u32 address, u32 size)
{ {
auto& system = Core::System::GetInstance(); auto& memory = m_system.GetMemory();
auto& memory = system.GetMemory();
while (size--) while (size--)
{ {
u8 byte = memory.Read_U8(address++); u8 byte = memory.Read_U8(address++);
@ -59,8 +62,7 @@ void IEXIDevice::DMAWrite(u32 address, u32 size)
void IEXIDevice::DMARead(u32 address, u32 size) void IEXIDevice::DMARead(u32 address, u32 size)
{ {
auto& system = Core::System::GetInstance(); auto& memory = m_system.GetMemory();
auto& memory = system.GetMemory();
while (size--) while (size--)
{ {
u8 byte = 0; u8 byte = 0;
@ -101,7 +103,8 @@ void IEXIDevice::TransferByte(u8& byte)
} }
// F A C T O R Y // 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) const Memcard::HeaderData& memcard_header_data)
{ {
std::unique_ptr<IEXIDevice> result; std::unique_ptr<IEXIDevice> result;
@ -112,58 +115,58 @@ std::unique_ptr<IEXIDevice> EXIDevice_Create(const EXIDeviceType device_type, co
switch (device_type) switch (device_type)
{ {
case EXIDeviceType::Dummy: case EXIDeviceType::Dummy:
result = std::make_unique<CEXIDummy>("Dummy"); result = std::make_unique<CEXIDummy>(system, "Dummy");
break; break;
case EXIDeviceType::MemoryCard: case EXIDeviceType::MemoryCard:
case EXIDeviceType::MemoryCardFolder: case EXIDeviceType::MemoryCardFolder:
{ {
bool gci_folder = (device_type == 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; break;
} }
case EXIDeviceType::MaskROM: case EXIDeviceType::MaskROM:
result = std::make_unique<CEXIIPL>(); result = std::make_unique<CEXIIPL>(system);
break; break;
case EXIDeviceType::AD16: case EXIDeviceType::AD16:
result = std::make_unique<CEXIAD16>(); result = std::make_unique<CEXIAD16>(system);
break; break;
case EXIDeviceType::Microphone: case EXIDeviceType::Microphone:
result = std::make_unique<CEXIMic>(channel_num); result = std::make_unique<CEXIMic>(system, channel_num);
break; break;
case EXIDeviceType::Ethernet: case EXIDeviceType::Ethernet:
result = std::make_unique<CEXIETHERNET>(BBADeviceType::TAP); result = std::make_unique<CEXIETHERNET>(system, BBADeviceType::TAP);
break; break;
#if defined(__APPLE__) #if defined(__APPLE__)
case EXIDeviceType::EthernetTapServer: case EXIDeviceType::EthernetTapServer:
result = std::make_unique<CEXIETHERNET>(BBADeviceType::TAPSERVER); result = std::make_unique<CEXIETHERNET>(system, BBADeviceType::TAPSERVER);
break; break;
#endif #endif
case EXIDeviceType::EthernetXLink: case EXIDeviceType::EthernetXLink:
result = std::make_unique<CEXIETHERNET>(BBADeviceType::XLINK); result = std::make_unique<CEXIETHERNET>(system, BBADeviceType::XLINK);
break; break;
case EXIDeviceType::EthernetBuiltIn: case EXIDeviceType::EthernetBuiltIn:
result = std::make_unique<CEXIETHERNET>(BBADeviceType::BuiltIn); result = std::make_unique<CEXIETHERNET>(system, BBADeviceType::BuiltIn);
break; break;
case EXIDeviceType::Gecko: case EXIDeviceType::Gecko:
result = std::make_unique<CEXIGecko>(); result = std::make_unique<CEXIGecko>(system);
break; break;
case EXIDeviceType::AGP: case EXIDeviceType::AGP:
result = std::make_unique<CEXIAgp>(slot); result = std::make_unique<CEXIAgp>(system, slot);
break; break;
case EXIDeviceType::AMBaseboard: case EXIDeviceType::AMBaseboard:
case EXIDeviceType::None: case EXIDeviceType::None:
default: default:
result = std::make_unique<IEXIDevice>(); result = std::make_unique<IEXIDevice>(system);
break; break;
} }

View File

@ -11,6 +11,10 @@
class PointerWrap; class PointerWrap;
namespace Core
{
class System;
}
namespace Memcard namespace Memcard
{ {
struct HeaderData; struct HeaderData;
@ -44,6 +48,7 @@ enum class EXIDeviceType : int
class IEXIDevice class IEXIDevice
{ {
public: public:
explicit IEXIDevice(Core::System& system);
virtual ~IEXIDevice() = default; virtual ~IEXIDevice() = default;
// Immediate copy functions // Immediate copy functions
@ -69,12 +74,16 @@ public:
// such. // such.
EXIDeviceType m_device_type = EXIDeviceType::None; EXIDeviceType m_device_type = EXIDeviceType::None;
protected:
Core::System& m_system;
private: private:
// Byte transfer function for this device // Byte transfer function for this device
virtual void TransferByte(u8& byte); 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); const Memcard::HeaderData& memcard_header_data);
} // namespace ExpansionInterface } // namespace ExpansionInterface

View File

@ -9,7 +9,9 @@
namespace ExpansionInterface namespace ExpansionInterface
{ {
CEXIAD16::CEXIAD16() = default; CEXIAD16::CEXIAD16(Core::System& system) : IEXIDevice(system)
{
}
void CEXIAD16::SetCS(int cs) void CEXIAD16::SetCS(int cs)
{ {

View File

@ -12,7 +12,7 @@ namespace ExpansionInterface
class CEXIAD16 : public IEXIDevice class CEXIAD16 : public IEXIDevice
{ {
public: public:
CEXIAD16(); explicit CEXIAD16(Core::System& system);
void SetCS(int cs) override; void SetCS(int cs) override;
bool IsPresent() const override; bool IsPresent() const override;
void DoState(PointerWrap& p) override; void DoState(PointerWrap& p) override;

View File

@ -19,7 +19,7 @@
namespace ExpansionInterface namespace ExpansionInterface
{ {
CEXIAgp::CEXIAgp(Slot slot) CEXIAgp::CEXIAgp(Core::System& system, Slot slot) : IEXIDevice(system)
{ {
ASSERT(IsMemcardSlot(slot)); ASSERT(IsMemcardSlot(slot));
m_slot = slot; m_slot = slot;

View File

@ -17,7 +17,7 @@ enum class Slot : int;
class CEXIAgp : public IEXIDevice class CEXIAgp : public IEXIDevice
{ {
public: public:
CEXIAgp(const Slot slot); CEXIAgp(Core::System& system, const Slot slot);
virtual ~CEXIAgp() override; virtual ~CEXIAgp() override;
bool IsPresent() const override { return true; } bool IsPresent() const override { return true; }
void ImmWrite(u32 _uData, u32 _uSize) override; void ImmWrite(u32 _uData, u32 _uSize) override;

View File

@ -10,7 +10,8 @@
namespace ExpansionInterface 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}
{ {
} }

View File

@ -16,7 +16,7 @@ namespace ExpansionInterface
class CEXIDummy final : public IEXIDevice class CEXIDummy final : public IEXIDevice
{ {
public: public:
explicit CEXIDummy(const std::string& name); CEXIDummy(Core::System& system, const std::string& name);
void ImmWrite(u32 data, u32 size) override; void ImmWrite(u32 data, u32 size) override;
u32 ImmRead(u32 size) override; u32 ImmRead(u32 size) override;

View File

@ -27,7 +27,7 @@ namespace ExpansionInterface
// Multiple parts of this implementation depend on Dolphin // Multiple parts of this implementation depend on Dolphin
// being compiled for a little endian host. // 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 // Parse MAC address from config, and generate a new one if it doesn't
// exist or can't be parsed. // exist or can't be parsed.
@ -233,8 +233,7 @@ void CEXIETHERNET::DMAWrite(u32 addr, u32 size)
if (transfer.region == transfer.MX && transfer.direction == transfer.WRITE && if (transfer.region == transfer.MX && transfer.direction == transfer.WRITE &&
transfer.address == BBA_WRTXFIFOD) transfer.address == BBA_WRTXFIFOD)
{ {
auto& system = Core::System::GetInstance(); auto& memory = m_system.GetMemory();
auto& memory = system.GetMemory();
DirectFIFOWrite(memory.GetPointer(addr), size); DirectFIFOWrite(memory.GetPointer(addr), size);
} }
else else
@ -248,8 +247,7 @@ void CEXIETHERNET::DMAWrite(u32 addr, u32 size)
void CEXIETHERNET::DMARead(u32 addr, u32 size) void CEXIETHERNET::DMARead(u32 addr, u32 size)
{ {
DEBUG_LOG_FMT(SP1, "DMA read: {:08x} {:x}", addr, size); DEBUG_LOG_FMT(SP1, "DMA read: {:08x} {:x}", addr, size);
auto& system = Core::System::GetInstance(); auto& memory = m_system.GetMemory();
auto& memory = system.GetMemory();
memory.CopyToEmu(addr, &mBbaMem[transfer.address], size); memory.CopyToEmu(addr, &mBbaMem[transfer.address], size);
transfer.address += size; transfer.address += size;
} }

View File

@ -214,7 +214,7 @@ enum class BBADeviceType
class CEXIETHERNET : public IEXIDevice class CEXIETHERNET : public IEXIDevice
{ {
public: public:
explicit CEXIETHERNET(BBADeviceType type); CEXIETHERNET(Core::System& system, BBADeviceType type);
virtual ~CEXIETHERNET(); virtual ~CEXIETHERNET();
void SetCS(int cs) override; void SetCS(int cs) override;
bool IsPresent() const override; bool IsPresent() const override;

View File

@ -159,6 +159,10 @@ void GeckoSockServer::ClientThread()
client->disconnect(); client->disconnect();
} }
CEXIGecko::CEXIGecko(Core::System& system) : IEXIDevice(system)
{
}
void CEXIGecko::ImmReadWrite(u32& _uData, u32 _uSize) void CEXIGecko::ImmReadWrite(u32& _uData, u32 _uSize)
{ {
// We don't really care about _uSize // We don't really care about _uSize

View File

@ -49,7 +49,7 @@ private:
class CEXIGecko : public IEXIDevice, private GeckoSockServer class CEXIGecko : public IEXIDevice, private GeckoSockServer
{ {
public: public:
CEXIGecko() {} explicit CEXIGecko(Core::System& system);
bool IsPresent() const override { return true; } bool IsPresent() const override { return true; }
void ImmReadWrite(u32& _uData, u32 _uSize) override; void ImmReadWrite(u32& _uData, u32 _uSize) override;

View File

@ -99,7 +99,7 @@ void CEXIIPL::Descrambler(u8* data, u32 size)
} }
} }
CEXIIPL::CEXIIPL() CEXIIPL::CEXIIPL(Core::System& system) : IEXIDevice(system)
{ {
// Fill the ROM // Fill the ROM
m_rom = std::make_unique<u8[]>(ROM_SIZE); m_rom = std::make_unique<u8[]>(ROM_SIZE);
@ -130,7 +130,7 @@ CEXIIPL::CEXIIPL()
LoadFontFile((File::GetSysDirectory() + GC_SYS_DIR + DIR_SEP + FONT_WINDOWS_1252), 0x1fcf00); LoadFontFile((File::GetSysDirectory() + GC_SYS_DIR + DIR_SEP + FONT_WINDOWS_1252), 0x1fcf00);
} }
auto& sram = Core::System::GetInstance().GetSRAM(); auto& sram = system.GetSRAM();
// Clear RTC // Clear RTC
sram.rtc = 0; sram.rtc = 0;
@ -146,7 +146,7 @@ CEXIIPL::~CEXIIPL() = default;
void CEXIIPL::DoState(PointerWrap& p) void CEXIIPL::DoState(PointerWrap& p)
{ {
auto& sram = Core::System::GetInstance().GetSRAM(); auto& sram = m_system.GetSRAM();
p.Do(sram); p.Do(sram);
p.Do(g_rtc_flags); p.Do(g_rtc_flags);
@ -251,8 +251,8 @@ void CEXIIPL::SetCS(int cs)
void CEXIIPL::UpdateRTC() void CEXIIPL::UpdateRTC()
{ {
auto& sram = Core::System::GetInstance().GetSRAM(); auto& sram = m_system.GetSRAM();
sram.rtc = GetEmulatedTime(GC_EPOCH); sram.rtc = GetEmulatedTime(m_system, GC_EPOCH);
} }
bool CEXIIPL::IsPresent() const bool CEXIIPL::IsPresent() const
@ -342,7 +342,7 @@ void CEXIIPL::TransferByte(u8& data)
} }
else if (IN_RANGE(SRAM)) else if (IN_RANGE(SRAM))
{ {
auto& sram = Core::System::GetInstance().GetSRAM(); auto& sram = m_system.GetSRAM();
u32 dev_addr = DEV_ADDR_CURSOR(SRAM); u32 dev_addr = DEV_ADDR_CURSOR(SRAM);
if (m_command.is_write()) if (m_command.is_write())
sram[dev_addr] = data; sram[dev_addr] = data;
@ -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; u64 ltime = 0;
@ -405,16 +405,14 @@ u32 CEXIIPL::GetEmulatedTime(u32 epoch)
ltime = Movie::GetRecordingStartTime(); ltime = Movie::GetRecordingStartTime();
// let's keep time moving forward, regardless of what it starts at // let's keep time moving forward, regardless of what it starts at
ltime += ltime += system.GetCoreTiming().GetTicks() / SystemTimers::GetTicksPerSecond();
Core::System::GetInstance().GetCoreTiming().GetTicks() / SystemTimers::GetTicksPerSecond();
} }
else if (NetPlay::IsNetPlayRunning()) else if (NetPlay::IsNetPlayRunning())
{ {
ltime = NetPlay_GetEmulatedTime(); ltime = NetPlay_GetEmulatedTime();
// let's keep time moving forward, regardless of what it starts at // let's keep time moving forward, regardless of what it starts at
ltime += ltime += system.GetCoreTiming().GetTicks() / SystemTimers::GetTicksPerSecond();
Core::System::GetInstance().GetCoreTiming().GetTicks() / SystemTimers::GetTicksPerSecond();
} }
else else
{ {

View File

@ -16,7 +16,7 @@ namespace ExpansionInterface
class CEXIIPL : public IEXIDevice class CEXIIPL : public IEXIDevice
{ {
public: public:
CEXIIPL(); explicit CEXIIPL(Core::System& system);
~CEXIIPL() override; ~CEXIIPL() override;
void SetCS(int cs) override; void SetCS(int cs) override;
@ -26,7 +26,7 @@ public:
static constexpr u32 UNIX_EPOCH = 0; // 1970-01-01 00:00:00 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 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 u64 NetPlay_GetEmulatedTime();
static void Descrambler(u8* data, u32 size); static void Descrambler(u8* data, u32 size);

View File

@ -104,9 +104,9 @@ void CEXIMemoryCard::Shutdown()
s_et_transfer_complete.fill(nullptr); 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) 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 {}.", ASSERT_MSG(EXPANSIONINTERFACE, IsMemcardSlot(slot), "Trying to create invalid memory card in {}.",
slot); slot);
@ -144,7 +144,7 @@ CEXIMemoryCard::CEXIMemoryCard(const Slot slot, bool gci_folder,
m_memory_card_size = m_memory_card->GetCardId() * SIZE_TO_Mb; m_memory_card_size = m_memory_card->GetCardId() * SIZE_TO_Mb;
std::array<u8, 20> header{}; std::array<u8, 20> header{};
m_memory_card->Read(0, static_cast<s32>(header.size()), header.data()); 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); SetCardFlashID(&sram, header.data(), m_card_slot);
} }
@ -235,8 +235,7 @@ void CEXIMemoryCard::SetupRawMemcard(u16 size_mb)
CEXIMemoryCard::~CEXIMemoryCard() CEXIMemoryCard::~CEXIMemoryCard()
{ {
auto& system = Core::System::GetInstance(); auto& core_timing = m_system.GetCoreTiming();
auto& core_timing = system.GetCoreTiming();
core_timing.RemoveEvent(s_et_cmd_done[m_card_slot]); core_timing.RemoveEvent(s_et_cmd_done[m_card_slot]);
core_timing.RemoveEvent(s_et_transfer_complete[m_card_slot]); core_timing.RemoveEvent(s_et_transfer_complete[m_card_slot]);
} }
@ -269,8 +268,7 @@ void CEXIMemoryCard::TransferComplete()
void CEXIMemoryCard::CmdDoneLater(u64 cycles) void CEXIMemoryCard::CmdDoneLater(u64 cycles)
{ {
auto& system = Core::System::GetInstance(); auto& core_timing = m_system.GetCoreTiming();
auto& core_timing = system.GetCoreTiming();
core_timing.RemoveEvent(s_et_cmd_done[m_card_slot]); 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)); core_timing.ScheduleEvent(cycles, s_et_cmd_done[m_card_slot], static_cast<u64>(m_card_slot));
} }
@ -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 // read all at once instead of single byte at a time as done by IEXIDevice::DMARead
void CEXIMemoryCard::DMARead(u32 addr, u32 size) void CEXIMemoryCard::DMARead(u32 addr, u32 size)
{ {
auto& system = Core::System::GetInstance(); auto& memory = m_system.GetMemory();
auto& memory = system.GetMemory();
m_memory_card->Read(m_address, size, memory.GetPointer(addr)); m_memory_card->Read(m_address, size, memory.GetPointer(addr));
if ((m_address + size) % Memcard::BLOCK_SIZE == 0) if ((m_address + size) % Memcard::BLOCK_SIZE == 0)
@ -533,7 +530,7 @@ void CEXIMemoryCard::DMARead(u32 addr, u32 size)
} }
// Schedule transfer complete later based on read speed // Schedule transfer complete later based on read speed
system.GetCoreTiming().ScheduleEvent( m_system.GetCoreTiming().ScheduleEvent(
size * (SystemTimers::GetTicksPerSecond() / MC_TRANSFER_RATE_READ), size * (SystemTimers::GetTicksPerSecond() / MC_TRANSFER_RATE_READ),
s_et_transfer_complete[m_card_slot], static_cast<u64>(m_card_slot)); s_et_transfer_complete[m_card_slot], static_cast<u64>(m_card_slot));
} }
@ -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 // write all at once instead of single byte at a time as done by IEXIDevice::DMAWrite
void CEXIMemoryCard::DMAWrite(u32 addr, u32 size) void CEXIMemoryCard::DMAWrite(u32 addr, u32 size)
{ {
auto& system = Core::System::GetInstance(); auto& memory = m_system.GetMemory();
auto& memory = system.GetMemory();
m_memory_card->Write(m_address, size, memory.GetPointer(addr)); m_memory_card->Write(m_address, size, memory.GetPointer(addr));
if (((m_address + size) % Memcard::BLOCK_SIZE) == 0) if (((m_address + size) % Memcard::BLOCK_SIZE) == 0)
@ -552,7 +548,7 @@ void CEXIMemoryCard::DMAWrite(u32 addr, u32 size)
} }
// Schedule transfer complete later based on write speed // Schedule transfer complete later based on write speed
system.GetCoreTiming().ScheduleEvent( m_system.GetCoreTiming().ScheduleEvent(
size * (SystemTimers::GetTicksPerSecond() / MC_TRANSFER_RATE_WRITE), size * (SystemTimers::GetTicksPerSecond() / MC_TRANSFER_RATE_WRITE),
s_et_transfer_complete[m_card_slot], static_cast<u64>(m_card_slot)); s_et_transfer_complete[m_card_slot], static_cast<u64>(m_card_slot));
} }

View File

@ -36,7 +36,8 @@ enum class AllowMovieFolder
class CEXIMemoryCard : public IEXIDevice class CEXIMemoryCard : public IEXIDevice
{ {
public: 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; ~CEXIMemoryCard() override;
void SetCS(int cs) override; void SetCS(int cs) override;
bool IsInterruptSet() override; bool IsInterruptSet() override;

View File

@ -196,8 +196,8 @@ void CEXIMic::StreamReadOne()
u8 const CEXIMic::exi_id[] = {0, 0x0a, 0, 0, 0}; u8 const CEXIMic::exi_id[] = {0, 0x0a, 0, 0, 0};
CEXIMic::CEXIMic(int index) CEXIMic::CEXIMic(Core::System& system, int index)
: slot(index) : IEXIDevice(system), slot(index)
#ifdef _WIN32 #ifdef _WIN32
, ,
m_work_queue("Mic Worker", [](const std::function<void()>& func) { func(); }) m_work_queue("Mic Worker", [](const std::function<void()>& func) { func(); })
@ -265,13 +265,13 @@ void CEXIMic::SetCS(int cs)
void CEXIMic::UpdateNextInterruptTicks() void CEXIMic::UpdateNextInterruptTicks()
{ {
int diff = (SystemTimers::GetTicksPerSecond() / sample_rate) * buff_size_samples; 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); ExpansionInterface::ScheduleUpdateInterrupts(CoreTiming::FromThread::CPU, diff);
} }
bool CEXIMic::IsInterruptSet() 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) if (status.is_active)
UpdateNextInterruptTicks(); UpdateNextInterruptTicks();

View File

@ -17,7 +17,7 @@ namespace ExpansionInterface
class CEXIMic : public IEXIDevice class CEXIMic : public IEXIDevice
{ {
public: public:
CEXIMic(const int index); CEXIMic(Core::System& system, const int index);
virtual ~CEXIMic(); virtual ~CEXIMic();
void SetCS(int cs) override; void SetCS(int cs) override;
bool IsInterruptSet() override; bool IsInterruptSet() override;

View File

@ -284,7 +284,7 @@ void Init()
core_timing.SetFakeTBStartValue(static_cast<u64>(s_cpu_core_clock / TIMER_RATIO) * core_timing.SetFakeTBStartValue(static_cast<u64>(s_cpu_core_clock / TIMER_RATIO) *
static_cast<u64>(ExpansionInterface::CEXIIPL::GetEmulatedTime( static_cast<u64>(ExpansionInterface::CEXIIPL::GetEmulatedTime(
ExpansionInterface::CEXIIPL::GC_EPOCH))); system, ExpansionInterface::CEXIIPL::GC_EPOCH)));
core_timing.SetFakeTBStartTicks(core_timing.GetTicks()); core_timing.SetFakeTBStartTicks(core_timing.GetTicks());

View File

@ -362,7 +362,8 @@ bool ESDevice::LaunchIOS(u64 ios_title_id, HangPPC hang_ppc)
const ES::TicketReader ticket = FindSignedTicket(ios_title_id); const ES::TicketReader ticket = FindSignedTicket(ios_title_id);
ES::Content content; ES::Content content;
if (!tmd.IsValid() || !ticket.IsValid() || !tmd.GetContent(tmd.GetBootIndex(), &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" PanicAlertFmtT("Could not launch IOS {0:016x} because it is missing from the NAND.\n"
"The emulated software will likely hang now.", "The emulated software will likely hang now.",
@ -372,7 +373,7 @@ bool ESDevice::LaunchIOS(u64 ios_title_id, HangPPC hang_ppc)
return true; 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) s32 ESDevice::WriteLaunchFile(const ES::TMDReader& tmd, Ticks ticks)
@ -471,7 +472,8 @@ bool ESDevice::LaunchPPCTitle(u64 title_id)
bool ESDevice::BootstrapPPC() 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 = {}; m_pending_ppc_boot_content_path = {};
return result; return result;
} }

View File

@ -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. // 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. // 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. // Seeking and processing overhead is ignored as most time is spent reading from the NAND.
u64 ticks = 0; u64 ticks = 0;
@ -422,12 +422,11 @@ bool Kernel::BootstrapPPC(const std::string& boot_content_path)
if (dol.IsAncast()) if (dol.IsAncast())
INFO_LOG_FMT(IOS, "BootstrapPPC: Loading ancast image"); INFO_LOG_FMT(IOS, "BootstrapPPC: Loading ancast image");
if (!dol.LoadIntoMemory()) if (!dol.LoadIntoMemory(system))
return false; return false;
INFO_LOG_FMT(IOS, "BootstrapPPC: {}", boot_content_path); INFO_LOG_FMT(IOS, "BootstrapPPC: {}", boot_content_path);
Core::System::GetInstance().GetCoreTiming().ScheduleEvent(ticks, s_event_finish_ppc_bootstrap, system.GetCoreTiming().ScheduleEvent(ticks, s_event_finish_ppc_bootstrap, dol.IsAncast());
dol.IsAncast());
return true; return true;
} }
@ -478,7 +477,8 @@ static constexpr SystemTimers::TimeBaseTick GetIOSBootTicks(u32 version)
// Passing a boot content path is optional because we do not require IOSes // 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 // 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. // 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. // IOS suspends regular PPC<->ARM IPC before loading a new IOS.
// IPC is not resumed if the boot fails for any reason. // IPC is not resumed if the boot fails for any reason.
@ -494,7 +494,7 @@ bool Kernel::BootIOS(const u64 ios_title_id, HangPPC hang_ppc, const std::string
return false; return false;
ElfReader elf{binary.GetElf()}; ElfReader elf{binary.GetElf()};
if (!elf.LoadIntoMemory(true)) if (!elf.LoadIntoMemory(system, true))
return false; return false;
} }
@ -503,8 +503,8 @@ bool Kernel::BootIOS(const u64 ios_title_id, HangPPC hang_ppc, const std::string
if (Core::IsRunningAndStarted()) if (Core::IsRunningAndStarted())
{ {
Core::System::GetInstance().GetCoreTiming().ScheduleEvent( system.GetCoreTiming().ScheduleEvent(GetIOSBootTicks(GetVersion()), s_event_finish_ios_boot,
GetIOSBootTicks(GetVersion()), s_event_finish_ios_boot, ios_title_id); ios_title_id);
} }
else else
{ {
@ -914,7 +914,7 @@ static void FinishPPCBootstrap(Core::System& system, u64 userdata, s64 cycles_la
ReleasePPC(); ReleasePPC();
ASSERT(Core::IsCPUThread()); ASSERT(Core::IsCPUThread());
Core::CPUThreadGuard guard; Core::CPUThreadGuard guard(system);
SConfig::OnNewTitleLoad(guard); SConfig::OnNewTitleLoad(guard);
INFO_LOG_FMT(IOS, "Bootstrapping done."); INFO_LOG_FMT(IOS, "Bootstrapping done.");

View File

@ -20,6 +20,11 @@
class PointerWrap; class PointerWrap;
namespace Core
{
class System;
}
namespace IOS::HLE namespace IOS::HLE
{ {
namespace FS namespace FS
@ -134,8 +139,8 @@ public:
void SetGidForPPC(u16 gid); void SetGidForPPC(u16 gid);
u16 GetGidForPPC() const; u16 GetGidForPPC() const;
bool BootstrapPPC(const std::string& boot_content_path); bool BootstrapPPC(Core::System& system, const std::string& boot_content_path);
bool BootIOS(u64 ios_title_id, HangPPC hang_ppc = HangPPC::No, bool BootIOS(Core::System& system, u64 ios_title_id, HangPPC hang_ppc = HangPPC::No,
const std::string& boot_content_path = {}); const std::string& boot_content_path = {});
void InitIPC(); void InitIPC();
u32 GetVersion() const; u32 GetVersion() const;

View File

@ -61,7 +61,7 @@ bool Load()
auto& memory = system.GetMemory(); auto& memory = system.GetMemory();
ASSERT(Core::IsCPUThread()); ASSERT(Core::IsCPUThread());
Core::CPUThreadGuard guard; Core::CPUThreadGuard guard(system);
memory.Write_U32(0x00000000, ADDRESS_INIT_SEMAPHORE); memory.Write_U32(0x00000000, ADDRESS_INIT_SEMAPHORE);
memory.Write_U32(0x09142001, 0x3180); memory.Write_U32(0x09142001, 0x3180);

View File

@ -91,7 +91,8 @@ u64 NetKDTimeDevice::GetAdjustedUTC() const
{ {
using namespace ExpansionInterface; 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); tm* const gm_time = gmtime(&current_time);
const u32 emulated_time = mktime(gm_time); const u32 emulated_time = mktime(gm_time);
return u64(s64(emulated_time) + utcdiff); return u64(s64(emulated_time) + utcdiff);
@ -101,7 +102,8 @@ void NetKDTimeDevice::SetAdjustedUTC(u64 wii_utc)
{ {
using namespace ExpansionInterface; 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); tm* const gm_time = gmtime(&current_time);
const u32 emulated_time = mktime(gm_time); const u32 emulated_time = mktime(gm_time);
utcdiff = s64(emulated_time - wii_utc); utcdiff = s64(emulated_time - wii_utc);

View File

@ -201,7 +201,8 @@ std::string GetRTCDisplay()
{ {
using ExpansionInterface::CEXIIPL; 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); const tm* const gm_time = gmtime(&current_time);
std::ostringstream format_time; std::ostringstream format_time;

View File

@ -322,7 +322,7 @@ bool ApplyFramePatches()
auto& ppc_state = system.GetPPCState(); auto& ppc_state = system.GetPPCState();
ASSERT(Core::IsCPUThread()); 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 // 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. // callback hook we can end up catching the game in an exception vector.

View File

@ -83,7 +83,7 @@ static double HostReadFunc(expr_func* f, vec_expr_t* args, void* c)
return 0; return 0;
const u32 address = static_cast<u32>(expr_eval(&vec_nth(args, 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)); return Common::BitCast<T>(HostRead<U>(guard, address));
} }
@ -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 T var = static_cast<T>(expr_eval(&vec_nth(args, 0)));
const u32 address = static_cast<u32>(expr_eval(&vec_nth(args, 1))); 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); HostWrite<U>(guard, Common::BitCast<U>(var), address);
return var; return var;
} }
@ -115,8 +115,9 @@ static double CallstackFunc(expr_func* f, vec_expr_t* args, void* c)
std::vector<Dolphin_Debugger::CallstackEntry> stack; std::vector<Dolphin_Debugger::CallstackEntry> stack;
{ {
Core::CPUThreadGuard guard; auto& system = Core::System::GetInstance();
bool success = Dolphin_Debugger::GetCallstack(Core::System::GetInstance(), guard, stack); Core::CPUThreadGuard guard(system);
bool success = Dolphin_Debugger::GetCallstack(system, guard, stack);
if (!success) if (!success)
return 0; return 0;
} }
@ -163,7 +164,7 @@ static double StreqFunc(expr_func* f, vec_expr_t* args, void* c)
return 0; return 0;
std::array<std::string, 2> strs; std::array<std::string, 2> strs;
Core::CPUThreadGuard guard; Core::CPUThreadGuard guard(Core::System::GetInstance());
for (int i = 0; i < 2; i++) for (int i = 0; i < 2; i++)
{ {
std::optional<std::string> arg = ReadStringArg(guard, &vec_nth(args, i)); std::optional<std::string> arg = ReadStringArg(guard, &vec_nth(args, i));

View File

@ -997,7 +997,7 @@ void ProcessCommands(bool loop_until_continue)
case 'm': case 'm':
{ {
ASSERT(Core::IsCPUThread()); ASSERT(Core::IsCPUThread());
Core::CPUThreadGuard guard; Core::CPUThreadGuard guard(system);
ReadMemory(guard); ReadMemory(guard);
break; break;
@ -1005,7 +1005,7 @@ void ProcessCommands(bool loop_until_continue)
case 'M': case 'M':
{ {
ASSERT(Core::IsCPUThread()); ASSERT(Core::IsCPUThread());
Core::CPUThreadGuard guard; Core::CPUThreadGuard guard(system);
WriteMemory(guard); WriteMemory(guard);
auto& ppc_state = system.GetPPCState(); auto& ppc_state = system.GetPPCState();

View File

@ -343,7 +343,7 @@ void Interpreter::unknown_instruction(UGeckoInstruction inst)
{ {
ASSERT(Core::IsCPUThread()); ASSERT(Core::IsCPUThread());
auto& system = Core::System::GetInstance(); auto& system = Core::System::GetInstance();
Core::CPUThreadGuard guard; Core::CPUThreadGuard guard(system);
const u32 opcode = PowerPC::HostRead_U32(guard, last_pc); const u32 opcode = PowerPC::HostRead_U32(guard, last_pc);
const std::string disasm = Common::GekkoDisassembler::Disassemble(opcode, last_pc); const std::string disasm = Common::GekkoDisassembler::Disassemble(opcode, last_pc);

View File

@ -10,6 +10,7 @@
#include "Core/HLE/HLE.h" #include "Core/HLE/HLE.h"
#include "Core/PowerPC/Interpreter/ExceptionUtils.h" #include "Core/PowerPC/Interpreter/ExceptionUtils.h"
#include "Core/PowerPC/PowerPC.h" #include "Core/PowerPC/PowerPC.h"
#include "Core/System.h"
void Interpreter::bx(UGeckoInstruction inst) void Interpreter::bx(UGeckoInstruction inst)
{ {
@ -98,7 +99,7 @@ void Interpreter::HLEFunction(UGeckoInstruction inst)
m_end_block = true; m_end_block = true;
ASSERT(Core::IsCPUThread()); ASSERT(Core::IsCPUThread());
Core::CPUThreadGuard guard; Core::CPUThreadGuard guard(Core::System::GetInstance());
HLE::Execute(guard, PowerPC::ppcState.pc, inst.hex); HLE::Execute(guard, PowerPC::ppcState.pc, inst.hex);
} }

View File

@ -30,6 +30,7 @@
#include "Core/PowerPC/PPCSymbolDB.h" #include "Core/PowerPC/PPCSymbolDB.h"
#include "Core/PowerPC/PowerPC.h" #include "Core/PowerPC/PowerPC.h"
#include "Core/PowerPC/Profiler.h" #include "Core/PowerPC/Profiler.h"
#include "Core/System.h"
#if _M_X86 #if _M_X86
#include "Core/PowerPC/Jit64/Jit.h" #include "Core/PowerPC/Jit64/Jit.h"
@ -273,7 +274,7 @@ void CompileExceptionCheck(ExceptionType type)
if (type == ExceptionType::FIFOWrite) if (type == ExceptionType::FIFOWrite)
{ {
ASSERT(Core::IsCPUThread()); 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? // Check in case the code has been replaced since: do we need to do this?
const OpType optype = const OpType optype =

View File

@ -37,6 +37,7 @@
#include "Core/ConfigManager.h" #include "Core/ConfigManager.h"
#include "Core/Core.h" #include "Core/Core.h"
#include "Core/PowerPC/PowerPC.h" #include "Core/PowerPC/PowerPC.h"
#include "Core/System.h"
#include "DolphinQt/Config/CheatCodeEditor.h" #include "DolphinQt/Config/CheatCodeEditor.h"
#include "DolphinQt/Config/CheatWarningWidget.h" #include "DolphinQt/Config/CheatWarningWidget.h"
@ -288,7 +289,7 @@ void CheatSearchWidget::OnNextScanClicked()
} }
const Cheats::SearchErrorCode error_code = [this] { const Cheats::SearchErrorCode error_code = [this] {
Core::CPUThreadGuard guard; Core::CPUThreadGuard guard(Core::System::GetInstance());
return m_session->RunSearch(guard); return m_session->RunSearch(guard);
}(); }();
@ -397,7 +398,7 @@ bool CheatSearchWidget::RefreshValues()
tmp->SetFilterType(Cheats::FilterType::DoNotFilter); tmp->SetFilterType(Cheats::FilterType::DoNotFilter);
const Cheats::SearchErrorCode error_code = [&tmp] { const Cheats::SearchErrorCode error_code = [&tmp] {
Core::CPUThreadGuard guard; Core::CPUThreadGuard guard(Core::System::GetInstance());
return tmp->RunSearch(guard); return tmp->RunSearch(guard);
}(); }();

View File

@ -23,6 +23,7 @@
#include "Core/PowerPC/PPCSymbolDB.h" #include "Core/PowerPC/PPCSymbolDB.h"
#include "Core/PowerPC/PowerPC.h" #include "Core/PowerPC/PowerPC.h"
#include "Core/PowerPC/Profiler.h" #include "Core/PowerPC/Profiler.h"
#include "Core/System.h"
#include "DolphinQt/Debugger/CodeWidget.h" #include "DolphinQt/Debugger/CodeWidget.h"
#include "DolphinQt/Host.h" #include "DolphinQt/Host.h"
@ -485,7 +486,7 @@ void CodeDiffDialog::OnSetBLR()
return; return;
{ {
Core::CPUThreadGuard guard; Core::CPUThreadGuard guard(Core::System::GetInstance());
PowerPC::debug_interface.SetPatch(guard, symbol->address, 0x4E800020); PowerPC::debug_interface.SetPatch(guard, symbol->address, 0x4E800020);
} }

View File

@ -33,6 +33,7 @@
#include "Core/PowerPC/PPCAnalyst.h" #include "Core/PowerPC/PPCAnalyst.h"
#include "Core/PowerPC/PPCSymbolDB.h" #include "Core/PowerPC/PPCSymbolDB.h"
#include "Core/PowerPC/PowerPC.h" #include "Core/PowerPC/PowerPC.h"
#include "Core/System.h"
#include "DolphinQt/Debugger/PatchInstructionDialog.h" #include "DolphinQt/Debugger/PatchInstructionDialog.h"
#include "DolphinQt/Host.h" #include "DolphinQt/Host.h"
#include "DolphinQt/Resources.h" #include "DolphinQt/Resources.h"
@ -258,7 +259,7 @@ void CodeViewWidget::Update()
if (Core::GetState() == Core::State::Paused) if (Core::GetState() == Core::State::Paused)
{ {
Core::CPUThreadGuard guard; Core::CPUThreadGuard guard(Core::System::GetInstance());
Update(&guard); Update(&guard);
} }
else else
@ -532,7 +533,7 @@ void CodeViewWidget::SetAddress(u32 address, SetAddressUpdate update)
void CodeViewWidget::ReplaceAddress(u32 address, ReplaceWith replace) void CodeViewWidget::ReplaceAddress(u32 address, ReplaceWith replace)
{ {
Core::CPUThreadGuard guard; Core::CPUThreadGuard guard(Core::System::GetInstance());
PowerPC::debug_interface.SetPatch(guard, address, PowerPC::debug_interface.SetPatch(guard, address,
replace == ReplaceWith::BLR ? 0x4e800020 : 0x60000000); replace == ReplaceWith::BLR ? 0x4e800020 : 0x60000000);
@ -594,7 +595,7 @@ void CodeViewWidget::OnContextMenu()
bool follow_branch_enabled = false; bool follow_branch_enabled = false;
if (paused) if (paused)
{ {
Core::CPUThreadGuard guard; Core::CPUThreadGuard guard(Core::System::GetInstance());
const std::string disasm = PowerPC::debug_interface.Disassemble(&guard, PowerPC::ppcState.pc); const std::string disasm = PowerPC::debug_interface.Disassemble(&guard, PowerPC::ppcState.pc);
if (addr == PowerPC::ppcState.pc) if (addr == PowerPC::ppcState.pc)
@ -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 // 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. // 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; CodeTrace code_trace;
bool repeat = false; bool repeat = false;
@ -741,7 +742,7 @@ void CodeViewWidget::OnCopyTargetAddress()
const u32 addr = GetContextAddress(); const u32 addr = GetContextAddress();
const std::string code_line = [addr] { const std::string code_line = [addr] {
Core::CPUThreadGuard guard; Core::CPUThreadGuard guard(Core::System::GetInstance());
return PowerPC::debug_interface.Disassemble(&guard, addr); return PowerPC::debug_interface.Disassemble(&guard, addr);
}(); }();
@ -771,7 +772,7 @@ void CodeViewWidget::OnShowTargetInMemory()
const u32 addr = GetContextAddress(); const u32 addr = GetContextAddress();
const std::string code_line = [addr] { const std::string code_line = [addr] {
Core::CPUThreadGuard guard; Core::CPUThreadGuard guard(Core::System::GetInstance());
return PowerPC::debug_interface.Disassemble(&guard, addr); return PowerPC::debug_interface.Disassemble(&guard, addr);
}(); }();
@ -790,7 +791,7 @@ void CodeViewWidget::OnCopyCode()
const u32 addr = GetContextAddress(); const u32 addr = GetContextAddress();
const std::string text = [addr] { const std::string text = [addr] {
Core::CPUThreadGuard guard; Core::CPUThreadGuard guard(Core::System::GetInstance());
return PowerPC::debug_interface.Disassemble(&guard, addr); return PowerPC::debug_interface.Disassemble(&guard, addr);
}(); }();
@ -808,7 +809,7 @@ void CodeViewWidget::OnCopyFunction()
std::string text = symbol->name + "\r\n"; std::string text = symbol->name + "\r\n";
{ {
Core::CPUThreadGuard guard; Core::CPUThreadGuard guard(Core::System::GetInstance());
// we got a function // we got a function
const u32 start = symbol->address; const u32 start = symbol->address;
@ -828,7 +829,7 @@ void CodeViewWidget::OnCopyHex()
const u32 addr = GetContextAddress(); const u32 addr = GetContextAddress();
const u32 instruction = [addr] { const u32 instruction = [addr] {
Core::CPUThreadGuard guard; Core::CPUThreadGuard guard(Core::System::GetInstance());
return PowerPC::debug_interface.ReadInstruction(guard, addr); return PowerPC::debug_interface.ReadInstruction(guard, addr);
}(); }();
@ -856,7 +857,7 @@ void CodeViewWidget::OnAddFunction()
{ {
const u32 addr = GetContextAddress(); const u32 addr = GetContextAddress();
Core::CPUThreadGuard guard; Core::CPUThreadGuard guard(Core::System::GetInstance());
g_symbolDB.AddFunction(guard, addr); g_symbolDB.AddFunction(guard, addr);
emit SymbolsChanged(); emit SymbolsChanged();
@ -882,7 +883,7 @@ void CodeViewWidget::OnFollowBranch()
const u32 addr = GetContextAddress(); const u32 addr = GetContextAddress();
const u32 branch_addr = [addr] { const u32 branch_addr = [addr] {
Core::CPUThreadGuard guard; Core::CPUThreadGuard guard(Core::System::GetInstance());
return GetBranchFromAddress(guard, addr); return GetBranchFromAddress(guard, addr);
}(); }();
@ -945,7 +946,7 @@ void CodeViewWidget::OnSetSymbolSize()
if (!good) if (!good)
return; return;
Core::CPUThreadGuard guard; Core::CPUThreadGuard guard(Core::System::GetInstance());
PPCAnalyst::ReanalyzeFunction(guard, symbol->address, *symbol, size); PPCAnalyst::ReanalyzeFunction(guard, symbol->address, *symbol, size);
emit SymbolsChanged(); emit SymbolsChanged();
@ -973,7 +974,7 @@ void CodeViewWidget::OnSetSymbolEndAddress()
if (!good) if (!good)
return; return;
Core::CPUThreadGuard guard; Core::CPUThreadGuard guard(Core::System::GetInstance());
PPCAnalyst::ReanalyzeFunction(guard, symbol->address, *symbol, address - symbol->address); PPCAnalyst::ReanalyzeFunction(guard, symbol->address, *symbol, address - symbol->address);
emit SymbolsChanged(); emit SymbolsChanged();
@ -982,7 +983,7 @@ void CodeViewWidget::OnSetSymbolEndAddress()
void CodeViewWidget::OnReplaceInstruction() void CodeViewWidget::OnReplaceInstruction()
{ {
Core::CPUThreadGuard guard; Core::CPUThreadGuard guard(Core::System::GetInstance());
const u32 addr = GetContextAddress(); const u32 addr = GetContextAddress();
@ -1004,7 +1005,7 @@ void CodeViewWidget::OnReplaceInstruction()
void CodeViewWidget::OnRestoreInstruction() void CodeViewWidget::OnRestoreInstruction()
{ {
Core::CPUThreadGuard guard; Core::CPUThreadGuard guard(Core::System::GetInstance());
const u32 addr = GetContextAddress(); const u32 addr = GetContextAddress();

View File

@ -330,7 +330,7 @@ void CodeWidget::UpdateCallstack()
std::vector<Dolphin_Debugger::CallstackEntry> stack; std::vector<Dolphin_Debugger::CallstackEntry> stack;
const bool success = [&stack] { const bool success = [&stack] {
Core::CPUThreadGuard guard; Core::CPUThreadGuard guard(Core::System::GetInstance());
return Dolphin_Debugger::GetCallstack(Core::System::GetInstance(), guard, stack); return Dolphin_Debugger::GetCallstack(Core::System::GetInstance(), guard, stack);
}(); }();
@ -461,8 +461,8 @@ void CodeWidget::StepOver()
if (!cpu.IsStepping()) if (!cpu.IsStepping())
return; return;
const UGeckoInstruction inst = [] { const UGeckoInstruction inst = [&] {
Core::CPUThreadGuard guard; Core::CPUThreadGuard guard(system);
return PowerPC::HostRead_Instruction(guard, PowerPC::ppcState.pc); return PowerPC::HostRead_Instruction(guard, PowerPC::ppcState.pc);
}(); }();
@ -506,7 +506,7 @@ void CodeWidget::StepOut()
clock::time_point timeout = clock::now() + std::chrono::seconds(5); clock::time_point timeout = clock::now() + std::chrono::seconds(5);
{ {
Core::CPUThreadGuard guard; Core::CPUThreadGuard guard(system);
PowerPC::breakpoints.ClearAllTemporary(); PowerPC::breakpoints.ClearAllTemporary();

View File

@ -25,6 +25,7 @@
#include "Core/HW/AddressSpace.h" #include "Core/HW/AddressSpace.h"
#include "Core/PowerPC/BreakPoints.h" #include "Core/PowerPC/BreakPoints.h"
#include "Core/PowerPC/PowerPC.h" #include "Core/PowerPC/PowerPC.h"
#include "Core/System.h"
#include "DolphinQt/Host.h" #include "DolphinQt/Host.h"
#include "DolphinQt/Resources.h" #include "DolphinQt/Resources.h"
#include "DolphinQt/Settings.h" #include "DolphinQt/Settings.h"
@ -153,7 +154,7 @@ public:
u32 end_address = address + static_cast<u32>(bytes.size()) - 1; u32 end_address = address + static_cast<u32>(bytes.size()) - 1;
AddressSpace::Accessors* accessors = AddressSpace::GetAccessors(m_view->GetAddressSpace()); AddressSpace::Accessors* accessors = AddressSpace::GetAccessors(m_view->GetAddressSpace());
Core::CPUThreadGuard guard; Core::CPUThreadGuard guard(Core::System::GetInstance());
if (!bytes.empty() && accessors->IsValidAddress(guard, address) && if (!bytes.empty() && accessors->IsValidAddress(guard, address) &&
accessors->IsValidAddress(guard, end_address)) accessors->IsValidAddress(guard, end_address))
@ -442,7 +443,7 @@ void MemoryViewWidget::UpdateColumns()
if (Core::GetState() == Core::State::Paused) if (Core::GetState() == Core::State::Paused)
{ {
Core::CPUThreadGuard guard; Core::CPUThreadGuard guard(Core::System::GetInstance());
UpdateColumns(&guard); UpdateColumns(&guard);
} }
else else
@ -850,7 +851,7 @@ void MemoryViewWidget::OnCopyHex(u32 addr)
const AddressSpace::Accessors* accessors = AddressSpace::GetAccessors(m_address_space); const AddressSpace::Accessors* accessors = AddressSpace::GetAccessors(m_address_space);
const u64 value = [addr, accessors] { const u64 value = [addr, accessors] {
Core::CPUThreadGuard guard; Core::CPUThreadGuard guard(Core::System::GetInstance());
return accessors->ReadU64(guard, addr); return accessors->ReadU64(guard, addr);
}(); }();
@ -873,7 +874,7 @@ void MemoryViewWidget::OnContextMenu(const QPoint& pos)
[this, addr] { [this, addr] {
const AddressSpace::Accessors* accessors = AddressSpace::GetAccessors(m_address_space); const AddressSpace::Accessors* accessors = AddressSpace::GetAccessors(m_address_space);
Core::CPUThreadGuard guard; Core::CPUThreadGuard guard(Core::System::GetInstance());
return accessors->IsValidAddress(guard, addr); return accessors->IsValidAddress(guard, addr);
}(); }();

View File

@ -32,6 +32,7 @@
#include "Core/ConfigManager.h" #include "Core/ConfigManager.h"
#include "Core/Core.h" #include "Core/Core.h"
#include "Core/HW/AddressSpace.h" #include "Core/HW/AddressSpace.h"
#include "Core/System.h"
#include "DolphinQt/Debugger/MemoryViewWidget.h" #include "DolphinQt/Debugger/MemoryViewWidget.h"
#include "DolphinQt/Host.h" #include "DolphinQt/Host.h"
#include "DolphinQt/QtUtils/ModalMessageBox.h" #include "DolphinQt/QtUtils/ModalMessageBox.h"
@ -496,7 +497,7 @@ void MemoryWidget::SetAddress(u32 address)
AddressSpace::Accessors* accessors = AddressSpace::Accessors* accessors =
AddressSpace::GetAccessors(m_memory_view->GetAddressSpace()); AddressSpace::GetAccessors(m_memory_view->GetAddressSpace());
Core::CPUThreadGuard guard; Core::CPUThreadGuard guard(Core::System::GetInstance());
good = accessors->IsValidAddress(guard, current_addr); good = accessors->IsValidAddress(guard, current_addr);
} }
@ -653,7 +654,7 @@ void MemoryWidget::OnSetValue()
return; return;
} }
Core::CPUThreadGuard guard; Core::CPUThreadGuard guard(Core::System::GetInstance());
AddressSpace::Accessors* accessors = AddressSpace::GetAccessors(m_memory_view->GetAddressSpace()); AddressSpace::Accessors* accessors = AddressSpace::GetAccessors(m_memory_view->GetAddressSpace());
u32 end_address = target_addr.address + static_cast<u32>(bytes.size()) - 1; u32 end_address = target_addr.address + static_cast<u32>(bytes.size()) - 1;
@ -715,7 +716,7 @@ void MemoryWidget::OnSetValueFromFile()
AddressSpace::Accessors* accessors = AddressSpace::GetAccessors(m_memory_view->GetAddressSpace()); AddressSpace::Accessors* accessors = AddressSpace::GetAccessors(m_memory_view->GetAddressSpace());
Core::CPUThreadGuard guard; Core::CPUThreadGuard guard(Core::System::GetInstance());
for (u8 b : file_contents) for (u8 b : file_contents)
accessors->WriteU8(guard, target_addr.address++, b); accessors->WriteU8(guard, target_addr.address++, b);
@ -833,7 +834,7 @@ void MemoryWidget::FindValue(bool next)
AddressSpace::Accessors* accessors = AddressSpace::Accessors* accessors =
AddressSpace::GetAccessors(m_memory_view->GetAddressSpace()); AddressSpace::GetAccessors(m_memory_view->GetAddressSpace());
Core::CPUThreadGuard guard; Core::CPUThreadGuard guard(Core::System::GetInstance());
return accessors->Search(guard, target_addr.address, return accessors->Search(guard, target_addr.address,
reinterpret_cast<const u8*>(search_for.data()), reinterpret_cast<const u8*>(search_for.data()),
static_cast<u32>(search_for.size()), next); static_cast<u32>(search_for.size()), next);

View File

@ -296,7 +296,7 @@ void RegisterWidget::AutoStep(const std::string& reg) const
while (true) while (true)
{ {
const AutoStepResults results = [&trace] { const AutoStepResults results = [&trace] {
Core::CPUThreadGuard guard; Core::CPUThreadGuard guard(Core::System::GetInstance());
return trace.AutoStepping(guard, true); return trace.AutoStepping(guard, true);
}(); }();

View File

@ -15,6 +15,7 @@
#include "Core/Core.h" #include "Core/Core.h"
#include "Core/PowerPC/MMU.h" #include "Core/PowerPC/MMU.h"
#include "Core/PowerPC/PowerPC.h" #include "Core/PowerPC/PowerPC.h"
#include "Core/System.h"
#include "DolphinQt/Host.h" #include "DolphinQt/Host.h"
#include "DolphinQt/Settings.h" #include "DolphinQt/Settings.h"
@ -257,7 +258,7 @@ void ThreadWidget::Update()
m_thread_table->setRowCount(0); m_thread_table->setRowCount(0);
UpdateThreadContext({}); UpdateThreadContext({});
Core::CPUThreadGuard guard; Core::CPUThreadGuard guard(Core::System::GetInstance());
UpdateThreadCallstack(guard, {}); UpdateThreadCallstack(guard, {});
} }
if (emu_state != Core::State::Paused) if (emu_state != Core::State::Paused)
@ -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 // YAGCD - Section 4.2.1.4 Dolphin OS Globals
m_current_context->setText(format_hex_from(guard, 0x800000D4)); m_current_context->setText(format_hex_from(guard, 0x800000D4));
@ -471,7 +472,7 @@ void ThreadWidget::UpdateThreadCallstack(const Core::CPUThreadGuard& guard,
void ThreadWidget::OnSelectionChanged(int row) void ThreadWidget::OnSelectionChanged(int row)
{ {
Core::CPUThreadGuard guard; Core::CPUThreadGuard guard(Core::System::GetInstance());
Common::Debug::PartialContext context; Common::Debug::PartialContext context;
if (row >= 0 && size_t(row) < m_threads.size()) if (row >= 0 && size_t(row) < m_threads.size())

View File

@ -16,6 +16,7 @@
#include "Core/Core.h" #include "Core/Core.h"
#include "Core/PowerPC/MMU.h" #include "Core/PowerPC/MMU.h"
#include "Core/PowerPC/PowerPC.h" #include "Core/PowerPC/PowerPC.h"
#include "Core/System.h"
#include "DolphinQt/Host.h" #include "DolphinQt/Host.h"
#include "DolphinQt/QtUtils/ModalMessageBox.h" #include "DolphinQt/QtUtils/ModalMessageBox.h"
@ -166,7 +167,7 @@ void WatchWidget::Update()
m_table->setDisabled(false); m_table->setDisabled(false);
m_table->clearContents(); m_table->clearContents();
Core::CPUThreadGuard guard; Core::CPUThreadGuard guard(Core::System::GetInstance());
int size = static_cast<int>(PowerPC::debug_interface.GetWatches().size()); int size = static_cast<int>(PowerPC::debug_interface.GetWatches().size());
@ -295,7 +296,7 @@ void WatchWidget::OnLoad()
return; return;
} }
Core::CPUThreadGuard guard; Core::CPUThreadGuard guard(Core::System::GetInstance());
if (ini.GetLines("Watches", &watches, false)) if (ini.GetLines("Watches", &watches, false))
{ {
@ -405,7 +406,7 @@ void WatchWidget::OnItemChanged(QTableWidgetItem* item)
if (good) if (good)
{ {
Core::CPUThreadGuard guard; Core::CPUThreadGuard guard(Core::System::GetInstance());
if (column == COLUMN_INDEX_ADDRESS) if (column == COLUMN_INDEX_ADDRESS)
{ {
@ -430,7 +431,7 @@ void WatchWidget::OnItemChanged(QTableWidgetItem* item)
{ {
PowerPC::debug_interface.UpdateWatchLockedState(row, item->checkState() == Qt::Checked); PowerPC::debug_interface.UpdateWatchLockedState(row, item->checkState() == Qt::Checked);
const auto& watch = PowerPC::debug_interface.GetWatch(row); const auto& watch = PowerPC::debug_interface.GetWatch(row);
Core::CPUThreadGuard guard; Core::CPUThreadGuard guard(Core::System::GetInstance());
if (watch.locked) if (watch.locked)
LockWatchAddress(guard, watch.address); LockWatchAddress(guard, watch.address);
else else
@ -459,7 +460,7 @@ void WatchWidget::LockWatchAddress(const Core::CPUThreadGuard& guard, u32 addres
void WatchWidget::DeleteSelectedWatches() void WatchWidget::DeleteSelectedWatches()
{ {
{ {
Core::CPUThreadGuard guard; Core::CPUThreadGuard guard(Core::System::GetInstance());
std::vector<int> row_indices; std::vector<int> row_indices;
for (const auto& index : m_table->selectionModel()->selectedRows()) for (const auto& index : m_table->selectionModel()->selectedRows())
{ {
@ -491,7 +492,7 @@ void WatchWidget::DeleteWatch(const Core::CPUThreadGuard& guard, int row)
void WatchWidget::DeleteWatchAndUpdate(int row) void WatchWidget::DeleteWatchAndUpdate(int row)
{ {
{ {
Core::CPUThreadGuard guard; Core::CPUThreadGuard guard(Core::System::GetInstance());
DeleteWatch(guard, row); DeleteWatch(guard, row);
} }
@ -517,7 +518,7 @@ void WatchWidget::AddWatch(QString name, u32 addr)
void WatchWidget::LockSelectedWatches() void WatchWidget::LockSelectedWatches()
{ {
{ {
Core::CPUThreadGuard guard; Core::CPUThreadGuard guard(Core::System::GetInstance());
for (const auto& index : m_table->selectionModel()->selectedRows()) for (const auto& index : m_table->selectionModel()->selectedRows())
{ {
const auto* item = m_table->item(index.row(), index.column()); const auto* item = m_table->item(index.row(), index.column());
@ -539,7 +540,7 @@ void WatchWidget::LockSelectedWatches()
void WatchWidget::UnlockSelectedWatches() void WatchWidget::UnlockSelectedWatches()
{ {
{ {
Core::CPUThreadGuard guard; Core::CPUThreadGuard guard(Core::System::GetInstance());
for (const auto& index : m_table->selectionModel()->selectedRows()) for (const auto& index : m_table->selectionModel()->selectedRows())
{ {
const auto* item = m_table->item(index.row(), index.column()); const auto* item = m_table->item(index.row(), index.column());

View File

@ -1186,7 +1186,7 @@ void MenuBar::ClearSymbols()
void MenuBar::GenerateSymbolsFromAddress() void MenuBar::GenerateSymbolsFromAddress()
{ {
Core::CPUThreadGuard guard; Core::CPUThreadGuard guard(Core::System::GetInstance());
auto& system = Core::System::GetInstance(); auto& system = Core::System::GetInstance();
auto& memory = system.GetMemory(); auto& memory = system.GetMemory();
@ -1198,7 +1198,7 @@ void MenuBar::GenerateSymbolsFromAddress()
void MenuBar::GenerateSymbolsFromSignatureDB() void MenuBar::GenerateSymbolsFromSignatureDB()
{ {
Core::CPUThreadGuard guard; Core::CPUThreadGuard guard(Core::System::GetInstance());
auto& system = Core::System::GetInstance(); auto& system = Core::System::GetInstance();
auto& memory = system.GetMemory(); auto& memory = system.GetMemory();
@ -1244,7 +1244,7 @@ void MenuBar::GenerateSymbolsFromRSO()
return; return;
} }
Core::CPUThreadGuard guard; Core::CPUThreadGuard guard(Core::System::GetInstance());
RSOChainView rso_chain; RSOChainView rso_chain;
if (rso_chain.Load(guard, static_cast<u32>(address))) if (rso_chain.Load(guard, static_cast<u32>(address)))
@ -1300,7 +1300,7 @@ void MenuBar::GenerateSymbolsFromRSOAuto()
RSOChainView rso_chain; RSOChainView rso_chain;
const u32 address = item.mid(0, item.indexOf(QLatin1Char(' '))).toUInt(nullptr, 16); 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)) if (rso_chain.Load(guard, address))
{ {
@ -1315,7 +1315,7 @@ void MenuBar::GenerateSymbolsFromRSOAuto()
RSOVector MenuBar::DetectRSOModules(ParallelProgressDialog& progress) 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"}; constexpr std::array<std::string_view, 2> search_for = {".elf", ".plf"};
@ -1429,7 +1429,7 @@ void MenuBar::LoadSymbolMap()
g_symbolDB.Clear(); g_symbolDB.Clear();
{ {
Core::CPUThreadGuard guard; Core::CPUThreadGuard guard(Core::System::GetInstance());
PPCAnalyst::FindFunctions(guard, Memory::MEM1_BASE_ADDR + 0x1300000, PPCAnalyst::FindFunctions(guard, Memory::MEM1_BASE_ADDR + 0x1300000,
Memory::MEM1_BASE_ADDR + memory.GetRamSizeReal(), &g_symbolDB); Memory::MEM1_BASE_ADDR + memory.GetRamSizeReal(), &g_symbolDB);
@ -1523,7 +1523,7 @@ void MenuBar::SaveCode()
bool success; bool success;
{ {
Core::CPUThreadGuard guard; Core::CPUThreadGuard guard(Core::System::GetInstance());
success = g_symbolDB.SaveCodeMap(guard, path); success = g_symbolDB.SaveCodeMap(guard, path);
} }
@ -1537,7 +1537,7 @@ void MenuBar::SaveCode()
bool MenuBar::TryLoadMapFile(const QString& path, const bool bad) 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)) if (!g_symbolDB.LoadMap(guard, path.toStdString(), bad))
{ {
@ -1621,7 +1621,7 @@ void MenuBar::ApplySignatureFile()
SignatureDB db(load_path); SignatureDB db(load_path);
db.Load(load_path); db.Load(load_path);
{ {
Core::CPUThreadGuard guard; Core::CPUThreadGuard guard(Core::System::GetInstance());
db.Apply(guard, &g_symbolDB); db.Apply(guard, &g_symbolDB);
} }
db.List(); db.List();
@ -1692,7 +1692,7 @@ void MenuBar::SearchInstruction()
auto& system = Core::System::GetInstance(); auto& system = Core::System::GetInstance();
auto& memory = system.GetMemory(); auto& memory = system.GetMemory();
Core::CPUThreadGuard guard; Core::CPUThreadGuard guard(system);
bool found = false; bool found = false;
for (u32 addr = Memory::MEM1_BASE_ADDR; addr < Memory::MEM1_BASE_ADDR + memory.GetRamSizeReal(); for (u32 addr = Memory::MEM1_BASE_ADDR; addr < Memory::MEM1_BASE_ADDR + memory.GetRamSizeReal();