From a914c37365967afaf3148293a857c36af6f94ecb Mon Sep 17 00:00:00 2001 From: Aleksa Vučković Date: Fri, 21 Jan 2022 21:44:28 +0100 Subject: Separating assembly, moving #defines to .h & cleaning Makefile --- src/crt/crt0.s | 31 +++++++++++++++++++++++++++++++ src/crt/crti.s | 16 ++++++++++++++++ src/crt/crtn.s | 10 ++++++++++ 3 files changed, 57 insertions(+) create mode 100644 src/crt/crt0.s create mode 100644 src/crt/crti.s create mode 100644 src/crt/crtn.s (limited to 'src/crt') 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 diff --git a/src/crt/crti.s b/src/crt/crti.s new file mode 100644 index 0000000..5894e2d --- /dev/null +++ b/src/crt/crti.s @@ -0,0 +1,16 @@ +/* x86 crti.s */ +.section .init +.global _init +.type _init, @function +_init: + push %ebp + movl %esp, %ebp + /* gcc will nicely put the contents of crtbegin.o's .init section here. */ + +.section .fini +.global _fini +.type _fini, @function +_fini: + push %ebp + movl %esp, %ebp + /* gcc will nicely put the contents of crtbegin.o's .fini section here. */ diff --git a/src/crt/crtn.s b/src/crt/crtn.s new file mode 100644 index 0000000..0e1c314 --- /dev/null +++ b/src/crt/crtn.s @@ -0,0 +1,10 @@ +/* x86 crtn.s */ +.section .init + /* gcc will nicely put the contents of crtend.o's .init section here. */ + popl %ebp + ret + +.section .fini + /* gcc will nicely put the contents of crtend.o's .fini section here. */ + popl %ebp + ret -- cgit v1.2.3