From 3957b5fb42c3b69bea00a13c1e34e99c68841f17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Thu, 19 Dec 2013 11:45:39 +0100 Subject: [PATCH] Call ProxyBlock in ArmJit too. Plus various cleanup and one more string function. --- Core/HLE/ReplaceTables.cpp | 35 +++++++++++++-------------- Core/MIPS/ARM/ArmJit.cpp | 7 ++++-- Core/MIPS/JitCommon/JitBlockCache.cpp | 4 ++- Core/MIPS/JitCommon/JitBlockCache.h | 4 +-- Core/MIPS/x86/Jit.cpp | 11 +++------ 5 files changed, 31 insertions(+), 30 deletions(-) diff --git a/Core/HLE/ReplaceTables.cpp b/Core/HLE/ReplaceTables.cpp index f4cda40164..6e26c70393 100644 --- a/Core/HLE/ReplaceTables.cpp +++ b/Core/HLE/ReplaceTables.cpp @@ -63,9 +63,7 @@ static int Replace_memcpy() { if (bytes != 0) { u8 *dst = Memory::GetPointerUnchecked(destPtr); u8 *src = Memory::GetPointerUnchecked(srcPtr); - if (dst && src) { - memmove(dst, src, bytes); - } + memmove(dst, src, bytes); } RETURN(destPtr); return 10 + bytes / 4; // approximation @@ -78,9 +76,7 @@ static int Replace_memmove() { if (bytes != 0) { u8 *dst = Memory::GetPointerUnchecked(destPtr); u8 *src = Memory::GetPointerUnchecked(srcPtr); - if (dst && src) { - memmove(dst, src, bytes); - } + memmove(dst, src, bytes); } RETURN(destPtr); return 10 + bytes / 4; // approximation @@ -91,9 +87,7 @@ static int Replace_memset() { u8 *dst = Memory::GetPointerUnchecked(destPtr); u8 value = PARAM(1); u32 bytes = PARAM(2); - if (dst) { - memset(dst, value, bytes); - } + memset(dst, value, bytes); RETURN(destPtr); return 10 + bytes / 4; // approximation } @@ -110,9 +104,17 @@ static int Replace_strcpy() { u32 destPtr = PARAM(0); char *dst = (char *)Memory::GetPointerUnchecked(destPtr); const char *src = (const char *)Memory::GetPointerUnchecked(PARAM(1)); - if (dst && src) { - strcpy(dst, src); - } + strcpy(dst, src); + RETURN(destPtr); + return 10; // approximation +} + +static int Replace_strncpy() { + u32 destPtr = PARAM(0); + char *dst = (char *)Memory::GetPointerUnchecked(destPtr); + const char *src = (const char *)Memory::GetPointerUnchecked(PARAM(1)); + u32 bytes = PARAM(2); + strncpy(dst, src, bytes); RETURN(destPtr); return 10; // approximation } @@ -120,9 +122,7 @@ static int Replace_strcpy() { static int Replace_strcmp() { const char *a = (const char *)Memory::GetPointerUnchecked(PARAM(0)); const char *b = (const char *)Memory::GetPointerUnchecked(PARAM(1)); - if (a && b) { - RETURN(strcmp(a, b)); - } + RETURN(strcmp(a, b)); return 10; // approximation } @@ -130,9 +130,7 @@ static int Replace_strncmp() { const char *a = (const char *)Memory::GetPointerUnchecked(PARAM(0)); const char *b = (const char *)Memory::GetPointerUnchecked(PARAM(1)); u32 bytes = PARAM(2); - if (a && b) { - RETURN(strncmp(a, b, bytes)); - } + RETURN(strncmp(a, b, bytes)); return 10 + bytes / 4; // approximation } @@ -161,6 +159,7 @@ static const ReplacementTableEntry entries[] = { { "memset", &Replace_memset, 0, 0}, { "strlen", &Replace_strlen, 0, 0}, { "strcpy", &Replace_strcpy, 0, 0}, + { "strncpy", &Replace_strncpy, 0, 0}, { "strcmp", &Replace_strcmp, 0, 0}, { "strncmp", &Replace_strncmp, 0, 0}, { "fabsf", 0, &MIPSComp::Jit::Replace_fabsf, REPFLAG_ALLOWINLINE}, diff --git a/Core/MIPS/ARM/ArmJit.cpp b/Core/MIPS/ARM/ArmJit.cpp index 83c16de265..aac863da6a 100644 --- a/Core/MIPS/ARM/ArmJit.cpp +++ b/Core/MIPS/ARM/ArmJit.cpp @@ -171,7 +171,7 @@ void Jit::CompileDelaySlot(int flags) // delay slot, we're screwed. if (flags & DELAYSLOT_SAFE) MRS(R8); // Save flags register. R8 is preserved through function calls and is not allocated. - + js.inDelaySlot = true; MIPSOpcode op = Memory::Read_Instruction(js.compilerPC + 4); MIPSCompileOp(op); @@ -211,7 +211,6 @@ void Jit::Compile(u32 em_address) { void Jit::RunLoopUntil(u64 globalticks) { - // TODO: copy globalticks somewhere ((void (*)())enterCode)(); } @@ -368,6 +367,10 @@ bool Jit::ReplaceJalTo(u32 dest) { int cycles = (this->*repl)(); js.downcountAmount += cycles; // No writing exits, keep going! + + // Add a trigger so that if the inlined code changes, we invalidate this block. + // TODO: Correctly determine the size of this block. + blocks.ProxyBlock(js.blockStart, dest, 4, GetCodePtr()); return true; } else { return false; diff --git a/Core/MIPS/JitCommon/JitBlockCache.cpp b/Core/MIPS/JitCommon/JitBlockCache.cpp index 88e1a2d815..08ff53ea48 100644 --- a/Core/MIPS/JitCommon/JitBlockCache.cpp +++ b/Core/MIPS/JitCommon/JitBlockCache.cpp @@ -156,7 +156,9 @@ int JitBlockCache::AllocateBlock(u32 em_address) return num_blocks - 1; } -int JitBlockCache::CreateProxyBlock(u32 rootAddress, u32 startAddress, u32 size, const u8 *codePtr) { +int JitBlockCache::ProxyBlock(u32 rootAddress, u32 startAddress, u32 size, const u8 *codePtr) { + // TODO: If there's an existing block at the startAddress, add rootAddress as a proxy root of that block. + JitBlock &b = blocks[num_blocks]; b.invalid = false; b.originalAddress = startAddress; diff --git a/Core/MIPS/JitCommon/JitBlockCache.h b/Core/MIPS/JitCommon/JitBlockCache.h index c70c8bc179..4eac35ab33 100644 --- a/Core/MIPS/JitCommon/JitBlockCache.h +++ b/Core/MIPS/JitCommon/JitBlockCache.h @@ -59,7 +59,7 @@ const int MAX_JIT_BLOCK_EXITS = 8; // Fine to mess with them at block compile time though. struct JitBlock { bool ContainsAddress(u32 em_address); - + const u8 *checkedEntry; const u8 *normalEntry; @@ -91,7 +91,7 @@ public: int AllocateBlock(u32 em_address); // When a proxy block is invalidated, the block located at the rootAddress // is invalidated too. - int CreateProxyBlock(u32 rootAddress, u32 startAddress, u32 size, const u8 *codePtr); + int ProxyBlock(u32 rootAddress, u32 startAddress, u32 size, const u8 *codePtr); void FinalizeBlock(int block_num, bool block_link); void Clear(); diff --git a/Core/MIPS/x86/Jit.cpp b/Core/MIPS/x86/Jit.cpp index b0628d8cca..20261bd3fe 100644 --- a/Core/MIPS/x86/Jit.cpp +++ b/Core/MIPS/x86/Jit.cpp @@ -59,9 +59,8 @@ const bool USE_JIT_MISSMAP = false; static std::map notJitOps; template -std::pair flip_pair(const std::pair &p) -{ - return std::pair(p.second, p.first); +std::pair flip_pair(const std::pair &p) { + return std::pair(p.second, p.first); } u32 JitBreakpoint() @@ -286,9 +285,7 @@ void Jit::Compile(u32 em_address) void Jit::RunLoopUntil(u64 globalticks) { - // TODO: copy globalticks somewhere ((void (*)())asm_.enterCode)(); - // NOTICE_LOG(JIT, "Exited jitted code at %i, corestate=%i, dc=%i", CoreTiming::GetTicks() / 1000, (int)coreState, CoreTiming::downcount); } const u8 *Jit::DoJit(u32 em_address, JitBlock *b) @@ -429,7 +426,7 @@ bool Jit::ReplaceJalTo(u32 dest) { // Add a trigger so that if the inlined code changes, we invalidate this block. // TODO: Correctly determine the size of this block. - blocks.CreateProxyBlock(js.blockStart, dest, 4, GetCodePtr()); + blocks.ProxyBlock(js.blockStart, dest, 4, GetCodePtr()); return true; } else { return false; @@ -444,7 +441,7 @@ void Jit::Comp_ReplacementFunc(MIPSOpcode op) // Inlined function calls (caught in jal) are handled differently. int index = op.encoding & MIPS_EMUHACK_VALUE_MASK; - + const ReplacementTableEntry *entry = GetReplacementFunc(index); if (!entry) { ERROR_LOG(HLE, "Invalid replacement op %08x", op.encoding);