Merge pull request #12570 from AdmiralCurtiss/system-ios

Core: Move Emulation IOS instance to System.
This commit is contained in:
Mai 2024-02-08 08:59:01 -05:00 committed by GitHub
commit c61f9d92c7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
21 changed files with 65 additions and 51 deletions

View File

@ -573,7 +573,7 @@ bool CBoot::BootUp(Core::System& system, const Core::CPUThreadGuard& guard,
// 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.
SetupWiiMemory(system, IOS::HLE::IOSC::ConsoleType::Retail);
IOS::HLE::GetIOS()->BootIOS(Titles::IOS(58));
system.GetIOS()->BootIOS(Titles::IOS(58));
}
else
{
@ -701,7 +701,7 @@ void UpdateStateFlags(std::function<void(StateFlags*)> update_function)
{
CreateSystemMenuTitleDirs();
const std::string file_path = Common::GetTitleDataPath(Titles::SYSTEM_MENU) + "/" WII_STATE;
const auto fs = IOS::HLE::GetIOS()->GetFS();
const auto fs = Core::System::GetInstance().GetIOS()->GetFS();
constexpr IOS::HLE::FS::Mode rw_mode = IOS::HLE::FS::Mode::ReadWrite;
const auto file = fs->CreateAndOpenFile(IOS::SYSMENU_UID, IOS::SYSMENU_GID, file_path,
{rw_mode, rw_mode, rw_mode});
@ -721,7 +721,7 @@ void UpdateStateFlags(std::function<void(StateFlags*)> update_function)
void CreateSystemMenuTitleDirs()
{
const auto& es = IOS::HLE::GetIOS()->GetESCore();
const auto& es = Core::System::GetInstance().GetIOS()->GetESCore();
es.CreateTitleDirectories(Titles::SYSTEM_MENU, IOS::SYSMENU_GID);
}

View File

@ -362,7 +362,7 @@ bool CBoot::SetupWiiMemory(Core::System& system, IOS::HLE::IOSC::ConsoleType con
const std::string settings_file_path(Common::GetTitleDataPath(Titles::SYSTEM_MENU) +
"/" WII_SETTING);
const auto fs = IOS::HLE::GetIOS()->GetFS();
const auto fs = system.GetIOS()->GetFS();
{
Common::SettingsHandler::Buffer data;
const auto file = fs->OpenFile(IOS::SYSMENU_UID, IOS::SYSMENU_GID, settings_file_path,
@ -502,7 +502,7 @@ static void WriteEmptyPlayRecord()
{
CreateSystemMenuTitleDirs();
const std::string file_path = Common::GetTitleDataPath(Titles::SYSTEM_MENU) + "/play_rec.dat";
const auto fs = IOS::HLE::GetIOS()->GetFS();
const auto fs = Core::System::GetInstance().GetIOS()->GetFS();
constexpr IOS::HLE::FS::Mode rw_mode = IOS::HLE::FS::Mode::ReadWrite;
const auto playrec_file = fs->CreateAndOpenFile(IOS::SYSMENU_UID, IOS::SYSMENU_GID, file_path,
{rw_mode, rw_mode, rw_mode});
@ -559,11 +559,11 @@ 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 auto console_type = volume.GetTicket(data_partition).GetConsoleType();
if (!SetupWiiMemory(system, console_type) || !IOS::HLE::GetIOS()->BootIOS(ios))
if (!SetupWiiMemory(system, console_type) || !system.GetIOS()->BootIOS(ios))
return false;
auto di =
std::static_pointer_cast<IOS::HLE::DIDevice>(IOS::HLE::GetIOS()->GetDeviceByName("/dev/di"));
std::static_pointer_cast<IOS::HLE::DIDevice>(system.GetIOS()->GetDeviceByName("/dev/di"));
di->InitializeIfFirstTime();
di->ChangePartition(data_partition);
@ -596,7 +596,7 @@ bool CBoot::EmulatedBS2_Wii(Core::System& system, const Core::CPUThreadGuard& gu
// Warning: This call will set incorrect running game metadata if our volume parameter
// doesn't point to the same disc as the one that's inserted in the emulated disc drive!
IOS::HLE::GetIOS()->GetESDevice()->DIVerify(tmd, volume.GetTicket(partition));
system.GetIOS()->GetESDevice()->DIVerify(tmd, volume.GetTicket(partition));
return true;
}

View File

@ -12,6 +12,7 @@
#include "Core/IOS/ES/Formats.h"
#include "Core/IOS/IOS.h"
#include "Core/IOS/IOSC.h"
#include "Core/System.h"
#include "Core/WiiUtils.h"
#include "DiscIO/VolumeWad.h"
@ -21,7 +22,7 @@ bool CBoot::BootNANDTitle(Core::System& system, const u64 title_id)
state->type = 0x04; // TYPE_NANDBOOT
});
auto es = IOS::HLE::GetIOS()->GetESDevice();
auto es = system.GetIOS()->GetESDevice();
const IOS::ES::TicketReader ticket = es->GetCore().FindSignedTicket(title_id);
auto console_type = IOS::HLE::IOSC::ConsoleType::Retail;
if (ticket.IsValid())
@ -34,7 +35,7 @@ bool CBoot::BootNANDTitle(Core::System& system, const u64 title_id)
bool CBoot::Boot_WiiWAD(Core::System& system, const DiscIO::VolumeWAD& wad)
{
if (!WiiUtils::InstallWAD(*IOS::HLE::GetIOS(), wad, WiiUtils::InstallType::Temporary))
if (!WiiUtils::InstallWAD(*system.GetIOS(), wad, WiiUtils::InstallType::Temporary))
{
PanicAlertFmtT("Cannot boot this WAD because it could not be installed to the NAND.");
return false;

View File

@ -1016,7 +1016,7 @@ void UpdateWantDeterminism(bool initial)
RunAsCPUThread([&] {
s_wants_determinism = new_want_determinism;
const auto ios = IOS::HLE::GetIOS();
const auto ios = system.GetIOS();
if (ios)
ios->UpdateWantDeterminism(new_want_determinism);

View File

@ -63,7 +63,7 @@ void Init(Core::System& system, const Sram* override_sram)
void Shutdown(Core::System& system)
{
// IOS should always be shut down regardless of IsWii because it can be running in GC mode (MIOS).
IOS::HLE::Shutdown(); // Depends on Memory
IOS::HLE::Shutdown(system); // Depends on Memory
system.GetWiiIPC().Shutdown();
system.GetSystemTimers().Shutdown();
@ -111,7 +111,7 @@ void DoState(Core::System& system, PointerWrap& p)
{
system.GetWiiIPC().DoState(p);
p.DoMarker("IOS");
IOS::HLE::GetIOS()->DoState(p);
system.GetIOS()->DoState(p);
p.DoMarker("IOS::HLE");
}

View File

@ -232,7 +232,7 @@ void ProcessorInterfaceManager::ToggleResetButtonCallback(Core::System& system,
void ProcessorInterfaceManager::IOSNotifyResetButtonCallback(Core::System& system, u64 userdata,
s64 cyclesLate)
{
const auto ios = IOS::HLE::GetIOS();
const auto ios = system.GetIOS();
if (!ios)
return;
@ -244,7 +244,7 @@ void ProcessorInterfaceManager::IOSNotifyResetButtonCallback(Core::System& syste
void ProcessorInterfaceManager::IOSNotifyPowerButtonCallback(Core::System& system, u64 userdata,
s64 cyclesLate)
{
const auto ios = IOS::HLE::GetIOS();
const auto ios = system.GetIOS();
if (!ios)
return;

View File

@ -103,7 +103,7 @@ void SystemTimersManager::IPC_HLE_UpdateCallback(Core::System& system, u64 userd
{
if (system.IsWii())
{
IOS::HLE::GetIOS()->UpdateDevices();
system.GetIOS()->UpdateDevices();
auto& system_timers = system.GetSystemTimers();
system.GetCoreTiming().ScheduleEvent(system_timers.m_ipc_hle_period - cycles_late,
system_timers.m_event_type_ipc_hle);

View File

@ -140,8 +140,8 @@ void WiiIPC::RegisterMMIO(MMIO::Mapping* mmio, u32 base)
if ((val >> 2 & 1 && wii_ipc.m_ctrl.IY1) || (val >> 1 & 1 && wii_ipc.m_ctrl.IY2))
wii_ipc.m_ppc_irq_flags |= INT_CAUSE_IPC_BROADWAY;
if (wii_ipc.m_ctrl.X1)
HLE::GetIOS()->EnqueueIPCRequest(wii_ipc.m_ppc_msg);
HLE::GetIOS()->UpdateIPC();
system.GetIOS()->EnqueueIPCRequest(wii_ipc.m_ppc_msg);
system.GetIOS()->UpdateIPC();
system.GetCoreTiming().ScheduleEvent(0, wii_ipc.m_event_type_update_interrupts,
0);
}));
@ -152,7 +152,7 @@ void WiiIPC::RegisterMMIO(MMIO::Mapping* mmio, u32 base)
MMIO::ComplexWrite<u32>([](Core::System& system, u32, u32 val) {
auto& wii_ipc = system.GetWiiIPC();
wii_ipc.m_ppc_irq_flags &= ~val;
HLE::GetIOS()->UpdateIPC();
system.GetIOS()->UpdateIPC();
system.GetCoreTiming().ScheduleEvent(0, wii_ipc.m_event_type_update_interrupts,
0);
}));
@ -163,7 +163,7 @@ void WiiIPC::RegisterMMIO(MMIO::Mapping* mmio, u32 base)
wii_ipc.m_ppc_irq_masks = val;
if (wii_ipc.m_ppc_irq_masks & INT_CAUSE_IPC_BROADWAY) // wtf?
wii_ipc.Reset();
HLE::GetIOS()->UpdateIPC();
system.GetIOS()->UpdateIPC();
system.GetCoreTiming().ScheduleEvent(0, wii_ipc.m_event_type_update_interrupts,
0);
}));

View File

@ -602,7 +602,7 @@ std::optional<DIDevice::DIResult> DIDevice::StartImmediateTransfer(const IOCtlRe
static std::shared_ptr<DIDevice> GetDevice()
{
auto ios = GetIOS();
auto ios = Core::System::GetInstance().GetIOS();
if (!ios)
return nullptr;
auto di = ios->GetDeviceByName("/dev/di");

View File

@ -28,7 +28,7 @@ OpenRequest::OpenRequest(Core::System& system, const u32 address_) : Request(sys
auto& memory = system.GetMemory();
path = memory.GetString(memory.Read_U32(address + 0xc));
flags = static_cast<OpenMode>(memory.Read_U32(address + 0x10));
const EmulationKernel* ios = GetIOS();
const EmulationKernel* ios = system.GetIOS();
if (ios)
{
uid = ios->GetUidForPPC();

View File

@ -131,15 +131,15 @@ void ESDevice::InitializeEmulationState(CoreTiming::CoreTimingManager& core_timi
{
s_finish_init_event =
core_timing.RegisterEvent("IOS-ESFinishInit", [](Core::System& system_, u64, s64) {
GetIOS()->GetESDevice()->FinishInit();
system_.GetIOS()->GetESDevice()->FinishInit();
});
s_reload_ios_for_ppc_launch_event = core_timing.RegisterEvent(
"IOS-ESReloadIOSForPPCLaunch", [](Core::System& system_, u64 ios_id, s64) {
GetIOS()->GetESDevice()->LaunchTitle(ios_id, HangPPC::Yes);
system_.GetIOS()->GetESDevice()->LaunchTitle(ios_id, HangPPC::Yes);
});
s_bootstrap_ppc_for_launch_event =
core_timing.RegisterEvent("IOS-ESBootstrapPPCForLaunch", [](Core::System& system_, u64, s64) {
GetIOS()->GetESDevice()->BootstrapPPC();
system_.GetIOS()->GetESDevice()->BootstrapPPC();
});
}

View File

@ -64,8 +64,6 @@
namespace IOS::HLE
{
static std::unique_ptr<EmulationKernel> s_ios;
constexpr u64 ENQUEUE_REQUEST_FLAG = 0x100000000ULL;
static CoreTiming::EventType* s_event_enqueue;
static CoreTiming::EventType* s_event_finish_ppc_bootstrap;
@ -284,7 +282,7 @@ Kernel::Kernel(IOSC::ConsoleType console_type) : m_iosc(console_type)
{
// Until the Wii root and NAND path stuff is entirely managed by IOS and made non-static,
// using more than one IOS instance at a time is not supported.
ASSERT(GetIOS() == nullptr);
ASSERT(Core::System::GetInstance().GetIOS() == nullptr);
m_is_responsible_for_nand_root = !Core::WiiRootIsInitialized();
if (m_is_responsible_for_nand_root)
@ -477,8 +475,8 @@ private:
static void FinishIOSBoot(Core::System& system, u64 ios_title_id)
{
// Shut down the active IOS first before switching to the new one.
s_ios.reset();
s_ios = std::make_unique<EmulationKernel>(system, ios_title_id);
system.SetIOS(nullptr);
system.SetIOS(std::make_unique<EmulationKernel>(system, ios_title_id));
}
static constexpr SystemTimers::TimeBaseTick GetIOSBootTicks(u32 version)
@ -959,8 +957,9 @@ void Init(Core::System& system)
s_event_enqueue =
core_timing.RegisterEvent("IPCEvent", [](Core::System& system_, u64 userdata, s64) {
if (s_ios)
s_ios->HandleIPCEvent(userdata);
auto* ios = system_.GetIOS();
if (ios)
ios->HandleIPCEvent(userdata);
});
ESDevice::InitializeEmulationState(core_timing);
@ -976,7 +975,7 @@ void Init(Core::System& system)
core_timing.RegisterEvent("FinishDICommand", DIDevice::FinishDICommandCallback);
// Start with IOS80 to simulate part of the Wii boot process.
s_ios = std::make_unique<EmulationKernel>(system, Titles::SYSTEM_MENU_IOS);
system.SetIOS(std::make_unique<EmulationKernel>(system, Titles::SYSTEM_MENU_IOS));
// On a Wii, boot2 launches the system menu IOS, which then launches the system menu
// (which bootstraps the PPC). Bootstrapping the PPC results in memory values being set up.
// This means that the constants in the 0x3100 region are always set up by the time
@ -985,17 +984,12 @@ void Init(Core::System& system)
SetupMemory(system.GetMemory(), Titles::SYSTEM_MENU_IOS, MemorySetupType::Full);
}
void Shutdown()
void Shutdown(Core::System& system)
{
s_ios.reset();
system.SetIOS(nullptr);
ESDevice::FinalizeEmulationState();
}
EmulationKernel* GetIOS()
{
return s_ios.get();
}
// Based on a hardware test, a device takes at least ~2700 ticks to reply to an IPC request.
// Depending on how much work a command performs, this can take much longer (10000+)
// especially if the NAND filesystem is accessed.

View File

@ -217,7 +217,6 @@ private:
// Used for controlling and accessing an IOS instance that is tied to emulation.
void Init(Core::System& system);
void Shutdown();
EmulationKernel* GetIOS();
void Shutdown(Core::System& system);
} // namespace IOS::HLE

View File

@ -61,6 +61,8 @@ struct System::Impl
bool m_sound_stream_running = false;
bool m_audio_dump_started = false;
std::unique_ptr<IOS::HLE::EmulationKernel> m_ios;
AudioInterface::AudioInterfaceManager m_audio_interface;
CoreTiming::CoreTimingManager m_core_timing;
CommandProcessor::CommandProcessorManager m_command_processor;
@ -140,6 +142,16 @@ void System::SetAudioDumpStarted(bool started)
m_impl->m_audio_dump_started = started;
}
IOS::HLE::EmulationKernel* System::GetIOS() const
{
return m_impl->m_ios.get();
}
void System::SetIOS(std::unique_ptr<IOS::HLE::EmulationKernel> ios)
{
m_impl->m_ios = std::move(ios);
}
AudioInterface::AudioInterfaceManager& System::GetAudioInterface() const
{
return m_impl->m_audio_interface;

View File

@ -53,6 +53,10 @@ namespace GPFifo
{
class GPFifoManager;
}
namespace IOS::HLE
{
class EmulationKernel;
}
namespace HSP
{
class HSPManager;
@ -148,6 +152,9 @@ public:
bool IsAudioDumpStarted() const;
void SetAudioDumpStarted(bool started);
IOS::HLE::EmulationKernel* GetIOS() const;
void SetIOS(std::unique_ptr<IOS::HLE::EmulationKernel> ios);
AudioInterface::AudioInterfaceManager& GetAudioInterface() const;
CPU::CPUManager& GetCPU() const;
CoreTiming::CoreTimingManager& GetCoreTiming() const;

View File

@ -321,7 +321,7 @@ void InitializeWiiFileSystemContents(
std::optional<DiscIO::Riivolution::SavegameRedirect> save_redirect,
const BootSessionData& boot_session_data)
{
const auto fs = IOS::HLE::GetIOS()->GetFS();
const auto fs = Core::System::GetInstance().GetIOS()->GetFS();
// Some games (such as Mario Kart Wii) assume that NWC24 files will always be present
// even upon the first launch as they are normally created by the system menu.
@ -397,7 +397,7 @@ void CleanUpWiiFileSystemContents(const BootSessionData& boot_session_data)
File::MoveWithOverwrite(redirect.temp_path, redirect.real_path);
}
IOS::HLE::EmulationKernel* ios = IOS::HLE::GetIOS();
IOS::HLE::EmulationKernel* ios = Core::System::GetInstance().GetIOS();
// clear the redirects in the session FS, otherwise the back-copy might grab redirected files
s_nand_redirects.clear();

View File

@ -40,6 +40,7 @@
#include "Core/IOS/USB/Bluetooth/BTReal.h"
#include "Core/IOS/Uids.h"
#include "Core/SysConf.h"
#include "Core/System.h"
#include "DiscIO/DiscExtractor.h"
#include "DiscIO/Enums.h"
#include "DiscIO/Filesystem.h"
@ -1004,7 +1005,7 @@ bool RepairNAND(IOS::HLE::Kernel& ios)
static std::shared_ptr<IOS::HLE::Device> GetBluetoothDevice()
{
auto* ios = IOS::HLE::GetIOS();
auto* ios = Core::System::GetInstance().GetIOS();
return ios ? ios->GetDeviceByName("/dev/usb/oh1/57e/305") : nullptr;
}

View File

@ -23,12 +23,12 @@ void Platform::UpdateRunningFlag()
{
if (m_shutdown_requested.TestAndClear())
{
const auto ios = IOS::HLE::GetIOS();
auto& system = Core::System::GetInstance();
const auto ios = system.GetIOS();
const auto stm = ios ? ios->GetDeviceByName("/dev/stm/eventhook") : nullptr;
if (!m_tried_graceful_shutdown.IsSet() && stm &&
std::static_pointer_cast<IOS::HLE::STMEventHookDevice>(stm)->HasHookInstalled())
{
auto& system = Core::System::GetInstance();
system.GetProcessorInterface().PowerButton_Tap();
m_tried_graceful_shutdown.Set();
}

View File

@ -209,7 +209,7 @@ void WiimoteControllersWidget::ConnectWidgets()
void WiimoteControllersWidget::OnBluetoothPassthroughResetPressed()
{
const auto ios = IOS::HLE::GetIOS();
const auto ios = Core::System::GetInstance().GetIOS();
if (!ios)
{
@ -226,7 +226,7 @@ void WiimoteControllersWidget::OnBluetoothPassthroughResetPressed()
void WiimoteControllersWidget::OnBluetoothPassthroughSyncPressed()
{
const auto ios = IOS::HLE::GetIOS();
const auto ios = Core::System::GetInstance().GetIOS();
if (!ios)
{

View File

@ -252,7 +252,7 @@ void NetworkWidget::Update()
// needed because there's a race condition on the IOS instance otherwise
Core::CPUThreadGuard guard(Core::System::GetInstance());
auto* ios = IOS::HLE::GetIOS();
auto* ios = guard.GetSystem().GetIOS();
if (!ios)
return;

View File

@ -483,7 +483,7 @@ void SetUserDirectory(std::string custom_path)
bool TriggerSTMPowerEvent()
{
const auto ios = IOS::HLE::GetIOS();
const auto ios = Core::System::GetInstance().GetIOS();
if (!ios)
return false;