2 * Copyright (C) 2004-2007 Atmel Corporation
4 * This file is subject to the terms and conditions of the GNU Lesser General
5 * Public License. See the file "COPYING.LIB" in the main directory of this
6 * archive for more details.
8 * When we enter _start, the stack looks like this:
9 * argc argument counter
10 * argv[0] pointer to program name
11 * argv[1..argc-1] pointers to program args
13 * env[0..N] pointers to environment variables
16 * r12 contains a function pointer to be registered with `atexit'.
17 * This is how the dynamic linker arranges to have DT_FINI functions
18 * called for shared libraries that have been loaded before this
21 * We're going to call the following function:
22 * __uClibc_main(int (*main)(int, char **, char **), int argc,
23 * char **argv, void (*app_init)(void), void (*app_fini)(void),
24 * void (*rtld_fini)(void), void *stack_end)
26 * So we need to set up things as follows:
27 * r12 = address of main
30 * r9 = address of _init
31 * r8 = address of _fini
32 * sp[0] = whatever we got passed in r12
39 .type _start, @function
41 /* Clear the frame pointer and link register since this is the outermost frame. */
45 ld.w r11, sp++ /* argc */
46 mov r10, sp /* &argv[0] */
48 st.w --sp, r10 /* stack_end */
49 st.w --sp, r12 /* rtld_fini */
59 /* Ok, now run uClibc's main() -- should not return */
64 .long .L_RGOT - _GLOBAL_OFFSET_TABLE_
66 lddpc r9, __init_addr /* app_init */
67 lddpc r8, __fini_addr /* app_fini */
68 lddpc r12, __main_addr /* main */
70 /* Ok, now run uClibc's main() -- should not return */
71 lddpc pc, ___uClibc_main_addr
83 .size _start, . - _start
86 * The LSB says we need this.
88 .section ".note.ABI-tag", "a"
90 .long 2f - 1f /* namesz */
91 .long 4f - 3f /* descsz */
93 1: .asciz "GNU" /* name */
95 3: .long 0 /* Linux executable */
96 .long 2,6,0 /* Earliest compatible kernel */