Core/IOS/IOS: Remove global system accessors from internal functions

These functions can all be modified to take in the required instance,
rather than using the global system accessor.
This commit is contained in:
Lioncache 2023-12-18 12:04:56 -05:00
parent 0c9f9ca8b6
commit a13bcd87d4

View File

@ -105,11 +105,8 @@ constexpr u32 ADDR_DEVKIT_BOOT_PROGRAM_VERSION = 0x315e;
constexpr u32 ADDR_SYSMENU_SYNC = 0x3160;
constexpr u32 PLACEHOLDER = 0xDEADBEEF;
static bool SetupMemory(u64 ios_title_id, MemorySetupType setup_type)
static bool SetupMemory(Memory::MemoryManager& memory, u64 ios_title_id, MemorySetupType setup_type)
{
auto& system = Core::System::GetInstance();
auto& memory = system.GetMemory();
auto target_imv = std::find_if(
GetMemoryValues().begin(), GetMemoryValues().end(),
[&](const MemoryValues& imv) { return imv.ios_number == (ios_title_id & 0xffff); });
@ -196,22 +193,21 @@ static bool SetupMemory(u64 ios_title_id, MemorySetupType setup_type)
// by asserting the PPC's HRESET signal (via HW_RESETS).
// We will simulate that by resetting MSR and putting the PPC into an infinite loop.
// The memory write will not be observable since the PPC is not running any code...
static void ResetAndPausePPC()
static void ResetAndPausePPC(Core::System& system)
{
// This should be cleared when the PPC is released so that the write is not observable.
auto& system = Core::System::GetInstance();
auto& memory = system.GetMemory();
memory.Write_U32(0x48000000, 0x00000000); // b 0x0
auto& power_pc = system.GetPowerPC();
memory.Write_U32(0x48000000, 0x00000000); // b 0x0
power_pc.Reset();
power_pc.GetPPCState().pc = 0;
}
static void ReleasePPC()
static void ReleasePPC(Core::System& system)
{
auto& system = Core::System::GetInstance();
auto& memory = system.GetMemory();
memory.Write_U32(0, 0);
system.GetMemory().Write_U32(0, 0);
// HLE the bootstub that jumps to 0x3400.
// NAND titles start with address translation off at 0x3400 (via the PPC bootstub)
// The state of other CPU registers (like the BAT registers) doesn't matter much
@ -219,11 +215,10 @@ static void ReleasePPC()
system.GetPPCState().pc = 0x3400;
}
static void ReleasePPCAncast()
static void ReleasePPCAncast(Core::System& system)
{
auto& system = Core::System::GetInstance();
auto& memory = system.GetMemory();
memory.Write_U32(0, 0);
system.GetMemory().Write_U32(0, 0);
// On a real console the Espresso verifies and decrypts the Ancast image,
// then jumps to the decrypted ancast body.
// The Ancast loader already did this, so just jump to the decrypted body.
@ -324,7 +319,7 @@ EmulationKernel::EmulationKernel(Core::System& system, u64 title_id)
{
INFO_LOG_FMT(IOS, "Starting IOS {:016x}", title_id);
if (!SetupMemory(title_id, MemorySetupType::IOSReload))
if (!SetupMemory(m_system.GetMemory(), title_id, MemorySetupType::IOSReload))
WARN_LOG_FMT(IOS, "No information about this IOS -- cannot set up memory values");
if (title_id == Titles::MIOS)
@ -444,11 +439,11 @@ bool EmulationKernel::BootstrapPPC(const std::string& boot_content_path)
if (!dol.IsValid())
return false;
if (!SetupMemory(m_title_id, MemorySetupType::Full))
if (!SetupMemory(m_system.GetMemory(), m_title_id, MemorySetupType::Full))
return false;
// Reset the PPC and pause its execution until we're ready.
ResetAndPausePPC();
ResetAndPausePPC(m_system);
if (dol.IsAncast())
INFO_LOG_FMT(IOS, "BootstrapPPC: Loading ancast image");
@ -530,7 +525,7 @@ bool EmulationKernel::BootIOS(const u64 ios_title_id, HangPPC hang_ppc,
}
if (hang_ppc == HangPPC::Yes)
ResetAndPausePPC();
ResetAndPausePPC(m_system);
if (Core::IsRunningAndStarted())
{
@ -950,9 +945,9 @@ static void FinishPPCBootstrap(Core::System& system, u64 userdata, s64 cycles_la
// See Kernel::BootstrapPPC
const bool is_ancast = userdata == 1;
if (is_ancast)
ReleasePPCAncast();
ReleasePPCAncast(system);
else
ReleasePPC();
ReleasePPC(system);
ASSERT(Core::IsCPUThread());
Core::CPUThreadGuard guard(system);
@ -991,7 +986,7 @@ void Init()
// This means that the constants in the 0x3100 region are always set up by the time
// a game is launched. This is necessary because booting games from the game list skips
// a significant part of a Wii's boot process.
SetupMemory(Titles::SYSTEM_MENU_IOS, MemorySetupType::Full);
SetupMemory(system.GetMemory(), Titles::SYSTEM_MENU_IOS, MemorySetupType::Full);
}
void Shutdown()