Split out the ReplaceJalTo test logic.

This makes it so the IR, in the future, can work correctly for
replacements.
This commit is contained in:
Henrik Rydgård 2015-04-12 13:35:10 -07:00 committed by Unknown W. Brackets
parent c6113b831d
commit 70fa830ba5
6 changed files with 51 additions and 55 deletions

View File

@ -23,6 +23,7 @@
#include "Common/Log.h"
#include "Core/Config.h"
#include "Core/Debugger/Breakpoints.h"
#include "Core/Debugger/SymbolMap.h"
#include "Core/MemMap.h"
#include "Core/MIPS/JitCommon/JitCommon.h"
#include "Core/MIPS/MIPSCodeUtils.h"
@ -1246,3 +1247,35 @@ bool GetReplacedOpAt(u32 address, u32 *op) {
}
return false;
}
bool CanReplaceJalTo(u32 dest, const ReplacementTableEntry **entry, u32 *funcSize) {
MIPSOpcode op(Memory::Read_Opcode_JIT(dest));
if (!MIPS_IS_REPLACEMENT(op.encoding))
return false;
// Make sure we don't replace if there are any breakpoints inside.
*funcSize = symbolMap.GetFunctionSize(dest);
if (*funcSize == SymbolMap::INVALID_ADDRESS) {
if (CBreakPoints::IsAddressBreakPoint(dest)) {
return false;
}
*funcSize = (u32)sizeof(u32);
} else {
if (CBreakPoints::RangeContainsBreakPoint(dest, *funcSize)) {
return false;
}
}
int index = op.encoding & MIPS_EMUHACK_VALUE_MASK;
*entry = GetReplacementFunc(index);
if (!*entry) {
ERROR_LOG(HLE, "ReplaceJalTo: Invalid replacement op %08x at %08x", op.encoding, dest);
return false;
}
if ((*entry)->flags & (REPFLAG_HOOKENTER | REPFLAG_HOOKEXIT | REPFLAG_DISABLED)) {
// If it's a hook, we can't replace the jal, we have to go inside the func.
return false;
}
return true;
}

View File

@ -68,6 +68,7 @@ void WriteReplaceInstructions(u32 address, u64 hash, int size);
void RestoreReplacedInstruction(u32 address);
void RestoreReplacedInstructions(u32 startAddr, u32 endAddr);
bool GetReplacedOpAt(u32 address, u32 *op);
bool CanReplaceJalTo(u32 dest, const ReplacementTableEntry **entry, u32 *funcSize);
// For savestates. If you call SaveAndClearReplacements(), you must call RestoreSavedReplacements().
std::map<u32, u32> SaveAndClearReplacements();

View File

@ -397,19 +397,9 @@ void ArmJit::Comp_RunBlock(MIPSOpcode op)
bool ArmJit::ReplaceJalTo(u32 dest) {
#ifdef ARM
MIPSOpcode op(Memory::Read_Opcode_JIT(dest));
if (!MIPS_IS_REPLACEMENT(op.encoding))
return false;
int index = op.encoding & MIPS_EMUHACK_VALUE_MASK;
const ReplacementTableEntry *entry = GetReplacementFunc(index);
if (!entry) {
ERROR_LOG(HLE, "ReplaceJalTo: Invalid replacement op %08x at %08x", op.encoding, dest);
return false;
}
if (entry->flags & (REPFLAG_HOOKENTER | REPFLAG_HOOKEXIT | REPFLAG_DISABLED)) {
// If it's a hook, we can't replace the jal, we have to go inside the func.
const ReplacementTableEntry *entry = nullptr;
u32 funcSize = 0;
if (!CanReplaceJalTo(dest, &entry, &funcSize)) {
return false;
}
@ -442,7 +432,7 @@ bool ArmJit::ReplaceJalTo(u32 dest) {
// No writing exits, keep going!
// Add a trigger so that if the inlined code changes, we invalidate this block.
blocks.ProxyBlock(js.blockStart, dest, symbolMap.GetFunctionSize(dest) / sizeof(u32), GetCodePtr());
blocks.ProxyBlock(js.blockStart, dest, funcSize / sizeof(u32), GetCodePtr());
#endif
return true;
}

View File

@ -357,19 +357,9 @@ void Arm64Jit::Comp_RunBlock(MIPSOpcode op) {
bool Arm64Jit::ReplaceJalTo(u32 dest) {
#ifdef ARM64
MIPSOpcode op(Memory::Read_Opcode_JIT(dest));
if (!MIPS_IS_REPLACEMENT(op.encoding))
return false;
int index = op.encoding & MIPS_EMUHACK_VALUE_MASK;
const ReplacementTableEntry *entry = GetReplacementFunc(index);
if (!entry) {
ERROR_LOG(HLE, "ReplaceJalTo: Invalid replacement op %08x at %08x", op.encoding, dest);
return false;
}
if (entry->flags & (REPFLAG_HOOKENTER | REPFLAG_HOOKEXIT | REPFLAG_DISABLED)) {
// If it's a hook, we can't replace the jal, we have to go inside the func.
const ReplacementTableEntry *entry = nullptr;
u32 funcSize = 0;
if (!CanReplaceJalTo(dest, &entry, &funcSize)) {
return false;
}
INFO_LOG(HLE, "ReplaceJalTo to %s", entry->name);
@ -397,7 +387,7 @@ bool Arm64Jit::ReplaceJalTo(u32 dest) {
// No writing exits, keep going!
// Add a trigger so that if the inlined code changes, we invalidate this block.
blocks.ProxyBlock(js.blockStart, dest, symbolMap.GetFunctionSize(dest) / sizeof(u32), GetCodePtr());
blocks.ProxyBlock(js.blockStart, dest, funcSize / sizeof(u32), GetCodePtr());
#endif
return true;
}

View File

@ -239,7 +239,12 @@ void MipsJit::Comp_RunBlock(MIPSOpcode op)
}
bool MipsJit::ReplaceJalTo(u32 dest) {
return true;
const ReplacementTableEntry *entry = nullptr;
u32 funcSize = 0;
if (!CanReplaceJalTo(dest, &entry, &funcSize)) {
return false;
}
return false;
}
void MipsJit::Comp_ReplacementFunc(MIPSOpcode op)

View File

@ -533,32 +533,9 @@ void Jit::Comp_RunBlock(MIPSOpcode op)
}
bool Jit::ReplaceJalTo(u32 dest) {
MIPSOpcode op(Memory::Read_Opcode_JIT(dest));
if (!MIPS_IS_REPLACEMENT(op.encoding))
return false;
// Make sure we don't replace if there are any breakpoints inside.
u32 funcSize = symbolMap.GetFunctionSize(dest);
if (funcSize == SymbolMap::INVALID_ADDRESS) {
if (CBreakPoints::IsAddressBreakPoint(dest)) {
return false;
}
funcSize = (u32)sizeof(u32);
} else {
if (CBreakPoints::RangeContainsBreakPoint(dest, funcSize)) {
return false;
}
}
int index = op.encoding & MIPS_EMUHACK_VALUE_MASK;
const ReplacementTableEntry *entry = GetReplacementFunc(index);
if (!entry) {
ERROR_LOG(HLE, "ReplaceJalTo: Invalid replacement op %08x at %08x", op.encoding, dest);
return false;
}
if (entry->flags & (REPFLAG_HOOKENTER | REPFLAG_HOOKEXIT | REPFLAG_DISABLED)) {
// If it's a hook, we can't replace the jal, we have to go inside the func.
const ReplacementTableEntry *entry = nullptr;
u32 funcSize = 0;
if (!CanReplaceJalTo(dest, &entry, &funcSize)) {
return false;
}