1 /* Startup code for ARM & ELF
2 Copyright (C) 1995, 1996, 1997, 1998, 2001, 2002, 2005
3 Free Software Foundation, Inc.
4 This file is part of the GNU C Library.
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.
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.)
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
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.
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/>. */
37 /* This is the canonical entry point, usually the first thing in the text
40 Note that the code in the .init section has already been run.
41 This includes _init and _libc_init
44 At this entry point, most registers' values are unspecified, except:
46 a1 Contains a function pointer to be registered with `atexit'.
47 This is how the dynamic linker arranges to have DT_FINI
48 functions called for shared libraries that have been loaded
49 before this code runs.
51 sp The stack contains the arguments and environment:
56 (4*(argc+1))(sp) envp[0]
61 For uClinux it looks like this:
63 argc argument counter (integer)
66 argv[0] program name (pointer)
67 argv[1...N] program args (pointers)
68 argv[argc-1] end of args (integer)
70 env[0...N] environment variables (pointers)
73 ARM register quick reference:
75 Name Number ARM Procedure Calling Standard Role
77 a1 r0 argument 1 / integer result / scratch register / argc
78 a2 r1 argument 2 / scratch register / argv
79 a3 r2 argument 3 / scratch register / envp
80 a4 r3 argument 4 / scratch register
81 v1 r4 register variable
82 v2 r5 register variable
83 v3 r6 register variable
84 v4 r7 register variable
85 v5 r8 register variable
86 sb/v6 r9 static base / register variable
87 sl/v7 r10 stack limit / stack chunk handle / reg. variable
89 ip r12 scratch register / new-sb in inter-link-unit calls
90 sp r13 lower end of current stack frame
91 lr r14 link address / scratch register
92 pc r15 program counter
96 #include <bits/arm_asm.h>
100 .type _start,%function
101 .type _init,%function
102 .type _fini,%function
103 #ifndef __UCLIBC_CTOR_DTOR__
108 #if defined(THUMB1_ONLY)
111 /* Clear the frame pointer since this is the outermost frame. */
115 #ifdef __ARCH_USE_MMU__
116 /* Pop argc off the stack and save a pointer to argv */
121 * uClinux/arm stacks look a little different from normal
122 * MMU-full Linux/arm stacks (for no good reason)
124 /* pull argc and argv off the stack. We are going to push 3
125 * arguments, so pop one here to maintain doubleword alignment. */
130 /* Push stack limit and rtld_fini */
138 ldr r5, .L_GOT+4 /* _fini */
140 push {a1} /* Push _fini */
142 ldr r5, .L_GOT+8 /* _init */
145 ldr r5, .L_GOT+12 /* main */
149 /* Fetch address of fini */
154 /* Set up the other arguments in registers */
158 /* __uClibc_main (main, argc, argv, init, fini, rtld_fini, stack_end) */
159 /* Let the libc call main and exit with its return code. */
162 /* should never get here....*/
168 .word _GLOBAL_OFFSET_TABLE_-.L_GOT
173 #else /* !THUMB1_ONLY */
175 /* Clear the frame pointer and link register since this is the outermost frame. */
179 #ifdef __ARCH_USE_MMU__
180 /* Pop argc off the stack and save a pointer to argv */
185 * uClinux/arm stacks look a little different from normal
186 * MMU-full Linux/arm stacks (for no good reason)
188 /* pull argc and argv off the stack. We are going to push 3
189 * arguments, so pop one here to maintain doubleword alignment. */
194 /* Push stack limit */
205 ldr ip, .L_GOT+4 /* _fini */
207 str a1, [sp, #-4]! /* Push _fini */
209 ldr ip, .L_GOT+8 /* _init */
212 ldr ip, .L_GOT+12 /* main */
215 /* __uClibc_main (main, argc, argv, init, fini, rtld_fini, stack_end) */
216 /* Let the libc call main and exit with its return code. */
219 /* Fetch address of fini */
224 /* Set up the other arguments in registers */
228 /* __uClibc_main (main, argc, argv, init, fini, rtld_fini, stack_end) */
230 /* Let the libc call main and exit with its return code. */
234 /* should never get here....*/
239 .word _GLOBAL_OFFSET_TABLE_ - .L_GOT
246 /* Define a symbol for the first piece of initialized data. */
252 data_start = __data_start