aboutsummaryrefslogtreecommitdiff
path: root/02_process_init/entry.S
diff options
context:
space:
mode:
authorjohannst <johannes.stoelp@gmail.com>2020-11-24 21:23:08 +0100
committerjohannst <johannes.stoelp@gmail.com>2020-11-24 21:23:08 +0100
commitf9f2b6bb2d685556bc3346ca3f7e55f4c865fc16 (patch)
tree3ed8ac66323b6985713427d147826c5845212c13 /02_process_init/entry.S
parentf9e7e2003266e70c0d018f5712c431d187159e65 (diff)
downloaddynld-f9f2b6bb2d685556bc3346ca3f7e55f4c865fc16.tar.gz
dynld-f9f2b6bb2d685556bc3346ca3f7e55f4c865fc16.zip
add process init chapter
Add chapter on process initialization. Add program to visualize data provided by the Linux Kernel as specified in the SysV ABI. Add utils for syscalls and printing + tests.
Diffstat (limited to '02_process_init/entry.S')
-rw-r--r--02_process_init/entry.S27
1 files changed, 27 insertions, 0 deletions
diff --git a/02_process_init/entry.S b/02_process_init/entry.S
new file mode 100644
index 0000000..50425ba
--- /dev/null
+++ b/02_process_init/entry.S
@@ -0,0 +1,27 @@
+// Copyright (c) 2020 Johannes Stoelp
+
+#include <asm/unistd.h>
+
+.intel_syntax noprefix
+
+.section .text, "ax", @progbits
+.global _start
+_start:
+ // $rsp is guaranteed to be 16-byte aligned.
+
+ // Clear $rbp as specified by the SysV AMD64 ABI.
+ xor rbp, rbp
+
+ // Load pointer to process context prepared by execve(2) syscall as
+ // specified in the SysV AMD64 ABI.
+ // Save pointer in $rdi which is the arg0 (int/ptr) register.
+ lea rdi, [rsp]
+
+ // Stack frames must be 16-byte aligned before control is transfered to the
+ // callees entry point.
+ call entry
+
+ // Call exit(0) syscall.
+ mov rdi, 0
+ mov rax, __NR_exit
+ syscall