[Cleanup] IOS: Clean up the way ARM binaries are loaded

This commit removes the last usage of NANDContentManager in IOS code.

Another cleanup change is that loading ARM (IOS) binaries is now done
by the kernel in the BootIOS syscall, instead of being handled as a
special case in the MIOS code. This is more similar to how console
works and lets us easily extend the same logic to other IOS binaries
in the future, if we decide to actually load them.
This commit is contained in:
Léo Lam
2017-10-01 17:54:01 +02:00
parent 63a52fa707
commit ff6b3eb9ac
4 changed files with 84 additions and 102 deletions

View File

@ -6,16 +6,12 @@
#include <cstring>
#include <utility>
#include <vector>
#include "Common/CommonTypes.h"
#include "Common/FileUtil.h"
#include "Common/Logging/Log.h"
#include "Common/MsgHandler.h"
#include "Common/NandPaths.h"
#include "Common/Swap.h"
#include "Core/Boot/ElfReader.h"
#include "Core/CommonTitles.h"
#include "Core/ConfigManager.h"
#include "Core/Core.h"
#include "Core/DSPEmulator.h"
@ -24,10 +20,8 @@
#include "Core/HW/DVD/DVDInterface.h"
#include "Core/HW/Memmap.h"
#include "Core/HW/SystemTimers.h"
#include "Core/IOS/ES/Formats.h"
#include "Core/PowerPC/PPCSymbolDB.h"
#include "Core/PowerPC/PowerPC.h"
#include "DiscIO/NANDContentLoader.h"
namespace IOS
{
@ -35,73 +29,6 @@ namespace HLE
{
namespace MIOS
{
// Source: https://wiibrew.org/wiki/ARM_Binaries
struct ARMBinary final
{
explicit ARMBinary(const std::vector<u8>& bytes);
explicit ARMBinary(std::vector<u8>&& bytes);
bool IsValid() const;
std::vector<u8> GetElf() const;
u32 GetHeaderSize() const;
u32 GetElfOffset() const;
u32 GetElfSize() const;
private:
std::vector<u8> m_bytes;
};
ARMBinary::ARMBinary(const std::vector<u8>& bytes) : m_bytes(bytes)
{
}
ARMBinary::ARMBinary(std::vector<u8>&& bytes) : m_bytes(std::move(bytes))
{
}
bool ARMBinary::IsValid() const
{
// The header is at least 0x10.
if (m_bytes.size() < 0x10)
return false;
return m_bytes.size() >= (GetHeaderSize() + GetElfOffset() + GetElfSize());
}
std::vector<u8> ARMBinary::GetElf() const
{
const auto iterator = m_bytes.cbegin() + GetHeaderSize() + GetElfOffset();
return std::vector<u8>(iterator, iterator + GetElfSize());
}
u32 ARMBinary::GetHeaderSize() const
{
return Common::swap32(m_bytes.data());
}
u32 ARMBinary::GetElfOffset() const
{
return Common::swap32(m_bytes.data() + 0x4);
}
u32 ARMBinary::GetElfSize() const
{
return Common::swap32(m_bytes.data() + 0x8);
}
static std::vector<u8> GetMIOSBinary()
{
const auto& loader =
DiscIO::NANDContentManager::Access().GetNANDLoader(Titles::MIOS, Common::FROM_SESSION_ROOT);
if (!loader.IsValid())
return {};
const auto* content = loader.GetContentByIndex(loader.GetTMD().GetBootIndex());
if (!content)
return {};
return content->m_Data->Get();
}
static void ReinitHardware()
{
SConfig::GetInstance().bWii = false;
@ -125,22 +52,6 @@ bool Load()
Memory::Write_U32(0x00000000, ADDRESS_INIT_SEMAPHORE);
Memory::Write_U32(0x09142001, 0x3180);
ARMBinary mios{GetMIOSBinary()};
if (!mios.IsValid())
{
PanicAlertT("Failed to load MIOS. It is required for launching GameCube titles from Wii mode.");
Core::QueueHostJob(Core::Stop);
return false;
}
ElfReader elf{mios.GetElf()};
if (!elf.LoadIntoMemory(true))
{
PanicAlertT("Failed to load MIOS ELF into memory.");
Core::QueueHostJob(Core::Stop);
return false;
}
ReinitHardware();
NOTICE_LOG(IOS, "Reinitialised hardware.");