2013-11-30 19:57:44 +00:00
|
|
|
// Copyright (c) 2012- PPSSPP Project.
|
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, version 2.0 or later versions.
|
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License 2.0 for more details.
|
|
|
|
|
|
|
|
// A copy of the GPL 2.0 should have been included with the program.
|
|
|
|
// If not, see http://www.gnu.org/licenses/
|
|
|
|
|
|
|
|
// Official git repository and contact information can be found at
|
|
|
|
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
|
|
|
|
|
2013-12-17 22:40:27 +00:00
|
|
|
// Regular replacement funcs are just C functions. These take care of their
|
|
|
|
// own parameter parsing using the old school PARAM macros.
|
|
|
|
// The return value is the number of cycles to eat.
|
|
|
|
|
|
|
|
// JIT replacefuncs can be for inline or "outline" replacement.
|
|
|
|
// With inline replacement, we recognize the call to the functions
|
|
|
|
// at jal time already. With outline replacement, we just replace the
|
|
|
|
// implementation.
|
|
|
|
|
|
|
|
// In both cases the jit needs to know how much to subtract downcount.
|
|
|
|
//
|
|
|
|
// If the replacement func returned a positive number, this will be treated
|
|
|
|
// as the number of cycles to subtract.
|
|
|
|
// If the replacement func returns -1, it will be assumed that the subtraction
|
|
|
|
// was done by the replacement func.
|
2013-11-30 19:57:44 +00:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "Common/CommonTypes.h"
|
2014-12-12 23:09:37 +00:00
|
|
|
#include "Core/MIPS/JitCommon/NativeJit.h"
|
2013-11-30 19:57:44 +00:00
|
|
|
|
2013-12-17 22:40:27 +00:00
|
|
|
typedef int (* ReplaceFunc)();
|
|
|
|
|
|
|
|
enum {
|
2014-08-03 20:12:45 +00:00
|
|
|
REPFLAG_ALLOWINLINE = 0x01,
|
|
|
|
// Used to keep things around but disable them.
|
|
|
|
REPFLAG_DISABLED = 0x02,
|
|
|
|
// Note that this will re-execute in a function that loops at start.
|
|
|
|
REPFLAG_HOOKENTER = 0x04,
|
2014-05-31 05:45:06 +00:00
|
|
|
// Only hooks jr ra, so only use on funcs that have that.
|
2014-08-03 20:12:45 +00:00
|
|
|
REPFLAG_HOOKEXIT = 0x08,
|
2013-12-17 22:40:27 +00:00
|
|
|
};
|
2013-11-30 19:57:44 +00:00
|
|
|
|
|
|
|
// Kind of similar to HLE functions but with different data.
|
|
|
|
struct ReplacementTableEntry {
|
|
|
|
const char *name;
|
|
|
|
ReplaceFunc replaceFunc;
|
2013-12-17 22:40:27 +00:00
|
|
|
MIPSComp::MIPSReplaceFunc jitReplaceFunc;
|
|
|
|
int flags;
|
2014-05-31 06:28:21 +00:00
|
|
|
s32 hookOffset;
|
2013-11-30 19:57:44 +00:00
|
|
|
};
|
|
|
|
|
2013-12-17 22:40:27 +00:00
|
|
|
void Replacement_Init();
|
|
|
|
void Replacement_Shutdown();
|
|
|
|
|
2013-11-30 19:57:44 +00:00
|
|
|
int GetNumReplacementFuncs();
|
2015-02-21 23:48:09 +00:00
|
|
|
std::vector<int> GetReplacementFuncIndexes(u64 hash, int funcSize);
|
2013-12-17 22:40:27 +00:00
|
|
|
const ReplacementTableEntry *GetReplacementFunc(int index);
|
2013-12-18 10:42:19 +00:00
|
|
|
|
2014-05-31 05:45:06 +00:00
|
|
|
void WriteReplaceInstructions(u32 address, u64 hash, int size);
|
2014-04-12 08:13:50 +00:00
|
|
|
void RestoreReplacedInstruction(u32 address);
|
|
|
|
void RestoreReplacedInstructions(u32 startAddr, u32 endAddr);
|
2013-12-18 10:42:19 +00:00
|
|
|
bool GetReplacedOpAt(u32 address, u32 *op);
|
2015-04-12 20:35:10 +00:00
|
|
|
bool CanReplaceJalTo(u32 dest, const ReplacementTableEntry **entry, u32 *funcSize);
|
2014-05-27 14:50:08 +00:00
|
|
|
|
|
|
|
// For savestates. If you call SaveAndClearReplacements(), you must call RestoreSavedReplacements().
|
|
|
|
std::map<u32, u32> SaveAndClearReplacements();
|
|
|
|
void RestoreSavedReplacements(const std::map<u32, u32> &saved);
|