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#include <asm-offsets.h>
34#include <config.h>
35#include <version.h>
36
37
38
39
40
41
42
43
44
45.globl _start
46_start:
47 b reset
48 ldr pc, _undefined_instruction
49 ldr pc, _software_interrupt
50 ldr pc, _prefetch_abort
51 ldr pc, _data_abort
52 ldr pc, _not_used
53 ldr pc, _irq
54 ldr pc, _fiq
55
56_undefined_instruction:
57 .word undefined_instruction
58_software_interrupt:
59 .word software_interrupt
60_prefetch_abort:
61 .word prefetch_abort
62_data_abort:
63 .word data_abort
64_not_used:
65 .word not_used
66_irq:
67 .word irq
68_fiq:
69 .word fiq
70
71 .balignl 16,0xdeadbeef
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86.globl _TEXT_BASE
87_TEXT_BASE:
88
89 .word CONFIG_SPL_TEXT_BASE
90#else
91 .word CONFIG_SYS_TEXT_BASE
92#endif
93
94
95
96
97
98
99
100.globl _bss_start_ofs
101_bss_start_ofs:
102 .word __bss_start - _start
103
104.globl _bss_end_ofs
105_bss_end_ofs:
106 .word __bss_end - _start
107
108.globl _end_ofs
109_end_ofs:
110 .word _end - _start
111
112#ifdef CONFIG_USE_IRQ
113
114.globl IRQ_STACK_START
115IRQ_STACK_START:
116 .word 0x0badc0de
117
118
119.globl FIQ_STACK_START
120FIQ_STACK_START:
121 .word 0x0badc0de
122#endif
123
124
125.globl IRQ_STACK_START_IN
126IRQ_STACK_START_IN:
127 .word 0x0badc0de
128
129
130
131
132
133reset:
134
135
136
137 mrs r0,cpsr
138 bic r0,r0,
139 orr r0,r0,
140 msr cpsr,r0
141
142
143
144
145
146#ifndef CONFIG_SKIP_LOWLEVEL_INIT
147 bl cpu_init_crit
148#endif
149
150 bl _main
151
152
153
154 .globl c_runtime_cpu_setup
155c_runtime_cpu_setup:
156
157 mov pc, lr
158
159
160
161
162
163
164
165
166
167
168
169
170#ifndef CONFIG_SKIP_LOWLEVEL_INIT
171cpu_init_crit:
172
173
174
175 mov pc, lr
176#endif
177
178
179
180
181
182
183
184
185@
186@ IRQ stack frame.
187@
188#define S_FRAME_SIZE 72
189
190#define S_OLD_R0 68
191#define S_PSR 64
192#define S_PC 60
193#define S_LR 56
194#define S_SP 52
195
196#define S_IP 48
197#define S_FP 44
198#define S_R10 40
199#define S_R9 36
200#define S_R8 32
201#define S_R7 28
202#define S_R6 24
203#define S_R5 20
204#define S_R4 16
205#define S_R3 12
206#define S_R2 8
207#define S_R1 4
208#define S_R0 0
209
210#define MODE_SVC 0x13
211#define I_BIT 0x80
212
213
214
215
216
217
218 .macro bad_save_user_regs
219 @ carve out a frame on current user stack
220 sub sp, sp,
221 stmia sp, {r0 - r12} @ Save user registers (now in svc mode) r0-r12
222
223 ldr r2, IRQ_STACK_START_IN
224 @ get values for "aborted" pc and cpsr (into parm regs)
225 ldmia r2, {r2 - r3}
226 add r0, sp,
227 add r5, sp,
228 mov r1, lr
229 stmia r5, {r0 - r3} @ save sp_SVC, lr_SVC, pc, cpsr
230 mov r0, sp @ save current stack into r0 (param register)
231 .endm
232
233 .macro irq_save_user_regs
234 sub sp, sp,
235 stmia sp, {r0 - r12} @ Calling r0-r12
236 @ !!!! R8 NEEDS to be saved !!!! a reserved stack spot would be good.
237 add r8, sp,
238 stmdb r8, {sp, lr}^ @ Calling SP, LR
239 str lr, [r8,
240 mrs r6, spsr
241 str r6, [r8,
242 str r0, [r8,
243 mov r0, sp
244 .endm
245
246 .macro irq_restore_user_regs
247 ldmia sp, {r0 - lr}^ @ Calling r0 - lr
248 mov r0, r0
249 ldr lr, [sp,
250 add sp, sp,
251 subs pc, lr,
252 .endm
253
254 .macro get_bad_stack
255 ldr r13, IRQ_STACK_START_IN @ setup our mode stack
256
257 str lr, [r13] @ save caller lr in position 0 of saved stack
258 mrs lr, spsr @ get the spsr
259 str lr, [r13,
260 mov r13,
261 @ msr spsr_c, r13
262 msr spsr, r13 @ switch modes, make sure moves will execute
263 mov lr, pc @ capture return pc
264 movs pc, lr @ jump to next instruction & switch modes.
265 .endm
266
267 .macro get_irq_stack @ setup IRQ stack
268 ldr sp, IRQ_STACK_START
269 .endm
270
271 .macro get_fiq_stack @ setup FIQ stack
272 ldr sp, FIQ_STACK_START
273 .endm
274
275
276
277
278 .align 5
279.globl undefined_instruction
280undefined_instruction:
281 get_bad_stack
282 bad_save_user_regs
283 bl do_undefined_instruction
284
285 .align 5
286.globl software_interrupt
287software_interrupt:
288 get_bad_stack
289 bad_save_user_regs
290 bl do_software_interrupt
291
292 .align 5
293.globl prefetch_abort
294prefetch_abort:
295 get_bad_stack
296 bad_save_user_regs
297 bl do_prefetch_abort
298
299 .align 5
300.globl data_abort
301data_abort:
302 get_bad_stack
303 bad_save_user_regs
304 bl do_data_abort
305
306 .align 5
307.globl not_used
308not_used:
309 get_bad_stack
310 bad_save_user_regs
311 bl do_not_used
312
313#ifdef CONFIG_USE_IRQ
314 .align 5
315.globl irq
316irq:
317 get_irq_stack
318 irq_save_user_regs
319 bl do_irq
320 irq_restore_user_regs
321
322 .align 5
323.globl fiq
324fiq:
325 get_fiq_stack
326
327 irq_save_user_regs
328 bl do_fiq
329 irq_restore_user_regs
330
331#else
332
333 .align 5
334.globl irq
335irq:
336 get_bad_stack
337 bad_save_user_regs
338 bl do_irq
339
340 .align 5
341.globl fiq
342fiq:
343 get_bad_stack
344 bad_save_user_regs
345 bl do_fiq
346
347#endif
348