|
@@ -6,12 +6,12 @@
|
|
* archive for more details.
|
|
* archive for more details.
|
|
*
|
|
*
|
|
* When we enter _start, the stack looks like this:
|
|
* When we enter _start, the stack looks like this:
|
|
- * argc argument counter
|
|
+ * argc argument counter
|
|
- * argv[0] pointer to program name
|
|
+ * argv[0] pointer to program name
|
|
- * argv[1..argc-1] pointers to program args
|
|
+ * argv[1..argc-1] pointers to program args
|
|
- * NULL
|
|
+ * NULL
|
|
- * env[0..N] pointers to environment variables
|
|
+ * env[0..N] pointers to environment variables
|
|
- * NULL
|
|
+ * NULL
|
|
*
|
|
*
|
|
* r12 contains a function pointer to be registered with `atexit'.
|
|
* r12 contains a function pointer to be registered with `atexit'.
|
|
* This is how the dynamic linker arranges to have DT_FINI functions
|
|
* This is how the dynamic linker arranges to have DT_FINI functions
|
|
@@ -20,78 +20,78 @@
|
|
*
|
|
*
|
|
* We're going to call the following function:
|
|
* We're going to call the following function:
|
|
* __uClibc_main(int (*main)(int, char **, char **), int argc,
|
|
* __uClibc_main(int (*main)(int, char **, char **), int argc,
|
|
- * char **argv, void (*app_init)(void), void (*app_fini)(void),
|
|
+ * char **argv, void (*app_init)(void), void (*app_fini)(void),
|
|
- * void (*rtld_fini)(void), void *stack_end)
|
|
+ * void (*rtld_fini)(void), void *stack_end)
|
|
*
|
|
*
|
|
* So we need to set up things as follows:
|
|
* So we need to set up things as follows:
|
|
- * r12 = address of main
|
|
+ * r12 = address of main
|
|
- * r11 = argc
|
|
+ * r11 = argc
|
|
- * r10 = &argv[0]
|
|
+ * r10 = &argv[0]
|
|
- * r9 = address of _init
|
|
+ * r9 = address of _init
|
|
- * r8 = address of _fini
|
|
+ * r8 = address of _fini
|
|
- * sp[0] = whatever we got passed in r12
|
|
+ * sp[0] = whatever we got passed in r12
|
|
*/
|
|
*/
|
|
|
|
|
|
#include <features.h>
|
|
#include <features.h>
|
|
|
|
|
|
- .text
|
|
+ .text
|
|
- .global _start
|
|
+ .global _start
|
|
- .type _start, @function
|
|
+ .type _start, @function
|
|
_start:
|
|
_start:
|
|
- /* Clear the frame pointer and link register since this is the outermost frame. */
|
|
+ /* Clear the frame pointer and link register since this is the outermost frame. */
|
|
- mov r7, 0
|
|
+ mov r7, 0
|
|
- mov lr, 0
|
|
+ mov lr, 0
|
|
|
|
|
|
- ld.w r11, sp++ /* argc */
|
|
+ ld.w r11, sp++ /* argc */
|
|
- mov r10, sp /* &argv[0] */
|
|
+ mov r10, sp /* &argv[0] */
|
|
|
|
|
|
- st.w --sp, r10 /* stack_end */
|
|
+ st.w --sp, r10 /* stack_end */
|
|
- st.w --sp, r12 /* rtld_fini */
|
|
+ st.w --sp, r12 /* rtld_fini */
|
|
|
|
|
|
#ifdef __PIC__
|
|
#ifdef __PIC__
|
|
- lddpc r6, .L_GOT
|
|
+ lddpc r6, .L_GOT
|
|
.L_RGOT:
|
|
.L_RGOT:
|
|
- rsub r6, pc
|
|
+ rsub r6, pc
|
|
- lda.w r9, _init
|
|
+ lda.w r9, _init
|
|
- lda.w r8, _fini
|
|
+ lda.w r8, _fini
|
|
- lda.w r12, main
|
|
+ lda.w r12, main
|
|
|
|
|
|
- /* Ok, now run uClibc's main() -- should not return */
|
|
+ /* Ok, now run uClibc's main() -- should not return */
|
|
- call __uClibc_main
|
|
+ call __uClibc_main
|
|
|
|
|
|
- .align 2
|
|
+ .align 2
|
|
.L_GOT:
|
|
.L_GOT:
|
|
- .long .L_RGOT - _GLOBAL_OFFSET_TABLE_
|
|
+ .long .L_RGOT - _GLOBAL_OFFSET_TABLE_
|
|
#else
|
|
#else
|
|
- lddpc r9, __init_addr /* app_init */
|
|
+ lddpc r9, __init_addr /* app_init */
|
|
- lddpc r8, __fini_addr /* app_fini */
|
|
+ lddpc r8, __fini_addr /* app_fini */
|
|
- lddpc r12, __main_addr /* main */
|
|
+ lddpc r12, __main_addr /* main */
|
|
|
|
|
|
- /* Ok, now run uClibc's main() -- should not return */
|
|
+ /* Ok, now run uClibc's main() -- should not return */
|
|
- lddpc pc, ___uClibc_main_addr
|
|
+ lddpc pc, ___uClibc_main_addr
|
|
|
|
|
|
- .align 2
|
|
+ .align 2
|
|
__init_addr:
|
|
__init_addr:
|
|
- .long _init
|
|
+ .long _init
|
|
__fini_addr:
|
|
__fini_addr:
|
|
- .long _fini
|
|
+ .long _fini
|
|
__main_addr:
|
|
__main_addr:
|
|
- .long main
|
|
+ .long main
|
|
___uClibc_main_addr:
|
|
___uClibc_main_addr:
|
|
- .long __uClibc_main
|
|
+ .long __uClibc_main
|
|
#endif
|
|
#endif
|
|
- .size _start, . - _start
|
|
+ .size _start, . - _start
|
|
|
|
|
|
- /*
|
|
+ /*
|
|
- * The LSB says we need this.
|
|
+ * The LSB says we need this.
|
|
- */
|
|
+ */
|
|
- .section ".note.ABI-tag", "a"
|
|
+ .section ".note.ABI-tag", "a"
|
|
- .align 4
|
|
+ .align 4
|
|
- .long 2f - 1f /* namesz */
|
|
+ .long 2f - 1f /* namesz */
|
|
- .long 4f - 3f /* descsz */
|
|
+ .long 4f - 3f /* descsz */
|
|
- .long 1 /* type */
|
|
+ .long 1 /* type */
|
|
-1: .asciz "GNU" /* name */
|
|
+1: .asciz "GNU" /* name */
|
|
-2: .align 4
|
|
+2: .align 4
|
|
-3: .long 0 /* Linux executable */
|
|
+3: .long 0 /* Linux executable */
|
|
- .long 2,6,0 /* Earliest compatible kernel */
|
|
+ .long 2,6,0 /* Earliest compatible kernel */
|
|
-4: .align 4
|
|
+4: .align 4
|