From d9d967ab8e33ce499e27c2db46df64eee96e5738 Mon Sep 17 00:00:00 2001 From: johannst Date: Tue, 29 Sep 2020 00:53:37 +0200 Subject: add prologue/epilogue + minor fixes --- src/arch/x86_64.md | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'src/arch') diff --git a/src/arch/x86_64.md b/src/arch/x86_64.md index e2bb527..63bea81 100644 --- a/src/arch/x86_64.md +++ b/src/arch/x86_64.md @@ -93,7 +93,7 @@ mov qword ptr [rax], 0xff // save 8 byte(s) at [rax] ----------- xmm0 1 .. .. - xmm7 7 + xmm7 8 ``` - Additional arguments are passed on the stack. Arguments are pushed right-to-left (RTL), meaning next arguments are closer to current `rsp`. @@ -136,7 +136,7 @@ must must save these registers in case they are used. - grows downwards - frames aligned on 16 byte boundary ```text - HI ADDR + Hi ADDR | +------------+ | | prev frame | | +------------+ <--- 16 byte aligned (X & ~0xf) @@ -145,9 +145,22 @@ must must save these registers in case they are used. | [rbp-8] | func stack | | | ... | v +------------+ - LO ADDR + Lo ADDR ``` +### Function prologue & epilogue +- prologue + ```x86asm + push rbp // save caller base pointer + mov rbp, rsp // save caller stack pointer + ``` +- epilogue + ```x86asm + mov rsp, rbp // restore caller stack pointer + pop rbp // restore caller base pointer + ``` + > Equivalent to `leave` instruction. + ## ASM skeleton Small assembler skeleton, ready to use with following properties: - use raw Linux syscalls (`man 2 syscall` for ABI) -- cgit v1.2.3