Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #9218 from JosJuice/aarch64-hle-hooks
JitArm64: Implement HLE function hooking
  • Loading branch information
degasus committed Nov 4, 2020
2 parents 3cd4c56 + fe986b6 commit 069840f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
28 changes: 21 additions & 7 deletions Source/Core/Core/PowerPC/JitArm64/Jit.cpp
Expand Up @@ -209,20 +209,16 @@ void JitArm64::FallBackToInterpreter(UGeckoInstruction inst)
}
}

void JitArm64::HLEFunction(UGeckoInstruction inst)
void JitArm64::HLEFunction(u32 hook_index)
{
FlushCarry();
gpr.Flush(FlushMode::FLUSH_ALL);
fpr.Flush(FlushMode::FLUSH_ALL);

MOVI2R(W0, js.compilerPC);
MOVI2R(W1, inst.hex);
MOVI2R(W1, hook_index);
MOVP2R(X30, &HLE::Execute);
BLR(X30);

ARM64Reg WA = gpr.GetReg();
LDR(INDEX_UNSIGNED, WA, PPC_REG, PPCSTATE_OFF(npc));
WriteExit(WA);
gpr.Unlock(WA);
}

void JitArm64::DoNothing(UGeckoInstruction inst)
Expand Down Expand Up @@ -490,6 +486,21 @@ void JitArm64::WriteExceptionExit(ARM64Reg dest, bool only_external)
B(dispatcher);
}

bool JitArm64::HandleFunctionHooking(u32 address)
{
return HLE::ReplaceFunctionIfPossible(address, [&](u32 hook_index, HLE::HookType type) {
HLEFunction(hook_index);

if (type != HLE::HookType::Replace)
return false;

LDR(INDEX_UNSIGNED, DISPATCHER_PC, PPC_REG, PPCSTATE_OFF(npc));
js.downcountAmount += js.st.numCycles;
WriteExit(DISPATCHER_PC);
return true;
});
}

void JitArm64::DumpCode(const u8* start, const u8* end)
{
std::string output;
Expand Down Expand Up @@ -748,6 +759,9 @@ void JitArm64::DoJit(u32 em_address, JitBlock* b, u32 nextPC)
SetJumpTarget(exit);
}

if (HandleFunctionHooking(op.address))
break;

if (!op.skip)
{
if ((opinfo->flags & FL_USE_FPU) && !js.firstFPInstructionFound)
Expand Down
4 changes: 3 additions & 1 deletion Source/Core/Core/PowerPC/JitArm64/Jit.h
Expand Up @@ -46,7 +46,7 @@ class JitArm64 : public JitBase, public Arm64Gen::ARM64CodeBlock, public CommonA
// OPCODES
void FallBackToInterpreter(UGeckoInstruction inst);
void DoNothing(UGeckoInstruction inst);
void HLEFunction(UGeckoInstruction inst);
void HLEFunction(u32 hook_index);

void DynaRunTable4(UGeckoInstruction inst);
void DynaRunTable19(UGeckoInstruction inst);
Expand Down Expand Up @@ -175,6 +175,8 @@ class JitArm64 : public JitBase, public Arm64Gen::ARM64CodeBlock, public CommonA
static void InitializeInstructionTables();
void CompileInstruction(PPCAnalyst::CodeOp& op);

bool HandleFunctionHooking(u32 address);

// Simple functions to switch between near and far code emitting
void SwitchToFarCode()
{
Expand Down

0 comments on commit 069840f

Please sign in to comment.