]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/uclibc/lib/contrib/uclibc/libc/sysdeps/linux/sparc/crt1.S
update
[l4.git] / l4 / pkg / uclibc / lib / contrib / uclibc / 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 /* macro out the 32 / 64 bit differences */
43 #if __WORDSIZE == 32
44 # define STACK_BIAS 0
45 # define ELE_SIZE 4
46 # define LD ld
47 #else
48 # define STACK_BIAS 2047 /* see glibc/sysdeps/unix/sysv/linux/sparc/sparc64/sysdep.h */
49 # define ELE_SIZE 8
50 # define LD ldx
51 #endif
52
53 .text
54 .align 4
55 .global _start
56 .type   _start,%function
57 #if defined(__UCLIBC_CTOR_DTOR__)
58 .type   _init,%function
59 .type   _fini,%function
60 #else
61 .weak   _init
62 .weak   _fini
63 #endif
64 .type   __uClibc_main,%function
65 /* Stick in a dummy reference to main(), so that if an application
66  * is linking when the main() function is in a static library (.a)
67  * we can be sure that main() actually gets linked in */
68 .global main
69 .type   main,%function
70
71 #ifdef __PIC__
72 .LLGETPC0:
73         retl
74         add     %o7, %l7, %l7
75 #endif
76
77 _start:
78 #ifdef __PIC__
79         sethi   %hi(_GLOBAL_OFFSET_TABLE_-4), %l7
80         call    .LLGETPC0
81         add     %l7, %lo(_GLOBAL_OFFSET_TABLE_+4), %l7
82 #endif
83
84         /* Terminate the stack frame, and reserve space for functions to
85          * drop their arguments.  */
86         mov     %g0, %fp
87         sub     %sp, 6*ELE_SIZE, %sp
88
89         /* Extract the arguments and environment as encoded on the stack.  The
90          * argument info starts after one register window (16 words) past the SP.  */
91         LD      [%sp+STACK_BIAS+22*ELE_SIZE], %o1   /* %o1 = argc */
92         add     %sp, STACK_BIAS+23*ELE_SIZE, %o2    /* %o2 = argv */
93
94         /* Load the addresses of the user entry points.  */
95         sethi   %hi(main), %o0
96         sethi   %hi(_init), %o3
97         sethi   %hi(_fini), %o4
98         or      %o0, %lo(main), %o0
99         or      %o3, %lo(_init), %o3
100         or      %o4, %lo(_fini), %o4
101 #ifdef __PIC__
102         /* Need a little more magic when building PIC to get addr of main */
103         LD      [%l7 + %o0], %o0
104         LD      [%l7 + %o3], %o3
105         LD      [%l7 + %o4], %o4
106 #endif
107
108         /* When starting a binary via the dynamic linker, %g1 contains the
109          * address of the shared library termination function, which will be
110          * registered with atexit().  If we are statically linked, this will
111          * be NULL.  */
112         mov     %g1, %o5
113
114         /* Let libc do the rest of the initialization, and call main.  */
115         call __uClibc_main
116         nop
117
118         /* Die very horribly if exit returns.  */
119 #if __WORDSIZE == 32
120         unimp
121 #else
122         illtrap 0
123 #endif
124
125 .size _start,.-_start
126
127 /* Define a symbol for the first piece of initialized data. */
128 .data
129 .global __data_start
130 __data_start:
131 .long 0
132 .weak data_start
133         data_start = __data_start