Update.
[glibc.git] / sysdeps / sparc / sparc64 / elf / start.S
blob73f42367eed5c288e90f2dabc055bbab43d7c624
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.  */
20 #include <sysdep.h>
23         .section ".text"
24         .align 4
25         .global _start
26         .type _start,#function
27 _start:
29   /* First order of business is to load %g4 with our base address.  */
30         sethi   %uhi(_start), %g4
31         or      %g4, %ulo(_start), %g4
32         sllx    %g4, 32, %g4
34   /* Terminate the stack frame, and reserve space for functions to
35      drop their arguments.  */
36         mov     %g0, %fp
37         sub     %sp, 6*8, %sp
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
46          mov    %g1, %l0
48   /* Now that we have the proper stack frame, register library termination
49      function, if there is any:  */
51         brz,pn  %l0, 1f
52          nop
53         call    atexit
54          mov    %l0, %o0
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
62         sllx    %o0, 3, %o2
63         add     %o2, %o1, %o2
64         sethi   %hi(__environ), %g2
65         add     %o2, 8, %o2
66         add     %g2, %g4, %g2
67         stx     %o2, [%g2+%lo(__environ)]
69         mov     %o0, %l0                /* tuck them away */
70         mov     %o1, %l1
72   /* Call _init, the entry point to our own .init section.  */
73         call    _init
74          mov    %o2, %l2
76   /* Register our .fini section with atexit.  */
77         sethi   %hi(_fini), %o0
78         add     %o0, %g4, %o0
79         call    atexit
80          add    %o0, %lo(_fini), %o0
82   /* Call the user's main and exit with its return value.  */
83         mov     %l0, %o0
84         mov     %l1, %o1
85         call    main
86          mov    %l2, %o2
87         call    exit
88          nop
90   /* Die very horribly if exit returns.  */
91         illtrap 0
93         .size _start,.-_start