1 /* Startup code compliant to the ELF SPARC ABI.
2 Copyright (C) 1996, 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/SPARC ABI (NOTE: I don't actually have it) says that
22 when the entry point runs, most registers' values are unspecified,
25 %g1 Contains a function pointer to be registered with `atexit'.
26 This is how the dynamic linker arranges to have DT_FINI
27 functions called for shared libraries that have been loaded
28 before this code runs.
30 %sp The stack contains the arguments and environment:
35 (4*(argc+1))(%sp) envp[0]
44 /* %g1 contains the address of the shared library termination
45 function, which we will register with `atexit' to be called by
46 `exit'. I suspect that on some systems, and when statically
47 linked, this will not be set by anything to any function
48 pointer; hopefully it will be zero so we don't try to call
50 orcc %g1, %g0, %o0 /* Move %g1 to %o0 while testing it. */
53 /* In delay slot: clear the frame pointer. The ABI suggests this
54 be done, to mark the outermost frame obviously. */
57 /* Call atexit, argument was set in %o0 above. */
62 /* We will use some local variables in registers below. %g1 and
63 the %oN registers are call-clobbered, so we can't just use them. */
69 /* Do essential libc initialization. In statically linked
70 programs under the GNU Hurd, this is what sets up the
71 arguments on the stack for the code below. */
72 call __libc_init_first
73 sethi %hi(_environ), TMP /* In delay slot: prepare to use &_environ. */
75 /* Extract the arguments and environment as encoded on the stack
76 and save them in local variables. */
77 ld [%sp + 64], ARGC /* After the register save area, ARGC. */
78 add %sp, 64+4, ARGV /* Next, the ARGV elements. */
79 /* After ARGC words that are the ARGV elements, and a zero word,
80 are the ENVP elements. Do ENVP = &ARGV[ARGC + 1]. */
84 /* Store ENVP in the global variable `_environ'. */
85 ld [TMP + %lo(_environ)], ENVP
87 /* Call `_init', which is the entry point to our own `.init'
88 section; and register with `atexit' to have `exit' call
89 `_fini', which is the entry point to our own `.fini' section. */
91 sethi %hi(_fini), TMP /* In delay slot of call. */
92 or TMP, %lo(_fini), %o0 /* Argument to atexit is &_fini. */
96 /* Call the user's main function, and exit with its value. */
102 call exit /* This should never return. */
104 unimp 0 /* Crash if somehow it does return. */
106 /* Define a symbol for the first piece of initialized data. */
112 data_start = __data_start