This repository has been archived by the owner on Sep 5, 2023. It is now read-only.
/
start.S
128 lines (107 loc) · 2.3 KB
/
start.S
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#include "dietfeatures.h"
#include "syscalls.h"
#include "arm-features.h"
#ifdef __ARM_EABI__
FUNC_START _start
mov fp, #0 @ clear the frame pointer
ldr a1, [sp] @ argc
add a2, sp, #4 @ argv
ldr ip, .L3
add a3, a2, a1, lsl #2 @ &argv[argc]
add a3, a3, #4 @ envp
str a3, [ip, #0] @ environ = envp
#ifdef WANT_ELFINFO
mov r6, a3 @ work on a copy of a3 so that common
@ 'main(argc, argv, envp)' function
@ stays valid
1: ldr r5, [r6], #4 @ load *envp and increment it
cmp r5, #0 @ read value==0?
bne 1b
str r6, [ip, #4] @ __elfinfo = envp
#endif
bl main
@
@ The exit status from main() is already in r0.
@ We need to branch to 'exit' in case we have linked with 'atexit'.
@
bl exit
FUNC_END _start
FUNC_START _exit
FUNC_START_WEAK exit
mov r7, #__NR_exit
swi 0 @ never returns.
.align 2
.L3: .word environ
FUNC_END exit
FUNC_END _exit
#else
FUNC_START _start
#ifdef WANT_DYNAMIC
mov a4, a1 @ save dynamic ld.so _fini
#endif
mov fp, #0 @ clear the frame pointer
ldr a1, [sp], #4 @ argc
mov a2, sp @ argv
ldr ip, .L3
add a3, a2, a1, lsl #2 @ &argv[argc]
add a3, a3, #4 @ envp
#ifdef __DYN_LIB
ldr sl, .L4
1: add sl, pc, sl
str a3, [ip, sl]! @ environ = envp; ip = GOT(environ)
#else
str a3, [ip, #0] @ environ = envp
#endif
#ifdef WANT_ELFINFO
mov r6, a3 @ work on a copy of a3 so that common
@ 'main(argc, argv, envp)' function
@ stays valid
1: ldr r5, [r6], #4 @ load *envp and increment it
cmp r5, #0 @ read value==0?
bne 1b
#ifdef __DYN_LIB
str r6, [ip, sl] @ __elfinfo = envp
#else
str r6, [ip, #4] @ __elfinfo = envp
#endif
#endif
#ifdef PROFILING
stmdb sp!, { r0 - r3 }
ldr r0, .L5
ldr r1, .L6
bl monitor
ldmia sp!, { r0 - r3 }
#endif
#ifdef WANT_DYNAMIC
bl _dyn_start
#else
bl CALL_IN_STARTCODE
#endif
@
@ The exit status from main() is already in r0.
@ We need to branch to 'exit' in case we have linked with 'atexit'.
@
bl exit
FUNC_END _start
FUNC_START _exit
FUNC_START_WEAK exit
#ifdef PROFILING
mov r4, r0 @ save a copy of exit status
bl _stop_monitor
mov r0, r4
#endif
swi $__NR_exit @ never returns.
FUNC_END exit
FUNC_END _exit
.align 2
#ifdef __DYN_LIB
.L3: .word environ(GOT)
.L4: .word _GLOBAL_OFFSET_TABLE_-(1b+8)
#else
.L3: .word environ
#endif
#ifdef PROFILING
.L5: .word .text
.L6: .word _etext
#endif
#endif