aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorjohannst <johannes.stoelp@gmail.com>2020-09-29 00:53:37 +0200
committerjohannst <johannes.stoelp@gmail.com>2020-09-29 00:53:37 +0200
commitd9d967ab8e33ce499e27c2db46df64eee96e5738 (patch)
tree208d2abf2ce2aa1ed51e9240fb1218e6665b172f
parentfa9002a374541675d36f861232ae868b095722b3 (diff)
downloadnotes-d9d967ab8e33ce499e27c2db46df64eee96e5738.tar.gz
notes-d9d967ab8e33ce499e27c2db46df64eee96e5738.zip
add prologue/epilogue + minor fixes
-rw-r--r--src/arch/x86_64.md19
1 files changed, 16 insertions, 3 deletions
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)