Merge pull request #6354 from leoetlino/hle

HLE: Minor cleanup
This commit is contained in:
Anthony 2018-02-07 23:36:31 -08:00 committed by GitHub
commit c30ac55cf4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 52 additions and 64 deletions

View File

@ -43,41 +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},
{"PanicAlert", HLE_Misc::HLEPanicAlert, HLE_HOOK_REPLACE, HLE_TYPE_DEBUG},
{"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
@ -117,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);
@ -131,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))
@ -203,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;
}
@ -226,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<u32>(patch - OSPatches);
u32 addr = 0;

View File

@ -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);
}

View File

@ -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.

View File

@ -6,7 +6,6 @@
namespace HLE_Misc
{
void HLEPanicAlert();
void UnimplementedFunction();
void HBReload();
void GeckoCodeHandlerICacheFlush();

View File

@ -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();

View File

@ -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;

View File

@ -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;