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