1 /* Startup code for elf64-sparc
2 Copyright (C) 1997 Free Software Foundation, Inc.
3 Contributed by Richard Henderson <richard@gnu.ai.mit.edu>, 1997.
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. */
26 .type _start,#function
29 /* First order of business is to load %g4 with our base address. */
30 sethi %uhi(_start), %g4
31 or %g4, %ulo(_start), %g4
34 /* Terminate the stack frame, and reserve space for functions to
35 drop their arguments. */
39 /* Save %g1. When starting a binary via the dynamic linker, %g1
40 contains the address of the shared library termination function,
41 which we will register below with atexit() to be called by exit().
42 If we are statically linked, this will be NULL. */
44 /* Do essential libc initialization (sp points to argc, argv, and envp) */
45 call __libc_init_first
48 /* Now that we have the proper stack frame, register library termination
49 function, if there is any: */
57 /* Extract the arguments and environment as encoded on the stack. The
58 argument info starts after one register window (16 words) past the SP,
59 plus the bias we added, plus the magic v9 STACK_BIAS. */
60 ldx [%sp+STACK_BIAS+22*8], %o0
61 add %sp, STACK_BIAS+23*8, %o1
64 sethi %hi(__environ), %g2
67 stx %o2, [%g2+%lo(__environ)]
69 mov %o0, %l0 /* tuck them away */
72 /* Call _init, the entry point to our own .init section. */
76 /* Register our .fini section with atexit. */
80 add %o0, %lo(_fini), %o0
82 /* Call the user's main and exit with its return value. */
90 /* Die very horribly if exit returns. */