1 /* Startup code compliant to the ELF Mips ABI.
2 Copyright (C) 1995, 1997, 2000, 2001 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20 #define __ASSEMBLY__ 1
24 #error ENTRY_POINT needs to be defined for start.S on MIPS/ELF.
27 /* This is the canonical entry point, usually the first thing in the text
28 segment. The SVR4/Mips ABI (pages 3-31, 3-32) says that when the entry
29 point runs, most registers' values are unspecified, except for:
31 v0 ($2) Contains a function pointer to be registered with `atexit'.
32 This is how the dynamic linker arranges to have DT_FINI
33 functions called for shared libraries that have been loaded
34 before this code runs.
36 sp ($29) The stack contains the arguments and environment:
41 (4*(argc+1))(%esp) envp[0]
44 ra ($31) The return address register is set to zero so that programs
45 that search backword through stack frames recognize the last
51 __libc_start_main (int (*main) (int, char **, char **), int argc,
52 char **argv, void (*init) (void), void (*fini) (void),
53 void (*rtld_fini) (void), void *stack_end)
56 /* A macro to (re)initialize gp. We can get the run time address of 0f in
57 ra ($31) by blezal instruction. In this early phase, we can't save gp
58 in stack and .cprestore doesn't work properly. So we set gp by using
70 .type ENTRY_POINT,@function
77 la $4, main /* main */
78 lw $5, 0($29) /* argc */
79 addu $6, $29, 4 /* argv */
80 /* Allocate space on the stack for seven arguments and make sure
81 the stack is aligned to double words (8 bytes). */
84 la $7, _init /* init */
86 sw $8, 16($29) /* fini */
87 sw $2, 20($29) /* rtld_fini */
88 sw $29, 24($29) /* stack_end */
90 hlt: b hlt /* Crash if somehow it does return. */
92 /* Define a symbol for the first piece of initialized data. */
98 data_start = __data_start