Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
hrydgard
GitHub Repository: hrydgard/ppsspp
Path: blob/master/Core/HLE/ReplaceTables.h
5755 views
1
// Copyright (c) 2012- PPSSPP Project.
2
3
// This program is free software: you can redistribute it and/or modify
4
// it under the terms of the GNU General Public License as published by
5
// the Free Software Foundation, version 2.0 or later versions.
6
7
// This program is distributed in the hope that it will be useful,
8
// but WITHOUT ANY WARRANTY; without even the implied warranty of
9
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
// GNU General Public License 2.0 for more details.
11
12
// A copy of the GPL 2.0 should have been included with the program.
13
// If not, see http://www.gnu.org/licenses/
14
15
// Official git repository and contact information can be found at
16
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
17
18
19
// Regular replacement funcs are just C functions. These take care of their
20
// own parameter parsing using the old school PARAM macros.
21
// The return value is the number of cycles to eat.
22
23
// Replacement functions are replaced by function hash, also checking the size to reduce
24
// collisions. This is not really super safe, and we probably should restrict them by
25
// game ID, really...
26
27
// JIT replacefuncs can be for inline or "outline" replacement.
28
// With inline replacement, we recognize the call to the functions
29
// at jal time already. With outline replacement, we just replace the
30
// implementation, which gets jumped to from other functions.
31
32
// In both cases the jit needs to know how much to subtract downcount.
33
//
34
// If the replacement func returned a positive number, this will be treated
35
// as the number of cycles to subtract.
36
// If the replacement func returns -1, it will be assumed that the subtraction
37
// was done by the replacement func.
38
39
#pragma once
40
41
#include <map>
42
43
#include "Common/CommonTypes.h"
44
#include "Core/MIPS/JitCommon/JitCommon.h"
45
46
typedef int (* ReplaceFunc)();
47
48
enum {
49
REPFLAG_ALLOWINLINE = 0x01,
50
// Used to keep things around but disable them.
51
REPFLAG_DISABLED = 0x02,
52
// Note that this will re-execute in a function that loops at start.
53
REPFLAG_HOOKENTER = 0x04,
54
// Only hooks jr ra, so only use on funcs that have that.
55
REPFLAG_HOOKEXIT = 0x08,
56
// Function may take a lot of time and execute in slices (executed multiple times.)
57
REPFLAG_SLICED = 0x10,
58
};
59
60
// Kind of similar to HLE functions but with different data.
61
struct ReplacementTableEntry {
62
const char *name;
63
ReplaceFunc replaceFunc;
64
MIPSComp::MIPSReplaceFunc jitReplaceFunc;
65
int flags;
66
s32 hookOffset;
67
};
68
69
void Replacement_Init();
70
void Replacement_Shutdown();
71
72
int GetNumReplacementFuncs();
73
std::vector<int> GetReplacementFuncIndexes(u64 hash, int funcSize);
74
const ReplacementTableEntry *GetReplacementFunc(size_t index);
75
76
void WriteReplaceInstructions(u32 address, u64 hash, int size);
77
void RestoreReplacedInstruction(u32 address);
78
void RestoreReplacedInstructions(u32 startAddr, u32 endAddr);
79
bool GetReplacedOpAt(u32 address, u32 *op);
80
bool CanReplaceJalTo(u32 dest, const ReplacementTableEntry **entry, u32 *funcSize);
81
82
// For savestates. If you call SaveAndClearReplacements(), you must call RestoreSavedReplacements().
83
std::map<u32, u32> SaveAndClearReplacements();
84
void RestoreSavedReplacements(const std::map<u32, u32> &saved);
85
86