Merge pull request #12630 from mitaclaw/ppc-symbols-global

PPCSymbolDB: Move instance to PowerPCManager
This commit is contained in:
Admiral H. Curtiss
2024-03-17 06:03:05 +01:00
committed by GitHub
41 changed files with 201 additions and 160 deletions
+5 -5
View File
@@ -376,11 +376,11 @@ bool CBoot::FindMapFile(std::string* existing_map_file, std::string* writable_ma
return false;
}
bool CBoot::LoadMapFromFilename(const Core::CPUThreadGuard& guard)
bool CBoot::LoadMapFromFilename(const Core::CPUThreadGuard& guard, PPCSymbolDB& ppc_symbol_db)
{
std::string strMapFilename;
bool found = FindMapFile(&strMapFilename, nullptr);
if (found && g_symbolDB.LoadMap(guard, strMapFilename))
if (found && ppc_symbol_db.LoadMap(guard, strMapFilename))
{
UpdateDebugger_MapLoaded();
return true;
@@ -514,9 +514,9 @@ bool CBoot::BootUp(Core::System& system, const Core::CPUThreadGuard& guard,
{
SConfig& config = SConfig::GetInstance();
if (!g_symbolDB.IsEmpty())
if (auto& ppc_symbol_db = system.GetPPCSymbolDB(); !ppc_symbol_db.IsEmpty())
{
g_symbolDB.Clear();
ppc_symbol_db.Clear();
UpdateDebugger_MapLoaded();
}
@@ -595,7 +595,7 @@ bool CBoot::BootUp(Core::System& system, const Core::CPUThreadGuard& guard,
ppc_state.pc = executable.reader->GetEntryPoint();
if (executable.reader->LoadSymbols(guard))
if (executable.reader->LoadSymbols(guard, system.GetPPCSymbolDB()))
{
UpdateDebugger_MapLoaded();
HLE::PatchFunctions(system);
+4 -2
View File
@@ -19,6 +19,8 @@
#include "DiscIO/VolumeDisc.h"
#include "DiscIO/VolumeWad.h"
class PPCSymbolDB;
namespace Core
{
class CPUThreadGuard;
@@ -168,7 +170,7 @@ public:
//
// Returns true if a map file exists, false if none could be found.
static bool FindMapFile(std::string* existing_map_file, std::string* writable_map_file);
static bool LoadMapFromFilename(const Core::CPUThreadGuard& guard);
static bool LoadMapFromFilename(const Core::CPUThreadGuard& guard, PPCSymbolDB& ppc_symbol_db);
private:
static bool DVDRead(Core::System& system, const DiscIO::VolumeDisc& disc, u64 dvd_offset,
@@ -215,7 +217,7 @@ public:
virtual bool IsValid() const = 0;
virtual bool IsWii() 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, PPCSymbolDB& ppc_symbol_db) const = 0;
protected:
std::vector<u8> m_bytes;
+4 -1
View File
@@ -27,7 +27,10 @@ public:
bool IsAncast() const { return m_is_ancast; };
u32 GetEntryPoint() const override { return m_dolheader.entryPoint; }
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, PPCSymbolDB& ppc_symbol_db) const override
{
return false;
}
private:
enum
+3 -3
View File
@@ -180,7 +180,7 @@ SectionID ElfReader::GetSectionByName(const char* name, int firstSection) const
return -1;
}
bool ElfReader::LoadSymbols(const Core::CPUThreadGuard& guard) const
bool ElfReader::LoadSymbols(const Core::CPUThreadGuard& guard, PPCSymbolDB& ppc_symbol_db) const
{
bool hasSymbols = false;
SectionID sec = GetSectionByName(".symtab");
@@ -218,11 +218,11 @@ bool ElfReader::LoadSymbols(const Core::CPUThreadGuard& guard) const
default:
continue;
}
g_symbolDB.AddKnownSymbol(guard, value, size, name, symtype);
ppc_symbol_db.AddKnownSymbol(guard, value, size, name, symtype);
hasSymbols = true;
}
}
g_symbolDB.Index();
ppc_symbol_db.Index();
return hasSymbols;
}
+1 -1
View File
@@ -36,7 +36,7 @@ public:
u32 GetEntryPoint() const override { return entryPoint; }
u32 GetFlags() const { return (u32)(header->e_flags); }
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, PPCSymbolDB& ppc_symbol_db) const override;
// TODO: actually check for validity.
bool IsValid() const override { return true; }
bool IsWii() const override;
+5 -4
View File
@@ -205,13 +205,14 @@ void SConfig::OnNewTitleLoad(const Core::CPUThreadGuard& guard)
if (!Core::IsRunning())
return;
if (!g_symbolDB.IsEmpty())
auto& system = guard.GetSystem();
auto& ppc_symbol_db = system.GetPPCSymbolDB();
if (!ppc_symbol_db.IsEmpty())
{
g_symbolDB.Clear();
ppc_symbol_db.Clear();
Host_NotifyMapLoaded();
}
CBoot::LoadMapFromFilename(guard);
auto& system = Core::System::GetInstance();
CBoot::LoadMapFromFilename(guard, ppc_symbol_db);
HLE::Reload(system);
PatchEngine::Reload();
HiresTexture::Update();
@@ -54,7 +54,8 @@ static void WalkTheStack(const Core::CPUThreadGuard& guard,
// instead of "pointing ahead"
bool GetCallstack(const Core::CPUThreadGuard& guard, std::vector<CallstackEntry>& output)
{
const auto& ppc_state = guard.GetSystem().GetPPCState();
auto& power_pc = guard.GetSystem().GetPowerPC();
const auto& ppc_state = power_pc.GetPPCState();
if (!Core::IsRunning() || !PowerPC::MMU::HostIsRAMAddress(guard, ppc_state.gpr[1]))
return false;
@@ -68,14 +69,16 @@ bool GetCallstack(const Core::CPUThreadGuard& guard, std::vector<CallstackEntry>
return false;
}
auto& ppc_symbol_db = power_pc.GetSymbolDB();
output.push_back({
.Name = fmt::format(" * {} [ LR = {:08x} ]\n", g_symbolDB.GetDescription(LR(ppc_state)),
.Name = fmt::format(" * {} [ LR = {:08x} ]\n", ppc_symbol_db.GetDescription(LR(ppc_state)),
LR(ppc_state) - 4),
.vAddress = LR(ppc_state) - 4,
});
WalkTheStack(guard, [&output](u32 func_addr) {
std::string func_desc = g_symbolDB.GetDescription(func_addr);
WalkTheStack(guard, [&output, &ppc_symbol_db](u32 func_addr) {
std::string func_desc = ppc_symbol_db.GetDescription(func_addr);
if (func_desc.empty() || func_desc == "Invalid")
func_desc = "(unknown)";
@@ -91,7 +94,9 @@ bool GetCallstack(const Core::CPUThreadGuard& guard, std::vector<CallstackEntry>
void PrintCallstack(const Core::CPUThreadGuard& guard, Common::Log::LogType type,
Common::Log::LogLevel level)
{
const auto& ppc_state = guard.GetSystem().GetPPCState();
auto& power_pc = guard.GetSystem().GetPowerPC();
const auto& ppc_state = power_pc.GetPPCState();
auto& ppc_symbol_db = power_pc.GetSymbolDB();
GENERIC_LOG_FMT(type, level, "== STACK TRACE - SP = {:08x} ==", ppc_state.gpr[1]);
@@ -100,14 +105,14 @@ void PrintCallstack(const Core::CPUThreadGuard& guard, Common::Log::LogType type
GENERIC_LOG_FMT(type, level, " LR = 0 - this is bad");
}
if (g_symbolDB.GetDescription(ppc_state.pc) != g_symbolDB.GetDescription(LR(ppc_state)))
if (ppc_symbol_db.GetDescription(ppc_state.pc) != ppc_symbol_db.GetDescription(LR(ppc_state)))
{
GENERIC_LOG_FMT(type, level, " * {} [ LR = {:08x} ]", g_symbolDB.GetDescription(LR(ppc_state)),
LR(ppc_state));
GENERIC_LOG_FMT(type, level, " * {} [ LR = {:08x} ]",
ppc_symbol_db.GetDescription(LR(ppc_state)), LR(ppc_state));
}
WalkTheStack(guard, [type, level](u32 func_addr) {
std::string func_desc = g_symbolDB.GetDescription(func_addr);
WalkTheStack(guard, [type, level, &ppc_symbol_db](u32 func_addr) {
std::string func_desc = ppc_symbol_db.GetDescription(func_addr);
if (func_desc.empty() || func_desc == "Invalid")
func_desc = "(unknown)";
GENERIC_LOG_FMT(type, level, " * {} [ addr = {:08x} ]", func_desc, func_addr);
@@ -90,7 +90,8 @@ void PPCPatches::UnPatch(std::size_t index)
PatchEngine::RemoveMemoryPatch(index);
}
PPCDebugInterface::PPCDebugInterface(Core::System& system) : m_system(system)
PPCDebugInterface::PPCDebugInterface(Core::System& system, PPCSymbolDB& ppc_symbol_db)
: m_system(system), m_ppc_symbol_db(ppc_symbol_db)
{
}
@@ -423,7 +424,7 @@ u32 PPCDebugInterface::GetColor(const Core::CPUThreadGuard* guard, u32 address)
if (!PowerPC::MMU::HostIsRAMAddress(*guard, address))
return 0xeeeeee;
Common::Symbol* symbol = g_symbolDB.GetSymbolFromAddr(address);
const Common::Symbol* const symbol = m_ppc_symbol_db.GetSymbolFromAddr(address);
if (!symbol)
return 0xFFFFFF;
if (symbol->type != Common::Symbol::Type::Function)
@@ -443,7 +444,7 @@ u32 PPCDebugInterface::GetColor(const Core::CPUThreadGuard* guard, u32 address)
std::string PPCDebugInterface::GetDescription(u32 address) const
{
return g_symbolDB.GetDescription(address);
return m_ppc_symbol_db.GetDescription(address);
}
std::optional<u32>
@@ -17,6 +17,7 @@ namespace Core
class CPUThreadGuard;
class System;
} // namespace Core
class PPCSymbolDB;
void ApplyMemoryPatch(const Core::CPUThreadGuard&, Common::Debug::MemoryPatch& patch,
bool store_existing_value = true);
@@ -36,7 +37,7 @@ private:
class PPCDebugInterface final : public Core::DebugInterface
{
public:
explicit PPCDebugInterface(Core::System& system);
explicit PPCDebugInterface(Core::System& system, PPCSymbolDB& ppc_symbol_db);
~PPCDebugInterface() override;
// Watches
@@ -112,4 +113,5 @@ private:
PPCPatches m_patches;
std::shared_ptr<Core::NetworkCaptureLogger> m_network_logger;
Core::System& m_system;
PPCSymbolDB& m_ppc_symbol_db;
};
+13 -9
View File
@@ -106,7 +106,9 @@ void PatchFixedFunctions(Core::System& system)
void PatchFunctions(Core::System& system)
{
auto& ppc_state = system.GetPPCState();
auto& power_pc = system.GetPowerPC();
auto& ppc_state = power_pc.GetPPCState();
auto& ppc_symbol_db = power_pc.GetSymbolDB();
// Remove all hooks that aren't fixed address hooks
for (auto i = s_hooked_addresses.begin(); i != s_hooked_addresses.end();)
@@ -128,7 +130,7 @@ void PatchFunctions(Core::System& system)
if (os_patches[i].flags == HookFlag::Fixed)
continue;
for (const auto& symbol : g_symbolDB.GetSymbolsFromName(os_patches[i].name))
for (const auto& symbol : ppc_symbol_db.GetSymbolsFromName(os_patches[i].name))
{
for (u32 addr = symbol->address; addr < symbol->address + symbol->size; addr += 4)
{
@@ -178,14 +180,14 @@ u32 GetHookByAddress(u32 address)
return (iter != s_hooked_addresses.end()) ? iter->second : 0;
}
u32 GetHookByFunctionAddress(u32 address)
u32 GetHookByFunctionAddress(PPCSymbolDB& ppc_symbol_db, u32 address)
{
const u32 index = GetHookByAddress(address);
// Fixed hooks use a fixed address and don't patch the whole function
if (index == 0 || os_patches[index].flags == HookFlag::Fixed)
return index;
const auto symbol = g_symbolDB.GetSymbolFromAddr(address);
const Common::Symbol* const symbol = ppc_symbol_db.GetSymbolFromAddr(address);
return (symbol && symbol->address == address) ? index : 0;
}
@@ -199,9 +201,10 @@ HookFlag GetHookFlagsByIndex(u32 index)
return os_patches[index].flags;
}
TryReplaceFunctionResult TryReplaceFunction(u32 address, PowerPC::CoreMode mode)
TryReplaceFunctionResult TryReplaceFunction(PPCSymbolDB& ppc_symbol_db, u32 address,
PowerPC::CoreMode mode)
{
const u32 hook_index = GetHookByFunctionAddress(address);
const u32 hook_index = GetHookByFunctionAddress(ppc_symbol_db, address);
if (hook_index == 0)
return {};
@@ -229,7 +232,8 @@ u32 UnPatch(Core::System& system, std::string_view patch_name)
if (patch == std::end(os_patches))
return 0;
auto& ppc_state = system.GetPPCState();
auto& power_pc = system.GetPowerPC();
auto& ppc_state = power_pc.GetPPCState();
if (patch->flags == HookFlag::Fixed)
{
@@ -252,10 +256,10 @@ u32 UnPatch(Core::System& system, std::string_view patch_name)
return addr;
}
const auto& symbols = g_symbolDB.GetSymbolsFromName(patch_name);
const auto symbols = power_pc.GetSymbolDB().GetSymbolsFromName(patch_name);
if (!symbols.empty())
{
const auto& symbol = symbols[0];
const Common::Symbol* const symbol = symbols.front();
for (u32 addr = symbol->address; addr < symbol->address + symbol->size; addr += 4)
{
s_hooked_addresses.erase(addr);
+5 -2
View File
@@ -18,6 +18,8 @@ namespace PowerPC
enum class CoreMode;
}
class PPCSymbolDB;
namespace HLE
{
using HookFunction = void (*)(const Core::CPUThreadGuard&);
@@ -66,7 +68,7 @@ void ExecuteFromJIT(u32 current_pc, u32 hook_index, Core::System& system);
// Returns the HLE hook index of the address
u32 GetHookByAddress(u32 address);
// Returns the HLE hook index if the address matches the function start
u32 GetHookByFunctionAddress(u32 address);
u32 GetHookByFunctionAddress(PPCSymbolDB& ppc_symbol_db, u32 address);
HookType GetHookTypeByIndex(u32 index);
HookFlag GetHookFlagsByIndex(u32 index);
@@ -74,6 +76,7 @@ bool IsEnabled(HookFlag flag, PowerPC::CoreMode mode);
// Performs the backend-independent preliminary checking for whether a function
// can be HLEd. If it can be, the information needed for HLEing it is returned.
TryReplaceFunctionResult TryReplaceFunction(u32 address, PowerPC::CoreMode mode);
TryReplaceFunctionResult TryReplaceFunction(PPCSymbolDB& ppc_symbol_db, u32 address,
PowerPC::CoreMode mode);
} // namespace HLE
+6 -5
View File
@@ -67,21 +67,22 @@ bool Load(Core::System& system)
ReinitHardware(system);
NOTICE_LOG_FMT(IOS, "Reinitialised hardware.");
auto& power_pc = system.GetPowerPC();
auto& ppc_symbol_db = power_pc.GetSymbolDB();
// Load symbols for the IPL if they exist.
if (!g_symbolDB.IsEmpty())
if (!ppc_symbol_db.IsEmpty())
{
g_symbolDB.Clear();
ppc_symbol_db.Clear();
Host_NotifyMapLoaded();
}
if (g_symbolDB.LoadMap(guard, File::GetUserPath(D_MAPS_IDX) + "mios-ipl.map"))
if (ppc_symbol_db.LoadMap(guard, File::GetUserPath(D_MAPS_IDX) + "mios-ipl.map"))
{
::HLE::Clear();
::HLE::PatchFunctions(system);
Host_NotifyMapLoaded();
}
auto& power_pc = system.GetPowerPC();
const PowerPC::CoreMode core_mode = power_pc.GetMode();
power_pc.SetMode(PowerPC::CoreMode::Interpreter);
+4 -4
View File
@@ -365,8 +365,7 @@ bool MemChecks::OverlapsMemcheck(u32 address, u32 length) const
});
}
bool TMemCheck::Action(Core::System& system, Core::DebugInterface* debug_interface, u64 value,
u32 addr, bool write, size_t size, u32 pc)
bool TMemCheck::Action(Core::System& system, u64 value, u32 addr, bool write, size_t size, u32 pc)
{
if (!is_enabled)
return false;
@@ -376,9 +375,10 @@ bool TMemCheck::Action(Core::System& system, Core::DebugInterface* debug_interfa
{
if (log_on_hit)
{
auto& ppc_symbol_db = system.GetPPCSymbolDB();
NOTICE_LOG_FMT(MEMMAP, "MBP {:08x} ({}) {}{} {:x} at {:08x} ({})", pc,
debug_interface->GetDescription(pc), write ? "Write" : "Read", size * 8, value,
addr, debug_interface->GetDescription(addr));
ppc_symbol_db.GetDescription(pc), write ? "Write" : "Read", size * 8, value,
addr, ppc_symbol_db.GetDescription(addr));
}
if (break_on_hit)
return true;
+1 -6
View File
@@ -11,10 +11,6 @@
#include "Common/CommonTypes.h"
#include "Core/PowerPC/Expression.h"
namespace Core
{
class DebugInterface;
}
namespace Core
{
class System;
@@ -49,8 +45,7 @@ struct TMemCheck
std::optional<Expression> condition;
// returns whether to break
bool Action(Core::System& system, Core::DebugInterface* debug_interface, u64 value, u32 addr,
bool write, size_t size, u32 pc);
bool Action(Core::System& system, u64 value, u32 addr, bool write, size_t size, u32 pc);
};
// Code breakpoints.
@@ -271,7 +271,7 @@ bool CachedInterpreter::HandleFunctionHooking(u32 address)
{
// CachedInterpreter inherits from JitBase and is considered a JIT by relevant code.
// (see JitInterface and how m_mode is set within PowerPC.cpp)
const auto result = HLE::TryReplaceFunction(address, PowerPC::CoreMode::JIT);
const auto result = HLE::TryReplaceFunction(m_ppc_symbol_db, address, PowerPC::CoreMode::JIT);
if (!result)
return false;
@@ -65,8 +65,9 @@ void Interpreter::UpdatePC()
}
Interpreter::Interpreter(Core::System& system, PowerPC::PowerPCState& ppc_state, PowerPC::MMU& mmu,
Core::BranchWatch& branch_watch)
: m_system(system), m_ppc_state(ppc_state), m_mmu(mmu), m_branch_watch(branch_watch)
Core::BranchWatch& branch_watch, PPCSymbolDB& ppc_symbol_db)
: m_system(system), m_ppc_state(ppc_state), m_mmu(mmu), m_branch_watch(branch_watch),
m_ppc_symbol_db(ppc_symbol_db)
{
}
@@ -107,7 +108,8 @@ void Interpreter::Trace(const UGeckoInstruction& inst)
bool Interpreter::HandleFunctionHooking(u32 address)
{
const auto result = HLE::TryReplaceFunction(address, PowerPC::CoreMode::Interpreter);
const auto result =
HLE::TryReplaceFunction(m_ppc_symbol_db, address, PowerPC::CoreMode::Interpreter);
if (!result)
return false;
@@ -19,12 +19,13 @@ namespace PowerPC
class MMU;
struct PowerPCState;
} // namespace PowerPC
class PPCSymbolDB;
class Interpreter : public CPUCoreBase
{
public:
Interpreter(Core::System& system, PowerPC::PowerPCState& ppc_state, PowerPC::MMU& mmu,
Core::BranchWatch& branch_watch);
Core::BranchWatch& branch_watch, PPCSymbolDB& ppc_symbol_db);
Interpreter(const Interpreter&) = delete;
Interpreter(Interpreter&&) = delete;
Interpreter& operator=(const Interpreter&) = delete;
@@ -317,6 +318,7 @@ private:
PowerPC::PowerPCState& m_ppc_state;
PowerPC::MMU& m_mmu;
Core::BranchWatch& m_branch_watch;
PPCSymbolDB& m_ppc_symbol_db;
UGeckoInstruction m_prev_inst{};
u32 m_last_pc = 0;
+1 -1
View File
@@ -1285,7 +1285,7 @@ void Jit64::IntializeSpeculativeConstants()
bool Jit64::HandleFunctionHooking(u32 address)
{
const auto result = HLE::TryReplaceFunction(address, PowerPC::CoreMode::JIT);
const auto result = HLE::TryReplaceFunction(m_ppc_symbol_db, address, PowerPC::CoreMode::JIT);
if (!result)
return false;
+1 -1
View File
@@ -781,7 +781,7 @@ void JitArm64::WriteConditionalExceptionExit(int exception, ARM64Reg temp_gpr, A
bool JitArm64::HandleFunctionHooking(u32 address)
{
const auto result = HLE::TryReplaceFunction(address, PowerPC::CoreMode::JIT);
const auto result = HLE::TryReplaceFunction(m_ppc_symbol_db, address, PowerPC::CoreMode::JIT);
if (!result)
return false;
@@ -94,7 +94,8 @@ void JitTrampoline(JitBase& jit, u32 em_address)
JitBase::JitBase(Core::System& system)
: m_code_buffer(code_buffer_size), m_system(system), m_ppc_state(system.GetPPCState()),
m_mmu(system.GetMMU()), m_branch_watch(system.GetPowerPC().GetBranchWatch())
m_mmu(system.GetMMU()), m_branch_watch(system.GetPowerPC().GetBranchWatch()),
m_ppc_symbol_db(system.GetPPCSymbolDB())
{
m_registered_config_callback_id = CPUThreadConfigCallback::AddConfigChangedCallback([this] {
if (DoesConfigNeedRefresh())

Some files were not shown because too many files have changed in this diff Show More