From fea75d045cecac3124f284eb42e6bfdd56048d9b Mon Sep 17 00:00:00 2001 From: JosJuice Date: Tue, 1 Aug 2017 15:23:44 +0200 Subject: [PATCH 1/4] Boot: Split out some code to a new function SetupGCMemory Just like the existing function SetupWiiMemory. --- Source/Core/Core/Boot/Boot.cpp | 7 +++-- Source/Core/Core/Boot/Boot.h | 1 + Source/Core/Core/Boot/Boot_BS2Emu.cpp | 41 ++++++++++++++------------- 3 files changed, 26 insertions(+), 23 deletions(-) diff --git a/Source/Core/Core/Boot/Boot.cpp b/Source/Core/Core/Boot/Boot.cpp index fd442a2a5b..1b32f5854b 100644 --- a/Source/Core/Core/Boot/Boot.cpp +++ b/Source/Core/Core/Boot/Boot.cpp @@ -324,18 +324,19 @@ bool CBoot::BootUp(std::unique_ptr boot) SetDefaultDisc(); + SetupMSR(); + SetupBAT(config.bWii); + if (config.bWii) { HID4.SBE = 1; - SetupMSR(); - SetupBAT(config.bWii); // 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(nullptr, 0x000000010000003a); } else { - EmulatedBS2_GC(nullptr, true); + SetupGCMemory(); } PC = executable.reader->GetEntryPoint(); diff --git a/Source/Core/Core/Boot/Boot.h b/Source/Core/Core/Boot/Boot.h index 69f784c827..265ca79cda 100644 --- a/Source/Core/Core/Boot/Boot.h +++ b/Source/Core/Core/Boot/Boot.h @@ -107,6 +107,7 @@ private: static bool EmulatedBS2(bool is_wii, const DiscIO::Volume* volume); static bool Load_BS2(const std::string& boot_rom_filename); + static void SetupGCMemory(); static bool SetupWiiMemory(const DiscIO::Volume* volume, u64 ios_title_id); }; diff --git a/Source/Core/Core/Boot/Boot_BS2Emu.cpp b/Source/Core/Core/Boot/Boot_BS2Emu.cpp index 54beca3ce1..beb59a950d 100644 --- a/Source/Core/Core/Boot/Boot_BS2Emu.cpp +++ b/Source/Core/Core/Boot/Boot_BS2Emu.cpp @@ -152,25 +152,8 @@ bool CBoot::RunApploader(bool is_wii, const DiscIO::Volume& volume) return true; } -// __________________________________________________________________________________________________ -// GameCube Bootstrap 2 HLE: -// copy the apploader to 0x81200000 -// execute the apploader, function by function, using the above utility. -bool CBoot::EmulatedBS2_GC(const DiscIO::Volume* volume, bool skip_app_loader) +void CBoot::SetupGCMemory() { - INFO_LOG(BOOT, "Faking GC BS2..."); - - SetupMSR(); - SetupBAT(/*is_wii*/ false); - - // Write necessary values - // Here we write values to memory that the apploader does not take care of. Game info goes - // to 0x80000000 according to YAGCD 4.2. - - // It's possible to boot DOL and ELF files without a disc inserted - if (volume) - DVDRead(*volume, /*offset*/ 0x00000000, /*address*/ 0x00000000, 0x20, DiscIO::PARTITION_NONE); - // Booted from bootrom. 0xE5207C22 = booted from jtag PowerPC::HostWrite_U32(0x0D15EA5E, 0x80000020); @@ -182,8 +165,8 @@ bool CBoot::EmulatedBS2_GC(const DiscIO::Volume* volume, bool skip_app_loader) // (Seem to take different EXI paths, see Ikaruga for example) PowerPC::HostWrite_U32(0x10000006, 0x8000002C); - const bool ntsc = DiscIO::IsNTSC(SConfig::GetInstance().m_region); - PowerPC::HostWrite_U32(ntsc ? 0 : 1, 0x800000CC); // Fake the VI Init of the IPL (YAGCD 4.2.1.4) + // Fake the VI Init of the IPL (YAGCD 4.2.1.4) + PowerPC::HostWrite_U32(DiscIO::IsNTSC(SConfig::GetInstance().m_region) ? 0 : 1, 0x800000CC); PowerPC::HostWrite_U32(0x01000000, 0x800000d0); // ARAM Size. 16MB main + 4/16/32MB external // (retail consoles have no external ARAM) @@ -199,10 +182,28 @@ bool CBoot::EmulatedBS2_GC(const DiscIO::Volume* volume, bool skip_app_loader) // HIO checks this // PowerPC::HostWrite_U16(0x8200, 0x000030e6); // Console type +} + +// __________________________________________________________________________________________________ +// GameCube Bootstrap 2 HLE: +// copy the apploader to 0x81200000 +// execute the apploader, function by function, using the above utility. +bool CBoot::EmulatedBS2_GC(const DiscIO::Volume* volume, bool skip_app_loader) +{ + INFO_LOG(BOOT, "Faking GC BS2..."); + + SetupMSR(); + SetupBAT(/*is_wii*/ false); + + SetupGCMemory(); if (!volume) return false; + DVDRead(*volume, /*offset*/ 0x00000000, /*address*/ 0x00000000, 0x20, DiscIO::PARTITION_NONE); + + const bool ntsc = DiscIO::IsNTSC(SConfig::GetInstance().m_region); + // Setup pointers like real BS2 does // StackPointer, used to be set to 0x816ffff0 From 42d7dc2e08939d9b6944e0ef36ec37c970d884d5 Mon Sep 17 00:00:00 2001 From: JosJuice Date: Tue, 1 Aug 2017 15:25:00 +0200 Subject: [PATCH 2/4] Boot: Remove skip_app_loader parameter --- Source/Core/Core/Boot/Boot.h | 2 +- Source/Core/Core/Boot/Boot_BS2Emu.cpp | 5 +---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/Source/Core/Core/Boot/Boot.h b/Source/Core/Core/Boot/Boot.h index 265ca79cda..333f0e4fc5 100644 --- a/Source/Core/Core/Boot/Boot.h +++ b/Source/Core/Core/Boot/Boot.h @@ -102,7 +102,7 @@ private: static void SetupMSR(); static void SetupBAT(bool is_wii); static bool RunApploader(bool is_wii, const DiscIO::Volume& volume); - static bool EmulatedBS2_GC(const DiscIO::Volume* volume, bool skip_app_loader = false); + static bool EmulatedBS2_GC(const DiscIO::Volume* volume); static bool EmulatedBS2_Wii(const DiscIO::Volume* volume); static bool EmulatedBS2(bool is_wii, const DiscIO::Volume* volume); static bool Load_BS2(const std::string& boot_rom_filename); diff --git a/Source/Core/Core/Boot/Boot_BS2Emu.cpp b/Source/Core/Core/Boot/Boot_BS2Emu.cpp index beb59a950d..21503de918 100644 --- a/Source/Core/Core/Boot/Boot_BS2Emu.cpp +++ b/Source/Core/Core/Boot/Boot_BS2Emu.cpp @@ -188,7 +188,7 @@ void CBoot::SetupGCMemory() // GameCube Bootstrap 2 HLE: // copy the apploader to 0x81200000 // execute the apploader, function by function, using the above utility. -bool CBoot::EmulatedBS2_GC(const DiscIO::Volume* volume, bool skip_app_loader) +bool CBoot::EmulatedBS2_GC(const DiscIO::Volume* volume) { INFO_LOG(BOOT, "Faking GC BS2..."); @@ -213,9 +213,6 @@ bool CBoot::EmulatedBS2_GC(const DiscIO::Volume* volume, bool skip_app_loader) // Global pointer to Small Data Area Base (Luigi's Mansion's apploader uses it) PowerPC::ppcState.gpr[13] = ntsc ? 0x81465320 : 0x814b4fc0; - if (skip_app_loader) - return false; - return RunApploader(/*is_wii*/ false, *volume); } From eb6f0a7258fcc28f1fcd07f435fdf674b05079a2 Mon Sep 17 00:00:00 2001 From: JosJuice Date: Tue, 1 Aug 2017 15:28:06 +0200 Subject: [PATCH 3/4] Boot: Remove volume parameter from SetupWiiMemory --- Source/Core/Core/Boot/Boot.cpp | 2 +- Source/Core/Core/Boot/Boot.h | 2 +- Source/Core/Core/Boot/Boot_BS2Emu.cpp | 10 ++++------ Source/Core/Core/Boot/Boot_WiiWAD.cpp | 2 +- 4 files changed, 7 insertions(+), 9 deletions(-) diff --git a/Source/Core/Core/Boot/Boot.cpp b/Source/Core/Core/Boot/Boot.cpp index 1b32f5854b..052f4eabe0 100644 --- a/Source/Core/Core/Boot/Boot.cpp +++ b/Source/Core/Core/Boot/Boot.cpp @@ -332,7 +332,7 @@ bool CBoot::BootUp(std::unique_ptr boot) HID4.SBE = 1; // 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(nullptr, 0x000000010000003a); + SetupWiiMemory(0x000000010000003a); } else { diff --git a/Source/Core/Core/Boot/Boot.h b/Source/Core/Core/Boot/Boot.h index 333f0e4fc5..041a27f294 100644 --- a/Source/Core/Core/Boot/Boot.h +++ b/Source/Core/Core/Boot/Boot.h @@ -108,7 +108,7 @@ private: static bool Load_BS2(const std::string& boot_rom_filename); static void SetupGCMemory(); - static bool SetupWiiMemory(const DiscIO::Volume* volume, u64 ios_title_id); + static bool SetupWiiMemory(u64 ios_title_id); }; class BootExecutableReader diff --git a/Source/Core/Core/Boot/Boot_BS2Emu.cpp b/Source/Core/Core/Boot/Boot_BS2Emu.cpp index 21503de918..b3e3fb3fa0 100644 --- a/Source/Core/Core/Boot/Boot_BS2Emu.cpp +++ b/Source/Core/Core/Boot/Boot_BS2Emu.cpp @@ -216,7 +216,7 @@ bool CBoot::EmulatedBS2_GC(const DiscIO::Volume* volume) return RunApploader(/*is_wii*/ false, *volume); } -bool CBoot::SetupWiiMemory(const DiscIO::Volume* volume, u64 ios_title_id) +bool CBoot::SetupWiiMemory(u64 ios_title_id) { static const std::map region_settings = { {DiscIO::Region::NTSC_J, {"JPN", "NTSC", "JP", "LJ"}}, @@ -282,10 +282,6 @@ bool CBoot::SetupWiiMemory(const DiscIO::Volume* volume, u64 ios_title_id) 0x80000060 Copyright code */ - // When booting a WAD or the system menu, there will probably not be a disc inserted - if (volume) - DVDRead(*volume, 0x00000000, 0x00000000, 0x20, DiscIO::PARTITION_NONE); // Game Code - Memory::Write_U32(0x0D15EA5E, 0x00000020); // Another magic word Memory::Write_U32(0x00000001, 0x00000024); // Unknown Memory::Write_U32(Memory::REALRAM_SIZE, 0x00000028); // MEM1 size 24MB @@ -345,9 +341,11 @@ bool CBoot::EmulatedBS2_Wii(const DiscIO::Volume* volume) if (!tmd.IsValid()) return false; - if (!SetupWiiMemory(volume, tmd.GetIOSId())) + if (!SetupWiiMemory(tmd.GetIOSId())) return false; + DVDRead(*volume, 0x00000000, 0x00000000, 0x20, DiscIO::PARTITION_NONE); // Game Code + // 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 // as the game is running. The 6 byte ID at 0x00 is overwritten sometime diff --git a/Source/Core/Core/Boot/Boot_WiiWAD.cpp b/Source/Core/Core/Boot/Boot_WiiWAD.cpp index cb2f3e9c10..145ae48a1f 100644 --- a/Source/Core/Core/Boot/Boot_WiiWAD.cpp +++ b/Source/Core/Core/Boot/Boot_WiiWAD.cpp @@ -94,7 +94,7 @@ bool CBoot::Boot_WiiWAD(const std::string& _pFilename) IOS::HLE::CreateVirtualFATFilesystem(); // setup Wii memory - if (!SetupWiiMemory(nullptr, ContentLoader.GetTMD().GetIOSId())) + if (!SetupWiiMemory(ContentLoader.GetTMD().GetIOSId())) return false; IOS::HLE::Device::ES::LoadWAD(_pFilename); From 363547a5b2e0a0279e44be02e651258e47be2b93 Mon Sep 17 00:00:00 2001 From: JosJuice Date: Tue, 1 Aug 2017 15:38:02 +0200 Subject: [PATCH 4/4] Boot: Make EmulatedBS2 require a volume --- Source/Core/Core/Boot/Boot.cpp | 2 +- Source/Core/Core/Boot/Boot.h | 6 ++--- Source/Core/Core/Boot/Boot_BS2Emu.cpp | 35 +++++++++++---------------- 3 files changed, 18 insertions(+), 25 deletions(-) diff --git a/Source/Core/Core/Boot/Boot.cpp b/Source/Core/Core/Boot/Boot.cpp index 052f4eabe0..be4ef2636c 100644 --- a/Source/Core/Core/Boot/Boot.cpp +++ b/Source/Core/Core/Boot/Boot.cpp @@ -298,7 +298,7 @@ bool CBoot::BootUp(std::unique_ptr boot) if (!volume) return false; - if (!EmulatedBS2(config.bWii, volume)) + if (!EmulatedBS2(config.bWii, *volume)) return false; // Try to load the symbol map if there is one, and then scan it for diff --git a/Source/Core/Core/Boot/Boot.h b/Source/Core/Core/Boot/Boot.h index 041a27f294..f5428616af 100644 --- a/Source/Core/Core/Boot/Boot.h +++ b/Source/Core/Core/Boot/Boot.h @@ -102,9 +102,9 @@ private: static void SetupMSR(); static void SetupBAT(bool is_wii); static bool RunApploader(bool is_wii, const DiscIO::Volume& volume); - static bool EmulatedBS2_GC(const DiscIO::Volume* volume); - static bool EmulatedBS2_Wii(const DiscIO::Volume* volume); - static bool EmulatedBS2(bool is_wii, const DiscIO::Volume* volume); + static bool EmulatedBS2_GC(const DiscIO::Volume& volume); + static bool EmulatedBS2_Wii(const DiscIO::Volume& volume); + static bool EmulatedBS2(bool is_wii, const DiscIO::Volume& volume); static bool Load_BS2(const std::string& boot_rom_filename); static void SetupGCMemory(); diff --git a/Source/Core/Core/Boot/Boot_BS2Emu.cpp b/Source/Core/Core/Boot/Boot_BS2Emu.cpp index b3e3fb3fa0..910fe5db81 100644 --- a/Source/Core/Core/Boot/Boot_BS2Emu.cpp +++ b/Source/Core/Core/Boot/Boot_BS2Emu.cpp @@ -188,7 +188,7 @@ void CBoot::SetupGCMemory() // GameCube Bootstrap 2 HLE: // copy the apploader to 0x81200000 // execute the apploader, function by function, using the above utility. -bool CBoot::EmulatedBS2_GC(const DiscIO::Volume* volume) +bool CBoot::EmulatedBS2_GC(const DiscIO::Volume& volume) { INFO_LOG(BOOT, "Faking GC BS2..."); @@ -197,10 +197,7 @@ bool CBoot::EmulatedBS2_GC(const DiscIO::Volume* volume) SetupGCMemory(); - if (!volume) - return false; - - DVDRead(*volume, /*offset*/ 0x00000000, /*address*/ 0x00000000, 0x20, DiscIO::PARTITION_NONE); + DVDRead(volume, /*offset*/ 0x00000000, /*address*/ 0x00000000, 0x20, DiscIO::PARTITION_NONE); const bool ntsc = DiscIO::IsNTSC(SConfig::GetInstance().m_region); @@ -213,7 +210,7 @@ bool CBoot::EmulatedBS2_GC(const DiscIO::Volume* volume) // Global pointer to Small Data Area Base (Luigi's Mansion's apploader uses it) PowerPC::ppcState.gpr[13] = ntsc ? 0x81465320 : 0x814b4fc0; - return RunApploader(/*is_wii*/ false, *volume); + return RunApploader(/*is_wii*/ false, volume); } bool CBoot::SetupWiiMemory(u64 ios_title_id) @@ -326,17 +323,14 @@ bool CBoot::SetupWiiMemory(u64 ios_title_id) // Wii Bootstrap 2 HLE: // copy the apploader to 0x81200000 // execute the apploader -bool CBoot::EmulatedBS2_Wii(const DiscIO::Volume* volume) +bool CBoot::EmulatedBS2_Wii(const DiscIO::Volume& volume) { INFO_LOG(BOOT, "Faking Wii BS2..."); - if (!volume) + if (volume.GetVolumeType() != DiscIO::Platform::WII_DISC) return false; - if (volume->GetVolumeType() != DiscIO::Platform::WII_DISC) - return false; - - const DiscIO::Partition partition = volume->GetGamePartition(); - const IOS::ES::TMDReader tmd = volume->GetTMD(partition); + const DiscIO::Partition partition = volume.GetGamePartition(); + const IOS::ES::TMDReader tmd = volume.GetTMD(partition); if (!tmd.IsValid()) return false; @@ -344,13 +338,13 @@ bool CBoot::EmulatedBS2_Wii(const DiscIO::Volume* volume) if (!SetupWiiMemory(tmd.GetIOSId())) return false; - DVDRead(*volume, 0x00000000, 0x00000000, 0x20, DiscIO::PARTITION_NONE); // Game Code + DVDRead(volume, 0x00000000, 0x00000000, 0x20, DiscIO::PARTITION_NONE); // Game Code // 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 // as the game is running. The 6 byte ID at 0x00 is overwritten sometime // after this check during booting. - DVDRead(*volume, 0, 0x3180, 4, partition); + DVDRead(volume, 0, 0x3180, 4, partition); SetupMSR(); SetupBAT(/*is_wii*/ true); @@ -361,20 +355,19 @@ bool CBoot::EmulatedBS2_Wii(const DiscIO::Volume* volume) PowerPC::ppcState.gpr[1] = 0x816ffff0; // StackPointer - if (!RunApploader(/*is_wii*/ true, *volume)) + if (!RunApploader(/*is_wii*/ true, volume)) return false; // 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::Device::ES::DIVerify(tmd, volume->GetTicket(partition)); + IOS::HLE::Device::ES::DIVerify(tmd, volume.GetTicket(partition)); return true; } -// Returns true if apploader has run successfully. -// If is_wii is true and volume is not nullptr, the disc that volume -// point to must currently be inserted into the emulated disc drive. -bool CBoot::EmulatedBS2(bool is_wii, const DiscIO::Volume* volume) +// Returns true if apploader has run successfully. If is_wii is true, the disc +// that volume refers to must currently be inserted into the emulated disc drive. +bool CBoot::EmulatedBS2(bool is_wii, const DiscIO::Volume& volume) { return is_wii ? EmulatedBS2_Wii(volume) : EmulatedBS2_GC(volume); }