From a184ab93b6e65a09883ab1031dead7a9c01b5d5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Lam?= Date: Sun, 4 Feb 2018 14:41:55 +0100 Subject: [PATCH 1/2] HLE: Remove an unused function There is nothing using PanicAlert in either official titles or libogc. --- Source/Core/Core/HLE/HLE.cpp | 2 -- Source/Core/Core/HLE/HLE_Misc.cpp | 9 --------- Source/Core/Core/HLE/HLE_Misc.h | 1 - 3 files changed, 12 deletions(-) diff --git a/Source/Core/Core/HLE/HLE.cpp b/Source/Core/Core/HLE/HLE.cpp index 7cc2743e8b..1598ad1eb4 100644 --- a/Source/Core/Core/HLE/HLE.cpp +++ b/Source/Core/Core/HLE/HLE.cpp @@ -45,8 +45,6 @@ static const SPatch OSPatches[] = { // Placeholder, OSPatches[0] is the "non-existent function" index {"FAKE_TO_SKIP_0", HLE_Misc::UnimplementedFunction, HLE_HOOK_REPLACE, HLE_TYPE_GENERIC}, - {"PanicAlert", HLE_Misc::HLEPanicAlert, HLE_HOOK_REPLACE, HLE_TYPE_DEBUG}, - // Name doesn't matter, installed in CBoot::BootUp() {"HBReload", HLE_Misc::HBReload, HLE_HOOK_REPLACE, HLE_TYPE_GENERIC}, diff --git a/Source/Core/Core/HLE/HLE_Misc.cpp b/Source/Core/Core/HLE/HLE_Misc.cpp index 7523836d00..9388b16a2c 100644 --- a/Source/Core/Core/HLE/HLE_Misc.cpp +++ b/Source/Core/Core/HLE/HLE_Misc.cpp @@ -6,7 +6,6 @@ #include "Common/CommonTypes.h" #include "Common/Logging/Log.h" -#include "Common/MsgHandler.h" #include "Core/GeckoCode.h" #include "Core/HW/CPU.h" #include "Core/Host.h" @@ -21,14 +20,6 @@ void UnimplementedFunction() NPC = LR; } -// If you want a function to panic, you can rename it PanicAlert :p -// Don't know if this is worth keeping. -void HLEPanicAlert() -{ - ::PanicAlert("HLE: PanicAlert %08x", LR); - NPC = LR; -} - void HBReload() { // There isn't much we can do. Just stop cleanly. diff --git a/Source/Core/Core/HLE/HLE_Misc.h b/Source/Core/Core/HLE/HLE_Misc.h index 7bf2d8496c..fcfc9c968e 100644 --- a/Source/Core/Core/HLE/HLE_Misc.h +++ b/Source/Core/Core/HLE/HLE_Misc.h @@ -6,7 +6,6 @@ namespace HLE_Misc { -void HLEPanicAlert(); void UnimplementedFunction(); void HBReload(); void GeckoCodeHandlerICacheFlush(); From 3deb8ce0741c07a2e511e3acf43db56a5b80dd87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Lam?= Date: Sun, 4 Feb 2018 14:50:55 +0100 Subject: [PATCH 2/2] HLE: Use enum classes for HookType and HookFlag --- Source/Core/Core/HLE/HLE.cpp | 58 +++++++++---------- Source/Core/Core/HLE/HLE.h | 22 +++---- .../CachedInterpreter/CachedInterpreter.cpp | 8 +-- .../Core/PowerPC/Interpreter/Interpreter.cpp | 8 +-- Source/Core/Core/PowerPC/Jit64/Jit.cpp | 8 +-- 5 files changed, 52 insertions(+), 52 deletions(-) diff --git a/Source/Core/Core/HLE/HLE.cpp b/Source/Core/Core/HLE/HLE.cpp index 1598ad1eb4..d3291a9a4d 100644 --- a/Source/Core/Core/HLE/HLE.cpp +++ b/Source/Core/Core/HLE/HLE.cpp @@ -43,39 +43,39 @@ struct SPatch // clang-format off static const SPatch OSPatches[] = { // Placeholder, OSPatches[0] is the "non-existent function" index - {"FAKE_TO_SKIP_0", HLE_Misc::UnimplementedFunction, HLE_HOOK_REPLACE, HLE_TYPE_GENERIC}, + {"FAKE_TO_SKIP_0", HLE_Misc::UnimplementedFunction, HookType::Replace, HookFlag::Generic}, // Name doesn't matter, installed in CBoot::BootUp() - {"HBReload", HLE_Misc::HBReload, HLE_HOOK_REPLACE, HLE_TYPE_GENERIC}, + {"HBReload", HLE_Misc::HBReload, HookType::Replace, HookFlag::Generic}, // Debug/OS Support - {"OSPanic", HLE_OS::HLE_OSPanic, HLE_HOOK_REPLACE, HLE_TYPE_DEBUG}, + {"OSPanic", HLE_OS::HLE_OSPanic, HookType::Replace, HookFlag::Debug}, // This needs to be put before vprintf (because vprintf is called indirectly by this) - {"JUTWarningConsole_f", HLE_OS::HLE_GeneralDebugPrint, HLE_HOOK_START, HLE_TYPE_DEBUG}, + {"JUTWarningConsole_f", HLE_OS::HLE_GeneralDebugPrint, HookType::Start, HookFlag::Debug}, - {"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_GeneralDebugVPrint, HLE_HOOK_START, HLE_TYPE_DEBUG}, - {"printf", HLE_OS::HLE_GeneralDebugPrint, HLE_HOOK_START, HLE_TYPE_DEBUG}, - {"vdprintf", HLE_OS::HLE_LogVDPrint, HLE_HOOK_START, HLE_TYPE_DEBUG}, - {"dprintf", HLE_OS::HLE_LogDPrint, HLE_HOOK_START, HLE_TYPE_DEBUG}, - {"vfprintf", HLE_OS::HLE_LogVFPrint, HLE_HOOK_START, HLE_TYPE_DEBUG}, - {"fprintf", HLE_OS::HLE_LogFPrint, HLE_HOOK_START, HLE_TYPE_DEBUG}, - {"nlPrintf", HLE_OS::HLE_GeneralDebugPrint, HLE_HOOK_START, HLE_TYPE_DEBUG}, - {"DWC_Printf", 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?) + {"OSReport", HLE_OS::HLE_GeneralDebugPrint, HookType::Start, HookFlag::Debug}, + {"DEBUGPrint", HLE_OS::HLE_GeneralDebugPrint, HookType::Start, HookFlag::Debug}, + {"WUD_DEBUGPrint", HLE_OS::HLE_GeneralDebugPrint, HookType::Start, HookFlag::Debug}, + {"vprintf", HLE_OS::HLE_GeneralDebugVPrint, HookType::Start, HookFlag::Debug}, + {"printf", HLE_OS::HLE_GeneralDebugPrint, HookType::Start, HookFlag::Debug}, + {"vdprintf", HLE_OS::HLE_LogVDPrint, HookType::Start, HookFlag::Debug}, + {"dprintf", HLE_OS::HLE_LogDPrint, HookType::Start, HookFlag::Debug}, + {"vfprintf", HLE_OS::HLE_LogVFPrint, HookType::Start, HookFlag::Debug}, + {"fprintf", HLE_OS::HLE_LogFPrint, HookType::Start, HookFlag::Debug}, + {"nlPrintf", HLE_OS::HLE_GeneralDebugPrint, HookType::Start, HookFlag::Debug}, + {"DWC_Printf", HLE_OS::HLE_GeneralDebugPrint, HookType::Start, HookFlag::Debug}, + {"puts", HLE_OS::HLE_GeneralDebugPrint, HookType::Start, HookFlag::Debug}, // gcc-optimized printf? + {"___blank", HLE_OS::HLE_GeneralDebugPrint, HookType::Start, HookFlag::Debug}, // used for early init things (normally) + {"__write_console", HLE_OS::HLE_write_console, HookType::Start, HookFlag::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}, - {"AppLoaderReport", HLE_OS::HLE_GeneralDebugPrint, HLE_HOOK_REPLACE, HLE_TYPE_FIXED} // apploader needs OSReport-like function + {"GeckoCodehandler", HLE_Misc::GeckoCodeHandlerICacheFlush, HookType::Start, HookFlag::Fixed}, + {"GeckoHandlerReturnTrampoline", HLE_Misc::GeckoReturnTrampoline, HookType::Replace, HookFlag::Fixed}, + {"AppLoaderReport", HLE_OS::HLE_GeneralDebugPrint, HookType::Replace, HookFlag::Fixed} // apploader needs OSReport-like function }; static const SPatch OSBreakPoints[] = { - {"FAKE_TO_SKIP_0", HLE_Misc::UnimplementedFunction, HLE_HOOK_START, HLE_TYPE_GENERIC}, + {"FAKE_TO_SKIP_0", HLE_Misc::UnimplementedFunction, HookType::Start, HookFlag::Generic}, }; // clang-format on @@ -115,7 +115,7 @@ void PatchFunctions() // Remove all hooks that aren't fixed address hooks for (auto i = s_original_instructions.begin(); i != s_original_instructions.end();) { - if (OSPatches[i->second].flags != HLE_TYPE_FIXED) + if (OSPatches[i->second].flags != HookFlag::Fixed) { PowerPC::ppcState.iCache.Invalidate(i->first); i = s_original_instructions.erase(i); @@ -129,7 +129,7 @@ void PatchFunctions() for (u32 i = 1; i < ArraySize(OSPatches); ++i) { // Fixed hooks don't map to symbols - if (OSPatches[i].flags == HLE_TYPE_FIXED) + if (OSPatches[i].flags == HookFlag::Fixed) continue; for (const auto& symbol : g_symbolDB.GetSymbolsFromName(OSPatches[i].m_szPatchName)) @@ -201,19 +201,19 @@ u32 GetFirstFunctionIndex(u32 address) return first == std::end(s_original_instructions) ? index : 0; } -int GetFunctionTypeByIndex(u32 index) +HookType GetFunctionTypeByIndex(u32 index) { return OSPatches[index].type; } -int GetFunctionFlagsByIndex(u32 index) +HookFlag GetFunctionFlagsByIndex(u32 index) { return OSPatches[index].flags; } -bool IsEnabled(int flags) +bool IsEnabled(HookFlag flag) { - return flags != HLE::HLE_TYPE_DEBUG || SConfig::GetInstance().bEnableDebugging || + return flag != HLE::HookFlag::Debug || SConfig::GetInstance().bEnableDebugging || PowerPC::GetMode() == PowerPC::CoreMode::Interpreter; } @@ -224,7 +224,7 @@ u32 UnPatch(const std::string& patch_name) if (patch == std::end(OSPatches)) return 0; - if (patch->flags == HLE_TYPE_FIXED) + if (patch->flags == HookFlag::Fixed) { u32 patch_idx = static_cast(patch - OSPatches); u32 addr = 0; diff --git a/Source/Core/Core/HLE/HLE.h b/Source/Core/Core/HLE/HLE.h index 2ea49640f9..a944c6b56c 100644 --- a/Source/Core/Core/HLE/HLE.h +++ b/Source/Core/Core/HLE/HLE.h @@ -10,18 +10,18 @@ namespace HLE { -enum HookType +enum class HookType { - HLE_HOOK_START = 0, // Hook the beginning of the function and execute the function afterwards - HLE_HOOK_REPLACE = 1, // Replace the function with the HLE version - HLE_HOOK_NONE = 2, // Do not hook the function + Start, // Hook the beginning of the function and execute the function afterwards + Replace, // Replace the function with the HLE version + None, // Do not hook the function }; -enum HookFlag +enum class HookFlag { - HLE_TYPE_GENERIC = 0, // Miscellaneous function - HLE_TYPE_DEBUG = 1, // Debug output function - HLE_TYPE_FIXED = 2, // An arbitrary hook mapped to a fixed address instead of a symbol + Generic, // Miscellaneous function + Debug, // Debug output function + Fixed, // An arbitrary hook mapped to a fixed address instead of a symbol }; void PatchFixedFunctions(); @@ -38,8 +38,8 @@ void Execute(u32 _CurrentPC, u32 _Instruction); 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); +HookType GetFunctionTypeByIndex(u32 index); +HookFlag GetFunctionFlagsByIndex(u32 index); -bool IsEnabled(int flags); +bool IsEnabled(HookFlag flag); } diff --git a/Source/Core/Core/PowerPC/CachedInterpreter/CachedInterpreter.cpp b/Source/Core/Core/PowerPC/CachedInterpreter/CachedInterpreter.cpp index ff7739905c..50823cf4d7 100644 --- a/Source/Core/Core/PowerPC/CachedInterpreter/CachedInterpreter.cpp +++ b/Source/Core/Core/PowerPC/CachedInterpreter/CachedInterpreter.cpp @@ -208,15 +208,15 @@ void CachedInterpreter::Jit(u32 address) u32 function = HLE::GetFirstFunctionIndex(ops[i].address); if (function != 0) { - int type = HLE::GetFunctionTypeByIndex(function); - if (type == HLE::HLE_HOOK_START || type == HLE::HLE_HOOK_REPLACE) + HLE::HookType type = HLE::GetFunctionTypeByIndex(function); + if (type == HLE::HookType::Start || type == HLE::HookType::Replace) { - int flags = HLE::GetFunctionFlagsByIndex(function); + HLE::HookFlag flags = HLE::GetFunctionFlagsByIndex(function); if (HLE::IsEnabled(flags)) { m_code.emplace_back(WritePC, ops[i].address); m_code.emplace_back(Interpreter::HLEFunction, function); - if (type == HLE::HLE_HOOK_REPLACE) + if (type == HLE::HookType::Replace) { m_code.emplace_back(EndBlock, js.downcountAmount); m_code.emplace_back(); diff --git a/Source/Core/Core/PowerPC/Interpreter/Interpreter.cpp b/Source/Core/Core/PowerPC/Interpreter/Interpreter.cpp index 8d2216aff7..928ec241b9 100644 --- a/Source/Core/Core/PowerPC/Interpreter/Interpreter.cpp +++ b/Source/Core/Core/PowerPC/Interpreter/Interpreter.cpp @@ -105,14 +105,14 @@ int Interpreter::SingleStepInner() u32 function = HLE::GetFirstFunctionIndex(PC); if (function != 0) { - int type = HLE::GetFunctionTypeByIndex(function); - if (type == HLE::HLE_HOOK_START || type == HLE::HLE_HOOK_REPLACE) + HLE::HookType type = HLE::GetFunctionTypeByIndex(function); + if (type == HLE::HookType::Start || type == HLE::HookType::Replace) { - int flags = HLE::GetFunctionFlagsByIndex(function); + HLE::HookFlag flags = HLE::GetFunctionFlagsByIndex(function); if (HLE::IsEnabled(flags)) { HLEFunction(function); - if (type == HLE::HLE_HOOK_START) + if (type == HLE::HookType::Start) { // Run the original. function = 0; diff --git a/Source/Core/Core/PowerPC/Jit64/Jit.cpp b/Source/Core/Core/PowerPC/Jit64/Jit.cpp index facfe820e5..ffaea8b8de 100644 --- a/Source/Core/Core/PowerPC/Jit64/Jit.cpp +++ b/Source/Core/Core/PowerPC/Jit64/Jit.cpp @@ -803,14 +803,14 @@ const u8* Jit64::DoJit(u32 em_address, PPCAnalyst::CodeBuffer* code_buf, JitBloc u32 function = HLE::GetFirstFunctionIndex(ops[i].address); if (function != 0) { - int type = HLE::GetFunctionTypeByIndex(function); - if (type == HLE::HLE_HOOK_START || type == HLE::HLE_HOOK_REPLACE) + HLE::HookType type = HLE::GetFunctionTypeByIndex(function); + if (type == HLE::HookType::Start || type == HLE::HookType::Replace) { - int flags = HLE::GetFunctionFlagsByIndex(function); + HLE::HookFlag flags = HLE::GetFunctionFlagsByIndex(function); if (HLE::IsEnabled(flags)) { HLEFunction(function); - if (type == HLE::HLE_HOOK_REPLACE) + if (type == HLE::HookType::Replace) { MOV(32, R(RSCRATCH), PPCSTATE(npc)); js.downcountAmount += js.st.numCycles;