mirror of
https://github.com/libretro/ppsspp.git
synced 2024-12-02 22:26:25 +00:00
Merge pull request #7680 from unknownbrackets/ir-parts
Even more parts of the jit-ir branch
This commit is contained in:
commit
ca14497111
@ -405,7 +405,7 @@
|
||||
<ClCompile Include="MIPS\ARM\ArmJit.cpp">
|
||||
<Filter>MIPS\ARM</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="MIPS\ARM\MipsJit.cpp">
|
||||
<ClCompile Include="MIPS\MIPS\MipsJit.cpp">
|
||||
<Filter>MIPS\MIPS</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="MIPS\ARM\ArmRegCache.cpp">
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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();
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -24,7 +24,6 @@
|
||||
namespace MIPSCodeUtils
|
||||
{
|
||||
|
||||
#define FULLOP_JR_RA 0x03e00008
|
||||
#define OP_SYSCALL 0x0000000c
|
||||
#define OP_SYSCALL_MASK 0xFC00003F
|
||||
#define _RS ((op>>21) & 0x1F)
|
||||
|
@ -38,14 +38,6 @@ void DisassembleFake(const u8 *data, int size) {
|
||||
namespace MIPSComp
|
||||
{
|
||||
|
||||
FakeJitOptions::FakeJitOptions() {
|
||||
enableBlocklink = true;
|
||||
immBranches = false;
|
||||
continueBranches = false;
|
||||
continueJumps = false;
|
||||
continueMaxInstructions = 300;
|
||||
}
|
||||
|
||||
FakeJit::FakeJit(MIPSState *mips) : blocks(mips, this), mips_(mips)
|
||||
{
|
||||
logBlocks = 0;
|
||||
|
@ -30,17 +30,6 @@ namespace MIPSComp
|
||||
|
||||
typedef int FakeReg;
|
||||
|
||||
struct FakeJitOptions
|
||||
{
|
||||
FakeJitOptions();
|
||||
|
||||
bool enableBlocklink;
|
||||
bool immBranches;
|
||||
bool continueBranches;
|
||||
bool continueJumps;
|
||||
int continueMaxInstructions;
|
||||
};
|
||||
|
||||
class FakeJit : public FakeGen::FakeXCodeBlock
|
||||
{
|
||||
public:
|
||||
@ -166,7 +155,7 @@ private:
|
||||
void WriteSyscallExit();
|
||||
|
||||
JitBlockCache blocks;
|
||||
FakeJitOptions jo;
|
||||
JitOptions jo;
|
||||
JitState js;
|
||||
|
||||
MIPSState *mips_;
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -208,6 +208,33 @@ void GPRRegCache::FlushR(X64Reg reg)
|
||||
StoreFromRegister(xregs[reg].mipsReg);
|
||||
}
|
||||
|
||||
void GPRRegCache::FlushRemap(MIPSGPReg oldreg, MIPSGPReg newreg) {
|
||||
OpArg oldLocation = regs[oldreg].location;
|
||||
if (!oldLocation.IsSimpleReg()) {
|
||||
PanicAlert("FlushRemap: Must already be in an x86 register");
|
||||
}
|
||||
|
||||
X64Reg xr = oldLocation.GetSimpleReg();
|
||||
|
||||
if (oldreg == newreg) {
|
||||
xregs[xr].dirty = true;
|
||||
return;
|
||||
}
|
||||
|
||||
StoreFromRegister(oldreg);
|
||||
|
||||
// Now, if newreg already was mapped somewhere, get rid of that.
|
||||
DiscardRegContentsIfCached(newreg);
|
||||
|
||||
// Now, take over the old register.
|
||||
regs[newreg].location = oldLocation;
|
||||
regs[newreg].away = true;
|
||||
regs[newreg].locked = true;
|
||||
xregs[xr].mipsReg = newreg;
|
||||
xregs[xr].dirty = true;
|
||||
xregs[xr].free = false;
|
||||
}
|
||||
|
||||
int GPRRegCache::SanityCheck() const {
|
||||
for (int i = 0; i < NUM_MIPS_GPRS; i++) {
|
||||
const MIPSGPReg r = MIPSGPReg(i);
|
||||
|
@ -86,6 +86,10 @@ public:
|
||||
}
|
||||
void Flush();
|
||||
void FlushBeforeCall();
|
||||
|
||||
// Flushes one register and reuses the register for another one. Dirtyness is implied.
|
||||
void FlushRemap(MIPSGPReg oldreg, MIPSGPReg newreg);
|
||||
|
||||
int SanityCheck() const;
|
||||
void KillImmediate(MIPSGPReg preg, bool doLoad, bool makeDirty);
|
||||
|
||||
|
@ -108,6 +108,36 @@ void FPURegCache::ReduceSpillLockV(const u8 *vec, VectorSize sz) {
|
||||
}
|
||||
}
|
||||
|
||||
void FPURegCache::FlushRemap(int oldreg, int newreg) {
|
||||
OpArg oldLocation = regs[oldreg].location;
|
||||
if (!oldLocation.IsSimpleReg()) {
|
||||
PanicAlert("FlushRemap: Must already be in an x86 SSE register");
|
||||
}
|
||||
if (regs[oldreg].lane != 0) {
|
||||
PanicAlert("FlushRemap only supports FPR registers");
|
||||
}
|
||||
|
||||
X64Reg xr = oldLocation.GetSimpleReg();
|
||||
|
||||
if (oldreg == newreg) {
|
||||
xregs[xr].dirty = true;
|
||||
return;
|
||||
}
|
||||
|
||||
StoreFromRegister(oldreg);
|
||||
|
||||
// Now, if newreg already was mapped somewhere, get rid of that.
|
||||
DiscardR(newreg);
|
||||
|
||||
// Now, take over the old register.
|
||||
regs[newreg].location = oldLocation;
|
||||
regs[newreg].away = true;
|
||||
regs[newreg].locked = true;
|
||||
regs[newreg].lane = 0;
|
||||
xregs[xr].mipsReg = newreg;
|
||||
xregs[xr].dirty = true;
|
||||
}
|
||||
|
||||
void FPURegCache::MapRegV(int vreg, int flags) {
|
||||
MapReg(vreg + 32, (flags & MAP_NOINIT) != MAP_NOINIT, (flags & MAP_DIRTY) != 0);
|
||||
}
|
||||
|
@ -119,6 +119,9 @@ public:
|
||||
|
||||
void SetEmitter(Gen::XEmitter *emitter) {emit = emitter;}
|
||||
|
||||
// Flushes one register and reuses the register for another one. Dirtyness is implied.
|
||||
void FlushRemap(int oldreg, int newreg);
|
||||
|
||||
void Flush();
|
||||
int SanityCheck() const;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user