From 7d1b7436d4c294f7ce0191291040e31160cceed9 Mon Sep 17 00:00:00 2001 From: Bananymous Date: Thu, 21 Mar 2024 15:20:20 +0200 Subject: [PATCH] LibC: Dummy ctr* files for i386 This allows compilation of libc for i386 targets --- libc/arch/i386/crt0.S | 33 +++++++++++++++++++++++++++++++++ libc/arch/i386/crti.S | 16 ++++++++++++++++ libc/arch/i386/crtn.S | 10 ++++++++++ 3 files changed, 59 insertions(+) create mode 100644 libc/arch/i386/crt0.S create mode 100644 libc/arch/i386/crti.S create mode 100644 libc/arch/i386/crtn.S diff --git a/libc/arch/i386/crt0.S b/libc/arch/i386/crt0.S new file mode 100644 index 00000000..66678945 --- /dev/null +++ b/libc/arch/i386/crt0.S @@ -0,0 +1,33 @@ +.section .text + +.global _start +_start: + # zero out stack frame + pushl $0 + pushl $0 + movl %esp, %ebp + + # FIXME: handle stack alignment + ud2 + + # push argc, argv, environ for call to main + pushl %edx + pushl %esi + pushl %edi + + # initialize libc + pushl %edx + call _init_libc + addl $4, %esp + + # call global constructos + call _init + + # call main, arguments are already on stack + call main + + # cleanly exit the process + pushl %eax + call exit + +.size _start, . - _start diff --git a/libc/arch/i386/crti.S b/libc/arch/i386/crti.S new file mode 100644 index 00000000..75175fd5 --- /dev/null +++ b/libc/arch/i386/crti.S @@ -0,0 +1,16 @@ +/* i386 crti.s */ +.section .init +.global _init +.type _init, @function +_init: + pushl %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: + pushl %ebp + movl %esp, %ebp + /* gcc will nicely put the contents of crtbegin.o's .fini section here. */ diff --git a/libc/arch/i386/crtn.S b/libc/arch/i386/crtn.S new file mode 100644 index 00000000..935c8d1b --- /dev/null +++ b/libc/arch/i386/crtn.S @@ -0,0 +1,10 @@ +/* i386 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