forked from linux4sam/at91bootstrap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
crt0_gnu.S
247 lines (211 loc) · 4.58 KB
/
crt0_gnu.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
/*
* Copyright (C) 2006 Microchip Technology Inc. and its subsidiaries
*
* SPDX-License-Identifier: MIT
*/
#include <hardware.h>
#include <mon_macros.h>
.section start
.text
/*----------------------------------------------------------------------------
Area Definition
----------------
Must be defined as function to put first in the code as it must be mapped
at offset 0 of the flash EBI_CSR0, ie. at address 0 before remap.
_---------------------------------------------------------------------------*/
/* Application startup entry point */
.globl reset
.align 4
reset:
/* Exception vectors (should be a branch to be detected as a valid code by the rom */
_exception_vectors:
b reset_vector /* reset */
b undef_vector /* Undefined Instruction */
b swi_vector /* Software Interrupt */
b pabt_vector /* Prefetch Abort */
b dabt_vector /* Data Abort */
.word _romsize /* Size of the binary for ROMCode loading */
b irq_vector /* IRQ : read the AIC */
b fiq_vector /* FIQ */
undef_vector:
b undef_vector
swi_vector:
b swi_vector
pabt_vector:
b pabt_vector
dabt_vector:
subs pc, r14, #4 /* return */
nop
rsvd_vector:
b rsvd_vector
irq_vector:
b irq_vector
fiq_vector:
b fiq_vector
reset_vector:
#if defined(CONFIG_CPU_V7)
/*
* We must configure VBAR for the reset vectors to be at
* the start of SRAM (CONFIG_LINK_ADDR)
*/
mrc p15, 0, r2, c12, c0, 0 /* Read VBAR into R2 */
mov r2,#LINK_ADDR
mcr p15, 0, r2, c12, c0, 0
#endif /* CONFIG_CPU_V7 */
#ifdef BACKUP_REGISTER_BOOT_MODE_R4
ldr r1, =BACKUP_REGISTER_BOOT_MODE_R4
str r4, [r1]
#endif
/* Init the stack */
_init_stack:
#if defined(CONFIG_ENTER_NWD)
ldr sp,=SVC_STACK_BASE
#else
ldr sp,=TOP_OF_MEMORY
#endif
#ifdef CONFIG_FLASH
/*
* When running from NOR, we must relocate to SRAM prior to resetting
* the clocks and SMC timings.
*/
_relocate_to_sram:
#if 0
/* relocation is slow, disable the watchdog or it will trigger */
ldr r1, =0xFFFFFD44
mov r2, #0x00008000
str r2, [r1]
#endif
mov r1, #0
ldr r3, =_stext
ldr r4, =_edata
1:
cmp r3, r4
ldrcc r2, [r1], #4
strcc r2, [r3], #4
bcc 1b
#endif /* CONFIG_FLASH */
#if defined(CONFIG_PMC_COMMON)
ldr r4, = lowlevel_clock_init
mov lr, pc
bx r4
#endif /* CONFIG_PMC */
#if defined(CONFIG_CPU_V7)
/* Clear Abort condition if it is pending with help of the abort handler */
ldr r1, =(CPSR_A_BIT)
mrs r0, cpsr
eor r0, r0, r1
msr cpsr_x, r0
nop
eor r0, r0, r1
msr cpsr_x, r0
#endif
/* Copy the data section in RAM at .data link address */
_init_data:
ldr r2, =_lp_data
ldmia r2, {r1, r3, r4}
1:
cmp r3, r4
ldrcc r2, [r1], #4
strcc r2, [r3], #4
bcc 1b
/* Initialize the bss segment */
_init_bss:
adr r2, _lp_bss
ldmia r2, {r3, r4}
mov r2, #0
1:
cmp r3, r4
strcc r2, [r3], #4
bcc 1b
#if defined(CONFIG_ENTER_NWD)
/* Copy the monitor in RAM at its VMA address */
_init_mon:
ldr r2, =_lp_mon
ldmia r2, {r1, r3, r4}
1:
cmp r3, r4
ldrcc r2, [r1], #4
strcc r2, [r3], #4
bcc 1b
#endif
/* Branch on C code Main function (with interworking) */
_branch_main:
ldr r4, = main
mov lr, pc
bx r4
/* Branch to the application at the end of the bootstrap init */
_go:
#ifdef BACKUP_REGISTER_BOOT_MODE_R4
ldr r1, =BACKUP_REGISTER_BOOT_MODE_R4
ldr r4, [r1]
#endif
ldr r1, =MACH_TYPE
mov lr, pc
/* we endless loop here and not jump to any application
* if we are configured to not load anything
*/
#if defined(CONFIG_ENTER_NWD) || !defined(CONFIG_JUMP_TO_SW)
loop:
#ifdef CONFIG_BKPT_NOTIFY_DONE
bkpt
#endif
b loop
#endif
bx r0
/*#ifdef CONFIG_THUMB*/
.globl set_cp15
set_cp15:
mcr p15, 0, r0, c1, c0, 0
bx lr
.globl get_cp15
get_cp15:
mrc p15, 0, r0, c1, c0, 0
bx lr
.global disable_irq
disable_irq:
mrs r0, cpsr
orr r0, r0, #0xc0
msr cpsr_c, r0
bx lr
.global get_cpsr
get_cpsr:
mrs r0, cpsr
bx lr
.global set_cpsr
set_cpsr:
msr cpsr_c, r0
bx lr
.global disable_icache
disable_icache:
mrc p15, 0, r0, c1, c0, 0
mvn r1, #(1 << 12)
and r0, r0, r1
mcr p15, 0, r0, c1, c0, 0
bx lr
.global disable_dcache
disable_dcache:
mrc p15, 0, r0, c1, c0, 0
mvn r1, #(1 << 2)
and r0, r0, r1
mcr p15, 0, r0, c1, c0, 0
bx lr
.global flush_idcache
flush_idcache:
mov r0, #0
mcr p15, 0, r0, c7, c7, 0
bx lr
/*#endif*/
.align
_lp_data:
.word _edummy
.word _sdata
.word _edata
_lp_bss:
.word _sbss
.word _ebss
#if defined(CONFIG_ENTER_NWD)
_lp_mon:
.word _emon_dummy
.word _smon_text
.word _emon_text
#endif