Core/HLE/HLE: Remove global system accessors
We can get rid of the global system accessors by requiring passing in relevant state that the function needs and making callsites do the work. This *does* add a global accessor to the PPCAnalyzer, however, this already has global accessors present elsewhere within its code, so they can be removed all at once in a follow up change.
This commit is contained in:
parent
04300114f7
commit
f4277a901a
|
@ -200,7 +200,7 @@ HookFlag GetHookFlagsByIndex(u32 index)
|
||||||
return os_patches[index].flags;
|
return os_patches[index].flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
TryReplaceFunctionResult TryReplaceFunction(u32 address)
|
TryReplaceFunctionResult TryReplaceFunction(u32 address, PowerPC::CoreMode mode)
|
||||||
{
|
{
|
||||||
const u32 hook_index = GetHookByFunctionAddress(address);
|
const u32 hook_index = GetHookByFunctionAddress(address);
|
||||||
if (hook_index == 0)
|
if (hook_index == 0)
|
||||||
|
@ -211,16 +211,16 @@ TryReplaceFunctionResult TryReplaceFunction(u32 address)
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
const HookFlag flags = GetHookFlagsByIndex(hook_index);
|
const HookFlag flags = GetHookFlagsByIndex(hook_index);
|
||||||
if (!IsEnabled(flags))
|
if (!IsEnabled(flags, mode))
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
return {type, hook_index};
|
return {type, hook_index};
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsEnabled(HookFlag flag)
|
bool IsEnabled(HookFlag flag, PowerPC::CoreMode mode)
|
||||||
{
|
{
|
||||||
return flag != HLE::HookFlag::Debug || Config::IsDebuggingEnabled() ||
|
return flag != HLE::HookFlag::Debug || Config::IsDebuggingEnabled() ||
|
||||||
Core::System::GetInstance().GetPowerPC().GetMode() == PowerPC::CoreMode::Interpreter;
|
mode == PowerPC::CoreMode::Interpreter;
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 UnPatch(Core::System& system, std::string_view patch_name)
|
u32 UnPatch(Core::System& system, std::string_view patch_name)
|
||||||
|
|
|
@ -13,6 +13,11 @@ class CPUThreadGuard;
|
||||||
class System;
|
class System;
|
||||||
} // namespace Core
|
} // namespace Core
|
||||||
|
|
||||||
|
namespace PowerPC
|
||||||
|
{
|
||||||
|
enum class CoreMode;
|
||||||
|
}
|
||||||
|
|
||||||
namespace HLE
|
namespace HLE
|
||||||
{
|
{
|
||||||
using HookFunction = void (*)(const Core::CPUThreadGuard&);
|
using HookFunction = void (*)(const Core::CPUThreadGuard&);
|
||||||
|
@ -65,10 +70,10 @@ u32 GetHookByFunctionAddress(u32 address);
|
||||||
HookType GetHookTypeByIndex(u32 index);
|
HookType GetHookTypeByIndex(u32 index);
|
||||||
HookFlag GetHookFlagsByIndex(u32 index);
|
HookFlag GetHookFlagsByIndex(u32 index);
|
||||||
|
|
||||||
bool IsEnabled(HookFlag flag);
|
bool IsEnabled(HookFlag flag, PowerPC::CoreMode mode);
|
||||||
|
|
||||||
// Performs the backend-independent preliminary checking for whether a function
|
// Performs the backend-independent preliminary checking for whether a function
|
||||||
// can be HLEd. If it can be, the information needed for HLEing it is returned.
|
// can be HLEd. If it can be, the information needed for HLEing it is returned.
|
||||||
TryReplaceFunctionResult TryReplaceFunction(u32 address);
|
TryReplaceFunctionResult TryReplaceFunction(u32 address, PowerPC::CoreMode mode);
|
||||||
|
|
||||||
} // namespace HLE
|
} // namespace HLE
|
||||||
|
|
|
@ -269,7 +269,9 @@ bool CachedInterpreter::CheckIdle(CachedInterpreter& cached_interpreter, u32 idl
|
||||||
|
|
||||||
bool CachedInterpreter::HandleFunctionHooking(u32 address)
|
bool CachedInterpreter::HandleFunctionHooking(u32 address)
|
||||||
{
|
{
|
||||||
const auto result = HLE::TryReplaceFunction(address);
|
// CachedInterpreter inherits from JitBase and is considered a JIT by relevant code.
|
||||||
|
// (see JitInterface and how m_mode is set within PowerPC.cpp)
|
||||||
|
const auto result = HLE::TryReplaceFunction(address, PowerPC::CoreMode::JIT);
|
||||||
if (!result)
|
if (!result)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
|
|
@ -106,7 +106,7 @@ void Interpreter::Trace(const UGeckoInstruction& inst)
|
||||||
|
|
||||||
bool Interpreter::HandleFunctionHooking(u32 address)
|
bool Interpreter::HandleFunctionHooking(u32 address)
|
||||||
{
|
{
|
||||||
const auto result = HLE::TryReplaceFunction(address);
|
const auto result = HLE::TryReplaceFunction(address, PowerPC::CoreMode::Interpreter);
|
||||||
if (!result)
|
if (!result)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
|
|
@ -1274,7 +1274,7 @@ void Jit64::IntializeSpeculativeConstants()
|
||||||
|
|
||||||
bool Jit64::HandleFunctionHooking(u32 address)
|
bool Jit64::HandleFunctionHooking(u32 address)
|
||||||
{
|
{
|
||||||
const auto result = HLE::TryReplaceFunction(address);
|
const auto result = HLE::TryReplaceFunction(address, PowerPC::CoreMode::JIT);
|
||||||
if (!result)
|
if (!result)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
|
|
@ -781,7 +781,7 @@ void JitArm64::WriteConditionalExceptionExit(int exception, ARM64Reg temp_gpr, A
|
||||||
|
|
||||||
bool JitArm64::HandleFunctionHooking(u32 address)
|
bool JitArm64::HandleFunctionHooking(u32 address)
|
||||||
{
|
{
|
||||||
const auto result = HLE::TryReplaceFunction(address);
|
const auto result = HLE::TryReplaceFunction(address, PowerPC::CoreMode::JIT);
|
||||||
if (!result)
|
if (!result)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
|
|
@ -998,7 +998,8 @@ u32 PPCAnalyzer::Analyze(u32 address, CodeBlock* block, CodeBuffer* buffer,
|
||||||
crDiscardable = BitSet8{};
|
crDiscardable = BitSet8{};
|
||||||
}
|
}
|
||||||
|
|
||||||
const bool hle = !!HLE::TryReplaceFunction(op.address);
|
const auto ppc_mode = Core::System::GetInstance().GetPowerPC().GetMode();
|
||||||
|
const bool hle = !!HLE::TryReplaceFunction(op.address, ppc_mode);
|
||||||
const bool may_exit_block = hle || op.canEndBlock || op.canCauseException;
|
const bool may_exit_block = hle || op.canEndBlock || op.canCauseException;
|
||||||
|
|
||||||
const bool opWantsFPRF = op.wantsFPRF;
|
const bool opWantsFPRF = op.wantsFPRF;
|
||||||
|
|
Loading…
Reference in New Issue