From 3f06f3e87dd11db89157b24b2d2b013aa8208fd2 Mon Sep 17 00:00:00 2001 From: Ryan Houdek Date: Sun, 17 Nov 2019 17:03:23 -0800 Subject: [PATCH] Fixes bug in PUSH op with RSP source. We were modifying RSP to adjust the stack first. Then if the source used RSP then it was offset by the store size. `push [rsp]` was broken before this --- Source/Interface/Core/OpcodeDispatcher.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Source/Interface/Core/OpcodeDispatcher.cpp b/Source/Interface/Core/OpcodeDispatcher.cpp index 2c9e6a31d..663668f6c 100644 --- a/Source/Interface/Core/OpcodeDispatcher.cpp +++ b/Source/Interface/Core/OpcodeDispatcher.cpp @@ -193,15 +193,6 @@ void OpDispatchBuilder::SBBOp(OpcodeArgs) { void OpDispatchBuilder::PUSHOp(OpcodeArgs) { uint8_t Size = GetSrcSize(Op); - auto Constant = _Constant(Size); - - auto OldSP = _LoadContext(8, offsetof(FEXCore::Core::CPUState, gregs[FEXCore::X86State::REG_RSP])); - - auto NewSP = _Sub(OldSP, Constant); - - // Store the new stack pointer - _StoreContext(8, offsetof(FEXCore::Core::CPUState, gregs[FEXCore::X86State::REG_RSP]), NewSP); - OrderedNode *Src; if (Op->OP == 0x68 || Op->OP == 0x6A) { // Immediate Push Src = LoadSource(Op, Op->Src1, Op->Flags, -1); @@ -211,6 +202,15 @@ void OpDispatchBuilder::PUSHOp(OpcodeArgs) { Src = LoadSource(Op, Op->Dest, Op->Flags, -1); } + auto Constant = _Constant(Size); + + auto OldSP = _LoadContext(8, offsetof(FEXCore::Core::CPUState, gregs[FEXCore::X86State::REG_RSP])); + + auto NewSP = _Sub(OldSP, Constant); + + // Store the new stack pointer + _StoreContext(8, offsetof(FEXCore::Core::CPUState, gregs[FEXCore::X86State::REG_RSP]), NewSP); + // Store our value to the new stack location _StoreMem(Size, NewSP, Src, Size); }