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, write to the Free
35 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
38 /* This is the canonical entry point, usually the first thing in the text
41 Note that the code in the .init section has already been run.
42 This includes _init and _libc_init
45 At this entry point, most registers' values are unspecified, except:
47 a1 Contains a function pointer to be registered with `atexit'.
48 This is how the dynamic linker arranges to have DT_FINI
49 functions called for shared libraries that have been loaded
50 before this code runs.
52 sp The stack contains the arguments and environment:
57 (4*(argc+1))(sp) envp[0]
62 For uClinux it looks like this:
64 argc argument counter (integer)
67 argv[0] program name (pointer)
68 argv[1...N] program args (pointers)
69 argv[argc-1] end of args (integer)
71 env[0...N] environment variables (pointers)
74 ARM register quick reference:
76 Name Number ARM Procedure Calling Standard Role
78 a1 r0 argument 1 / integer result / scratch register / argc
79 a2 r1 argument 2 / scratch register / argv
80 a3 r2 argument 3 / scratch register / envp
81 a4 r3 argument 4 / scratch register
82 v1 r4 register variable
83 v2 r5 register variable
84 v3 r6 register variable
85 v4 r7 register variable
86 v5 r8 register variable
87 sb/v6 r9 static base / register variable
88 sl/v7 r10 stack limit / stack chunk handle / reg. variable
90 ip r12 scratch register / new-sb in inter-link-unit calls
91 sp r13 lower end of current stack frame
92 lr r14 link address / scratch register
93 pc r15 program counter
97 #include <bits/arm_asm.h>
101 .type _start,%function
102 .type _init,%function
103 .type _fini,%function
104 #ifndef __UCLIBC_CTOR_DTOR__
109 #if defined(THUMB1_ONLY)
112 /* Clear the frame pointer since this is the outermost frame. */
116 #ifdef __ARCH_USE_MMU__
117 /* Pop argc off the stack and save a pointer to argv */
122 * uClinux/arm stacks look a little different from normal
123 * MMU-full Linux/arm stacks (for no good reason)
125 /* pull argc and argv off the stack. We are going to push 3
126 * arguments, so pop one here to maintain doubleword alignment. */
131 /* Push stack limit and rtld_fini */
140 ldr r5, .L_GOT+4 /* _fini */
142 push {a1} /* Push _fini */
144 ldr r5, .L_GOT+8 /* _init */
147 ldr r5, .L_GOT+12 /* main */
151 /* Fetch address of fini */
156 /* Set up the other arguments in registers */
160 /* __uClibc_main (main, argc, argv, init, fini, rtld_fini, stack_end) */
161 /* Let the libc call main and exit with its return code. */
164 /* should never get here....*/
170 .word _GLOBAL_OFFSET_TABLE_-.L_GOT
175 #else /* !THUMB1_ONLY */
177 /* Clear the frame pointer and link register since this is the outermost frame. */
181 #ifdef __ARCH_USE_MMU__
182 /* Pop argc off the stack and save a pointer to argv */
187 * uClinux/arm stacks look a little different from normal
188 * MMU-full Linux/arm stacks (for no good reason)
190 /* pull argc and argv off the stack. We are going to push 3
191 * arguments, so pop one here to maintain doubleword alignment. */
196 /* Push stack limit */
207 ldr ip, .L_GOT+4 /* _fini */
209 str a1, [sp, #-4]! /* Push _fini */
211 ldr ip, .L_GOT+8 /* _init */
214 ldr ip, .L_GOT+12 /* main */
217 /* __uClibc_main (main, argc, argv, init, fini, rtld_fini, stack_end) */
218 /* Let the libc call main and exit with its return code. */
221 /* Fetch address of fini */
226 /* Set up the other arguments in registers */
230 /* __uClibc_main (main, argc, argv, init, fini, rtld_fini, stack_end) */
232 /* Let the libc call main and exit with its return code. */
236 /* should never get here....*/
242 .word _GLOBAL_OFFSET_TABLE_-(.L_GOT_OFF+4)
243 #else /* __thumb2__ */
244 .word _GLOBAL_OFFSET_TABLE_-(.L_GOT_OFF+8)
252 /* Define a symbol for the first piece of initialized data. */
258 data_start = __data_start