-
Notifications
You must be signed in to change notification settings - Fork 2.6k
/
HLE_Misc.cpp
82 lines (73 loc) · 2.91 KB
/
HLE_Misc.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// Copyright 2008 Dolphin Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include "Core/HLE/HLE_Misc.h"
#include "Common/Common.h"
#include "Common/CommonTypes.h"
#include "Core/Core.h"
#include "Core/GeckoCode.h"
#include "Core/HW/CPU.h"
#include "Core/Host.h"
#include "Core/PowerPC/MMU.h"
#include "Core/PowerPC/PowerPC.h"
#include "Core/System.h"
namespace HLE_Misc
{
// If you just want to kill a function, one of the three following are usually appropriate.
// According to the PPC ABI, the return value is always in r3.
void UnimplementedFunction(const Core::CPUThreadGuard& guard)
{
auto& system = guard.GetSystem();
auto& ppc_state = system.GetPPCState();
ppc_state.npc = LR(ppc_state);
}
void HBReload(const Core::CPUThreadGuard& guard)
{
// There isn't much we can do. Just stop cleanly.
auto& system = guard.GetSystem();
system.GetCPU().Break();
Host_Message(HostMessageID::WMUserStop);
}
void GeckoCodeHandlerICacheFlush(const Core::CPUThreadGuard& guard)
{
auto& system = guard.GetSystem();
auto& ppc_state = system.GetPPCState();
auto& jit_interface = system.GetJitInterface();
// Work around the codehandler not properly invalidating the icache, but
// only the first few frames.
// (Project M uses a conditional to only apply patches after something has
// been read into memory, or such, so we do the first 5 frames. More
// robust alternative would be to actually detect memory writes, but that
// would be even uglier.)
u32 gch_gameid = PowerPC::MMU::HostRead_U32(guard, Gecko::INSTALLER_BASE_ADDRESS);
if (gch_gameid - Gecko::MAGIC_GAMEID == 5)
{
return;
}
else if (gch_gameid - Gecko::MAGIC_GAMEID > 5)
{
gch_gameid = Gecko::MAGIC_GAMEID;
}
PowerPC::MMU::HostWrite_U32(guard, gch_gameid + 1, Gecko::INSTALLER_BASE_ADDRESS);
ppc_state.iCache.Reset(jit_interface);
}
// Because Dolphin messes around with the CPU state instead of patching the game binary, we
// need a way to branch into the GCH from an arbitrary PC address. Branching is easy, returning
// back is the hard part. This HLE function acts as a trampoline that restores the original LR, SP,
// and PC before the magic, invisible BL instruction happened.
void GeckoReturnTrampoline(const Core::CPUThreadGuard& guard)
{
auto& system = guard.GetSystem();
auto& ppc_state = system.GetPPCState();
// Stack frame is built in GeckoCode.cpp, Gecko::RunCodeHandler.
const u32 SP = ppc_state.gpr[1];
ppc_state.gpr[1] = PowerPC::MMU::HostRead_U32(guard, SP + 8);
ppc_state.npc = PowerPC::MMU::HostRead_U32(guard, SP + 12);
LR(ppc_state) = PowerPC::MMU::HostRead_U32(guard, SP + 16);
ppc_state.cr.Set(PowerPC::MMU::HostRead_U32(guard, SP + 20));
for (int i = 0; i < 14; ++i)
{
ppc_state.ps[i].SetBoth(PowerPC::MMU::HostRead_U64(guard, SP + 24 + 2 * i * sizeof(u64)),
PowerPC::MMU::HostRead_U64(guard, SP + 24 + (2 * i + 1) * sizeof(u64)));
}
}
} // namespace HLE_Misc