Debugger: IOP Function Tree

Co-authored-by: Ziemas <ziemas@ziemas.se>
This commit is contained in:
Ty Lamontagne
2023-10-26 18:26:16 -04:00
committed by refractionpcsx2
parent 85539c7bb9
commit 46a0c2d5b6
10 changed files with 468 additions and 61 deletions

View File

@@ -25,6 +25,10 @@
#include "x86/iR3000A.h"
#include "VMManager.h"
#include <ctype.h>
#include <fmt/format.h>
#include <string.h>
#include <sys/stat.h>
#include "common/FileSystem.h"
#include "common/Path.h"
@@ -42,10 +46,10 @@
#endif
#if !defined(S_ISREG) && defined(S_IFMT) && defined(S_IFREG)
#define S_ISREG(m) (((m)&S_IFMT) == S_IFREG)
#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
#endif
#if !defined(S_ISDIR) && defined(S_IFMT) && defined(S_IFDIR)
#define S_ISDIR(m) (((m)&S_IFMT) == S_IFDIR)
#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
#endif
#ifndef O_BINARY
@@ -1017,6 +1021,31 @@ namespace R3000A
namespace loadcore
{
u32 GetModList(u32 a0reg)
{
u32 lcptr = iopMemRead32(0x3f0);
u32 lcstring = irxFindLoadcore(lcptr);
u32 list = 0;
if (lcstring == 0)
{
list = lcptr - 0x20;
}
else
{
list = lcstring + 0x18;
}
u32 mod = iopMemRead32(list);
while (mod != 0)
{
mod = iopMemRead32(mod);
}
return list;
}
// Gets the thread list ptr from thbase
u32 GetThreadList(u32 a0reg, u32 version)
{
@@ -1035,8 +1064,49 @@ namespace R3000A
return list;
}
int RegisterLibraryEntries_HLE()
void LoadFuncs(u32 a0reg)
{
const std::string modname = iopMemReadString(a0reg + 12, 8);
ModuleVersion version = {iopMemRead8(a0 + 9), iopMemRead8(a0 + 8)};
DevCon.WriteLn(Color_Gray, "RegisterLibraryEntries: %8.8s version %x.%02x", modname.data(), version.major, version.minor);
if (R3000SymbolMap.AddModule(modname, version))
{
u32 func = a0reg + 20;
u32 funcptr = iopMemRead32(func);
u32 index = 0;
while (funcptr != 0)
{
const std::string funcname = std::string(irxImportFuncname(modname, index));
if (!funcname.empty())
{
R3000SymbolMap.AddModuleExport(modname, version, fmt::format("{}[{:02}]::{}", modname, index, funcname).c_str(), funcptr, 0);
}
else
{
R3000SymbolMap.AddModuleExport(modname, version, fmt::format("{}[{:02}]::unkn_{:02}", modname, index, index).c_str(), funcptr, 0);
}
index++;
func += 4;
funcptr = iopMemRead32(func);
}
}
}
void ReleaseFuncs(u32 a0reg)
{
const std::string modname = iopMemReadString(a0reg + 12, 8);
ModuleVersion version = {iopMemRead8(a0 + 9), iopMemRead8(a0 + 8)};
DevCon.WriteLn(Color_Gray, "ReleaseLibraryEntries: %8.8s version %x.%02x", modname.data(), version.major, version.minor);
R3000SymbolMap.RemoveModule(modname, version);
}
void RegisterLibraryEntries_DEBUG()
{
LoadFuncs(a0);
const std::string modname = iopMemReadString(a0 + 12);
if (modname == "thbase")
{
@@ -1044,13 +1114,12 @@ namespace R3000A
CurrentBiosInformation.iopThreadListAddr = GetThreadList(a0, version);
}
return 0;
CurrentBiosInformation.iopModListAddr = GetModList(a0);
}
void RegisterLibraryEntries_DEBUG()
void ReleaseLibraryEntries_DEBUG()
{
const std::string modname = iopMemReadString(a0 + 12);
DevCon.WriteLn(Color_Gray, "RegisterLibraryEntries: %8.8s version %x.%02x", modname.data(), (unsigned)iopMemRead8(a0 + 9), (unsigned)iopMemRead8(a0 + 8));
ReleaseFuncs(a0);
}
} // namespace loadcore
@@ -1099,6 +1168,24 @@ namespace R3000A
}
} // namespace sifcmd
u32 irxFindLoadcore(u32 entrypc)
{
u32 i;
i = entrypc;
while (entrypc - i < 0x50)
{
// find loadcore string
if (iopMemRead32(i) == 0x49497350 && iopMemRead32(i + 4) == 0x64616F6C)
{
return i;
}
i -= 4;
}
return 0;
}
u32 irxImportTableAddr(u32 entrypc)
{
u32 i;
@@ -1128,10 +1215,10 @@ namespace R3000A
// case 3: ???
}
return 0;
return "";
}
// clang-format off
// clang-format off
#define MODULE(n) \
if (#n == libname) \
{ \
@@ -1157,11 +1244,6 @@ namespace R3000A
EXPORT_H( 14, Kprintf)
END_MODULE
// For grabbing the thread list from thbase
MODULE(loadcore)
EXPORT_H( 6, RegisterLibraryEntries)
END_MODULE
// Special case with ioman and iomanX
// They are mostly compatible excluding stat structures
if(libname == "ioman" || libname == "iomanx")
@@ -1201,6 +1283,7 @@ namespace R3000A
// clang-format off
MODULE(loadcore)
EXPORT_D( 6, RegisterLibraryEntries)
EXPORT_D( 7, ReleaseLibraryEntries);
END_MODULE
MODULE(intrman)
EXPORT_D( 4, RegisterIntrHandler)