1 /* Startup code compliant to the ELF Mips ABI.
2 Copyright (C) 1995, 1997 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 Library General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 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 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with the GNU C Library; see the file COPYING.LIB. If not,
17 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. */
20 /* This is the canonical entry point, usually the first thing in the text
21 segment. The SVR4/Mips ABI (pages 3-31, 3-32) says that when the entry
22 point runs, most registers' values are unspecified, except for:
24 v1 ($2) Contains a function pointer to be registered with `atexit'.
25 This is how the dynamic linker arranges to have DT_FINI
26 functions called for shared libraries that have been loaded
27 before this code runs.
29 sp ($29) The stack contains the arguments and environment:
34 (4*(argc+1))(%esp) envp[0]
37 ra ($31) The return address register is set to zero so that programs
38 that search backword through stack frames recognize the last
43 /* A macro to (re)initialize gp. We can get the run time address of 0f in
44 ra ($31) by blezal instruction. In this early phase, we can't save gp
45 in stack and .cprestore doesn't work properly. So we set gp by using
63 /* $2 contains the address of the shared library termination
64 function, which we will register with `atexit' to be called by
65 `exit'. I suspect that on some systems, and when statically
66 linked, this will not be set by anything to any function
67 pointer; hopefully it will be zero so we don't try to call
77 /* Do essential libc initialization. In statically linked
78 programs under the GNU Hurd, this is what sets up the
79 arguments on the stack for the code below. Since the argument
80 registers (a0 - a3) saved to the first 4 stack entries by
81 the prologue of __libc_init_first, we preload them to
82 prevent clobbering the stack tops. In Hurd case, stack pointer
83 ($29) may be VM_MAX_ADDRESS here. If so, we must modify it. */
110 #endif /* __mips64 */
112 jal __libc_init_first
126 #endif /* __mips64 */
128 /* Call `_init', which is the entry point to our own `.init'
129 section; and register with `atexit' to have `exit' call
130 `_fini', which is the entry point to our own `.fini' section. */
139 #endif /* __mips64 */
146 /* Extract the arguments and environment as encoded on the stack
147 and set up the arguments for `main': argc, argv, envp. */
149 ld $4, 0($29) /* argc */
150 daddu $5, $29, 8 /* argv */
153 daddu $6, $5, $6 /* envp = &argv[argc + 1] */
155 lw $4, 0($29) /* argc */
156 addu $5, $29, 4 /* argv */
159 addu $6, $5, $6 /* envp = &argv[argc + 1] */
160 #endif /* __mips64 */
162 /* Call the user's main function, and exit with its value. */
168 jal exit /* This should never return. */
169 hlt: b hlt /* Crash if somehow it does return. */
171 /* Define a symbol for the first piece of initialized data. */
179 #endif /* __mips64 */
181 data_start = __data_start