From e259b3fa76b951a75174e6d1adce1c0e73551b55 Mon Sep 17 00:00:00 2001 From: Sepalani Date: Wed, 23 Nov 2016 00:06:39 +0000 Subject: [PATCH 1/6] [HLE] Fixes XFB and invisible printf --- Source/Core/Core/HLE/HLE.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Source/Core/Core/HLE/HLE.cpp b/Source/Core/Core/HLE/HLE.cpp index e2e2a20919..c4ff14e63a 100644 --- a/Source/Core/Core/HLE/HLE.cpp +++ b/Source/Core/Core/HLE/HLE.cpp @@ -55,17 +55,17 @@ static const SPatch OSPatches[] = { {"OSPanic", HLE_OS::HLE_OSPanic, HLE_HOOK_REPLACE, HLE_TYPE_DEBUG}, // This needs to be put before vprintf (because vprintf is called indirectly by this) - {"JUTWarningConsole_f", HLE_OS::HLE_GeneralDebugPrint, HLE_HOOK_REPLACE, HLE_TYPE_DEBUG}, + {"JUTWarningConsole_f", HLE_OS::HLE_GeneralDebugPrint, HLE_HOOK_START, HLE_TYPE_DEBUG}, - {"OSReport", HLE_OS::HLE_GeneralDebugPrint, HLE_HOOK_REPLACE, HLE_TYPE_DEBUG}, - {"DEBUGPrint", HLE_OS::HLE_GeneralDebugPrint, HLE_HOOK_REPLACE, HLE_TYPE_DEBUG}, - {"WUD_DEBUGPrint", HLE_OS::HLE_GeneralDebugPrint, HLE_HOOK_REPLACE, HLE_TYPE_DEBUG}, - {"vprintf", HLE_OS::HLE_GeneralDebugPrint, HLE_HOOK_REPLACE, HLE_TYPE_DEBUG}, - {"printf", HLE_OS::HLE_GeneralDebugPrint, HLE_HOOK_REPLACE, HLE_TYPE_DEBUG}, - {"nlPrintf", HLE_OS::HLE_GeneralDebugPrint, HLE_HOOK_REPLACE, HLE_TYPE_DEBUG}, - {"puts", HLE_OS::HLE_GeneralDebugPrint, HLE_HOOK_REPLACE, HLE_TYPE_DEBUG}, // gcc-optimized printf? - {"___blank", HLE_OS::HLE_GeneralDebugPrint, HLE_HOOK_REPLACE, HLE_TYPE_DEBUG}, // used for early init things (normally) - {"__write_console", HLE_OS::HLE_write_console, HLE_HOOK_REPLACE, HLE_TYPE_DEBUG}, // used by sysmenu (+more?) + {"OSReport", HLE_OS::HLE_GeneralDebugPrint, HLE_HOOK_START, HLE_TYPE_DEBUG}, + {"DEBUGPrint", HLE_OS::HLE_GeneralDebugPrint, HLE_HOOK_START, HLE_TYPE_DEBUG}, + {"WUD_DEBUGPrint", HLE_OS::HLE_GeneralDebugPrint, HLE_HOOK_START, HLE_TYPE_DEBUG}, + {"vprintf", HLE_OS::HLE_GeneralDebugPrint, HLE_HOOK_START, HLE_TYPE_DEBUG}, + {"printf", HLE_OS::HLE_GeneralDebugPrint, HLE_HOOK_START, HLE_TYPE_DEBUG}, + {"nlPrintf", HLE_OS::HLE_GeneralDebugPrint, HLE_HOOK_START, HLE_TYPE_DEBUG}, + {"puts", HLE_OS::HLE_GeneralDebugPrint, HLE_HOOK_START, HLE_TYPE_DEBUG}, // gcc-optimized printf? + {"___blank", HLE_OS::HLE_GeneralDebugPrint, HLE_HOOK_START, HLE_TYPE_DEBUG}, // used for early init things (normally) + {"__write_console", HLE_OS::HLE_write_console, HLE_HOOK_START, HLE_TYPE_DEBUG}, // used by sysmenu (+more?) {"GeckoCodehandler", HLE_Misc::GeckoCodeHandlerICacheFlush, HLE_HOOK_START, HLE_TYPE_FIXED}, {"GeckoHandlerReturnTrampoline", HLE_Misc::GeckoReturnTrampoline, HLE_HOOK_REPLACE, HLE_TYPE_FIXED}, From 4f9e5e1141637804494703e0335869667e1585fd Mon Sep 17 00:00:00 2001 From: Sepalani Date: Wed, 23 Nov 2016 00:09:48 +0000 Subject: [PATCH 2/6] [HLE] Added GetFirstFunctionIndex matching the start address --- Source/Core/Core/HLE/HLE.cpp | 13 +++++++++++-- Source/Core/Core/HLE/HLE.h | 5 ++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/Source/Core/Core/HLE/HLE.cpp b/Source/Core/Core/HLE/HLE.cpp index c4ff14e63a..dc29237439 100644 --- a/Source/Core/Core/HLE/HLE.cpp +++ b/Source/Core/Core/HLE/HLE.cpp @@ -183,12 +183,21 @@ void Execute(u32 _CurrentPC, u32 _Instruction) // OSPatches[pos].m_szPatchName); } -u32 GetFunctionIndex(u32 addr) +u32 GetFunctionIndex(u32 address) { - auto iter = s_original_instructions.find(addr); + auto iter = s_original_instructions.find(address); return (iter != s_original_instructions.end()) ? iter->second : 0; } +u32 GetFirstFunctionIndex(u32 address) +{ + u32 index = GetFunctionIndex(address); + auto first = std::find_if( + s_original_instructions.begin(), s_original_instructions.end(), + [=](const auto& entry) { return entry.second == index && entry.first < address; }); + return first == std::end(s_original_instructions) ? index : 0; +} + int GetFunctionTypeByIndex(u32 index) { return OSPatches[index].type; diff --git a/Source/Core/Core/HLE/HLE.h b/Source/Core/Core/HLE/HLE.h index 8cc513124f..2ea49640f9 100644 --- a/Source/Core/Core/HLE/HLE.h +++ b/Source/Core/Core/HLE/HLE.h @@ -34,7 +34,10 @@ u32 UnPatch(const std::string& patchName); bool UnPatch(u32 addr, const std::string& name = {}); void Execute(u32 _CurrentPC, u32 _Instruction); -u32 GetFunctionIndex(u32 em_address); +// Returns the HLE function index if the address is located in the function +u32 GetFunctionIndex(u32 address); +// Returns the HLE function index if the address matches the function start +u32 GetFirstFunctionIndex(u32 address); int GetFunctionTypeByIndex(u32 index); int GetFunctionFlagsByIndex(u32 index); From e0e93fc3a632c0a7cb2b6790367ae46e9cbea360 Mon Sep 17 00:00:00 2001 From: Sepalani Date: Wed, 23 Nov 2016 00:12:12 +0000 Subject: [PATCH 3/6] [HLE] Interpreter: Fixes invalid logs --- Source/Core/Core/PowerPC/Interpreter/Interpreter.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Core/Core/PowerPC/Interpreter/Interpreter.cpp b/Source/Core/Core/PowerPC/Interpreter/Interpreter.cpp index 80396fd6f7..5cacf63a4f 100644 --- a/Source/Core/Core/PowerPC/Interpreter/Interpreter.cpp +++ b/Source/Core/Core/PowerPC/Interpreter/Interpreter.cpp @@ -100,7 +100,7 @@ static void Trace(UGeckoInstruction& inst) int Interpreter::SingleStepInner() { static UGeckoInstruction instCode; - u32 function = HLE::GetFunctionIndex(PC); + u32 function = HLE::GetFirstFunctionIndex(PC); if (function != 0) { int type = HLE::GetFunctionTypeByIndex(function); From 51def492c78d33ca704af36d6ab3632185258049 Mon Sep 17 00:00:00 2001 From: Sepalani Date: Wed, 23 Nov 2016 00:12:41 +0000 Subject: [PATCH 4/6] [HLE] CachedInterpreter: Fixes invalid logs --- .../Core/Core/PowerPC/CachedInterpreter/CachedInterpreter.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Core/Core/PowerPC/CachedInterpreter/CachedInterpreter.cpp b/Source/Core/Core/PowerPC/CachedInterpreter/CachedInterpreter.cpp index 4bd0b57811..214ce53a51 100644 --- a/Source/Core/Core/PowerPC/CachedInterpreter/CachedInterpreter.cpp +++ b/Source/Core/Core/PowerPC/CachedInterpreter/CachedInterpreter.cpp @@ -205,7 +205,7 @@ void CachedInterpreter::Jit(u32 address) { js.downcountAmount += ops[i].opinfo->numCycles; - u32 function = HLE::GetFunctionIndex(ops[i].address); + u32 function = HLE::GetFirstFunctionIndex(ops[i].address); if (function != 0) { int type = HLE::GetFunctionTypeByIndex(function); From 5ea798b7269533dbf760acd5a5dfd99c3686ca8d Mon Sep 17 00:00:00 2001 From: Sepalani Date: Wed, 23 Nov 2016 00:13:11 +0000 Subject: [PATCH 5/6] [HLE] Jit: Fixes invalid logs --- Source/Core/Core/PowerPC/Jit64/Jit.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Core/Core/PowerPC/Jit64/Jit.cpp b/Source/Core/Core/PowerPC/Jit64/Jit.cpp index 05a235a731..a4e68617c6 100644 --- a/Source/Core/Core/PowerPC/Jit64/Jit.cpp +++ b/Source/Core/Core/PowerPC/Jit64/Jit.cpp @@ -797,7 +797,7 @@ const u8* Jit64::DoJit(u32 em_address, PPCAnalyst::CodeBuffer* code_buf, JitBloc SetJumpTarget(noExtIntEnable); } - u32 function = HLE::GetFunctionIndex(ops[i].address); + u32 function = HLE::GetFirstFunctionIndex(ops[i].address); if (function != 0) { int type = HLE::GetFunctionTypeByIndex(function); From f392e472cc6ebc0faf8f4f65155801c487bf8f59 Mon Sep 17 00:00:00 2001 From: Sepalani Date: Wed, 23 Nov 2016 00:26:36 +0000 Subject: [PATCH 6/6] [HLE] JitIL: Fixes invalid logs --- Source/Core/Core/PowerPC/Jit64IL/JitIL.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Core/Core/PowerPC/Jit64IL/JitIL.cpp b/Source/Core/Core/PowerPC/Jit64IL/JitIL.cpp index b94b8a486f..740771241d 100644 --- a/Source/Core/Core/PowerPC/Jit64IL/JitIL.cpp +++ b/Source/Core/Core/PowerPC/Jit64IL/JitIL.cpp @@ -604,7 +604,7 @@ const u8* JitIL::DoJit(u32 em_address, PPCAnalyst::CodeBuffer* code_buf, JitBloc if (i == (code_block.m_num_instructions - 1)) js.isLastInstruction = true; - u32 function = HLE::GetFunctionIndex(ops[i].address); + u32 function = HLE::GetFirstFunctionIndex(ops[i].address); if (function != 0) { int type = HLE::GetFunctionTypeByIndex(function);