CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
hrydgard

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: hrydgard/ppsspp
Path: blob/master/Core/HLE/ReplaceTables.h
Views: 1401
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
// Regular replacement funcs are just C functions. These take care of their
19
// own parameter parsing using the old school PARAM macros.
20
// The return value is the number of cycles to eat.
21
22
// JIT replacefuncs can be for inline or "outline" replacement.
23
// With inline replacement, we recognize the call to the functions
24
// at jal time already. With outline replacement, we just replace the
25
// implementation.
26
27
// In both cases the jit needs to know how much to subtract downcount.
28
//
29
// If the replacement func returned a positive number, this will be treated
30
// as the number of cycles to subtract.
31
// If the replacement func returns -1, it will be assumed that the subtraction
32
// was done by the replacement func.
33
34
#pragma once
35
36
#include <map>
37
38
#include "Common/CommonTypes.h"
39
#include "Core/MIPS/JitCommon/JitCommon.h"
40
41
typedef int (* ReplaceFunc)();
42
43
enum {
44
REPFLAG_ALLOWINLINE = 0x01,
45
// Used to keep things around but disable them.
46
REPFLAG_DISABLED = 0x02,
47
// Note that this will re-execute in a function that loops at start.
48
REPFLAG_HOOKENTER = 0x04,
49
// Only hooks jr ra, so only use on funcs that have that.
50
REPFLAG_HOOKEXIT = 0x08,
51
// Function may take a lot of time and execute in slices (executed multiple times.)
52
REPFLAG_SLICED = 0x10,
53
};
54
55
// Kind of similar to HLE functions but with different data.
56
struct ReplacementTableEntry {
57
const char *name;
58
ReplaceFunc replaceFunc;
59
MIPSComp::MIPSReplaceFunc jitReplaceFunc;
60
int flags;
61
s32 hookOffset;
62
};
63
64
void Replacement_Init();
65
void Replacement_Shutdown();
66
67
int GetNumReplacementFuncs();
68
std::vector<int> GetReplacementFuncIndexes(u64 hash, int funcSize);
69
const ReplacementTableEntry *GetReplacementFunc(size_t index);
70
71
void WriteReplaceInstructions(u32 address, u64 hash, int size);
72
void RestoreReplacedInstruction(u32 address);
73
void RestoreReplacedInstructions(u32 startAddr, u32 endAddr);
74
bool GetReplacedOpAt(u32 address, u32 *op);
75
bool CanReplaceJalTo(u32 dest, const ReplacementTableEntry **entry, u32 *funcSize);
76
77
// For savestates. If you call SaveAndClearReplacements(), you must call RestoreSavedReplacements().
78
std::map<u32, u32> SaveAndClearReplacements();
79
void RestoreSavedReplacements(const std::map<u32, u32> &saved);
80
81