]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/uclibc/lib/contrib/uclibc/libc/sysdeps/linux/sh/crt1.S
Inital import
[l4.git] / l4 / pkg / uclibc / lib / contrib / uclibc / libc / sysdeps / linux / sh / crt1.S
1 /* Startup code for SH & ELF.
2    Copyright (C) 1999 Free Software Foundation, Inc.
3    Copyright (C) 2001 Hewlett-Packard Australia
4    Copyright (C) 2002 Stefan Allius
5
6  This program is free software; you can redistribute it and/or modify it under
7  the terms of the GNU Library General Public License as published by the Free
8  Software Foundation; either version 2 of the License, or (at your option) any
9  later version.
10
11  This program is distributed in the hope that it will be useful, but WITHOUT
12  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13  FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more
14  details.
15
16  You should have received a copy of the GNU Library General Public License
17  along with this program; if not, write to the Free Software Foundation, Inc.,
18  59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21
22 /* This is the canonical entry point, usually the first thing in the text
23    segment.
24
25         At this entry point, most registers' values are unspecified, except:
26
27    r4   Contains a function pointer to be registered with `atexit'.
28                 This is how the dynamic linker arranges to have DT_FINI
29                 functions called for shared libraries that have been loaded
30                 before this code runs.
31
32    sp           The stack contains the arguments and environment:
33                 0(sp)                   argc
34                 4(sp)                   argv[0]
35                 ...
36                 (4*argc)(sp)            NULL
37                 (4*(argc+1))(sp)        envp[0]
38                 ...
39                                         NULL
40 */
41
42 #include <features.h>
43
44         .text
45         .globl _start
46         .type _start,%function
47         .type main,%function
48 _start:
49         /* Clear the frame pointer since this is the outermost frame. */
50         mov #0, r14
51
52         /* Pop argc off the stack and save a pointer to argv */
53         mov.l @r15+,r5
54         mov r15, r6
55
56         /* Push the stack_end, rtld_fini and fini func onto the stack */
57         mov.l r6,@-r15
58         mov.l r4,@-r15
59
60 #ifdef __PIC__
61         mova  L_got, r0
62         mov.l L_got, r12
63         add r0, r12
64
65         mov.l L_fini,r0
66         add r12, r0
67         mov.l r0,@-r15
68
69         /* Set up the main/init funcs that go in registers */
70         mov.l L_main, r4
71         add r12, r4
72         mov.l L_init, r7
73         add r12, r7
74
75         /* __uClibc_main (main, argc, argv, init, fini, rtld_fini, stack_end) */
76
77         /* Let the libc call main and exit with its return code.  */
78         mov.l L_uClibc_main,r0
79         mov.l @(r0,r12),r1
80         jsr @r1
81         nop
82         /* We should not get here. */
83         mov.l L_abort,r0
84         mov.l @(r0,r12),r1
85         jsr @r1
86         nop
87 #else
88         mov.l L_fini,r0
89         mov.l r0,@-r15
90
91         /* Set up the main/init funcs that go in registers */
92         mov.l L_main,r4
93         mov.l L_init,r7
94
95         /* __uClibc_main (main, argc, argv, init, fini, rtld_fini, stack_end) */
96
97         /* Let the libc call main and exit with its return code.  */
98         mov.l L_uClibc_main,r1
99         jsr @r1
100         nop
101         /* We should not get here. */
102         mov.l L_abort,r1
103         jmp @r1
104         nop
105 #endif
106
107         .size _start,.-_start
108         .align  2
109
110 #ifdef __PIC__
111 L_got:
112         .long   _GLOBAL_OFFSET_TABLE_
113 L_main:
114         .long   main@GOTOFF
115 L_init:
116         .long   _init@GOTOFF
117 L_fini:
118         .long   _fini@GOTOFF
119 L_uClibc_main:
120         .long   __uClibc_main@GOT
121 L_abort:
122         .long   abort@GOT
123 #else
124 L_main:
125         .long   main
126 L_init:
127         .long   _init
128 L_fini:
129         .long   _fini
130 L_uClibc_main:
131         .long   __uClibc_main
132 L_abort:
133         .long   abort
134 #endif
135
136 /* Define a symbol for the first piece of initialized data.  */
137         .data
138         .globl __data_start
139 __data_start:
140         .long 0
141         .weak data_start
142         data_start = __data_start