Kernel/LibC: Add crt* files to LibC and remove crt0 from kernel

There was no reason for libc get crt0 from kernel.
This commit is contained in:
2023-10-30 11:06:13 +02:00
parent f33c0bad99
commit 0b5fcb3f88
5 changed files with 49 additions and 19 deletions

35
libc/arch/x86_64/crt0.S Normal file
View File

@@ -0,0 +1,35 @@
.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
# Save argc, argv, environ
pushq %rdx
pushq %rsi
pushq %rdi
# Prepare malloc, environment
movq %rdx, %rdi
call _init_libc
# Call global constructos
call _init
# Restore argc, argv, environ
popq %rdi
popq %rsi
popq %rdx
# Run main
call main
# Cleanly exit the process
movl %eax, %edi
call exit
.size _start, . - _start

16
libc/arch/x86_64/crti.S Normal file
View File

@@ -0,0 +1,16 @@
/* x86-64 crti.s */
.section .init
.global _init
.type _init, @function
_init:
pushq %rbp
movq %rsp, %rbp
/* gcc will nicely put the contents of crtbegin.o's .init section here. */
.section .fini
.global _fini
.type _fini, @function
_fini:
pushq %rbp
movq %rsp, %rbp
/* gcc will nicely put the contents of crtbegin.o's .fini section here. */

10
libc/arch/x86_64/crtn.S Normal file
View File

@@ -0,0 +1,10 @@
/* x86-64 crtn.s */
.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