Core/Boot: Pass around System.

This commit is contained in:
Admiral H. Curtiss 2023-03-08 02:50:29 +01:00
parent 912cd456fb
commit 7044cff011
No known key found for this signature in database
GPG Key ID: F051B4C4044F33FB
10 changed files with 43 additions and 40 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

@ -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);
@ -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

@ -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
{ {

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;