refactor: from guest threads to EE scheduler

This commit is contained in:
Ran-j
2026-07-25 21:23:24 -03:00
parent f3687c5ae6
commit cc941d2f4f
41 changed files with 5018 additions and 7410 deletions
+9 -3
View File
@@ -177,7 +177,7 @@ namespace ps2recomp
m_ss << fmt::format("{}ctx->pc = 0x{:X}u;\n", indent, target);
if (target <= sourcePc && !isCallLikeEdge())
{
m_ss << fmt::format("{}if (runtime->shouldPreemptGuestExecution()) {{\n", indent);
m_ss << fmt::format("{}if (runtime->eeCheckpointDue()) {{\n", indent);
m_ss << fmt::format("{} return;\n", indent);
m_ss << fmt::format("{}}}\n", indent);
}
@@ -296,10 +296,16 @@ namespace ps2recomp
const std::string_view handlerName = isSyscall ? resolvedSyscallName : resolvedStubName;
m_ss << indent << "{\n";
m_ss << indent << " const uint32_t __entryPc = ctx->pc;\n";
if (kind == StaticBranchKind::Call)
{
m_ss << fmt::format("{} ctx->pc = 0x{:X}u;\n", indent, fallthroughPc());
}
else
{
m_ss << indent << " ctx->pc = getRegU32(ctx, 31);\n";
}
m_ss << indent << " " << (isSyscall ? "ps2_syscalls::" : "ps2_stubs::")
<< handlerName << "(rdram, ctx, runtime);\n";
m_ss << indent << " if (ctx->pc == __entryPc) { ctx->pc = getRegU32(ctx, 31); }\n";
m_ss << indent << "}\n";
if (kind == StaticBranchKind::Jump)
+1 -1
View File
@@ -226,7 +226,7 @@ namespace ps2recomp
}
}
// Fallthrough with no terminating branch: advance ctx->pc past the function so dispatchLoop doesn't re-call it forever.
// Fallthrough with no terminating branch: publish the next PC so the EE dispatcher does not re-enter this function.
if (!instructions.empty() && !lastInstructionWasControlFlow)
{
ss << " ctx->pc = 0x" << std::hex << function.end << "u;\n"
+2 -7
View File
@@ -1078,7 +1078,7 @@ namespace ps2recomp
stub << "#ifdef _DEBUG\n";
stub << " PS_LOG_ENTRY(\"" << generatedName << "\");\n";
stub << "#endif\n";
stub << " const uint32_t __entryPc = ctx->pc;\n"
stub << " ctx->pc = getRegU32(ctx, 31);\n"
<< " ";
if (function.isSkipped)
@@ -1115,12 +1115,7 @@ namespace ps2recomp
}
}
stub << "\n"
<< " if (ctx->pc == __entryPc)\n"
<< " {\n"
<< " ctx->pc = getRegU32(ctx, 31);\n"
<< " }\n"
<< "}";
stub << "\n}";
m_generatedStubs[function.start] = stub.str();
}
}
+3 -1
View File
@@ -41,7 +41,9 @@ namespace ps2recomp
case SPECIAL_JALR:
return fmt::format("// JALR ${}, ${} - Handled by branch logic", inst.rd, inst.rs);
case SPECIAL_SYSCALL:
return fmt::format("runtime->handleSyscall(rdram, ctx, 0x{:X}u);", (inst.raw >> 6) & 0xFFFFFu);
return fmt::format("ctx->pc = 0x{:X}u;\nruntime->handleSyscall(rdram, ctx, 0x{:X}u);",
inst.address + 4u,
(inst.raw >> 6) & 0xFFFFFu);
case SPECIAL_BREAK:
return fmt::format("runtime->handleBreak(rdram, ctx);");
case SPECIAL_SYNC: