feat: runtime fixes and finish implementations

This commit is contained in:
Ran-j
2025-05-29 18:11:53 -03:00
parent e3ed780196
commit 5fde9612a9
4 changed files with 76 additions and 13 deletions
+3 -3
View File
@@ -285,8 +285,8 @@ namespace ps2recomp
ss << "#define WRITE64(addr, val) (*(uint64_t*)((rdram) + ((addr) & PS2_RAM_MASK)) = (val))\n";
ss << "#define WRITE128(addr, val) (*((__m128i*)((rdram) + ((addr) & PS2_RAM_MASK))) = (val))\n\n";
ss << "// Function lookup for indirect calls\n";
ss << "#define LOOKUP_FUNC(addr) runtime->lookupFunction(addr)\n\n";
// ss << "// Function lookup for indirect calls\n";
// ss << "#define LOOKUP_FUNC(addr, runtime) runtime->lookupFunction(addr)\n\n";
// Packed Compare Greater Than (PCGT)
ss << "#define PS2_PCGTW(a, b) _mm_cmpgt_epi32((__m128i)(a), (__m128i)(b))\n";
@@ -467,7 +467,7 @@ namespace ps2recomp
ss << "// Function: " << function.name << "\n";
ss << "// Address: 0x" << std::hex << function.start << " - 0x" << function.end << std::dec << "\n";
ss << "void " << function.name << "(uint8_t* rdram, R5900Context* ctx) {\n\n";
ss << "void " << function.name << "(uint8_t* rdram, R5900Context* ctx, PS2Runtime *runtime) {\n\n";
for (size_t i = 0; i < instructions.size(); ++i)
{
+2 -2
View File
@@ -21,7 +21,7 @@ namespace ps2recomp
try
{
m_config = m_configManager.loadConfig();
for (const auto &name : m_config.skipFunctions)
{
m_skipFunctions[name] = true;
@@ -198,7 +198,7 @@ namespace ps2recomp
{
if (function.isRecompiled)
{
ss << "void " << function.name << "(uint8_t* rdram, R5900Context* ctx);\n";
ss << "void " << function.name << "(uint8_t* rdram, R5900Context* ctx, PS2Runtime *runtime);\n";
}
}
+21 -5
View File
@@ -384,20 +384,36 @@ public:
bool loadELF(const std::string &elfPath);
void run();
using RecompiledFunction = void (*)(uint8_t *, R5900Context *);
using RecompiledFunction = void (*)(uint8_t *, R5900Context *, PS2Runtime *);
void registerFunction(uint32_t address, RecompiledFunction func);
RecompiledFunction lookupFunction(uint32_t address);
void SignalException(R5900Context* ctx, PS2Exception exception);
void executeVU0Microprogram(uint8_t* rdram, R5900Context* ctx, uint32_t address);
void SignalException(R5900Context *ctx, PS2Exception exception);
void executeVU0Microprogram(uint8_t *rdram, R5900Context *ctx, uint32_t address);
void vu0StartMicroProgram(uint8_t *rdram, R5900Context *ctx, uint32_t address);
public:
void handleSyscall(uint8_t *rdram, R5900Context *ctx);
void handleBreak(uint8_t *rdram, R5900Context *ctx);
void handleTrap(uint8_t *rdram, R5900Context *ctx);
void handleTLBR(uint8_t *rdram, R5900Context *ctx);
void handleTLBWI(uint8_t *rdram, R5900Context *ctx);
void handleTLBWR(uint8_t *rdram, R5900Context *ctx);
void handleTLBP(uint8_t *rdram, R5900Context *ctx);
void clearLLBit(R5900Context *ctx);
public:
bool check_overflow = false;
private:
void HandleIntegerOverflow(R5900Context* ctx);
void HandleIntegerOverflow(R5900Context *ctx);
private:
PS2Memory m_memory;
R5900Context m_cpuContext;
bool check_overflow = false;
std::unordered_map<uint32_t, RecompiledFunction> m_functionTable;
+50 -3
View File
@@ -163,7 +163,7 @@ PS2Runtime::RecompiledFunction PS2Runtime::lookupFunction(uint32_t address)
std::cerr << "Warning: Function at address 0x" << std::hex << address << std::dec << " not found" << std::endl;
static RecompiledFunction defaultFunction = [](uint8_t *rdram, R5900Context *ctx)
static RecompiledFunction defaultFunction = [](uint8_t *rdram, R5900Context *ctx, PS2Runtime* runtime)
{
std::cerr << "Error: Called unimplemented function at address 0x" << std::hex << ctx->pc << std::dec << std::endl;
};
@@ -185,12 +185,59 @@ void PS2Runtime::executeVU0Microprogram(uint8_t *rdram, R5900Context *ctx, uint3
std::cout << "VU0 microprogram call to address 0x" << std::hex << address
<< " - not implemented" << std::dec << std::endl;
// mayve implement like this or a vu0_interpreter
// mayve implement like this or a vu0_interpreter
// Placeholder for VU0 microprogram execution
// auto microprog = findCompiledMicroprogram(address);
// if (microprog) microprog(rdram, ctx);
}
void PS2Runtime::vu0StartMicroProgram(uint8_t *rdram, R5900Context *ctx, uint32_t address)
{
std::cout << "VU0 microprogram call to address 0x" << std::hex << address
<< " - not implemented" << std::dec << std::endl;
}
void PS2Runtime::handleSyscall(uint8_t *rdram, R5900Context *ctx)
{
std::cout << "Syscall encountered at PC: 0x" << std::hex << ctx->pc << std::dec << std::endl;
}
void PS2Runtime::handleBreak(uint8_t *rdram, R5900Context *ctx)
{
std::cout << "Break encountered at PC: 0x" << std::hex << ctx->pc << std::dec << std::endl;
}
void PS2Runtime::handleTrap(uint8_t *rdram, R5900Context *ctx)
{
std::cout << "Trap encountered at PC: 0x" << std::hex << ctx->pc << std::dec << std::endl;
}
void PS2Runtime::handleTLBR(uint8_t *rdram, R5900Context *ctx)
{
std::cout << "TLBR (TLB Read) at PC: 0x" << std::hex << ctx->pc << std::dec << std::endl;
}
void PS2Runtime::handleTLBWI(uint8_t *rdram, R5900Context *ctx)
{
std::cout << "TLBWI (TLB Write Indexed) at PC: 0x" << std::hex << ctx->pc << std::dec << std::endl;
}
void PS2Runtime::handleTLBWR(uint8_t *rdram, R5900Context *ctx)
{
std::cout << "TLBWR (TLB Write Random) at PC: 0x" << std::hex << ctx->pc << std::dec << std::endl;
}
void PS2Runtime::handleTLBP(uint8_t *rdram, R5900Context *ctx)
{
std::cout << "TLBP (TLB Probe) at PC: 0x" << std::hex << ctx->pc << std::dec << std::endl;
}
void PS2Runtime::clearLLBit(R5900Context *ctx)
{
ctx->cop0_status &= ~0x00000002; // LL bit is bit 1 in the status register
std::cout << "LL bit cleared at PC: 0x" << std::hex << ctx->pc << std::dec << std::endl;
}
void PS2Runtime::HandleIntegerOverflow(R5900Context *ctx)
{
std::cerr << "Integer overflow exception at PC: 0x" << std::hex << ctx->pc << std::dec << std::endl;
@@ -218,7 +265,7 @@ void PS2Runtime::run()
try
{
// Call the entry point function
entryPoint(m_memory.getRDRAM(), &m_cpuContext);
entryPoint(m_memory.getRDRAM(), &m_cpuContext, this);
std::cout << "Program execution completed successfully" << std::endl;
}