summaryrefslogtreecommitdiff
path: root/src/crt/crt0.s
diff options
context:
space:
mode:
authorAleksa Vučković <aleksav013@gmail.com>2022-01-21 21:44:28 +0100
committerAleksa Vučković <aleksav013@gmail.com>2022-01-21 23:24:55 +0100
commita914c37365967afaf3148293a857c36af6f94ecb (patch)
treeb7086b0b0b6e4bf427210fcfd31c7745920a73a5 /src/crt/crt0.s
parented84017353c6fc9421b223ff6ec62f8d881d8098 (diff)
Separating assembly, moving #defines to .h & cleaning Makefile
Diffstat (limited to 'src/crt/crt0.s')
-rw-r--r--src/crt/crt0.s31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/crt/crt0.s b/src/crt/crt0.s
new file mode 100644
index 0000000..8c735f1
--- /dev/null
+++ b/src/crt/crt0.s
@@ -0,0 +1,31 @@
+.section .text
+
+.global _start
+_start:
+ # Set up end of the stack frame linked list.
+ movl $0, %ebp
+ pushl %ebp # rip=0
+ pushl %ebp # rbp=0
+ movl %esp, %ebp
+
+ # We need those in a moment when we call main.
+ pushl %esi
+ pushl %edi
+
+ # Prepare signals, memory allocation, stdio and such.
+# call initialize_standard_library
+
+ # Run the global constructors.
+ call _init
+
+ # Restore argc and argv.
+ popl %edi
+ popl %esi
+
+ # Run main
+ call main
+
+ # Terminate the process with the exit code.
+ movl %eax, %edi
+# call exit
+.size _start, . - _start