From fd0927d080276193570e4e32a2dd7e41587ead05 Mon Sep 17 00:00:00 2001 From: Nemoumbra Date: Fri, 9 Feb 2024 14:18:28 +0300 Subject: [PATCH 1/8] Moved 'MIPSInstruction' to the header --- Core/MIPS/MIPSTables.cpp | 45 -------------------------------------- Core/MIPS/MIPSTables.h | 47 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 45 deletions(-) diff --git a/Core/MIPS/MIPSTables.cpp b/Core/MIPS/MIPSTables.cpp index 4b909c2d0308..a0d44dfdc5bf 100644 --- a/Core/MIPS/MIPSTables.cpp +++ b/Core/MIPS/MIPSTables.cpp @@ -31,51 +31,6 @@ #include "Core/Reporting.h" #include "Core/Debugger/Breakpoints.h" -#include "JitCommon/JitCommon.h" - -enum MipsEncoding { - Imme, - Spec, - Spe2, - Spe3, - RegI, - Cop0, - Cop0CO, - Cop1, - Cop1BC, - Cop1S, - Cop1W, - Cop2, - Cop2BC2, - Cop2Rese, - VFPU0, - VFPU1, - VFPU3, - VFPU4Jump, - VFPU7, - VFPU4, - VFPU5, - VFPU6, - VFPUMatrix1, - VFPU9, - ALLEGREX0, - Emu, - Rese, - NumEncodings, - - Instruc = -1, - Inval = -2, -}; - -struct MIPSInstruction { - MipsEncoding altEncoding; - const char *name; - MIPSComp::MIPSCompileFunc compile; - MIPSDisFunc disasm; - MIPSInterpretFunc interpret; - //MIPSInstructionInfo information; - MIPSInfo flags; -}; #define INVALID {Inval} #define INVALID_X_8 INVALID,INVALID,INVALID,INVALID,INVALID,INVALID,INVALID,INVALID diff --git a/Core/MIPS/MIPSTables.h b/Core/MIPS/MIPSTables.h index 9c53a07ea011..43eac9546663 100644 --- a/Core/MIPS/MIPSTables.h +++ b/Core/MIPS/MIPSTables.h @@ -22,6 +22,8 @@ #include "Common/CommonTypes.h" #include "Core/MIPS/MIPS.h" +#include "JitCommon/JitCommon.h" + #define CONDTYPE_MASK 0x00000007 #define CONDTYPE_EQ 0x00000001 #define CONDTYPE_NE 0x00000002 @@ -121,6 +123,51 @@ struct MIPSInfo { typedef void (CDECL *MIPSDisFunc)(MIPSOpcode opcode, uint32_t pc, char *out, size_t outSize); typedef void (CDECL *MIPSInterpretFunc)(MIPSOpcode opcode); +enum MipsEncoding { + Imme, + Spec, + Spe2, + Spe3, + RegI, + Cop0, + Cop0CO, + Cop1, + Cop1BC, + Cop1S, + Cop1W, + Cop2, + Cop2BC2, + Cop2Rese, + VFPU0, + VFPU1, + VFPU3, + VFPU4Jump, + VFPU7, + VFPU4, + VFPU5, + VFPU6, + VFPUMatrix1, + VFPU9, + ALLEGREX0, + Emu, + Rese, + NumEncodings, + + Instruc = -1, + Inval = -2, +}; + + +struct MIPSInstruction { + MipsEncoding altEncoding; + const char *name; + MIPSComp::MIPSCompileFunc compile; + MIPSDisFunc disasm; + MIPSInterpretFunc interpret; + //MIPSInstructionInfo information; + MIPSInfo flags; +}; + namespace MIPSComp { class MIPSFrontendInterface; } From 83b4be49059ea73978b08c917816239e70abf33a Mon Sep 17 00:00:00 2001 From: Nemoumbra Date: Fri, 9 Feb 2024 19:14:41 +0300 Subject: [PATCH 2/8] Added a mechanism to use custom MIPS instruction handlers --- Core/Core.vcxproj | 2 + Core/Core.vcxproj.filters | 6 +++ Core/MIPS/MIPSHooks.cpp | 45 ++++++++++++++++++++ Core/MIPS/MIPSHooks.h | 54 ++++++++++++++++++++++++ Core/MIPS/MIPSTables.cpp | 87 ++++++++++++++++++++++++++++----------- Core/System.cpp | 5 +++ 6 files changed, 174 insertions(+), 25 deletions(-) create mode 100644 Core/MIPS/MIPSHooks.cpp create mode 100644 Core/MIPS/MIPSHooks.h diff --git a/Core/Core.vcxproj b/Core/Core.vcxproj index c9acd32dc19f..912762b22b19 100644 --- a/Core/Core.vcxproj +++ b/Core/Core.vcxproj @@ -989,6 +989,7 @@ + true true @@ -1400,6 +1401,7 @@ + true true diff --git a/Core/Core.vcxproj.filters b/Core/Core.vcxproj.filters index 0918b045f4d4..0fa6ecac1f82 100644 --- a/Core/Core.vcxproj.filters +++ b/Core/Core.vcxproj.filters @@ -129,6 +129,9 @@ MIPS + + MIPS + MIPS\x86 @@ -1344,6 +1347,9 @@ MIPS + + MIPS + MIPS\x86 diff --git a/Core/MIPS/MIPSHooks.cpp b/Core/MIPS/MIPSHooks.cpp new file mode 100644 index 000000000000..9904edb2658b --- /dev/null +++ b/Core/MIPS/MIPSHooks.cpp @@ -0,0 +1,45 @@ +// Copyright (c) 2024- 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/. + +#include "Core/MIPS/MIPSHooks.h" + +#include +#include + + +MIPSNames MIPSNameLookupTable; +static std::vector> stack; + +namespace MIPSHooks { + + void Reset() { + for (auto&[instr, func] : stack) { + instr->interpret = func; + } + stack.clear(); + } + + void Hook(const char* name, MIPSInterpretFunc func) { + auto current_handler = MIPSNameLookupTable.GetInstructionByName(name); + if (!current_handler) { + return; + } + + stack.emplace_back(current_handler, current_handler->interpret); + current_handler->interpret = func; + } +} diff --git a/Core/MIPS/MIPSHooks.h b/Core/MIPS/MIPSHooks.h new file mode 100644 index 000000000000..27280608304d --- /dev/null +++ b/Core/MIPS/MIPSHooks.h @@ -0,0 +1,54 @@ +// Copyright (c) 2024- 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/. + +#pragma once + +#include + +#include "Core/MIPS/MIPSTables.h" + +class MIPSNames { +private: + std::map name_lookup_table; +public: + template + void RegisterInstructions(MIPSInstruction (&table)[size]) { + for (uint32_t i = 0; i < size; ++i) { + // register the name if it's valid + if (table[i].name) { + name_lookup_table.emplace(table[i].name, &table[i]); + } + } + } + + MIPSInstruction* GetInstructionByName(std::string name) { + auto it = name_lookup_table.find(name); + if (it == name_lookup_table.end()) { + return nullptr; + } + return it->second; + } +}; + +extern MIPSNames MIPSNameLookupTable; + +namespace MIPSHooks { + void Init(); // implemented in the MIPSTables.cpp + void Reset(); + void Hook(const char* name, MIPSInterpretFunc func); +} + diff --git a/Core/MIPS/MIPSTables.cpp b/Core/MIPS/MIPSTables.cpp index a0d44dfdc5bf..0fa08432ad2b 100644 --- a/Core/MIPS/MIPSTables.cpp +++ b/Core/MIPS/MIPSTables.cpp @@ -31,6 +31,8 @@ #include "Core/Reporting.h" #include "Core/Debugger/Breakpoints.h" +#include "Core/MIPS/MIPSHooks.h" + #define INVALID {Inval} #define INVALID_X_8 INVALID,INVALID,INVALID,INVALID,INVALID,INVALID,INVALID,INVALID @@ -47,7 +49,7 @@ using namespace MIPSComp; // %s/&Jit::\(.\{-}\),/JITFUNC(\1),/g // regregreg instructions -static const MIPSInstruction tableImmediate[64] = // xxxxxx ..... ..... ................ +static MIPSInstruction tableImmediate[64] = // xxxxxx ..... ..... ................ { //0 ENCODING(Spec), @@ -126,7 +128,7 @@ static const MIPSInstruction tableImmediate[64] = // xxxxxx ..... ..... ........ INSTR("vflush", JITFUNC(Comp_DoNothing), Dis_Vflush, Int_Vflush, IS_VFPU|VFPU_NO_PREFIX), }; -static const MIPSInstruction tableSpecial[64] = // 000000 ..... ..... ..... ..... xxxxxx +static MIPSInstruction tableSpecial[64] = // 000000 ..... ..... ..... ..... xxxxxx { INSTR("sll", JITFUNC(Comp_ShiftType), Dis_ShiftType, Int_ShiftType, OUT_RD|IN_RT|IN_SA), INVALID, // copu @@ -203,7 +205,7 @@ static const MIPSInstruction tableSpecial[64] = // 000000 ..... ..... ..... .... }; // Theoretically should not hit these. -static const MIPSInstruction tableSpecial2[64] = // 011100 ..... ..... ..... ..... xxxxxx +static MIPSInstruction tableSpecial2[64] = // 011100 ..... ..... ..... ..... xxxxxx { INSTR("halt", JITFUNC(Comp_Generic), Dis_Generic, 0, 0), INVALID, INVALID, INVALID, INVALID, INVALID, INVALID, INVALID, @@ -223,7 +225,7 @@ static const MIPSInstruction tableSpecial2[64] = // 011100 ..... ..... ..... ... INVALID_X_8, }; -static const MIPSInstruction tableSpecial3[64] = // 011111 ..... ..... ..... ..... xxxxxx +static MIPSInstruction tableSpecial3[64] = // 011111 ..... ..... ..... ..... xxxxxx { INSTR("ext", JITFUNC(Comp_Special3), Dis_Special3, Int_Special3, IN_RS|OUT_RT), INVALID, @@ -253,7 +255,7 @@ static const MIPSInstruction tableSpecial3[64] = // 011111 ..... ..... ..... ... INVALID, INVALID, INVALID, INVALID, }; -static const MIPSInstruction tableRegImm[32] = // 000001 ..... xxxxx ................ +static MIPSInstruction tableRegImm[32] = // 000001 ..... xxxxx ................ { INSTR("bltz", JITFUNC(Comp_RelBranchRI), Dis_RelBranch, Int_RelBranchRI, IS_CONDBRANCH|IN_IMM16|IN_RS|DELAYSLOT|CONDTYPE_LTZ), INSTR("bgez", JITFUNC(Comp_RelBranchRI), Dis_RelBranch, Int_RelBranchRI, IS_CONDBRANCH|IN_IMM16|IN_RS|DELAYSLOT|CONDTYPE_GEZ), @@ -286,7 +288,7 @@ static const MIPSInstruction tableRegImm[32] = // 000001 ..... xxxxx ........... INSTR("synci", JITFUNC(Comp_Generic), Dis_Generic, 0, 0), }; -static const MIPSInstruction tableCop2[32] = // 010010 xxxxx ..... ................ +static MIPSInstruction tableCop2[32] = // 010010 xxxxx ..... ................ { INSTR("mfc2", JITFUNC(Comp_Generic), Dis_Generic, 0, OUT_RT), INVALID, @@ -310,7 +312,7 @@ static const MIPSInstruction tableCop2[32] = // 010010 xxxxx ..... ............. INVALID_X_8, }; -static const MIPSInstruction tableCop2BC2[4] = // 010010 01000 ...xx ................ +static MIPSInstruction tableCop2BC2[4] = // 010010 01000 ...xx ................ { INSTR("bvf", JITFUNC(Comp_VBranch), Dis_VBranch, Int_VBranch, IS_CONDBRANCH|IN_IMM16|IN_VFPU_CC|DELAYSLOT|IS_VFPU), INSTR("bvt", JITFUNC(Comp_VBranch), Dis_VBranch, Int_VBranch, IS_CONDBRANCH|IN_IMM16|IN_VFPU_CC|DELAYSLOT|IS_VFPU), @@ -318,7 +320,7 @@ static const MIPSInstruction tableCop2BC2[4] = // 010010 01000 ...xx ........... INSTR("bvtl", JITFUNC(Comp_VBranch), Dis_VBranch, Int_VBranch, IS_CONDBRANCH|IN_IMM16|IN_VFPU_CC|DELAYSLOT|LIKELY|IS_VFPU), }; -static const MIPSInstruction tableCop0[32] = // 010000 xxxxx ..... ................ +static MIPSInstruction tableCop0[32] = // 010000 xxxxx ..... ................ { INSTR("mfc0", JITFUNC(Comp_Generic), Dis_Generic, 0, OUT_RT), // unused INVALID, @@ -344,7 +346,7 @@ static const MIPSInstruction tableCop0[32] = // 010000 xxxxx ..... ............. }; // we won't encounter these since we only do user mode emulation -static const MIPSInstruction tableCop0CO[64] = // 010000 1.... ..... ..... ..... xxxxxx +static MIPSInstruction tableCop0CO[64] = // 010000 1.... ..... ..... ..... xxxxxx { INVALID, INSTR("tlbr", JITFUNC(Comp_Generic), Dis_Generic, 0, 0), @@ -372,7 +374,7 @@ static const MIPSInstruction tableCop0CO[64] = // 010000 1.... ..... ..... ..... INVALID_X_8, }; -static const MIPSInstruction tableCop1[32] = // 010001 xxxxx ..... ..... ........... +static MIPSInstruction tableCop1[32] = // 010001 xxxxx ..... ..... ........... { INSTR("mfc1", JITFUNC(Comp_mxc1), Dis_mxc1, Int_mxc1, IN_FS|OUT_RT|IS_FPU), INVALID, @@ -391,7 +393,7 @@ static const MIPSInstruction tableCop1[32] = // 010001 xxxxx ..... ..... ....... INVALID_X_8, }; -static const MIPSInstruction tableCop1BC[32] = // 010001 01000 xxxxx ................ +static MIPSInstruction tableCop1BC[32] = // 010001 01000 xxxxx ................ { INSTR("bc1f", JITFUNC(Comp_FPUBranch), Dis_FPUBranch, Int_FPUBranch, IS_CONDBRANCH|IN_IMM16|IN_FPUFLAG|DELAYSLOT|CONDTYPE_FPUFALSE|IS_FPU), INSTR("bc1t", JITFUNC(Comp_FPUBranch), Dis_FPUBranch, Int_FPUBranch, IS_CONDBRANCH|IN_IMM16|IN_FPUFLAG|DELAYSLOT|CONDTYPE_FPUTRUE|IS_FPU), @@ -404,7 +406,7 @@ static const MIPSInstruction tableCop1BC[32] = // 010001 01000 xxxxx ........... INVALID_X_8, }; -static const MIPSInstruction tableCop1S[64] = // 010001 10000 ..... ..... ..... xxxxxx +static MIPSInstruction tableCop1S[64] = // 010001 10000 ..... ..... ..... xxxxxx { INSTR("add.s", JITFUNC(Comp_FPU3op), Dis_FPU3op, Int_FPU3op, OUT_FD|IN_FS|IN_FT|IS_FPU), INSTR("sub.s", JITFUNC(Comp_FPU3op), Dis_FPU3op, Int_FPU3op, OUT_FD|IN_FS|IN_FT|IS_FPU), @@ -452,7 +454,7 @@ static const MIPSInstruction tableCop1S[64] = // 010001 10000 ..... ..... ..... INSTR("c.ngt", JITFUNC(Comp_FPUComp), Dis_FPUComp, Int_FPUComp, IN_FS|IN_FT|OUT_FPUFLAG|IS_FPU), }; -static const MIPSInstruction tableCop1W[64] = // 010001 10100 ..... ..... ..... xxxxxx +static MIPSInstruction tableCop1W[64] = // 010001 10100 ..... ..... ..... xxxxxx { INVALID_X_8, //8 @@ -476,7 +478,7 @@ static const MIPSInstruction tableCop1W[64] = // 010001 10100 ..... ..... ..... INVALID_X_8, }; -static const MIPSInstruction tableVFPU0[8] = // 011000 xxx ....... . ....... . ....... +static MIPSInstruction tableVFPU0[8] = // 011000 xxx ....... . ....... . ....... { INSTR("vadd", JITFUNC(Comp_VecDo3), Dis_VectorSet3, Int_VecDo3, MIPSInfo(IN_OTHER|OUT_OTHER|IS_VFPU|OUT_EAT_PREFIX, 2)), INSTR("vsub", JITFUNC(Comp_VecDo3), Dis_VectorSet3, Int_VecDo3, MIPSInfo(IN_OTHER|OUT_OTHER|IS_VFPU|OUT_EAT_PREFIX, 2)), @@ -487,7 +489,7 @@ static const MIPSInstruction tableVFPU0[8] = // 011000 xxx ....... . ....... . . INSTR("vdiv", JITFUNC(Comp_VecDo3), Dis_VectorSet3, Int_VecDo3, IN_OTHER|OUT_OTHER|IS_VFPU|OUT_EAT_PREFIX), }; -static const MIPSInstruction tableVFPU1[8] = // 011001 xxx ....... . ....... . ....... +static MIPSInstruction tableVFPU1[8] = // 011001 xxx ....... . ....... . ....... { INSTR("vmul", JITFUNC(Comp_VecDo3), Dis_VectorSet3, Int_VecDo3, IN_OTHER|OUT_OTHER|IS_VFPU|OUT_EAT_PREFIX), INSTR("vdot", JITFUNC(Comp_VDot), Dis_VectorDot, Int_VDot, IN_OTHER|OUT_OTHER|IS_VFPU|OUT_EAT_PREFIX), @@ -499,7 +501,7 @@ static const MIPSInstruction tableVFPU1[8] = // 011001 xxx ....... . ....... . . INVALID, }; -static const MIPSInstruction tableVFPU3[8] = // 011011 xxx ....... . ....... . ....... +static MIPSInstruction tableVFPU3[8] = // 011011 xxx ....... . ....... . ....... { INSTR("vcmp", JITFUNC(Comp_Vcmp), Dis_Vcmp, Int_Vcmp, IN_OTHER|OUT_VFPU_CC|IS_VFPU|OUT_EAT_PREFIX), INVALID, @@ -511,7 +513,7 @@ static const MIPSInstruction tableVFPU3[8] = // 011011 xxx ....... . ....... . . INSTR("vslt", JITFUNC(Comp_VecDo3), Dis_VectorSet3, Int_Vslt, IN_OTHER|OUT_OTHER|IS_VFPU|OUT_EAT_PREFIX), }; -static const MIPSInstruction tableVFPU4Jump[32] = // 110100 xxxxx ..... . ....... . ....... +static MIPSInstruction tableVFPU4Jump[32] = // 110100 xxxxx ..... . ....... . ....... { ENCODING(VFPU4), ENCODING(VFPU7), @@ -543,7 +545,7 @@ static const MIPSInstruction tableVFPU4Jump[32] = // 110100 xxxxx ..... . ...... INSTR("vwbn", JITFUNC(Comp_Generic), Dis_Vwbn, Int_Vwbn, IN_OTHER|OUT_OTHER|IS_VFPU|OUT_EAT_PREFIX), }; -static const MIPSInstruction tableVFPU7[32] = // 110100 00001 xxxxx . ....... . ....... +static MIPSInstruction tableVFPU7[32] = // 110100 00001 xxxxx . ....... . ....... { INSTR("vrnds", JITFUNC(Comp_Generic), Dis_Vrnds, Int_Vrnds, IN_OTHER|OUT_OTHER|IS_VFPU|OUT_EAT_PREFIX), INSTR("vrndi", JITFUNC(Comp_Generic), Dis_VrndX, Int_VrndX, IN_OTHER|OUT_OTHER|IS_VFPU|OUT_EAT_PREFIX), @@ -578,7 +580,7 @@ static const MIPSInstruction tableVFPU7[32] = // 110100 00001 xxxxx . ....... . // 110100 00000 10100 0000000000000000 // 110100 00000 10111 0000000000000000 -static const MIPSInstruction tableVFPU4[32] = // 110100 00000 xxxxx . ....... . ....... +static MIPSInstruction tableVFPU4[32] = // 110100 00000 xxxxx . ....... . ....... { INSTR("vmov", JITFUNC(Comp_VV2Op), Dis_VectorSet2, Int_VV2Op, IN_OTHER|OUT_OTHER|IS_VFPU|OUT_EAT_PREFIX), INSTR("vabs", JITFUNC(Comp_VV2Op), Dis_VectorSet2, Int_VV2Op, IN_OTHER|OUT_OTHER|IS_VFPU|OUT_EAT_PREFIX), @@ -608,7 +610,7 @@ static const MIPSInstruction tableVFPU4[32] = // 110100 00000 xxxxx . ....... . INVALID, INVALID, INVALID, }; -static const MIPSInstruction tableVFPU5[8] = // 110111 xxx ....... ................ +static MIPSInstruction tableVFPU5[8] = // 110111 xxx ....... ................ { INSTR("vpfxs", JITFUNC(Comp_VPFX), Dis_VPFXST, Int_VPFX, IN_IMM16|OUT_OTHER|IS_VFPU), INSTR("vpfxs", JITFUNC(Comp_VPFX), Dis_VPFXST, Int_VPFX, IN_IMM16|OUT_OTHER|IS_VFPU), @@ -620,7 +622,7 @@ static const MIPSInstruction tableVFPU5[8] = // 110111 xxx ....... ............. INSTR("vfim.s", JITFUNC(Comp_Vfim), Dis_Viim, Int_Viim, IN_IMM16|OUT_OTHER|IS_VFPU|OUT_EAT_PREFIX), }; -static const MIPSInstruction tableVFPU6[32] = // 111100 xxxxx ..... . ....... . ....... +static MIPSInstruction tableVFPU6[32] = // 111100 xxxxx ..... . ....... . ....... { //0 INSTR("vmmul", JITFUNC(Comp_Vmmul), Dis_MatrixMult, Int_Vmmul, IN_OTHER|OUT_OTHER|IS_VFPU|OUT_EAT_PREFIX), @@ -665,7 +667,7 @@ static const MIPSInstruction tableVFPU6[32] = // 111100 xxxxx ..... . ....... . }; // TODO: Should this only be when bit 20 is 0? -static const MIPSInstruction tableVFPUMatrixSet1[16] = // 111100 11100 .xxxx . ....... . ....... (rm x is 16) +static MIPSInstruction tableVFPUMatrixSet1[16] = // 111100 11100 .xxxx . ....... . ....... (rm x is 16) { INSTR("vmmov", JITFUNC(Comp_Vmmov), Dis_MatrixSet2, Int_Vmmov, IN_OTHER|OUT_OTHER|IS_VFPU|OUT_EAT_PREFIX), INVALID, @@ -680,7 +682,7 @@ static const MIPSInstruction tableVFPUMatrixSet1[16] = // 111100 11100 .xxxx . . INVALID_X_8, }; -static const MIPSInstruction tableVFPU9[32] = // 110100 00010 xxxxx . ....... . ....... +static MIPSInstruction tableVFPU9[32] = // 110100 00010 xxxxx . ....... . ....... { INSTR("vsrt1", JITFUNC(Comp_Generic), Dis_Vbfy, Int_Vsrt1, IN_OTHER|OUT_OTHER|IS_VFPU|OUT_EAT_PREFIX), INSTR("vsrt2", JITFUNC(Comp_Generic), Dis_Vbfy, Int_Vsrt2, IN_OTHER|OUT_OTHER|IS_VFPU|OUT_EAT_PREFIX), @@ -720,7 +722,7 @@ static const MIPSInstruction tableVFPU9[32] = // 110100 00010 xxxxx . ....... . INVALID, INVALID, INVALID, INVALID, }; -static const MIPSInstruction tableALLEGREX0[32] = // 011111 ..... ..... ..... xxxxx 100000 - or ending with 011000? +static MIPSInstruction tableALLEGREX0[32] = // 011111 ..... ..... ..... xxxxx 100000 - or ending with 011000? { INVALID, INVALID, @@ -751,7 +753,7 @@ static const MIPSInstruction tableALLEGREX0[32] = // 011111 ..... ..... ..... x INVALID, }; -static const MIPSInstruction tableEMU[4] = { +static MIPSInstruction tableEMU[4] = { INSTR("RUNBLOCK", JITFUNC(Comp_RunBlock), Dis_Emuhack, Int_Emuhack, 0xFFFFFFFF), INSTR("RetKrnl", 0, Dis_Emuhack, Int_Emuhack, 0), INSTR("CallRepl", JITFUNC(Comp_ReplacementFunc), Dis_Emuhack, Int_Emuhack, 0), @@ -826,6 +828,7 @@ static const MIPSInstruction *mipsTables[NumEncodings] = { 0, }; + //arm encoding table //const MIPSInstruction mipsinstructions[] = //{ @@ -1079,3 +1082,37 @@ std::string MIPSDisasmAt(u32 compilerPC) { MIPSDisAsm(Memory::Read_Instruction(compilerPC), 0, temp, sizeof(temp)); return temp; } + + +namespace MIPSHooks { + void Init() { + MIPSNameLookupTable.RegisterInstructions(tableImmediate); + MIPSNameLookupTable.RegisterInstructions(tableSpecial); + MIPSNameLookupTable.RegisterInstructions(tableSpecial2); + MIPSNameLookupTable.RegisterInstructions(tableSpecial3); + MIPSNameLookupTable.RegisterInstructions(tableRegImm); + MIPSNameLookupTable.RegisterInstructions(tableCop0); + MIPSNameLookupTable.RegisterInstructions(tableCop0CO); + MIPSNameLookupTable.RegisterInstructions(tableCop1); + MIPSNameLookupTable.RegisterInstructions(tableCop1BC); + MIPSNameLookupTable.RegisterInstructions(tableCop1S); + MIPSNameLookupTable.RegisterInstructions(tableCop1W); + MIPSNameLookupTable.RegisterInstructions(tableCop2); + MIPSNameLookupTable.RegisterInstructions(tableCop2BC2); + + MIPSNameLookupTable.RegisterInstructions(tableVFPU0); + MIPSNameLookupTable.RegisterInstructions(tableVFPU1); + MIPSNameLookupTable.RegisterInstructions(tableVFPU3); + MIPSNameLookupTable.RegisterInstructions(tableVFPU4Jump); + MIPSNameLookupTable.RegisterInstructions(tableVFPU7); + MIPSNameLookupTable.RegisterInstructions(tableVFPU4); + MIPSNameLookupTable.RegisterInstructions(tableVFPU5); + MIPSNameLookupTable.RegisterInstructions(tableVFPU6); + MIPSNameLookupTable.RegisterInstructions(tableVFPUMatrixSet1); + MIPSNameLookupTable.RegisterInstructions(tableVFPU9); + MIPSNameLookupTable.RegisterInstructions(tableALLEGREX0); + + // I don't know if that's even helpful... + MIPSNameLookupTable.RegisterInstructions(tableEMU); + } +} diff --git a/Core/System.cpp b/Core/System.cpp index 8e800b747eeb..45dca78969b5 100644 --- a/Core/System.cpp +++ b/Core/System.cpp @@ -75,6 +75,8 @@ #include "GPU/Debugger/RecordFormat.h" #include "Core/RetroAchievements.h" +#include "Core/MIPS/MIPSHooks.h" + enum CPUThreadState { CPU_THREAD_NOT_RUNNING, CPU_THREAD_PENDING, @@ -323,6 +325,9 @@ bool CPU_Init(std::string *errorString, FileLoader *loadedFile) { CoreTiming::Init(); + // Prepare the MIPS hooks mapping (only needs to be run once) + MIPSHooks::Init(); + // Init all the HLE modules HLEInit(); From 0e9f7c41cc4d036371d1c2e31e830cf0a9ca5211 Mon Sep 17 00:00:00 2001 From: Nemoumbra Date: Fri, 9 Feb 2024 23:59:15 +0300 Subject: [PATCH 3/8] Added other platforms --- CMakeLists.txt | 2 ++ UWP/CoreUWP/CoreUWP.vcxproj | 2 ++ UWP/CoreUWP/CoreUWP.vcxproj.filters | 6 ++++++ android/jni/Android.mk | 1 + 4 files changed, 11 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index e60000d9521f..dede539d7ea6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2250,6 +2250,8 @@ add_library(${CoreLibName} ${CoreLinkType} Core/MIPS/MIPSStackWalk.h Core/MIPS/MIPSTables.cpp Core/MIPS/MIPSTables.h + Core/MIPS/MIPSHooks.cpp + Core/MIPS/MIPSHooks.h Core/MIPS/MIPSVFPUUtils.cpp Core/MIPS/MIPSVFPUUtils.h Core/MIPS/MIPSVFPUFallbacks.cpp diff --git a/UWP/CoreUWP/CoreUWP.vcxproj b/UWP/CoreUWP/CoreUWP.vcxproj index 207fa9ad799f..3495fe89d0b2 100644 --- a/UWP/CoreUWP/CoreUWP.vcxproj +++ b/UWP/CoreUWP/CoreUWP.vcxproj @@ -300,6 +300,7 @@ + @@ -575,6 +576,7 @@ + diff --git a/UWP/CoreUWP/CoreUWP.vcxproj.filters b/UWP/CoreUWP/CoreUWP.vcxproj.filters index 82bf9b68af8a..cbdb74176054 100644 --- a/UWP/CoreUWP/CoreUWP.vcxproj.filters +++ b/UWP/CoreUWP/CoreUWP.vcxproj.filters @@ -549,6 +549,9 @@ MIPS + + MIPS + MIPS @@ -1609,6 +1612,9 @@ MIPS + + MIPS + MIPS diff --git a/android/jni/Android.mk b/android/jni/Android.mk index e4e6838e7fcf..97134675757a 100644 --- a/android/jni/Android.mk +++ b/android/jni/Android.mk @@ -430,6 +430,7 @@ EXEC_AND_LIB_FILES := \ $(SRC)/Core/MIPS/MIPSIntVFPU.cpp.arm \ $(SRC)/Core/MIPS/MIPSStackWalk.cpp \ $(SRC)/Core/MIPS/MIPSTables.cpp \ + $(SRC)/Core/MIPS/MIPSHooks.cpp \ $(SRC)/Core/MIPS/MIPSVFPUUtils.cpp.arm \ $(SRC)/Core/MIPS/MIPSVFPUFallbacks.cpp.arm \ $(SRC)/Core/MIPS/MIPSCodeUtils.cpp.arm \ From 5957079eb7dedbbbde103e93917fe1ab281b5c61 Mon Sep 17 00:00:00 2001 From: Nemoumbra Date: Sat, 10 Feb 2024 00:03:20 +0300 Subject: [PATCH 4/8] CmakeLists.txt formatting --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index dede539d7ea6..0839ba5f7ae3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2251,7 +2251,7 @@ add_library(${CoreLibName} ${CoreLinkType} Core/MIPS/MIPSTables.cpp Core/MIPS/MIPSTables.h Core/MIPS/MIPSHooks.cpp - Core/MIPS/MIPSHooks.h + Core/MIPS/MIPSHooks.h Core/MIPS/MIPSVFPUUtils.cpp Core/MIPS/MIPSVFPUUtils.h Core/MIPS/MIPSVFPUFallbacks.cpp From 3039371ce5ba510ff9b4e0ff99b6f95af2351f26 Mon Sep 17 00:00:00 2001 From: Nemoumbra Date: Sat, 10 Feb 2024 14:45:39 +0300 Subject: [PATCH 5/8] Added logging to MIPSHooks --- Core/MIPS/MIPSHooks.cpp | 4 ++++ Core/MIPS/MIPSHooks.h | 7 ++++++- Core/MIPS/MIPSTables.cpp | 6 +++++- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/Core/MIPS/MIPSHooks.cpp b/Core/MIPS/MIPSHooks.cpp index 9904edb2658b..494dda1d26ef 100644 --- a/Core/MIPS/MIPSHooks.cpp +++ b/Core/MIPS/MIPSHooks.cpp @@ -27,8 +27,10 @@ static std::vector> stack; namespace MIPSHooks { void Reset() { + INFO_LOG(CPU, "Resetting the interpreter hooks"); for (auto&[instr, func] : stack) { instr->interpret = func; + VERBOSE_LOG(CPU, "Resetting %s", instr->name); } stack.clear(); } @@ -36,10 +38,12 @@ namespace MIPSHooks { void Hook(const char* name, MIPSInterpretFunc func) { auto current_handler = MIPSNameLookupTable.GetInstructionByName(name); if (!current_handler) { + WARN_LOG(CPU, "Cannot setup a hook: unknown instruction '%s'", name); return; } stack.emplace_back(current_handler, current_handler->interpret); current_handler->interpret = func; + INFO_LOG(CPU, "Enabled a hook for %s", name); } } diff --git a/Core/MIPS/MIPSHooks.h b/Core/MIPS/MIPSHooks.h index 27280608304d..b042acf9faa2 100644 --- a/Core/MIPS/MIPSHooks.h +++ b/Core/MIPS/MIPSHooks.h @@ -20,6 +20,7 @@ #include #include "Core/MIPS/MIPSTables.h" +#include "Common/Log.h" class MIPSNames { private: @@ -31,6 +32,7 @@ class MIPSNames { // register the name if it's valid if (table[i].name) { name_lookup_table.emplace(table[i].name, &table[i]); + VERBOSE_LOG(CPU, "Registered %s", table[i].name); } } } @@ -47,8 +49,11 @@ class MIPSNames { extern MIPSNames MIPSNameLookupTable; namespace MIPSHooks { - void Init(); // implemented in the MIPSTables.cpp + // Fills the MIPSNameLookupTable + void Init(); + // Disables the hooks void Reset(); + // Tries to register a hook void Hook(const char* name, MIPSInterpretFunc func); } diff --git a/Core/MIPS/MIPSTables.cpp b/Core/MIPS/MIPSTables.cpp index 0fa08432ad2b..62ce45a3b7a5 100644 --- a/Core/MIPS/MIPSTables.cpp +++ b/Core/MIPS/MIPSTables.cpp @@ -1086,6 +1086,8 @@ std::string MIPSDisasmAt(u32 compilerPC) { namespace MIPSHooks { void Init() { + VERBOSE_LOG(CPU, "Initalizing the MIPS name lookup table..."); + MIPSNameLookupTable.RegisterInstructions(tableImmediate); MIPSNameLookupTable.RegisterInstructions(tableSpecial); MIPSNameLookupTable.RegisterInstructions(tableSpecial2); @@ -1112,7 +1114,9 @@ namespace MIPSHooks { MIPSNameLookupTable.RegisterInstructions(tableVFPU9); MIPSNameLookupTable.RegisterInstructions(tableALLEGREX0); - // I don't know if that's even helpful... + // I don't know if that could be helpful, but why not? MIPSNameLookupTable.RegisterInstructions(tableEMU); + + INFO_LOG(CPU, "MIPS name lookup table initialized"); } } From 19de0eed90894127b2332937bc1955e444c49471 Mon Sep 17 00:00:00 2001 From: Nemoumbra Date: Sat, 10 Feb 2024 20:47:20 +0300 Subject: [PATCH 6/8] Buildfix: Include -> Compile --- UWP/CoreUWP/CoreUWP.vcxproj | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/UWP/CoreUWP/CoreUWP.vcxproj b/UWP/CoreUWP/CoreUWP.vcxproj index 3495fe89d0b2..321590f3bcc6 100644 --- a/UWP/CoreUWP/CoreUWP.vcxproj +++ b/UWP/CoreUWP/CoreUWP.vcxproj @@ -124,6 +124,7 @@ + @@ -375,6 +376,7 @@ + @@ -576,7 +578,7 @@ - + From babc25f727f3a24dbf1d348369b3a936f521165a Mon Sep 17 00:00:00 2001 From: Nemoumbra Date: Sat, 10 Feb 2024 20:56:19 +0300 Subject: [PATCH 7/8] Oops, wrong branch --- UWP/CoreUWP/CoreUWP.vcxproj | 2 -- 1 file changed, 2 deletions(-) diff --git a/UWP/CoreUWP/CoreUWP.vcxproj b/UWP/CoreUWP/CoreUWP.vcxproj index 321590f3bcc6..5e325e6d3798 100644 --- a/UWP/CoreUWP/CoreUWP.vcxproj +++ b/UWP/CoreUWP/CoreUWP.vcxproj @@ -124,7 +124,6 @@ - @@ -376,7 +375,6 @@ - From 84c98fd010f0eb0d6e83dde8c79c40c9ecffed38 Mon Sep 17 00:00:00 2001 From: Nemoumbra Date: Sat, 10 Feb 2024 20:59:31 +0300 Subject: [PATCH 8/8] Buildfix for the libretro --- libretro/Makefile.common | 1 + 1 file changed, 1 insertion(+) diff --git a/libretro/Makefile.common b/libretro/Makefile.common index 611be9130aa0..794c35a74b01 100644 --- a/libretro/Makefile.common +++ b/libretro/Makefile.common @@ -727,6 +727,7 @@ SOURCES_CXX += \ $(COREDIR)/MIPS/MIPSInt.cpp \ $(COREDIR)/MIPS/MIPSIntVFPU.cpp \ $(COREDIR)/MIPS/MIPSTables.cpp \ + $(COREDIR)/MIPS/MIPSHooks.cpp \ $(COREDIR)/MIPS/MIPSStackWalk.cpp \ $(COREDIR)/MIPS/MIPSVFPUUtils.cpp \ $(COREDIR)/MIPS/MIPSVFPUFallbacks.cpp \