mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-04-12 09:51:24 +02:00
HLE: Improve naming
Replace 'function' with 'hook' when appropriate
This commit is contained in:
parent
17ad2ac719
commit
4c75b96254
@ -21,19 +21,9 @@
|
||||
|
||||
namespace HLE
|
||||
{
|
||||
using HookFunction = void (*)();
|
||||
|
||||
// Map addresses to the HLE hook function id
|
||||
// Map addresses to the HLE hook index
|
||||
static std::map<u32, u32> s_hooked_addresses;
|
||||
|
||||
struct Hook
|
||||
{
|
||||
char name[128];
|
||||
HookFunction function;
|
||||
HookType type;
|
||||
HookFlag flags;
|
||||
};
|
||||
|
||||
// clang-format off
|
||||
constexpr std::array<Hook, 23> os_patches{{
|
||||
// Placeholder, os_patches[0] is the "non-existent function" index
|
||||
@ -148,16 +138,16 @@ void Reload()
|
||||
PatchFunctions();
|
||||
}
|
||||
|
||||
void Execute(u32 current_pc, u32 instruction)
|
||||
void Execute(u32 current_pc, u32 hook_index)
|
||||
{
|
||||
const unsigned int function_index = instruction & 0xFFFFF;
|
||||
if (function_index > 0 && function_index < os_patches.size())
|
||||
hook_index &= 0xFFFFF;
|
||||
if (hook_index > 0 && hook_index < os_patches.size())
|
||||
{
|
||||
os_patches[function_index].function();
|
||||
os_patches[hook_index].function();
|
||||
}
|
||||
else
|
||||
{
|
||||
PanicAlert("HLE system tried to call an undefined HLE function %i.", function_index);
|
||||
PanicAlert("HLE system tried to call an undefined HLE function %i.", hook_index);
|
||||
}
|
||||
}
|
||||
|
||||
@ -178,12 +168,12 @@ u32 GetHookByFunctionAddress(u32 address)
|
||||
return (symbol && symbol->address == address) ? index : 0;
|
||||
}
|
||||
|
||||
HookType GetFunctionTypeByIndex(u32 index)
|
||||
HookType GetHookTypeByIndex(u32 index)
|
||||
{
|
||||
return os_patches[index].type;
|
||||
}
|
||||
|
||||
HookFlag GetFunctionFlagsByIndex(u32 index)
|
||||
HookFlag GetHookFlagsByIndex(u32 index)
|
||||
{
|
||||
return os_patches[index].flags;
|
||||
}
|
||||
|
@ -10,6 +10,8 @@
|
||||
|
||||
namespace HLE
|
||||
{
|
||||
using HookFunction = void (*)();
|
||||
|
||||
enum class HookType
|
||||
{
|
||||
Start, // Hook the beginning of the function and execute the function afterwards
|
||||
@ -24,6 +26,14 @@ enum class HookFlag
|
||||
Fixed, // An arbitrary hook mapped to a fixed address instead of a symbol
|
||||
};
|
||||
|
||||
struct Hook
|
||||
{
|
||||
char name[128];
|
||||
HookFunction function;
|
||||
HookType type;
|
||||
HookFlag flags;
|
||||
};
|
||||
|
||||
void PatchFixedFunctions();
|
||||
void PatchFunctions();
|
||||
void Clear();
|
||||
@ -31,14 +41,14 @@ void Reload();
|
||||
|
||||
void Patch(u32 pc, std::string_view func_name);
|
||||
u32 UnPatch(std::string_view patch_name);
|
||||
void Execute(u32 _CurrentPC, u32 _Instruction);
|
||||
void Execute(u32 current_pc, u32 hook_index);
|
||||
|
||||
// Returns the HLE function index of the address
|
||||
// Returns the HLE hook index of the address
|
||||
u32 GetHookByAddress(u32 address);
|
||||
// Returns the HLE function index if the address matches the function start
|
||||
// Returns the HLE hook index if the address matches the function start
|
||||
u32 GetHookByFunctionAddress(u32 address);
|
||||
HookType GetFunctionTypeByIndex(u32 index);
|
||||
HookFlag GetFunctionFlagsByIndex(u32 index);
|
||||
HookType GetHookTypeByIndex(u32 index);
|
||||
HookFlag GetHookFlagsByIndex(u32 index);
|
||||
|
||||
bool IsEnabled(HookFlag flag);
|
||||
|
||||
@ -56,18 +66,18 @@ bool IsEnabled(HookFlag flag);
|
||||
template <typename FunctionObject>
|
||||
bool ReplaceFunctionIfPossible(u32 address, FunctionObject fn)
|
||||
{
|
||||
const u32 function = GetHookByFunctionAddress(address);
|
||||
if (function == 0)
|
||||
const u32 hook_index = GetHookByFunctionAddress(address);
|
||||
if (hook_index == 0)
|
||||
return false;
|
||||
|
||||
const HookType type = GetFunctionTypeByIndex(function);
|
||||
const HookType type = GetHookTypeByIndex(hook_index);
|
||||
if (type != HookType::Start && type != HookType::Replace)
|
||||
return false;
|
||||
|
||||
const HookFlag flags = GetFunctionFlagsByIndex(function);
|
||||
const HookFlag flags = GetHookFlagsByIndex(hook_index);
|
||||
if (!IsEnabled(flags))
|
||||
return false;
|
||||
|
||||
return fn(function, type);
|
||||
return fn(hook_index, type);
|
||||
}
|
||||
} // namespace HLE
|
||||
|
@ -192,9 +192,9 @@ static bool CheckIdle(u32 idle_pc)
|
||||
|
||||
bool CachedInterpreter::HandleFunctionHooking(u32 address)
|
||||
{
|
||||
return HLE::ReplaceFunctionIfPossible(address, [&](u32 function, HLE::HookType type) {
|
||||
return HLE::ReplaceFunctionIfPossible(address, [&](u32 hook_index, HLE::HookType type) {
|
||||
m_code.emplace_back(WritePC, address);
|
||||
m_code.emplace_back(Interpreter::HLEFunction, function);
|
||||
m_code.emplace_back(Interpreter::HLEFunction, hook_index);
|
||||
|
||||
if (type != HLE::HookType::Replace)
|
||||
return false;
|
||||
|
@ -141,8 +141,8 @@ static void Trace(UGeckoInstruction& inst)
|
||||
|
||||
bool Interpreter::HandleFunctionHooking(u32 address)
|
||||
{
|
||||
return HLE::ReplaceFunctionIfPossible(address, [](u32 function, HLE::HookType type) {
|
||||
HLEFunction(function);
|
||||
return HLE::ReplaceFunctionIfPossible(address, [](u32 hook_index, HLE::HookType type) {
|
||||
HLEFunction(hook_index);
|
||||
return type != HLE::HookType::Start;
|
||||
});
|
||||
}
|
||||
|
@ -433,12 +433,12 @@ void Jit64::FallBackToInterpreter(UGeckoInstruction inst)
|
||||
}
|
||||
}
|
||||
|
||||
void Jit64::HLEFunction(UGeckoInstruction _inst)
|
||||
void Jit64::HLEFunction(u32 hook_index)
|
||||
{
|
||||
gpr.Flush();
|
||||
fpr.Flush();
|
||||
ABI_PushRegistersAndAdjustStack({}, 0);
|
||||
ABI_CallFunctionCC(HLE::Execute, js.compilerPC, _inst.hex);
|
||||
ABI_CallFunctionCC(HLE::Execute, js.compilerPC, hook_index);
|
||||
ABI_PopRegistersAndAdjustStack({}, 0);
|
||||
}
|
||||
|
||||
@ -1165,8 +1165,8 @@ void Jit64::IntializeSpeculativeConstants()
|
||||
|
||||
bool Jit64::HandleFunctionHooking(u32 address)
|
||||
{
|
||||
return HLE::ReplaceFunctionIfPossible(address, [&](u32 function, HLE::HookType type) {
|
||||
HLEFunction(function);
|
||||
return HLE::ReplaceFunctionIfPossible(address, [&](u32 hook_index, HLE::HookType type) {
|
||||
HLEFunction(hook_index);
|
||||
|
||||
if (type != HLE::HookType::Replace)
|
||||
return false;
|
||||
|
@ -129,7 +129,7 @@ public:
|
||||
using Instruction = void (Jit64::*)(UGeckoInstruction instCode);
|
||||
void FallBackToInterpreter(UGeckoInstruction _inst);
|
||||
void DoNothing(UGeckoInstruction _inst);
|
||||
void HLEFunction(UGeckoInstruction _inst);
|
||||
void HLEFunction(u32 hook_index);
|
||||
|
||||
void DynaRunTable4(UGeckoInstruction inst);
|
||||
void DynaRunTable19(UGeckoInstruction inst);
|
||||
|
Loading…
x
Reference in New Issue
Block a user