summaryrefslogtreecommitdiff
path: root/src/video_core/macro
diff options
context:
space:
mode:
authorGravatar Liam2022-05-08 02:48:03 -0400
committerGravatar Liam2022-05-08 02:48:03 -0400
commit7fe5004f9073b5d7a1bdd55e40b3ebf171a97afa (patch)
tree75bd2721685768cae3780cea0bc82df1c532ad81 /src/video_core/macro
parentMerge pull request #8300 from Morph1984/resultval-range (diff)
downloadyuzu-7fe5004f9073b5d7a1bdd55e40b3ebf171a97afa.tar.gz
yuzu-7fe5004f9073b5d7a1bdd55e40b3ebf171a97afa.tar.xz
yuzu-7fe5004f9073b5d7a1bdd55e40b3ebf171a97afa.zip
video_core/macro_jit_x64: warn on invalid parameter access
Diffstat (limited to 'src/video_core/macro')
-rw-r--r--src/video_core/macro/macro_jit_x64.cpp24
1 files changed, 21 insertions, 3 deletions
diff --git a/src/video_core/macro/macro_jit_x64.cpp b/src/video_core/macro/macro_jit_x64.cpp
index dc2b490d4..dc5376501 100644
--- a/src/video_core/macro/macro_jit_x64.cpp
+++ b/src/video_core/macro/macro_jit_x64.cpp
@@ -23,7 +23,8 @@ MICROPROFILE_DEFINE(MacroJitExecute, "GPU", "Execute macro JIT", MP_RGB(255, 255
23namespace Tegra { 23namespace Tegra {
24namespace { 24namespace {
25constexpr Xbyak::Reg64 STATE = Xbyak::util::rbx; 25constexpr Xbyak::Reg64 STATE = Xbyak::util::rbx;
26constexpr Xbyak::Reg32 RESULT = Xbyak::util::ebp; 26constexpr Xbyak::Reg32 RESULT = Xbyak::util::r10d;
27constexpr Xbyak::Reg64 MAX_PARAMETER = Xbyak::util::r11;
27constexpr Xbyak::Reg64 PARAMETERS = Xbyak::util::r12; 28constexpr Xbyak::Reg64 PARAMETERS = Xbyak::util::r12;
28constexpr Xbyak::Reg32 METHOD_ADDRESS = Xbyak::util::r14d; 29constexpr Xbyak::Reg32 METHOD_ADDRESS = Xbyak::util::r14d;
29constexpr Xbyak::Reg64 BRANCH_HOLDER = Xbyak::util::r15; 30constexpr Xbyak::Reg64 BRANCH_HOLDER = Xbyak::util::r15;
@@ -31,6 +32,7 @@ constexpr Xbyak::Reg64 BRANCH_HOLDER = Xbyak::util::r15;
31constexpr std::bitset<32> PERSISTENT_REGISTERS = Common::X64::BuildRegSet({ 32constexpr std::bitset<32> PERSISTENT_REGISTERS = Common::X64::BuildRegSet({
32 STATE, 33 STATE,
33 RESULT, 34 RESULT,
35 MAX_PARAMETER,
34 PARAMETERS, 36 PARAMETERS,
35 METHOD_ADDRESS, 37 METHOD_ADDRESS,
36 BRANCH_HOLDER, 38 BRANCH_HOLDER,
@@ -80,7 +82,7 @@ private:
80 u32 carry_flag{}; 82 u32 carry_flag{};
81 }; 83 };
82 static_assert(offsetof(JITState, maxwell3d) == 0, "Maxwell3D is not at 0x0"); 84 static_assert(offsetof(JITState, maxwell3d) == 0, "Maxwell3D is not at 0x0");
83 using ProgramType = void (*)(JITState*, const u32*); 85 using ProgramType = void (*)(JITState*, const u32*, const u32*);
84 86
85 struct OptimizerState { 87 struct OptimizerState {
86 bool can_skip_carry{}; 88 bool can_skip_carry{};
@@ -112,7 +114,7 @@ void MacroJITx64Impl::Execute(const std::vector<u32>& parameters, u32 method) {
112 JITState state{}; 114 JITState state{};
113 state.maxwell3d = &maxwell3d; 115 state.maxwell3d = &maxwell3d;
114 state.registers = {}; 116 state.registers = {};
115 program(&state, parameters.data()); 117 program(&state, parameters.data(), parameters.data() + parameters.size());
116} 118}
117 119
118void MacroJITx64Impl::Compile_ALU(Macro::Opcode opcode) { 120void MacroJITx64Impl::Compile_ALU(Macro::Opcode opcode) {
@@ -488,6 +490,7 @@ void MacroJITx64Impl::Compile() {
488 // JIT state 490 // JIT state
489 mov(STATE, Common::X64::ABI_PARAM1); 491 mov(STATE, Common::X64::ABI_PARAM1);
490 mov(PARAMETERS, Common::X64::ABI_PARAM2); 492 mov(PARAMETERS, Common::X64::ABI_PARAM2);
493 mov(MAX_PARAMETER, Common::X64::ABI_PARAM3);
491 xor_(RESULT, RESULT); 494 xor_(RESULT, RESULT);
492 xor_(METHOD_ADDRESS, METHOD_ADDRESS); 495 xor_(METHOD_ADDRESS, METHOD_ADDRESS);
493 xor_(BRANCH_HOLDER, BRANCH_HOLDER); 496 xor_(BRANCH_HOLDER, BRANCH_HOLDER);
@@ -598,7 +601,22 @@ bool MacroJITx64Impl::Compile_NextInstruction() {
598 return true; 601 return true;
599} 602}
600 603
604static void WarnInvalidParameter(uintptr_t parameter, uintptr_t max_parameter) {
605 LOG_CRITICAL(HW_GPU,
606 "Macro JIT: invalid parameter access 0x{:x} (0x{:x} is the last parameter)",
607 parameter, max_parameter - sizeof(u32));
608}
609
601Xbyak::Reg32 MacroJITx64Impl::Compile_FetchParameter() { 610Xbyak::Reg32 MacroJITx64Impl::Compile_FetchParameter() {
611 Xbyak::Label parameter_ok{};
612 cmp(PARAMETERS, MAX_PARAMETER);
613 jb(parameter_ok, T_NEAR);
614 Common::X64::ABI_PushRegistersAndAdjustStack(*this, PersistentCallerSavedRegs(), 0);
615 mov(Common::X64::ABI_PARAM1, PARAMETERS);
616 mov(Common::X64::ABI_PARAM2, MAX_PARAMETER);
617 Common::X64::CallFarFunction(*this, &WarnInvalidParameter);
618 Common::X64::ABI_PopRegistersAndAdjustStack(*this, PersistentCallerSavedRegs(), 0);
619 L(parameter_ok);
602 mov(eax, dword[PARAMETERS]); 620 mov(eax, dword[PARAMETERS]);
603 add(PARAMETERS, sizeof(u32)); 621 add(PARAMETERS, sizeof(u32));
604 return eax; 622 return eax;