2000-02-01 Andreas Jaeger <aj@suse.de>

* sysdeps/mips/elf/start.S: Rewritten for __libc_start_main.
This commit is contained in:
Andreas Jaeger 2000-02-01 08:28:15 +00:00
parent 16e4bf6fec
commit fc16ca3254

View File

@ -1,5 +1,5 @@
/* Startup code compliant to the ELF Mips ABI.
Copyright (C) 1995, 1997 Free Software Foundation, Inc.
Copyright (C) 1995, 1997, 2000 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@ -45,6 +45,12 @@
stack frame.
*/
/* We need to call:
__libc_start_main (int (*main) (int, char **, char **), int argc,
char **argv, void (*init) (void), void (*fini) (void),
void (*rtld_fini) (void), void *stack_end)
*/
#ifdef PIC
/* A macro to (re)initialize gp. We can get the run time address of 0f in
ra ($31) by blezal instruction. In this early phase, we can't save gp
@ -66,84 +72,28 @@ ENTRY_POINT:
#endif
move $31, $0
/* $2 contains the address of the shared library termination
function, which we will register with `atexit' to be called by
`exit'. I suspect that on some systems, and when statically
linked, this will not be set by anything to any function
pointer; hopefully it will be zero so we don't try to call
random pointers. */
beq $2, $0, nofini
move $4, $2
jal atexit
#ifdef PIC
SET_GP
#endif
nofini:
/* Do essential libc initialization. In statically linked
programs under the GNU Hurd, this is what sets up the
arguments on the stack for the code below. Since the argument
registers (a0 - a3) saved to the first 4 stack entries by
the prologue of __libc_init_first, we preload them to
prevent clobbering the stack tops. In Hurd case, stack pointer
($29) may be VM_MAX_ADDRESS here. If so, we must modify it. */
#if 0
jal mach_host_self
#endif
li $4, 0x80000000
bne $29, $4, 1f
subu $29, 16
sw $0, 0($29)
sw $0, 4($29)
sw $0, 8($29)
sw $0, 12($29)
1:
lw $4, 0($29)
lw $5, 4($29)
lw $6, 8($29)
lw $7, 12($29)
jal __libc_init_first
#ifdef PIC
SET_GP
#endif
lw $4, 0($29)
lw $5, 4($29)
lw $6, 8($29)
lw $7, 12($29)
/* Call `_init', which is the entry point to our own `.init'
section; and register with `atexit' to have `exit' call
`_fini', which is the entry point to our own `.fini' section. */
jal _init
#ifdef PIC
SET_GP
#endif
#if (__mips64)
dla $4, _fini
#else /* __mips64 */
la $4, _fini
#endif /* __mips64 */
jal atexit
#ifdef PIC
SET_GP
dla $4, main /* main */
lw $5, 0($29) /* argc */
addu $6, $29, 4 /* argv */
/* Allocate space on the stack for seven arguments but align to 32. */
subu $29, 32
dla $7, _init /* init */
dla $8, _fini
#else
la $4, main /* main */
lw $5, 0($29) /* argc */
addu $6, $29, 4 /* argv */
/* Allocate space on the stack for seven arguments but align to 32. */
subu $29, 32
la $7, _init /* init */
la $8, _fini
#endif
sw $8, 16($29) /* fini */
sw $2, 20($29) /* rtld_fini */
sw $29, 24($29) /* stack_end */
jal __libc_start_main
/* Extract the arguments and environment as encoded on the stack
and set up the arguments for `main': argc, argv, envp. */
lw $4, 0($29) /* argc */
addu $5, $29, 4 /* argv */
sll $6, $4, 2
addu $6, $6, 4
addu $6, $5, $6 /* envp = &argv[argc + 1] */
/* Call the user's main function, and exit with its value. */
jal main
#ifdef PIC
SET_GP
#endif
move $4, $2
jal exit /* This should never return. */
hlt: b hlt /* Crash if somehow it does return. */
/* Define a symbol for the first piece of initialized data. */
@ -153,8 +103,3 @@ __data_start:
.long 0
.weak data_start
data_start = __data_start
.comm errno, 4, 4
#ifdef __ELF__
.type errno, @object
#endif