From fd8517e10937a5b72ed839ce900306f281d74b7d Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Sun, 22 Nov 2020 14:09:58 +0100 Subject: Fix frame pointer - pop was too early --- asm/intel64/encode.cpp | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) (limited to 'asm') diff --git a/asm/intel64/encode.cpp b/asm/intel64/encode.cpp index a51854a..1cc1a6d 100644 --- a/asm/intel64/encode.cpp +++ b/asm/intel64/encode.cpp @@ -214,22 +214,16 @@ void Asm::toMachineCode(const FlowGraph::Graph& graph, Segment& segment) segment.push_back(makeOp("mov", Asm::Args{{Asm::Args::Register64("rbp"), Asm::Args::Register64("rsp")}})); } else if (typeid(node_deref) == typeid(FlowGraph::DestroyScopeOp)) { - //FlowGraph::DestroyScopeOp& op {dynamic_cast(*node)}; // TODO: Destroy stack frame - segment.push_back(makeOp("pop", Asm::Args{{Asm::Args::Register64("rbp")}})); segment.push_back(makeLoadValue(graph.lastOp()->destination(), graph)); // TODO: Just get last operation result to eax for now segment.push_back(makeOp("xor", Asm::Args{{Asm::Args::Register64("rdi"), Asm::Args::Register64("rdi")}})); segment.push_back(makeOp("mov", Asm::Args{{Asm::Args::Register32("edi"), Asm::Args::Register32("eax")}})); -#if 0 - segment.push_back(makeOp("xor", Asm::Args{{Asm::Args::Register64("rbp"), Asm::Args::Register64("rbp")}})); - segment.push_back(makeOp("dec", Asm::Args{{Asm::Args::Register64("rbp")}})); - segment.push_back(makeOp("mov", Asm::Args{{Asm::Args::Mem32Ptr64("rbp", -4), Asm::Args::Immediate32(3)}})); - segment.push_back(makeOp("mov", Asm::Args{{Asm::Args::Register32("edi"), Asm::Args::Mem32Ptr64("rbp", -4)}})); - //segment.push_back(makeOp("mov", Asm::Args{{Asm::Args::Register32("edi"), Asm::Args::Immediate32(3)}})); -#endif - segment.push_back(makeOp("mov", Asm::Args{{Asm::Args::Register64("rax"), Asm::Args::Immediate32(60)}})); // syscall 60: exit() + + //FlowGraph::DestroyScopeOp& op {dynamic_cast(*node)}; // TODO: Destroy stack frame + segment.push_back(makeOp("pop", Asm::Args{{Asm::Args::Register64("rbp")}})); + segment.push_back(makeOp("syscall")); // rax: #syscall, rdi: exit code value } else if (typeid(node_deref) == typeid(FlowGraph::DataNode)) { // ignore: Immediate data is used in subsequent nodes -- cgit v1.2.3