forked from xerub/ibex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
entry.S
124 lines (108 loc) · 2.51 KB
/
entry.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
@ ibex - payload trampoline: create payload entrypoint (see linker script)
@
@ Copyright (c) 2010, 2015 xerub
@
@ This program is free software; you can redistribute it and/or modify
@ it under the terms of the GNU General Public License as published by
@ the Free Software Foundation; either version 2 of the License, or
@ (at your option) any later version.
@
@ This program is distributed in the hope that it will be useful,
@ but WITHOUT ANY WARRANTY; without even the implied warranty of
@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
@ GNU General Public License for more details.
@
@ You should have received a copy of the GNU General Public License
@ along with this program. If not, see <http://www.gnu.org/licenses/>.
.global _start
.arm
.type _start, %function
_start:
#ifdef __pie__
nop
ldr r2, =(_GLOBAL_OFFSET_TABLE_ + 0)
add r2, pc, r2
add r2, #(.Lsize - . - 4) @ .Lsize - (pcrel insn addr + 8)
#ifdef ANY_BASE
@ we were linked at non-zero base
ldr r9, .Laddr
sub r9, pc
add r9, #(. + 4 - _start) @ pcrel insn addr + 8
#endif
@ fixup GOT
ldr r3, .Ledata
0:
subs r3, r3, #4
ldrge r12, [r2, r3]
#ifdef ANY_BASE
subge r12, r9
#else
addge r12, r12, pc
subge r12, #(. + 4) @ pcrel insn addr + 8 // assume zero base
#endif
strge r12, [r2, r3]
bge 0b
@ fixup main trampoline
ldr r12, .Lmain
add r12, r2
str r12, .Lmain
@ short-circuit next run
mov r12, #0xEA000000
add r12, #((.Lsave - _start - 8) / 4) @ b .Lsave
str r12, _start
@ clear BSS
ldr r3, .Lend
add r3, r2
ldr r12, .Ledata
add r2, r12, r2
mov r12, #0
1:
sub r3, r3, #4
cmp r3, r2
strge r12, [r3]
bge 1b
@ clear icache
mcr p15, 0, r12, c7, c5, 0
.long 0xF57FF04F @ dsb sy
.long 0xF57FF06F @ isb sy
@ save registers
.Lsave:
adr r3, .Lregs
stmia r3, {r4-r8,r10,r11,sp,lr}
.Ljump:
.long 0xe59ff000 + (.Lmain - . - 8) @ ldr pc, =.Lmain
.Lend: .long end(GOTOFF)
.Ledata:.long edata(GOTOFF)
.Lmain: .long _main(GOTOFF)
#ifdef ANY_BASE
.Laddr: .long _start
#endif
#else /* !__pie__ */
@ clear BSS (once)
ldr r3, .Lend
cmp r3, #0
beq 0f
ldr r2, .Ledata
mov r12, #0
1:
sub r3, r3, #4
cmp r3, r2
strge r12, [r3]
bge 1b
str r12, .Lend
0:
adr r3, .Lregs
stmia r3, {r4-r8,r10,r11,sp,lr}
ldr pc, =_main @ b _main is shorter but cannot swith to Thumb
.Lend: .long end
.Ledata:.long edata
#endif /* !__pie__ */
.Lregs: .long 0, 0, 0, 0, 0, 0, 0, 0, 0
.global _exit
.type _exit, %function
_exit:
adr r1, .Lregs
ldmia r1, {r4-r8,r10,r11,sp,pc}
.size _exit, .-_exit
.Lsize:
.size _start, .-_start