From 5f4a0d817416ead6634be1ed3988e3131a5c2e17 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Thu, 19 Jun 2014 00:47:58 -0700 Subject: [PATCH 1/4] Fix a few minor warnings. --- Core/HLE/HLE.cpp | 2 +- GPU/GLES/Framebuffer.cpp | 2 +- GPU/GLES/StencilBuffer.cpp | 7 +++---- GPU/GLES/TextureCache.cpp | 2 +- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/Core/HLE/HLE.cpp b/Core/HLE/HLE.cpp index 3e68432aa9..4754531ebc 100644 --- a/Core/HLE/HLE.cpp +++ b/Core/HLE/HLE.cpp @@ -538,7 +538,7 @@ void CallSyscall(MIPSOpcode op) CallSyscallWithoutFlags(info); } else - ERROR_LOG_REPORT(HLE, "Unimplemented HLE function %s", info->name ? info->name : "(???)"); + ERROR_LOG_REPORT(HLE, "Unimplemented HLE function %s", info->name ? info->name : "(\?\?\?)"); if (g_Config.bShowDebugStats) { diff --git a/GPU/GLES/Framebuffer.cpp b/GPU/GLES/Framebuffer.cpp index 043d202ec9..6fc83e0e90 100644 --- a/GPU/GLES/Framebuffer.cpp +++ b/GPU/GLES/Framebuffer.cpp @@ -2094,7 +2094,7 @@ bool FramebufferManager::NotifyFramebufferCopy(u32 src, u32 dst, int size, bool const u32 vfb_size = FramebufferByteSize(vfb); const u32 vfb_bpp = vfb->format == GE_FORMAT_8888 ? 4 : 2; const u32 vfb_byteStride = vfb->fb_stride * vfb_bpp; - const u32 vfb_byteWidth = vfb->width * vfb_bpp; + const int vfb_byteWidth = vfb->width * vfb_bpp; if (dst >= vfb_address && (dst + size <= vfb_address + vfb_size || dst == vfb_address)) { const u32 offset = dst - vfb_address; diff --git a/GPU/GLES/StencilBuffer.cpp b/GPU/GLES/StencilBuffer.cpp index 0429f4b2a3..256ea7d620 100644 --- a/GPU/GLES/StencilBuffer.cpp +++ b/GPU/GLES/StencilBuffer.cpp @@ -50,10 +50,6 @@ static const char *stencil_vs = " gl_Position = a_position;\n" "}\n"; -static bool MaskedEqual(u32 addr1, u32 addr2) { - return (addr1 & 0x03FFFFFF) == (addr2 & 0x03FFFFFF); -} - bool FramebufferManager::NotifyStencilUpload(u32 addr, int size) { if (!MayIntersectFramebuffer(addr)) { return false; @@ -111,6 +107,9 @@ bool FramebufferManager::NotifyStencilUpload(u32 addr, int size) { case GE_FORMAT_8888: values = 256; break; + case GE_FORMAT_INVALID: + // Impossible. + break; } if (dstBuffer->fbo) { diff --git a/GPU/GLES/TextureCache.cpp b/GPU/GLES/TextureCache.cpp index b48a3f86e0..0db3d32b07 100644 --- a/GPU/GLES/TextureCache.cpp +++ b/GPU/GLES/TextureCache.cpp @@ -1083,7 +1083,7 @@ void TextureCache::SetTextureFramebuffer(TexCacheEntry *entry, VirtualFramebuffe gstate_c.flipTexture = true; gstate_c.curTextureXOffset = fbTexInfo_[entry->addr].xOffset; gstate_c.curTextureYOffset = fbTexInfo_[entry->addr].yOffset; - gstate_c.needShaderTexClamp = gstate_c.curTextureWidth != gstate.getTextureWidth(0) || gstate_c.curTextureHeight != gstate.getTextureHeight(0); + gstate_c.needShaderTexClamp = gstate_c.curTextureWidth != (u32)gstate.getTextureWidth(0) || gstate_c.curTextureHeight != (u32)gstate.getTextureHeight(0); if (gstate_c.curTextureXOffset != 0 || gstate_c.curTextureYOffset != 0) { gstate_c.needShaderTexClamp = true; } From 561d0e5ef966ae8d6fdcb016ccbc723f8b9710f2 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Thu, 19 Jun 2014 00:48:33 -0700 Subject: [PATCH 2/4] Check more ops for changing memory in debugger. --- Core/Debugger/Breakpoints.cpp | 2 +- Core/MIPS/MIPSAnalyst.cpp | 61 ++++++++++++++++++++++++++++------- Core/MIPS/MIPSAnalyst.h | 2 +- 3 files changed, 52 insertions(+), 13 deletions(-) diff --git a/Core/Debugger/Breakpoints.cpp b/Core/Debugger/Breakpoints.cpp index 8274c93ff8..893714792a 100644 --- a/Core/Debugger/Breakpoints.cpp +++ b/Core/Debugger/Breakpoints.cpp @@ -83,7 +83,7 @@ void MemCheck::JitCleanup() // Here's the tricky part: would this have changed memory? // Note that it did not actually get written. - bool changed = MIPSAnalyst::OpWouldChangeMemory(lastPC, lastAddr); + bool changed = MIPSAnalyst::OpWouldChangeMemory(lastPC, lastAddr, lastSize); if (changed) { ++numHits; diff --git a/Core/MIPS/MIPSAnalyst.cpp b/Core/MIPS/MIPSAnalyst.cpp index 23e70518d6..b904a0ffe5 100644 --- a/Core/MIPS/MIPSAnalyst.cpp +++ b/Core/MIPS/MIPSAnalyst.cpp @@ -495,29 +495,68 @@ namespace MIPSAnalyst { return (op & MIPSTABLE_IMM_MASK) == 0xB8000000; } - bool OpWouldChangeMemory(u32 pc, u32 addr) { - auto op = Memory::Read_Instruction(pc); + static bool IsSWC1Instr(MIPSOpcode op) { + return (op & MIPSTABLE_IMM_MASK) == 0xE4000000; + } + static bool IsSVSInstr(MIPSOpcode op) { + return (op & MIPSTABLE_IMM_MASK) == 0xE8000000; + } + static bool IsSVQInstr(MIPSOpcode op) { + return (op & MIPSTABLE_IMM_MASK) == 0xF8000000; + } + + bool OpWouldChangeMemory(u32 pc, u32 addr, u32 size) { + const auto op = Memory::Read_Instruction(pc); + + // TODO: Trap sc/ll, svl.q, svr.q? + int gprMask = 0; - // TODO: swl/swr are annoying, not handled yet. if (IsSWInstr(op)) gprMask = 0xFFFFFFFF; if (IsSHInstr(op)) gprMask = 0x0000FFFF; if (IsSBInstr(op)) gprMask = 0x000000FF; + if (IsSWLInstr(op)) { + const u32 shift = (addr & 3) * 8; + gprMask = 0xFFFFFFFF >> (24 - shift); + } + if (IsSWRInstr(op)) { + const u32 shift = (addr & 3) * 8; + gprMask = 0xFFFFFFFF << shift; + } + + u32 writeVal = 0xFFFFFFFF; + u32 prevVal = 0x00000000; if (gprMask != 0) { - MIPSGPReg reg = MIPS_GET_RT(op); - u32 writeVal = currentMIPS->r[reg] & gprMask; - u32 prevVal = Memory::Read_U32(addr) & gprMask; - - // TODO: Technically, the break might be for 1 byte in the middle of a sw. - return writeVal != prevVal; + MIPSGPReg rt = MIPS_GET_RT(op); + writeVal = currentMIPS->r[rt] & gprMask; + prevVal = Memory::Read_U32(addr) & gprMask; } - // TODO: Not handled yet. - return true; + if (IsSWC1Instr(op)) { + int ft = MIPS_GET_FT(op); + writeVal = currentMIPS->fi[ft]; + prevVal = Memory::Read_U32(addr); + } + + if (IsSVSInstr(op)) { + int vt = ((op >> 16) & 0x1f) | ((op & 3) << 5); + writeVal = currentMIPS->vi[voffset[vt]]; + prevVal = Memory::Read_U32(addr); + } + + if (IsSVQInstr(op)) { + int vt = (((op >> 16) & 0x1f)) | ((op & 1) << 5); + float rd[4]; + ReadVector(rd, V_Quad, vt); + return memcmp(rd, Memory::GetPointer(addr), sizeof(float) * 4) != 0; + } + + // TODO: Technically, the break might be for 1 byte in the middle of a sw. + return writeVal != prevVal; } AnalysisResults Analyze(u32 address) { diff --git a/Core/MIPS/MIPSAnalyst.h b/Core/MIPS/MIPSAnalyst.h index 932d0dda28..f296e88a66 100644 --- a/Core/MIPS/MIPSAnalyst.h +++ b/Core/MIPS/MIPSAnalyst.h @@ -127,7 +127,7 @@ namespace MIPSAnalyst bool IsDelaySlotNiceFPU(MIPSOpcode branchOp, MIPSOpcode op); bool IsSyscall(MIPSOpcode op); - bool OpWouldChangeMemory(u32 pc, u32 addr); + bool OpWouldChangeMemory(u32 pc, u32 addr, u32 size); void Shutdown(); From 9efbc2694b58cd19166a9eddc412b9cd93608d62 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Thu, 19 Jun 2014 01:08:45 -0700 Subject: [PATCH 3/4] Add an invalidate all method to the jit. --- Core/Debugger/Breakpoints.cpp | 4 ++-- Core/HLE/sceKernel.cpp | 7 ++----- Core/MIPS/ARM/ArmJit.cpp | 7 ++++++- Core/MIPS/ARM/ArmJit.h | 3 ++- Core/MIPS/MIPS.cpp | 2 +- Core/MIPS/MIPSInt.cpp | 2 +- Core/MIPS/PPC/PpcJit.cpp | 6 +++++- Core/MIPS/PPC/PpcJit.h | 3 ++- Core/MIPS/x86/Jit.cpp | 7 ++++++- Core/MIPS/x86/Jit.h | 3 ++- Windows/Debugger/CtrlDisAsmView.cpp | 2 +- 11 files changed, 30 insertions(+), 16 deletions(-) diff --git a/Core/Debugger/Breakpoints.cpp b/Core/Debugger/Breakpoints.cpp index 893714792a..785baa8927 100644 --- a/Core/Debugger/Breakpoints.cpp +++ b/Core/Debugger/Breakpoints.cpp @@ -413,9 +413,9 @@ void CBreakPoints::Update(u32 addr) // In case this is a delay slot, clear the previous instruction too. if (addr != 0) - MIPSComp::jit->ClearCacheAt(addr - 4, 8); + MIPSComp::jit->InvalidateCacheAt(addr - 4, 8); else - MIPSComp::jit->ClearCache(); + MIPSComp::jit->InvalidateCache(); if (resume) Core_EnableStepping(false); diff --git a/Core/HLE/sceKernel.cpp b/Core/HLE/sceKernel.cpp index 72b9b8d1a1..31c6584932 100644 --- a/Core/HLE/sceKernel.cpp +++ b/Core/HLE/sceKernel.cpp @@ -364,11 +364,8 @@ int sceKernelDcacheInvalidateRange(u32 addr, int size) } int sceKernelIcacheInvalidateRange(u32 addr, int size) { - DEBUG_LOG(CPU,"sceKernelIcacheInvalidateRange(%08x, %i)", addr, size); - // TODO: Make the JIT hash and compare the touched blocks. - if(MIPSComp::jit){ - MIPSComp::jit->ClearCacheAt(addr, size); - } + DEBUG_LOG(CPU, "sceKernelIcacheInvalidateRange(%08x, %i)", addr, size); + currentMIPS->InvalidateICache(addr, size); return 0; } diff --git a/Core/MIPS/ARM/ArmJit.cpp b/Core/MIPS/ARM/ArmJit.cpp index 1a69978a09..f4b736b6a7 100644 --- a/Core/MIPS/ARM/ArmJit.cpp +++ b/Core/MIPS/ARM/ArmJit.cpp @@ -146,7 +146,12 @@ void Jit::ClearCache() GenerateFixedCode(); } -void Jit::ClearCacheAt(u32 em_address, int length) +void Jit::InvalidateCache() +{ + blocks.Clear(); +} + +void Jit::InvalidateCacheAt(u32 em_address, int length) { blocks.InvalidateICache(em_address, length); } diff --git a/Core/MIPS/ARM/ArmJit.h b/Core/MIPS/ARM/ArmJit.h index 8595d6d527..ef254319f4 100644 --- a/Core/MIPS/ARM/ArmJit.h +++ b/Core/MIPS/ARM/ArmJit.h @@ -178,7 +178,8 @@ public: JitBlockCache *GetBlockCache() { return &blocks; } void ClearCache(); - void ClearCacheAt(u32 em_address, int length = 4); + void InvalidateCache(); + void InvalidateCacheAt(u32 em_address, int length = 4); void EatPrefix() { js.EatPrefix(); } diff --git a/Core/MIPS/MIPS.cpp b/Core/MIPS/MIPS.cpp index e8ffb19b71..a59e4d0382 100644 --- a/Core/MIPS/MIPS.cpp +++ b/Core/MIPS/MIPS.cpp @@ -328,5 +328,5 @@ u32 MIPSState::ReadFCR(int reg) { void MIPSState::InvalidateICache(u32 address, int length) { // Only really applies to jit. if (MIPSComp::jit) - MIPSComp::jit->ClearCacheAt(address, length); + MIPSComp::jit->InvalidateCacheAt(address, length); } diff --git a/Core/MIPS/MIPSInt.cpp b/Core/MIPS/MIPSInt.cpp index 602ee61f67..9a555b7d9a 100644 --- a/Core/MIPS/MIPSInt.cpp +++ b/Core/MIPS/MIPSInt.cpp @@ -133,7 +133,7 @@ namespace MIPSInt case 8: // Invalidate the instruction cache at this address if (MIPSComp::jit) { - MIPSComp::jit->ClearCacheAt(addr, 0x40); + MIPSComp::jit->InvalidateCacheAt(addr, 0x40); } break; diff --git a/Core/MIPS/PPC/PpcJit.cpp b/Core/MIPS/PPC/PpcJit.cpp index 8e4c67b6c6..583de42661 100644 --- a/Core/MIPS/PPC/PpcJit.cpp +++ b/Core/MIPS/PPC/PpcJit.cpp @@ -217,7 +217,11 @@ void Jit::ClearCache() { GenerateFixedCode(); } -void Jit::ClearCacheAt(u32 em_address, int length) { +void Jit::InvalidateCache() { + blocks.Clear(); +} + +void Jit::InvalidateCacheAt(u32 em_address, int length) { blocks.InvalidateICache(em_address, length); } diff --git a/Core/MIPS/PPC/PpcJit.h b/Core/MIPS/PPC/PpcJit.h index 19d98378d0..4f88017b72 100644 --- a/Core/MIPS/PPC/PpcJit.h +++ b/Core/MIPS/PPC/PpcJit.h @@ -286,7 +286,8 @@ namespace MIPSComp void WriteSyscallExit(); void ClearCache(); - void ClearCacheAt(u32 em_address, int length = 4); + void InvalidateCache(); + void InvalidateCacheAt(u32 em_address, int length = 4); void RunLoopUntil(u64 globalticks); void GenerateFixedCode(); diff --git a/Core/MIPS/x86/Jit.cpp b/Core/MIPS/x86/Jit.cpp index 66606e2635..d7a04fe350 100644 --- a/Core/MIPS/x86/Jit.cpp +++ b/Core/MIPS/x86/Jit.cpp @@ -218,7 +218,12 @@ void Jit::ClearCache() ClearCodeSpace(); } -void Jit::ClearCacheAt(u32 em_address, int length) +void Jit::InvalidateCache() +{ + blocks.Clear(); +} + +void Jit::InvalidateCacheAt(u32 em_address, int length) { blocks.InvalidateICache(em_address, length); } diff --git a/Core/MIPS/x86/Jit.h b/Core/MIPS/x86/Jit.h index 8fda662e61..c210ef6fc6 100644 --- a/Core/MIPS/x86/Jit.h +++ b/Core/MIPS/x86/Jit.h @@ -168,7 +168,8 @@ public: AsmRoutineManager &Asm() { return asm_; } void ClearCache(); - void ClearCacheAt(u32 em_address, int length = 4); + void InvalidateCache(); + void InvalidateCacheAt(u32 em_address, int length = 4); private: void GetStateAndFlushAll(RegCacheState &state); diff --git a/Windows/Debugger/CtrlDisAsmView.cpp b/Windows/Debugger/CtrlDisAsmView.cpp index e205b93ec5..61dfd8e221 100644 --- a/Windows/Debugger/CtrlDisAsmView.cpp +++ b/Windows/Debugger/CtrlDisAsmView.cpp @@ -298,7 +298,7 @@ void CtrlDisAsmView::assembleOpcode(u32 address, std::string defaultText) Memory::Write_U32(encoded, address); // In case this is a delay slot or combined instruction, clear cache above it too. if (MIPSComp::jit) - MIPSComp::jit->ClearCacheAt(address - 4, 8); + MIPSComp::jit->InvalidateCacheAt(address - 4, 8); scanFunctions(); if (address == curAddress) From 2f6b63385d6e110702abb1358c6a9cdc416efd1c Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Thu, 19 Jun 2014 01:16:24 -0700 Subject: [PATCH 4/4] On breakpoint change, don't wait for core too long. Fixes #6366. --- Core/Debugger/Breakpoints.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Core/Debugger/Breakpoints.cpp b/Core/Debugger/Breakpoints.cpp index 785baa8927..a27711bdaa 100644 --- a/Core/Debugger/Breakpoints.cpp +++ b/Core/Debugger/Breakpoints.cpp @@ -407,7 +407,7 @@ void CBreakPoints::Update(u32 addr) if (Core_IsStepping() == false) { Core_EnableStepping(true); - Core_WaitInactive(); + Core_WaitInactive(200); resume = true; }