commit 8e5823ad966f37c2f05c5648b95b79de82739700 Author: g1n Date: Mon Aug 2 18:57:15 2021 +0300 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5761abc --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.o diff --git a/x86_64/crt0.s b/x86_64/crt0.s new file mode 100644 index 0000000..bdc038e --- /dev/null +++ b/x86_64/crt0.s @@ -0,0 +1,31 @@ +.section .text + +.global _start +_start: + # Set up end of the stack frame linked list. + movq $0, %rbp + pushq %rbp # rip=0 + pushq %rbp # rbp=0 + movq %rsp, %rbp + + # We need those in a moment when we call main. + pushq %rsi + pushq %rdi + + # Prepare signals, memory allocation, stdio and such. + call initialize_standard_library + + # Run the global constructors. + call _init + + # Restore argc and argv. + popq %rdi + popq %rsi + + # Run main + call main + + # Terminate the process with the exit code. + movl %eax, %edi + call exit +.size _start, . - _start diff --git a/x86_64/crti.s b/x86_64/crti.s new file mode 100644 index 0000000..03ad2f9 --- /dev/null +++ b/x86_64/crti.s @@ -0,0 +1,13 @@ +.section .init +.global _init +_init: + push %rbp + movq %rsp, %rbp + /* gcc will nicely put the contents of crtbegin.o's .init section here. */ + +.section .fini +.global _fini +_fini: + push %rbp + movq %rsp, %rbp + /* gcc will nicely put the contents of crtbegin.o's .fini section here. */ diff --git a/x86_64/crtn.s b/x86_64/crtn.s new file mode 100644 index 0000000..762c7f6 --- /dev/null +++ b/x86_64/crtn.s @@ -0,0 +1,9 @@ +.section .init + /* gcc will nicely put the contents of crtend.o's .init section here. */ + popq %rbp + ret + +.section .fini + /* gcc will nicely put the contents of crtend.o's .fini section here. */ + popq %rbp + ret