diff --git a/libc/arch/i386/crt0.S b/libc/arch/i386/crt0.S new file mode 100644 index 0000000000..6667894507 --- /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 0000000000..75175fd594 --- /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 0000000000..935c8d1b82 --- /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