diff --git a/Common/ArmEmitter.h b/Common/ArmEmitter.h index 70eb182170..117b5ef28b 100644 --- a/Common/ArmEmitter.h +++ b/Common/ArmEmitter.h @@ -840,7 +840,7 @@ public: region_size = 0; } - bool IsInSpace(u8 *ptr) + bool IsInSpace(const u8 *ptr) const { return ptr >= region && ptr < region + region_size; } @@ -870,7 +870,7 @@ public: return region; } - size_t GetOffset(u8 *ptr) { + size_t GetOffset(const u8 *ptr) const { return ptr - region; } }; diff --git a/Common/ppcEmitter.h b/Common/ppcEmitter.h index 45156d09e3..64866b0df1 100644 --- a/Common/ppcEmitter.h +++ b/Common/ppcEmitter.h @@ -463,7 +463,7 @@ namespace PpcGen region_size = 0; } - bool IsInSpace(u8 *ptr) + bool IsInSpace(const u8 *ptr) const { return ptr >= region && ptr < region + region_size; } @@ -493,7 +493,7 @@ namespace PpcGen return region; } - size_t GetOffset(u8 *ptr) { + size_t GetOffset(const u8 *ptr) const { return ptr - region; } }; diff --git a/Common/x64Emitter.h b/Common/x64Emitter.h index cc8a5bac31..182a1992d4 100644 --- a/Common/x64Emitter.h +++ b/Common/x64Emitter.h @@ -756,7 +756,7 @@ public: region_size = 0; } - bool IsInSpace(u8 *ptr) + bool IsInSpace(const u8 *ptr) const { return ptr >= region && ptr < region + region_size; } @@ -782,7 +782,7 @@ public: return region; } - size_t GetOffset(u8 *ptr) { + size_t GetOffset(const u8 *ptr) const { return ptr - region; } }; diff --git a/Core/MIPS/ARM/ArmJit.h b/Core/MIPS/ARM/ArmJit.h index 1153fc751e..0d2f349395 100644 --- a/Core/MIPS/ARM/ArmJit.h +++ b/Core/MIPS/ARM/ArmJit.h @@ -65,6 +65,10 @@ public: void Compile(u32 em_address); // Compiles a block at current MIPS PC const u8 *DoJit(u32 em_address, JitBlock *b); + bool IsInDispatch(const u8 *p) { + return IsInSpace(p); + } + void CompileDelaySlot(int flags); void CompileAt(u32 addr); void EatInstruction(MIPSOpcode op); diff --git a/Core/MIPS/JitCommon/JitBlockCache.cpp b/Core/MIPS/JitCommon/JitBlockCache.cpp index b3a09e3b8b..71d0246300 100644 --- a/Core/MIPS/JitCommon/JitBlockCache.cpp +++ b/Core/MIPS/JitCommon/JitBlockCache.cpp @@ -254,6 +254,21 @@ void JitBlockCache::GetBlockNumbersFromAddress(u32 em_address, std::vector block_numbers->push_back(i); } +u32 JitBlockCache::GetAddressFromBlockPtr(const u8 *ptr) const { + if (!codeBlock_->IsInSpace(ptr)) + return (u32)-1; + + for (int i = 0; i < num_blocks; ++i) { + const auto &b = blocks[i]; + if (!b.invalid && ptr >= b.normalEntry && ptr < b.normalEntry + b.codeSize) { + return b.originalAddress; + } + } + + // It's in jit somewhere, but we must've deleted it. + return 0; +} + MIPSOpcode JitBlockCache::GetOriginalFirstOp(int block_num) { if (block_num >= num_blocks || block_num < 0) diff --git a/Core/MIPS/JitCommon/JitBlockCache.h b/Core/MIPS/JitCommon/JitBlockCache.h index eb417f09e6..57cd452379 100644 --- a/Core/MIPS/JitCommon/JitBlockCache.h +++ b/Core/MIPS/JitCommon/JitBlockCache.h @@ -109,6 +109,8 @@ public: void GetBlockNumbersFromAddress(u32 em_address, std::vector *block_numbers); int GetBlockNumberFromEmuHackOp(MIPSOpcode inst) const; + u32 GetAddressFromBlockPtr(const u8 *ptr) const; + MIPSOpcode GetOriginalFirstOp(int block_num); // DOES NOT WORK CORRECTLY WITH JIT INLINING diff --git a/Core/MIPS/PPC/PpcJit.h b/Core/MIPS/PPC/PpcJit.h index 8838548c00..c3a2587262 100644 --- a/Core/MIPS/PPC/PpcJit.h +++ b/Core/MIPS/PPC/PpcJit.h @@ -294,6 +294,10 @@ namespace MIPSComp void Compile(u32 em_address); // Compiles a block at current MIPS PC const u8 *DoJit(u32 em_address, JitBlock *b); + bool IsInDispatch(const u8 *p) { + return IsInSpace(p); + } + PpcJitOptions jo; PpcJitState js; diff --git a/Core/MIPS/x86/Jit.h b/Core/MIPS/x86/Jit.h index d11a261abd..45c0bb344d 100644 --- a/Core/MIPS/x86/Jit.h +++ b/Core/MIPS/x86/Jit.h @@ -72,6 +72,10 @@ public: void Compile(u32 em_address); // Compiles a block at current MIPS PC const u8 *DoJit(u32 em_address, JitBlock *b); + bool IsInDispatch(const u8 *p) { + return asm_.IsInSpace(p); + } + void CompileAt(u32 addr); void Comp_RunBlock(MIPSOpcode op); diff --git a/Windows/WndMainWindow.cpp b/Windows/WndMainWindow.cpp index cd4622bf6b..0d711dd9df 100644 --- a/Windows/WndMainWindow.cpp +++ b/Windows/WndMainWindow.cpp @@ -46,6 +46,8 @@ #include "Core/SaveState.h" #include "Core/System.h" #include "Core/Config.h" +#include "Core/MIPS/JitCommon/JitCommon.h" +#include "Core/MIPS/JitCommon/JitBlockCache.h" #include "Windows/EmuThread.h" #include "resource.h" @@ -75,6 +77,24 @@ #define ENABLE_TOUCH 0 +int verysleepy__useSendMessage = 1; + +const UINT WM_VERYSLEEPY_MSG = WM_APP + 0x3117; +// Respond TRUE to a message with this param value to indicate support. +const WPARAM VERYSLEEPY_WPARAM_SUPPORTED = 0; +// Respond TRUE to a message wit this param value after filling in the addr name. +const WPARAM VERYSLEEPY_WPARAM_GETADDRINFO = 1; + +struct VerySleepy_AddrInfo +{ + // Always zero for now. + int flags; + // This is the pointer (always passed as 64 bits.) + unsigned long long addr; + // Write the name here. + wchar_t name[256]; +}; + extern std::map windowsTransTable; static RECT g_normalRC = {0}; static std::wstring windowTitle; @@ -1523,6 +1543,43 @@ namespace MainWindow } return 0; + case WM_VERYSLEEPY_MSG: + switch (wParam) { + case VERYSLEEPY_WPARAM_SUPPORTED: + return TRUE; + + case VERYSLEEPY_WPARAM_GETADDRINFO: + { + VerySleepy_AddrInfo *info = (VerySleepy_AddrInfo *)lParam; + const u8 *ptr = (const u8 *)info->addr; + if (MIPSComp::jit) { + JitBlockCache *blocks = MIPSComp::jit->GetBlockCache(); + u32 jitAddr = blocks->GetAddressFromBlockPtr(ptr); + + // Returns 0 when it's valid, but unknown. + if (jitAddr == 0) { + wcscpy_s(info->name, L"Jit::UnknownOrDeletedBlock"); + return TRUE; + } + if (jitAddr != (u32)-1) { + swprintf_s(info->name, L"Jit::%08x", jitAddr); + return TRUE; + } + + // Perhaps it's in jit the dispatch runloop. + if (MIPSComp::jit->IsInDispatch(ptr)) { + wcscpy_s(info->name, L"Jit::RunLoopUntil"); + return TRUE; + } + } + } + return FALSE; + + default: + return FALSE; + } + break; + case WM_DROPFILES: { if (!EmuThread_Ready())