minix/lib/csu/i386/crtso.S
Arun Thomas 2a8fabf4ad Include directory reorg and makefile updates.
-Convert the include directory over to using bsdmake
 syntax
-Update/add mkfiles
-Modify install(1) so that it can create symlinks
-Update makefiles to use new install(1) options
-Rename /usr/include/ibm to /usr/include/i386
-Create /usr/include/machine symlink to arch header files
-Move vm_i386.h to its new home in the /usr/include/i386
-Update source files to #include the header files at their
 new homes.
-Add new gnu-includes target for building GCC headers
2010-03-08 11:04:59 +00:00

121 lines
2.7 KiB
ArmAsm

/* This is the C run-time start-off routine. It's job is to take the */
/* arguments as put on the stack by EXEC, and to parse them and set them up the */
/* way _main expects them. */
/* It also initializes environ when this variable isn't defined by the */
/* programmer. The detection of whether environ belong to us is rather */
/* simplistic. We simply check for some magic value, but there is no other */
/* way. */
#include <machine/vm.h>
.globl begtext, begdata, begbss
.text
begtext:
#ifdef __ACK__
.rom
#else
.data
#endif
begrom:
.data
begdata:
.bss
begbss:
.globl crtso, __penviron, __penvp, __fpu_present
.globl __minix_datastart, __minix_mainjump, __minix_unmapzero
.extern _main, _exit
#if defined(__ELF__)
.section .init
#else
.text
#endif
#if defined(__ELF__)
.globl __start
__start:
#endif
crtso:
xorl %ebp, %ebp /* clear for backtrace of core files */
movl (%esp), %eax /* argc */
leal 4(%esp), %edx /* argv */
leal 8(%esp,%eax,4), %ecx /* envp */
/* Test if environ is in the initialized data area and is set to our */
/* magic number. If so then it is not redefined by the user. */
movl $_environ, %ebx
cmpl $__edata, %ebx /* within initialized data? */
jae 0f
testb $3, %bl /* aligned? */
jne 0f
cmpl $0x53535353, (%ebx) /* is it our environ? */
jne 0f
movl %ebx, __penviron /* _penviron = &environ; */
0:
movl __penviron, %ebx
movl %ecx, (%ebx) /* *_penviron = envp; */
push %ecx /* push envp */
push %edx /* push argv */
push %eax /* push argc */
/* Test the EM bit of the MSW to determine if an FPU is present and */
/* set __fpu_present if one is found. */
smsw %ax
testb $0x4, %al /* EM bit in MSW */
sete __fpu_present /* True if not set */
jmp __minix_mainjump
.balign I386_PAGE_SIZE
__minix_mainjump:
/* unmap zero pages */
call __minix_unmapzero
call _main /* main(argc, argv, envp) */
push %eax /* push exit status */
call _exit
hlt /* force a trap if exit fails */
__minix_unmapzero:
/* unmap 0-page code */
push $I386_PAGE_SIZE
push $crtso
call _munmap_text /* unmap_text(crtso, I386_PAGE_SIZE) */
add $8, %esp
#ifdef __ACK__
/*
* ack uses separate segments for text and data by default. We have a
* common segment when compiling using any other compiler
*/
/* unmap 0-page data */
push $I386_PAGE_SIZE
push $romstart
call _munmap /* munmap(romstart, I386_PAGE_SIZE) */
add $8, %esp
#endif
ret
#ifdef __ACK__
.rom
romstart:
.space I386_PAGE_SIZE
__minix_datastart:
.space 4
#endif
.data
__penviron:
.long __penvp /* Pointer to environ, or hidden pointer */
.bss
.lcomm __penvp, 4 /* Hidden environment vector */
.lcomm __fpu_present, 4 /* FPU present flag */
.extern endtext /* Force loading of end labels. */