From 2d4c28826a5720c74d6201fb9f36392f2f7b8705 Mon Sep 17 00:00:00 2001 From: Henrik Rydgard Date: Wed, 18 Dec 2013 11:42:19 +0100 Subject: [PATCH] Show replaced instructions correctly in disassembly --- Core/HLE/ReplaceTables.cpp | 17 +++++++++++++++-- Core/HLE/ReplaceTables.h | 2 ++ Core/MIPS/JitCommon/JitCommon.h | 8 ++++---- Core/MemMap.cpp | 25 +++++++++++++++---------- 4 files changed, 36 insertions(+), 16 deletions(-) diff --git a/Core/HLE/ReplaceTables.cpp b/Core/HLE/ReplaceTables.cpp index 7dde74b9b..76f3eb687 100644 --- a/Core/HLE/ReplaceTables.cpp +++ b/Core/HLE/ReplaceTables.cpp @@ -198,8 +198,21 @@ const ReplacementTableEntry *GetReplacementFunc(int i) { void WriteReplaceInstruction(u32 address, u64 hash, int size) { int index = GetReplacementFuncIndex(hash, size); if (index >= 0) { - replacedInstructions[address] = Memory::Read_U32(address); - ILOG("Replaced %s at %08x", entries[index].name, address); + u32 prevInstr = Memory::Read_U32(address); + if (MIPS_IS_REPLACEMENT(prevInstr)) + return; + replacedInstructions[address] = prevInstr; + INFO_LOG(HLE, "Replaced %s at %08x", entries[index].name, address); Memory::Write_U32(MIPS_EMUHACK_CALL_REPLACEMENT | (int)index, address); } } + +bool GetReplacedOpAt(u32 address, u32 *op) { + auto iter = replacedInstructions.find(address); + if (iter != replacedInstructions.end()) { + *op = iter->second; + return true; + } else { + return false; + } +} diff --git a/Core/HLE/ReplaceTables.h b/Core/HLE/ReplaceTables.h index aa307c800..423dd8f0c 100644 --- a/Core/HLE/ReplaceTables.h +++ b/Core/HLE/ReplaceTables.h @@ -56,4 +56,6 @@ void Replacement_Shutdown(); int GetNumReplacementFuncs(); int GetReplacementFuncIndex(u64 hash, int funcSize); const ReplacementTableEntry *GetReplacementFunc(int index); + void WriteReplaceInstruction(u32 address, u64 hash, int size); +bool GetReplacedOpAt(u32 address, u32 *op); diff --git a/Core/MIPS/JitCommon/JitCommon.h b/Core/MIPS/JitCommon/JitCommon.h index c23b596c2..dfbbb1716 100644 --- a/Core/MIPS/JitCommon/JitCommon.h +++ b/Core/MIPS/JitCommon/JitCommon.h @@ -42,15 +42,15 @@ struct JitBlock; #define MIPS_JITBLOCK_MASK 0xFF000000 #define MIPS_EMUHACK_VALUE_MASK 0x00FFFFFF -#define MIPS_IS_EMUHACK(op) (((op) & 0xFC000000) == MIPS_EMUHACK_OPCODE) // masks away the subop -#define MIPS_IS_RUNBLOCK(op) (((op) & 0xFF000000) == MIPS_EMUHACK_OPCODE) // masks away the subop -#define MIPS_IS_REPLACEMENT(op) (((op) & 0xFF000000) == (MIPS_EMUHACK_OPCODE | (EMUOP_CALL_REPLACEMENT << 24))) // masks away the subop - // There are 2 bits available for sub-opcodes, 0x03000000. #define EMUOP_RUNBLOCK 0 // Runs a JIT block #define EMUOP_RETKERNEL 1 // Returns to the simulated PSP kernel from a thread #define EMUOP_CALL_REPLACEMENT 2 +#define MIPS_IS_EMUHACK(op) (((op) & 0xFC000000) == MIPS_EMUHACK_OPCODE) // masks away the subop +#define MIPS_IS_RUNBLOCK(op) (((op) & 0xFF000000) == MIPS_EMUHACK_OPCODE) // masks away the subop +#define MIPS_IS_REPLACEMENT(op) (((op) & 0xFF000000) == (MIPS_EMUHACK_OPCODE | (EMUOP_CALL_REPLACEMENT << 24))) // masks away the subop + #define MIPS_EMUHACK_CALL_REPLACEMENT (MIPS_EMUHACK_OPCODE | (EMUOP_CALL_REPLACEMENT << 24)) namespace MIPSComp { diff --git a/Core/MemMap.cpp b/Core/MemMap.cpp index 3bc417596..1bf39963c 100644 --- a/Core/MemMap.cpp +++ b/Core/MemMap.cpp @@ -23,17 +23,18 @@ #include "ChunkFile.h" #include "MemMap.h" -#include "Core.h" #include "MIPS/MIPS.h" #include "MIPS/JitCommon/JitCommon.h" #include "HLE/HLE.h" -#include "CPU.h" + +#include "Core/CPU.h" +#include "Core/Core.h" #include "Core/Debugger/SymbolMap.h" #include "Core/Debugger/Breakpoints.h" #include "Core/Config.h" +#include "Core/HLE/ReplaceTables.h" -namespace Memory -{ +namespace Memory { // The base pointer to the auto-mirrored arena. u8* base = NULL; @@ -173,7 +174,7 @@ void Clear() Opcode Read_Instruction(u32 address) { Opcode inst = Opcode(Read_U32(address)); - if (MIPS_IS_RUNBLOCK(inst) && MIPSComp::jit) + if (MIPS_IS_RUNBLOCK(inst.encoding) && MIPSComp::jit) { JitBlockCache *bc = MIPSComp::jit->GetBlockCache(); int block_num = bc->GetBlockNumberFromEmuHackOp(inst, true); @@ -182,8 +183,13 @@ Opcode Read_Instruction(u32 address) } else { return inst; } - } else if (MIPS_IS_REPLACEMENT(inst)) { - return inst; + } else if (MIPS_IS_REPLACEMENT(inst.encoding)) { + u32 op; + if (GetReplacedOpAt(address, &op)) { + return Opcode(op); + } else { + return inst; + } } else { return inst; } @@ -204,9 +210,8 @@ void Write_Opcode_JIT(const u32 _Address, const Opcode _Value) void Memset(const u32 _Address, const u8 _iValue, const u32 _iLength) { u8 *ptr = GetPointer(_Address); - if (ptr != NULL) - { - memset(ptr,_iValue,_iLength); + if (ptr != NULL) { + memset(ptr, _iValue, _iLength); } else {