CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
Path: blob/master/Core/MIPS/x86/JitSafeMem.h
Views: 1401
// Copyright (c) 2012- PPSSPP Project.12// This program is free software: you can redistribute it and/or modify3// it under the terms of the GNU General Public License as published by4// the Free Software Foundation, version 2.0 or later versions.56// This program is distributed in the hope that it will be useful,7// but WITHOUT ANY WARRANTY; without even the implied warranty of8// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the9// GNU General Public License 2.0 for more details.1011// A copy of the GPL 2.0 should have been included with the program.12// If not, see http://www.gnu.org/licenses/1314// Official git repository and contact information can be found at15// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.1617#pragma once1819#include <vector>2021class ThunkManager;2223namespace MIPSComp {2425class Jit;2627class JitSafeMem {28public:29JitSafeMem(Jit *jit, MIPSGPReg raddr, s32 offset, u32 alignMask = 0xFFFFFFFF);3031// Emit code necessary for a memory write, returns true if MOV to dest is needed.32bool PrepareWrite(Gen::OpArg &dest, int size);33// Emit code proceeding a slow write call, returns true if slow write is needed.34bool PrepareSlowWrite();35// Emit a slow write from src.36void DoSlowWrite(const void *safeFunc, const Gen::OpArg& src, int suboffset = 0);37template <typename T>38void DoSlowWrite(void (*safeFunc)(T val, u32 addr), const Gen::OpArg& src, int suboffset = 0) {39DoSlowWrite((const void *)safeFunc, src, suboffset);40}4142// Emit code necessary for a memory read, returns true if MOV from src is needed.43bool PrepareRead(Gen::OpArg &src, int size);44// Emit code for a slow read call, and returns true if result is in EAX.45bool PrepareSlowRead(const void *safeFunc);46template <typename T>47bool PrepareSlowRead(T (*safeFunc)(u32 addr)) {48return PrepareSlowRead((const void *)safeFunc);49}5051// Cleans up final code for the memory access.52void Finish();5354// WARNING: Only works for non-GPR. Do not use for reads into GPR.55Gen::OpArg NextFastAddress(int suboffset);56// WARNING: Only works for non-GPR. Do not use for reads into GPR.57void NextSlowRead(const void *safeFunc, int suboffset);58template <typename T>59void NextSlowRead(T (*safeFunc)(u32 addr), int suboffset) {60NextSlowRead((const void *)safeFunc, suboffset);61}6263private:64enum MemoryOpType {65MEM_READ,66MEM_WRITE,67};6869Gen::OpArg PrepareMemoryOpArg(MemoryOpType type);70void PrepareSlowAccess();71bool ImmValid();72void IndirectCALL(const void *safeFunc);7374Jit *jit_;75MIPSGPReg raddr_;76s32 offset_;77int size_;78bool needsCheck_;79bool needsSkip_;80bool fast_;81u32 alignMask_;82u32 iaddr_;83Gen::X64Reg xaddr_;84Gen::FixupBranch tooLow_, tooHigh_, skip_;85std::vector<Gen::FixupBranch> skipChecks_;86const u8 *safe_;87};8889// Kept separate to avoid mistakes in the above class not using jit_.90class JitSafeMemFuncs : public Gen::XCodeBlock91{92public:93JitSafeMemFuncs() {94}95~JitSafeMemFuncs() {96Shutdown();97}9899void Init(ThunkManager *thunks);100void Shutdown();101102const u8 *readU32;103const u8 *readU16;104const u8 *readU8;105const u8 *writeU32;106const u8 *writeU16;107const u8 *writeU8;108109private:110void CreateReadFunc(int bits, const void *fallbackFunc);111void CreateWriteFunc(int bits, const void *fallbackFunc);112113void CheckDirectEAX();114void StartDirectAccess();115116std::vector<Gen::FixupBranch> skips_;117ThunkManager *thunks_;118};119120};121122123