bump to 1.0.37
[uclibc-ng.git] / libc / sysdeps / linux / sh / crt1.S
blob2d3e68ed2a9057f7d330274ceeaff7c24a708845
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
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.
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.
16  You should have received a copy of the GNU Library General Public License
17  along with this program; if not, see <http://www.gnu.org/licenses/>.
21 /* This is the canonical entry point, usually the first thing in the text
22    segment.
24         At this entry point, most registers' values are unspecified, except:
26    r4   Contains a function pointer to be registered with `atexit'.
27                 This is how the dynamic linker arranges to have DT_FINI
28                 functions called for shared libraries that have been loaded
29                 before this code runs.
31    sp           The stack contains the arguments and environment:
32                 0(sp)                   argc
33                 4(sp)                   argv[0]
34                 ...
35                 (4*argc)(sp)            NULL
36                 (4*(argc+1))(sp)        envp[0]
37                 ...
38                                         NULL
41 #include <features.h>
43         .text
44         .globl _start
45         .type _start,%function
46         .type main,%function
47 _start:
48         /* Clear the frame pointer since this is the outermost frame. */
49         mov #0, r14
51         /* Pop argc off the stack and save a pointer to argv */
52         mov.l @r15+,r5
53         mov r15, r6
55         /* Push the stack_end, rtld_fini and fini func onto the stack */
56         mov.l r6,@-r15
57         mov.l r4,@-r15
59 #ifdef __PIC__
60         mova  L_got, r0
61         mov.l L_got, r12
62         add r0, r12
64         mov.l L_fini,r0
65         add r12, r0
66         mov.l r0,@-r15
68         /* Set up the main/init funcs that go in registers */
69         mov.l L_main, r4
70         add r12, r4
71         mov.l L_init, r7
72         add r12, r7
74         /* __uClibc_main (main, argc, argv, init, fini, rtld_fini, stack_end) */
76         /* Let the libc call main and exit with its return code.  */
77         mov.l L_uClibc_main,r0
78         mov.l @(r0,r12),r1
79         jsr @r1
80         nop
81         /* We should not get here. */
82         mov.l L_abort,r0
83         mov.l @(r0,r12),r1
84         jsr @r1
85         nop
86 #else
87         mov.l L_fini,r0
88         mov.l r0,@-r15
90         /* Set up the main/init funcs that go in registers */
91         mov.l L_main,r4
92         mov.l L_init,r7
94         /* __uClibc_main (main, argc, argv, init, fini, rtld_fini, stack_end) */
96         /* Let the libc call main and exit with its return code.  */
97         mov.l L_uClibc_main,r1
98         jsr @r1
99         nop
100         /* We should not get here. */
101         mov.l L_abort,r1
102         jmp @r1
103         nop
104 #endif
106         .size _start,.-_start
107         .align  2
109 #ifdef __PIC__
110 L_got:
111         .long   _GLOBAL_OFFSET_TABLE_
112 L_main:
113         .long   main@GOTOFF
114 L_init:
115         .long   _init@GOTOFF
116 L_fini:
117         .long   _fini@GOTOFF
118 L_uClibc_main:
119         .long   __uClibc_main@GOT
120 L_abort:
121         .long   abort@GOT
122 #else
123 L_main:
124         .long   main
125 L_init:
126         .long   _init
127 L_fini:
128         .long   _fini
129 L_uClibc_main:
130         .long   __uClibc_main
131 L_abort:
132         .long   abort
133 #endif
135 /* Define a symbol for the first piece of initialized data.  */
136         .data
137         .globl __data_start
138 __data_start:
139         .long 0
140         .weak data_start
141         data_start = __data_start