Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #11429 from AdmiralCurtiss/globals-ppc
Reduce usage of ppcState global.
  • Loading branch information
delroth committed Jan 27, 2023
2 parents f056cec + be2d394 commit 41272dc
Show file tree
Hide file tree
Showing 69 changed files with 1,721 additions and 1,431 deletions.
12 changes: 9 additions & 3 deletions Source/Core/Common/Debug/CodeTrace.cpp
Expand Up @@ -11,6 +11,7 @@
#include "Core/Debugger/PPCDebugInterface.h"
#include "Core/HW/CPU.h"
#include "Core/PowerPC/PowerPC.h"
#include "Core/System.h"

namespace
{
Expand Down Expand Up @@ -56,11 +57,13 @@ void CodeTrace::SetRegTracked(const std::string& reg)

InstructionAttributes CodeTrace::GetInstructionAttributes(const TraceOutput& instruction) const
{
auto& system = Core::System::GetInstance();

// Slower process of breaking down saved instruction. Only used when stepping through code if a
// decision has to be made, otherwise used afterwards on a log file.
InstructionAttributes tmp_attributes;
tmp_attributes.instruction = instruction.instruction;
tmp_attributes.address = PC;
tmp_attributes.address = system.GetPPCState().pc;
std::string instr = instruction.instruction;
std::smatch match;

Expand Down Expand Up @@ -106,11 +109,14 @@ InstructionAttributes CodeTrace::GetInstructionAttributes(const TraceOutput& ins

TraceOutput CodeTrace::SaveCurrentInstruction() const
{
auto& system = Core::System::GetInstance();
auto& ppc_state = system.GetPPCState();

// Quickly save instruction and memory target for fast logging.
TraceOutput output;
const std::string instr = PowerPC::debug_interface.Disassemble(PC);
const std::string instr = PowerPC::debug_interface.Disassemble(ppc_state.pc);
output.instruction = instr;
output.address = PC;
output.address = ppc_state.pc;

if (IsInstructionLoadStore(output.instruction))
output.memory_target = PowerPC::debug_interface.GetMemoryAddressFromInstruction(instr);
Expand Down
47 changes: 25 additions & 22 deletions Source/Core/Core/Boot/Boot.cpp
Expand Up @@ -458,22 +458,23 @@ bool CBoot::Load_BS2(Core::System& system, const std::string& boot_rom_filename)
memory.CopyToEmu(0x01200000, data.data() + 0x100, 0x700);
memory.CopyToEmu(0x01300000, data.data() + 0x820, 0x1AFE00);

PowerPC::ppcState.gpr[3] = 0xfff0001f;
PowerPC::ppcState.gpr[4] = 0x00002030;
PowerPC::ppcState.gpr[5] = 0x0000009c;

MSR.FP = 1;
MSR.DR = 1;
MSR.IR = 1;

PowerPC::ppcState.spr[SPR_HID0] = 0x0011c464;
PowerPC::ppcState.spr[SPR_IBAT3U] = 0xfff0001f;
PowerPC::ppcState.spr[SPR_IBAT3L] = 0xfff00001;
PowerPC::ppcState.spr[SPR_DBAT3U] = 0xfff0001f;
PowerPC::ppcState.spr[SPR_DBAT3L] = 0xfff00001;
SetupBAT(/*is_wii*/ false);

PC = 0x81200150;
auto& ppc_state = system.GetPPCState();
ppc_state.gpr[3] = 0xfff0001f;
ppc_state.gpr[4] = 0x00002030;
ppc_state.gpr[5] = 0x0000009c;

ppc_state.msr.FP = 1;
ppc_state.msr.DR = 1;
ppc_state.msr.IR = 1;

ppc_state.spr[SPR_HID0] = 0x0011c464;
ppc_state.spr[SPR_IBAT3U] = 0xfff0001f;
ppc_state.spr[SPR_IBAT3L] = 0xfff00001;
ppc_state.spr[SPR_DBAT3U] = 0xfff0001f;
ppc_state.spr[SPR_DBAT3L] = 0xfff00001;
SetupBAT(system, /*is_wii*/ false);

ppc_state.pc = 0x81200150;
return true;
}

Expand Down Expand Up @@ -543,16 +544,18 @@ bool CBoot::BootUp(Core::System& system, std::unique_ptr<BootParameters> boot)

SetDefaultDisc();

SetupMSR();
SetupHID(config.bWii);
SetupBAT(config.bWii);
auto& ppc_state = system.GetPPCState();

SetupMSR(ppc_state);
SetupHID(ppc_state, config.bWii);
SetupBAT(system, config.bWii);
CopyDefaultExceptionHandlers(system);

if (config.bWii)
{
// Set a value for the SP. It doesn't matter where this points to,
// as long as it is a valid location. This value is taken from a homebrew binary.
PowerPC::ppcState.gpr[1] = 0x8004d4bc;
ppc_state.gpr[1] = 0x8004d4bc;

// 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.
Expand All @@ -572,12 +575,12 @@ bool CBoot::BootUp(Core::System& system, std::unique_ptr<BootParameters> boot)

SConfig::OnNewTitleLoad();

PC = executable.reader->GetEntryPoint();
ppc_state.pc = executable.reader->GetEntryPoint();

if (executable.reader->LoadSymbols())
{
UpdateDebugger_MapLoaded();
HLE::PatchFunctions();
HLE::PatchFunctions(system);
}
return true;
}
Expand Down
15 changes: 10 additions & 5 deletions Source/Core/Core/Boot/Boot.h
Expand Up @@ -34,6 +34,11 @@ namespace IOS::HLE::FS
class FileSystem;
}

namespace PowerPC
{
struct PowerPCState;
}

struct RegionSetting
{
std::string area;
Expand Down Expand Up @@ -167,17 +172,17 @@ class CBoot
static bool DVDRead(const DiscIO::VolumeDisc& disc, u64 dvd_offset, u32 output_address,
u32 length, const DiscIO::Partition& partition);
static bool DVDReadDiscID(const DiscIO::VolumeDisc& disc, u32 output_address);
static void RunFunction(u32 address);
static void RunFunction(Core::System& system, u32 address);

static void UpdateDebugger_MapLoaded();

static bool Boot_WiiWAD(Core::System& system, const DiscIO::VolumeWAD& wad);
static bool BootNANDTitle(Core::System& system, u64 title_id);

static void SetupMSR();
static void SetupHID(bool is_wii);
static void SetupBAT(bool is_wii);
static bool RunApploader(bool is_wii, const DiscIO::VolumeDisc& volume,
static void SetupMSR(PowerPC::PowerPCState& ppc_state);
static void SetupHID(PowerPC::PowerPCState& ppc_state, bool is_wii);
static void SetupBAT(Core::System& system, bool is_wii);
static bool RunApploader(Core::System& system, bool is_wii, const DiscIO::VolumeDisc& volume,
const std::vector<DiscIO::Riivolution::Patch>& riivolution_patches);
static bool EmulatedBS2_GC(Core::System& system, const DiscIO::VolumeDisc& volume,
const std::vector<DiscIO::Riivolution::Patch>& riivolution_patches);
Expand Down

0 comments on commit 41272dc

Please sign in to comment.