OSDN Git Service

sparc: remove sparc64/sparcv9 code
[uclinux-h8/uClibc.git] / libc / sysdeps / linux / sparc / crt1.S
1 /* Startup code for elf{32,64}-sparc
2    Copyright (C) 1997, 1998, 2002, 2004 Free Software Foundation, Inc.
3    This file is part of the GNU C Library.
4    Contributed by Richard Henderson <richard@gnu.ai.mit.edu>, 1997.
5
6    The GNU C Library is free software; you can redistribute it and/or
7    modify it under the terms of the GNU Lesser General Public
8    License as published by the Free Software Foundation; either
9    version 2.1 of the License, or (at your option) any later version.
10
11    In addition to the permissions in the GNU Lesser General Public
12    License, the Free Software Foundation gives you unlimited
13    permission to link the compiled version of this file with other
14    programs, and to distribute those programs without any restriction
15    coming from the use of this file. (The GNU Lesser General Public
16    License restrictions do apply in other respects; for example, they
17    cover modification of the file, and distribution when not linked
18    into another program.)
19
20    Note that people who make modified versions of this file are not
21    obligated to grant this special exception for their modified
22    versions; it is their choice whether to do so. The GNU Lesser
23    General Public License gives permission to release a modified
24    version without this exception; this exception also makes it
25    possible to release a modified version which carries forward this
26    exception.
27
28    The GNU C Library is distributed in the hope that it will be useful,
29    but WITHOUT ANY WARRANTY; without even the implied warranty of
30    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
31    Lesser General Public License for more details.
32
33    You should have received a copy of the GNU Lesser General Public
34    License along with the GNU C Library; if not, see
35    <http://www.gnu.org/licenses/>.  */
36
37 /* Originally based on glibc's sysdeps/sparc/sparc{32,64}/elf/start.S */
38
39 #include <features.h>
40 #include <bits/wordsize.h>
41
42 # define STACK_BIAS 0
43 # define ELE_SIZE 4
44 # define LD ld
45
46 .text
47 .align 4
48 .global _start
49 .type   _start,%function
50 #if defined(__UCLIBC_CTOR_DTOR__)
51 .type   _init,%function
52 .type   _fini,%function
53 #else
54 .weak   _init
55 .weak   _fini
56 #endif
57 .type   __uClibc_main,%function
58 /* Stick in a dummy reference to main(), so that if an application
59  * is linking when the main() function is in a static library (.a)
60  * we can be sure that main() actually gets linked in */
61 .global main
62 .type   main,%function
63
64 #ifdef __PIC__
65 .LLGETPC0:
66         retl
67         add     %o7, %l7, %l7
68 #endif
69
70 _start:
71 #ifdef __PIC__
72         sethi   %hi(_GLOBAL_OFFSET_TABLE_-4), %l7
73         call    .LLGETPC0
74         add     %l7, %lo(_GLOBAL_OFFSET_TABLE_+4), %l7
75 #endif
76
77         /* Terminate the stack frame, and reserve space for functions to
78          * drop their arguments.  */
79         mov     %g0, %fp
80         sub     %sp, 6*ELE_SIZE, %sp
81
82         /* Extract the arguments and environment as encoded on the stack.  The
83          * argument info starts after one register window (16 words) past the SP.  */
84         LD      [%sp+STACK_BIAS+22*ELE_SIZE], %o1   /* %o1 = argc */
85         add     %sp, STACK_BIAS+23*ELE_SIZE, %o2    /* %o2 = argv */
86
87         /* Load the addresses of the user entry points.  */
88         sethi   %hi(main), %o0
89         sethi   %hi(_init), %o3
90         sethi   %hi(_fini), %o4
91         or      %o0, %lo(main), %o0
92         or      %o3, %lo(_init), %o3
93         or      %o4, %lo(_fini), %o4
94 #ifdef __PIC__
95         /* Need a little more magic when building PIC to get addr of main */
96         LD      [%l7 + %o0], %o0
97         LD      [%l7 + %o3], %o3
98         LD      [%l7 + %o4], %o4
99 #endif
100
101         /* When starting a binary via the dynamic linker, %g1 contains the
102          * address of the shared library termination function, which will be
103          * registered with atexit().  If we are statically linked, this will
104          * be NULL.  */
105         mov     %g1, %o5
106
107         /* Let libc do the rest of the initialization, and call main.  */
108         call __uClibc_main
109         nop
110
111         /* Die very horribly if exit returns.  */
112         unimp
113
114 .size _start,.-_start
115
116 /* Define a symbol for the first piece of initialized data. */
117 .data
118 .global __data_start
119 __data_start:
120 .long 0
121 .weak data_start
122         data_start = __data_start