blob: 27bcda598c65bb7786452df169d1d61a2f5dae0c [file] [log] [blame]
wdenkfe8c2802002-11-03 00:38:21 +00001/*
2 * armboot - Startup Code for SA1100 CPU
3 *
4 * Copyright (C) 1998 Dan Malek <dmalek@jlc.net>
5 * Copyright (C) 1999 Magnus Damm <kieraypc01.p.y.kie.era.ericsson.se>
6 * Copyright (C) 2000 Wolfgang Denk <wd@denx.de>
Albert ARIBAUDfa82f872011-08-04 18:45:45 +02007 * Copyright (c) 2001 Alex Züpke <azu@sysgo.de>
wdenkfe8c2802002-11-03 00:38:21 +00008 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02009 * SPDX-License-Identifier: GPL-2.0+
wdenkfe8c2802002-11-03 00:38:21 +000010 */
11
Wolfgang Denk25ddd1f2010-10-26 14:34:52 +020012#include <asm-offsets.h>
wdenkfe8c2802002-11-03 00:38:21 +000013#include <config.h>
14#include <version.h>
15
wdenkfe8c2802002-11-03 00:38:21 +000016/*
17 *************************************************************************
18 *
19 * Jump vector table as in table 3.1 in [1]
20 *
21 *************************************************************************
22 */
23
24
25.globl _start
26_start: b reset
27 ldr pc, _undefined_instruction
28 ldr pc, _software_interrupt
29 ldr pc, _prefetch_abort
30 ldr pc, _data_abort
31 ldr pc, _not_used
32 ldr pc, _irq
33 ldr pc, _fiq
34
35_undefined_instruction: .word undefined_instruction
36_software_interrupt: .word software_interrupt
37_prefetch_abort: .word prefetch_abort
38_data_abort: .word data_abort
39_not_used: .word not_used
40_irq: .word irq
41_fiq: .word fiq
42
43 .balignl 16,0xdeadbeef
44
45
46/*
47 *************************************************************************
48 *
49 * Startup Code (reset vector)
50 *
51 * do important init only if we don't start from memory!
52 * relocate armboot to ram
53 * setup stack
54 * jump to second stage
55 *
56 *************************************************************************
57 */
58
Heiko Schochere30ceca2010-09-17 13:10:48 +020059.globl _TEXT_BASE
wdenkfe8c2802002-11-03 00:38:21 +000060_TEXT_BASE:
Benoît Thébaudeau508611b2013-04-11 09:35:42 +000061#if defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_TEXT_BASE)
62 .word CONFIG_SPL_TEXT_BASE
63#else
Wolfgang Denk14d0a022010-10-07 21:51:12 +020064 .word CONFIG_SYS_TEXT_BASE
Benoît Thébaudeau508611b2013-04-11 09:35:42 +000065#endif
wdenkfe8c2802002-11-03 00:38:21 +000066
wdenkfe8c2802002-11-03 00:38:21 +000067/*
wdenkf6e20fc2004-02-08 19:38:38 +000068 * These are defined in the board-specific linker script.
Albert Aribaud3336ca62010-11-25 22:45:02 +010069 * Subtracting _start from them lets the linker put their
70 * relative position in the executable instead of leaving
71 * them null.
wdenkfe8c2802002-11-03 00:38:21 +000072 */
Albert Aribaud3336ca62010-11-25 22:45:02 +010073.globl _bss_start_ofs
74_bss_start_ofs:
75 .word __bss_start - _start
wdenkf6e20fc2004-02-08 19:38:38 +000076
Albert Aribaud3336ca62010-11-25 22:45:02 +010077.globl _bss_end_ofs
78_bss_end_ofs:
Simon Glass3929fb02013-03-14 06:54:53 +000079 .word __bss_end - _start
wdenkfe8c2802002-11-03 00:38:21 +000080
Po-Yu Chuangf326cbb2011-03-01 23:02:04 +000081.globl _end_ofs
82_end_ofs:
83 .word _end - _start
84
wdenkfe8c2802002-11-03 00:38:21 +000085#ifdef CONFIG_USE_IRQ
86/* IRQ stack memory (calculated at run-time) */
87.globl IRQ_STACK_START
88IRQ_STACK_START:
89 .word 0x0badc0de
90
91/* IRQ stack memory (calculated at run-time) */
92.globl FIQ_STACK_START
93FIQ_STACK_START:
94 .word 0x0badc0de
95#endif
96
Heiko Schochere30ceca2010-09-17 13:10:48 +020097/* IRQ stack memory (calculated at run-time) + 8 bytes */
98.globl IRQ_STACK_START_IN
99IRQ_STACK_START_IN:
100 .word 0x0badc0de
101
Heiko Schochere30ceca2010-09-17 13:10:48 +0200102/*
103 * the actual reset code
104 */
105
106reset:
107 /*
108 * set the cpu to SVC32 mode
109 */
110 mrs r0,cpsr
111 bic r0,r0,#0x1f
112 orr r0,r0,#0xd3
113 msr cpsr,r0
114
115 /*
116 * we do sys-critical inits only at reboot,
117 * not when booting from ram!
118 */
119#ifndef CONFIG_SKIP_LOWLEVEL_INIT
120 bl cpu_init_crit
121#endif
122
Albert ARIBAUDe05e5de2013-01-08 10:18:02 +0000123 bl _main
Heiko Schochere30ceca2010-09-17 13:10:48 +0200124
125/*------------------------------------------------------------------------------*/
126
Albert ARIBAUDe05e5de2013-01-08 10:18:02 +0000127 .globl c_runtime_cpu_setup
128c_runtime_cpu_setup:
129
130 mov pc, lr
131
wdenkfe8c2802002-11-03 00:38:21 +0000132/*
133 *************************************************************************
134 *
135 * CPU_init_critical registers
136 *
137 * setup important registers
138 * setup memory timing
139 *
140 *************************************************************************
141 */
142
143
Mike Williams16263082011-07-22 04:01:30 +0000144/* Interrupt-Controller base address */
wdenkfe8c2802002-11-03 00:38:21 +0000145IC_BASE: .word 0x90050000
146#define ICMR 0x04
147
148
149/* Reset-Controller */
150RST_BASE: .word 0x90030000
151#define RSRR 0x00
152#define RCSR 0x04
153
154
155/* PWR */
156PWR_BASE: .word 0x90020000
157#define PSPR 0x08
158#define PPCR 0x14
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200159cpuspeed: .word CONFIG_SYS_CPUSPEED
wdenkfe8c2802002-11-03 00:38:21 +0000160
161
162cpu_init_crit:
163 /*
164 * mask all IRQs
165 */
166 ldr r0, IC_BASE
167 mov r1, #0x00
168 str r1, [r0, #ICMR]
169
170 /* set clock speed */
171 ldr r0, PWR_BASE
172 ldr r1, cpuspeed
173 str r1, [r0, #PPCR]
174
175 /*
176 * before relocating, we have to setup RAM timing
177 * because memory timing is board-dependend, you will
wdenk400558b2005-04-02 23:52:25 +0000178 * find a lowlevel_init.S in your board directory.
wdenkfe8c2802002-11-03 00:38:21 +0000179 */
180 mov ip, lr
wdenk400558b2005-04-02 23:52:25 +0000181 bl lowlevel_init
wdenkfe8c2802002-11-03 00:38:21 +0000182 mov lr, ip
183
184 /*
185 * disable MMU stuff and enable I-cache
186 */
187 mrc p15,0,r0,c1,c0
188 bic r0, r0, #0x00002000 @ clear bit 13 (X)
189 bic r0, r0, #0x0000000f @ clear bits 3-0 (WCAM)
190 orr r0, r0, #0x00001000 @ set bit 12 (I) Icache
191 orr r0, r0, #0x00000002 @ set bit 2 (A) Align
192 mcr p15,0,r0,c1,c0
193
194 /*
195 * flush v4 I/D caches
196 */
197 mov r0, #0
198 mcr p15, 0, r0, c7, c7, 0 /* flush v3/v4 cache */
199 mcr p15, 0, r0, c8, c7, 0 /* flush v4 TLB */
200
201 mov pc, lr
202
203
wdenkfe8c2802002-11-03 00:38:21 +0000204/*
205 *************************************************************************
206 *
207 * Interrupt handling
208 *
209 *************************************************************************
210 */
211
212@
213@ IRQ stack frame.
214@
215#define S_FRAME_SIZE 72
216
217#define S_OLD_R0 68
218#define S_PSR 64
219#define S_PC 60
220#define S_LR 56
221#define S_SP 52
222
223#define S_IP 48
224#define S_FP 44
225#define S_R10 40
226#define S_R9 36
227#define S_R8 32
228#define S_R7 28
229#define S_R6 24
230#define S_R5 20
231#define S_R4 16
232#define S_R3 12
233#define S_R2 8
234#define S_R1 4
235#define S_R0 0
236
237#define MODE_SVC 0x13
238#define I_BIT 0x80
239
240/*
241 * use bad_save_user_regs for abort/prefetch/undef/swi ...
242 * use irq_save_user_regs / irq_restore_user_regs for IRQ/FIQ handling
243 */
244
245 .macro bad_save_user_regs
246 sub sp, sp, #S_FRAME_SIZE
247 stmia sp, {r0 - r12} @ Calling r0-r12
248 add r8, sp, #S_PC
249
Heiko Schochere30ceca2010-09-17 13:10:48 +0200250 ldr r2, IRQ_STACK_START_IN
wdenkfe8c2802002-11-03 00:38:21 +0000251 ldmia r2, {r2 - r4} @ get pc, cpsr, old_r0
252 add r0, sp, #S_FRAME_SIZE @ restore sp_SVC
253
254 add r5, sp, #S_SP
255 mov r1, lr
256 stmia r5, {r0 - r4} @ save sp_SVC, lr_SVC, pc, cpsr, old_r
257 mov r0, sp
258 .endm
259
260 .macro irq_save_user_regs
261 sub sp, sp, #S_FRAME_SIZE
262 stmia sp, {r0 - r12} @ Calling r0-r12
263 add r8, sp, #S_PC
264 stmdb r8, {sp, lr}^ @ Calling SP, LR
265 str lr, [r8, #0] @ Save calling PC
266 mrs r6, spsr
267 str r6, [r8, #4] @ Save CPSR
268 str r0, [r8, #8] @ Save OLD_R0
269 mov r0, sp
270 .endm
271
272 .macro irq_restore_user_regs
273 ldmia sp, {r0 - lr}^ @ Calling r0 - lr
274 mov r0, r0
275 ldr lr, [sp, #S_PC] @ Get PC
276 add sp, sp, #S_FRAME_SIZE
277 subs pc, lr, #4 @ return & move spsr_svc into cpsr
278 .endm
279
280 .macro get_bad_stack
Heiko Schochere30ceca2010-09-17 13:10:48 +0200281 ldr r13, IRQ_STACK_START_IN @ setup our mode stack
wdenkfe8c2802002-11-03 00:38:21 +0000282
283 str lr, [r13] @ save caller lr / spsr
284 mrs lr, spsr
285 str lr, [r13, #4]
286
287 mov r13, #MODE_SVC @ prepare SVC-Mode
288 msr spsr_c, r13
289 mov lr, pc
290 movs pc, lr
291 .endm
292
293 .macro get_irq_stack @ setup IRQ stack
294 ldr sp, IRQ_STACK_START
295 .endm
296
297 .macro get_fiq_stack @ setup FIQ stack
298 ldr sp, FIQ_STACK_START
299 .endm
300
301/*
302 * exception handlers
303 */
304 .align 5
305undefined_instruction:
306 get_bad_stack
307 bad_save_user_regs
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200308 bl do_undefined_instruction
wdenkfe8c2802002-11-03 00:38:21 +0000309
310 .align 5
311software_interrupt:
312 get_bad_stack
313 bad_save_user_regs
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200314 bl do_software_interrupt
wdenkfe8c2802002-11-03 00:38:21 +0000315
316 .align 5
317prefetch_abort:
318 get_bad_stack
319 bad_save_user_regs
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200320 bl do_prefetch_abort
wdenkfe8c2802002-11-03 00:38:21 +0000321
322 .align 5
323data_abort:
324 get_bad_stack
325 bad_save_user_regs
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200326 bl do_data_abort
wdenkfe8c2802002-11-03 00:38:21 +0000327
328 .align 5
329not_used:
330 get_bad_stack
331 bad_save_user_regs
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200332 bl do_not_used
wdenkfe8c2802002-11-03 00:38:21 +0000333
334#ifdef CONFIG_USE_IRQ
335
336 .align 5
337irq:
338 get_irq_stack
339 irq_save_user_regs
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200340 bl do_irq
wdenkfe8c2802002-11-03 00:38:21 +0000341 irq_restore_user_regs
342
343 .align 5
344fiq:
345 get_fiq_stack
346 /* someone ought to write a more effiction fiq_save_user_regs */
347 irq_save_user_regs
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200348 bl do_fiq
wdenkfe8c2802002-11-03 00:38:21 +0000349 irq_restore_user_regs
350
351#else
352
353 .align 5
354irq:
355 get_bad_stack
356 bad_save_user_regs
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200357 bl do_irq
wdenkfe8c2802002-11-03 00:38:21 +0000358
359 .align 5
360fiq:
361 get_bad_stack
362 bad_save_user_regs
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200363 bl do_fiq
wdenkfe8c2802002-11-03 00:38:21 +0000364
365#endif
366
367 .align 5
368.globl reset_cpu
369reset_cpu:
370 ldr r0, RST_BASE
371 mov r1, #0x0 @ set bit 3-0 ...
372 str r1, [r0, #RCSR] @ ... to clear in RCSR
373 mov r1, #0x1
374 str r1, [r0, #RSRR] @ and perform reset
375 b reset_cpu @ silly, but repeat endlessly