blob: 7bf094aec133cae3738543e8b20a990cb376d5e6 [file] [log] [blame]
wdenkfe8c2802002-11-03 00:38:21 +00001/*
2 * armboot - Startup Code for ARM920 CPU-core
3 *
Albert ARIBAUD60fbc8d2011-08-04 18:45:45 +02004 * Copyright (c) 2001 Marius Gröger <mag@sysgo.de>
5 * Copyright (c) 2002 Alex Züpke <azu@sysgo.de>
Detlev Zundelf1b3f2b2009-05-13 10:54:10 +02006 * Copyright (c) 2002 Gary Jennejohn <garyj@denx.de>
wdenkfe8c2802002-11-03 00:38:21 +00007 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02008 * SPDX-License-Identifier: GPL-2.0+
wdenkfe8c2802002-11-03 00:38:21 +00009 */
10
Wolfgang Denk0191e472010-10-26 14:34:52 +020011#include <asm-offsets.h>
Wolfgang Denk140f0442009-07-27 10:06:39 +020012#include <common.h>
wdenkfe8c2802002-11-03 00:38:21 +000013#include <config.h>
wdenkfe8c2802002-11-03 00:38:21 +000014
15/*
16 *************************************************************************
17 *
18 * Jump vector table as in table 3.1 in [1]
19 *
20 *************************************************************************
21 */
22
23
24.globl _start
kevin.morfitt@fearnside-systems.co.ukd1cacc72009-10-10 13:30:22 +090025_start: b start_code
wdenkfe8c2802002-11-03 00:38:21 +000026 ldr pc, _undefined_instruction
27 ldr pc, _software_interrupt
28 ldr pc, _prefetch_abort
29 ldr pc, _data_abort
30 ldr pc, _not_used
31 ldr pc, _irq
32 ldr pc, _fiq
33
34_undefined_instruction: .word undefined_instruction
35_software_interrupt: .word software_interrupt
36_prefetch_abort: .word prefetch_abort
37_data_abort: .word data_abort
38_not_used: .word not_used
39_irq: .word irq
40_fiq: .word fiq
41
42 .balignl 16,0xdeadbeef
43
44
45/*
46 *************************************************************************
47 *
Peter Pearse782cf162007-09-05 16:04:41 +010048 * Startup Code (called from the ARM reset exception vector)
wdenkfe8c2802002-11-03 00:38:21 +000049 *
50 * do important init only if we don't start from memory!
51 * relocate armboot to ram
52 * setup stack
53 * jump to second stage
54 *
55 *************************************************************************
56 */
57
wdenkfe8c2802002-11-03 00:38:21 +000058#ifdef CONFIG_USE_IRQ
59/* IRQ stack memory (calculated at run-time) */
60.globl IRQ_STACK_START
61IRQ_STACK_START:
62 .word 0x0badc0de
63
64/* IRQ stack memory (calculated at run-time) */
65.globl FIQ_STACK_START
66FIQ_STACK_START:
67 .word 0x0badc0de
68#endif
69
Heiko Schocher271a2402010-09-17 13:10:43 +020070/* IRQ stack memory (calculated at run-time) + 8 bytes */
71.globl IRQ_STACK_START_IN
72IRQ_STACK_START_IN:
73 .word 0x0badc0de
74
wdenkfe8c2802002-11-03 00:38:21 +000075/*
Peter Pearse782cf162007-09-05 16:04:41 +010076 * the actual start code
wdenkfe8c2802002-11-03 00:38:21 +000077 */
78
Peter Pearse782cf162007-09-05 16:04:41 +010079start_code:
wdenkfe8c2802002-11-03 00:38:21 +000080 /*
81 * set the cpu to SVC32 mode
82 */
kevin.morfitt@fearnside-systems.co.ukd1cacc72009-10-10 13:30:22 +090083 mrs r0, cpsr
84 bic r0, r0, #0x1f
85 orr r0, r0, #0xd3
86 msr cpsr, r0
Peter Pearse782cf162007-09-05 16:04:41 +010087
Jean-Christophe PLAGNIOL-VILLARD06f34962008-11-30 19:36:50 +010088#if defined(CONFIG_AT91RM9200DK) || defined(CONFIG_AT91RM9200EK)
Peter Pearsede5b02c2007-08-14 10:10:52 +010089 /*
Peter Pearse782cf162007-09-05 16:04:41 +010090 * relocate exception table
Peter Pearsede5b02c2007-08-14 10:10:52 +010091 */
92 ldr r0, =_start
93 ldr r1, =0x0
94 mov r2, #16
95copyex:
96 subs r2, r2, #1
97 ldr r3, [r0], #4
98 str r3, [r1], #4
99 bne copyex
100#endif
101
kevin.morfitt@fearnside-systems.co.uke0d81312009-11-17 18:30:34 +0900102#ifdef CONFIG_S3C24X0
Peter Pearse782cf162007-09-05 16:04:41 +0100103 /* turn off the watchdog */
104
105# if defined(CONFIG_S3C2400)
kevin.morfitt@fearnside-systems.co.ukd1cacc72009-10-10 13:30:22 +0900106# define pWTCON 0x15300000
Mike Williamsbf895ad2011-07-22 04:01:30 +0000107# define INTMSK 0x14400008 /* Interrupt-Controller base addresses */
Peter Pearse782cf162007-09-05 16:04:41 +0100108# define CLKDIVN 0x14800014 /* clock divisor register */
109#else
kevin.morfitt@fearnside-systems.co.ukd1cacc72009-10-10 13:30:22 +0900110# define pWTCON 0x53000000
Mike Williamsbf895ad2011-07-22 04:01:30 +0000111# define INTMSK 0x4A000008 /* Interrupt-Controller base addresses */
Peter Pearse782cf162007-09-05 16:04:41 +0100112# define INTSUBMSK 0x4A00001C
113# define CLKDIVN 0x4C000014 /* clock divisor register */
114# endif
115
kevin.morfitt@fearnside-systems.co.ukd1cacc72009-10-10 13:30:22 +0900116 ldr r0, =pWTCON
117 mov r1, #0x0
118 str r1, [r0]
wdenkfe8c2802002-11-03 00:38:21 +0000119
120 /*
121 * mask all IRQs by setting all bits in the INTMR - default
122 */
123 mov r1, #0xffffffff
124 ldr r0, =INTMSK
125 str r1, [r0]
wdenk7ac16102004-08-01 22:48:16 +0000126# if defined(CONFIG_S3C2410)
wdenkfe8c2802002-11-03 00:38:21 +0000127 ldr r1, =0x3ff
128 ldr r0, =INTSUBMSK
129 str r1, [r0]
wdenk7ac16102004-08-01 22:48:16 +0000130# endif
wdenkfe8c2802002-11-03 00:38:21 +0000131
132 /* FCLK:HCLK:PCLK = 1:2:4 */
133 /* default FCLK is 120 MHz ! */
134 ldr r0, =CLKDIVN
135 mov r1, #3
136 str r1, [r0]
kevin.morfitt@fearnside-systems.co.uke0d81312009-11-17 18:30:34 +0900137#endif /* CONFIG_S3C24X0 */
wdenkfe8c2802002-11-03 00:38:21 +0000138
139 /*
140 * we do sys-critical inits only at reboot,
141 * not when booting from ram!
142 */
wdenk3d3d99f2005-04-04 12:44:11 +0000143#ifndef CONFIG_SKIP_LOWLEVEL_INIT
wdenkfe8c2802002-11-03 00:38:21 +0000144 bl cpu_init_crit
145#endif
146
Albert ARIBAUDfacdae52013-01-08 10:18:02 +0000147 bl _main
Heiko Schocher271a2402010-09-17 13:10:43 +0200148
149/*------------------------------------------------------------------------------*/
150
Albert ARIBAUDfacdae52013-01-08 10:18:02 +0000151 .globl c_runtime_cpu_setup
152c_runtime_cpu_setup:
153
154 mov pc, lr
155
wdenkfe8c2802002-11-03 00:38:21 +0000156/*
157 *************************************************************************
158 *
159 * CPU_init_critical registers
160 *
161 * setup important registers
162 * setup memory timing
163 *
164 *************************************************************************
165 */
166
167
Wolfgang Denkf2e11a72006-04-03 15:46:10 +0200168#ifndef CONFIG_SKIP_LOWLEVEL_INIT
wdenkfe8c2802002-11-03 00:38:21 +0000169cpu_init_crit:
170 /*
171 * flush v4 I/D caches
172 */
173 mov r0, #0
174 mcr p15, 0, r0, c7, c7, 0 /* flush v3/v4 cache */
175 mcr p15, 0, r0, c8, c7, 0 /* flush v4 TLB */
176
177 /*
178 * disable MMU stuff and caches
179 */
180 mrc p15, 0, r0, c1, c0, 0
181 bic r0, r0, #0x00002300 @ clear bits 13, 9:8 (--V- --RS)
182 bic r0, r0, #0x00000087 @ clear bits 7, 2:0 (B--- -CAM)
183 orr r0, r0, #0x00000002 @ set bit 2 (A) Align
184 orr r0, r0, #0x00001000 @ set bit 12 (I) I-Cache
185 mcr p15, 0, r0, c1, c0, 0
186
wdenkfe8c2802002-11-03 00:38:21 +0000187 /*
188 * before relocating, we have to setup RAM timing
189 * because memory timing is board-dependend, you will
wdenk336b2bc2005-04-02 23:52:25 +0000190 * find a lowlevel_init.S in your board directory.
wdenkfe8c2802002-11-03 00:38:21 +0000191 */
192 mov ip, lr
Peter Pearsede5b02c2007-08-14 10:10:52 +0100193
wdenk336b2bc2005-04-02 23:52:25 +0000194 bl lowlevel_init
Ulf Samuelsson07f9b4e2009-03-27 23:26:43 +0100195
wdenkfe8c2802002-11-03 00:38:21 +0000196 mov lr, ip
wdenkfe8c2802002-11-03 00:38:21 +0000197 mov pc, lr
Wolfgang Denkf2e11a72006-04-03 15:46:10 +0200198#endif /* CONFIG_SKIP_LOWLEVEL_INIT */
wdenkfe8c2802002-11-03 00:38:21 +0000199
wdenkfe8c2802002-11-03 00:38:21 +0000200/*
201 *************************************************************************
202 *
203 * Interrupt handling
204 *
205 *************************************************************************
206 */
207
208@
209@ IRQ stack frame.
210@
211#define S_FRAME_SIZE 72
212
213#define S_OLD_R0 68
214#define S_PSR 64
215#define S_PC 60
216#define S_LR 56
217#define S_SP 52
218
219#define S_IP 48
220#define S_FP 44
221#define S_R10 40
222#define S_R9 36
223#define S_R8 32
224#define S_R7 28
225#define S_R6 24
226#define S_R5 20
227#define S_R4 16
228#define S_R3 12
229#define S_R2 8
230#define S_R1 4
231#define S_R0 0
232
kevin.morfitt@fearnside-systems.co.ukd1cacc72009-10-10 13:30:22 +0900233#define MODE_SVC 0x13
234#define I_BIT 0x80
wdenkfe8c2802002-11-03 00:38:21 +0000235
236/*
237 * use bad_save_user_regs for abort/prefetch/undef/swi ...
238 * use irq_save_user_regs / irq_restore_user_regs for IRQ/FIQ handling
239 */
240
241 .macro bad_save_user_regs
242 sub sp, sp, #S_FRAME_SIZE
243 stmia sp, {r0 - r12} @ Calling r0-r12
Heiko Schocher271a2402010-09-17 13:10:43 +0200244 ldr r2, IRQ_STACK_START_IN
wdenkf4688a22003-05-28 08:06:31 +0000245 ldmia r2, {r2 - r3} @ get pc, cpsr
wdenkfe8c2802002-11-03 00:38:21 +0000246 add r0, sp, #S_FRAME_SIZE @ restore sp_SVC
247
248 add r5, sp, #S_SP
249 mov r1, lr
wdenkf4688a22003-05-28 08:06:31 +0000250 stmia r5, {r0 - r3} @ save sp_SVC, lr_SVC, pc, cpsr
wdenkfe8c2802002-11-03 00:38:21 +0000251 mov r0, sp
252 .endm
253
254 .macro irq_save_user_regs
255 sub sp, sp, #S_FRAME_SIZE
256 stmia sp, {r0 - r12} @ Calling r0-r12
kevin.morfitt@fearnside-systems.co.ukd1cacc72009-10-10 13:30:22 +0900257 add r7, sp, #S_PC
258 stmdb r7, {sp, lr}^ @ Calling SP, LR
259 str lr, [r7, #0] @ Save calling PC
260 mrs r6, spsr
261 str r6, [r7, #4] @ Save CPSR
262 str r0, [r7, #8] @ Save OLD_R0
wdenkfe8c2802002-11-03 00:38:21 +0000263 mov r0, sp
264 .endm
265
266 .macro irq_restore_user_regs
267 ldmia sp, {r0 - lr}^ @ Calling r0 - lr
268 mov r0, r0
269 ldr lr, [sp, #S_PC] @ Get PC
270 add sp, sp, #S_FRAME_SIZE
kevin.morfitt@fearnside-systems.co.ukd1cacc72009-10-10 13:30:22 +0900271 /* return & move spsr_svc into cpsr */
272 subs pc, lr, #4
wdenkfe8c2802002-11-03 00:38:21 +0000273 .endm
274
275 .macro get_bad_stack
Heiko Schocher271a2402010-09-17 13:10:43 +0200276 ldr r13, IRQ_STACK_START_IN @ setup our mode stack
wdenkfe8c2802002-11-03 00:38:21 +0000277
278 str lr, [r13] @ save caller lr / spsr
279 mrs lr, spsr
kevin.morfitt@fearnside-systems.co.ukd1cacc72009-10-10 13:30:22 +0900280 str lr, [r13, #4]
wdenkfe8c2802002-11-03 00:38:21 +0000281
282 mov r13, #MODE_SVC @ prepare SVC-Mode
283 @ msr spsr_c, r13
284 msr spsr, r13
285 mov lr, pc
286 movs pc, lr
287 .endm
288
289 .macro get_irq_stack @ setup IRQ stack
290 ldr sp, IRQ_STACK_START
291 .endm
292
293 .macro get_fiq_stack @ setup FIQ stack
294 ldr sp, FIQ_STACK_START
295 .endm
296
297/*
298 * exception handlers
299 */
300 .align 5
301undefined_instruction:
302 get_bad_stack
303 bad_save_user_regs
Wolfgang Denka1be4762008-05-20 16:00:29 +0200304 bl do_undefined_instruction
wdenkfe8c2802002-11-03 00:38:21 +0000305
306 .align 5
307software_interrupt:
308 get_bad_stack
309 bad_save_user_regs
Wolfgang Denka1be4762008-05-20 16:00:29 +0200310 bl do_software_interrupt
wdenkfe8c2802002-11-03 00:38:21 +0000311
312 .align 5
313prefetch_abort:
314 get_bad_stack
315 bad_save_user_regs
Wolfgang Denka1be4762008-05-20 16:00:29 +0200316 bl do_prefetch_abort
wdenkfe8c2802002-11-03 00:38:21 +0000317
318 .align 5
319data_abort:
320 get_bad_stack
321 bad_save_user_regs
Wolfgang Denka1be4762008-05-20 16:00:29 +0200322 bl do_data_abort
wdenkfe8c2802002-11-03 00:38:21 +0000323
324 .align 5
325not_used:
326 get_bad_stack
327 bad_save_user_regs
Wolfgang Denka1be4762008-05-20 16:00:29 +0200328 bl do_not_used
wdenkfe8c2802002-11-03 00:38:21 +0000329
330#ifdef CONFIG_USE_IRQ
331
332 .align 5
333irq:
334 get_irq_stack
335 irq_save_user_regs
Wolfgang Denka1be4762008-05-20 16:00:29 +0200336 bl do_irq
wdenkfe8c2802002-11-03 00:38:21 +0000337 irq_restore_user_regs
338
339 .align 5
340fiq:
341 get_fiq_stack
342 /* someone ought to write a more effiction fiq_save_user_regs */
343 irq_save_user_regs
Wolfgang Denka1be4762008-05-20 16:00:29 +0200344 bl do_fiq
wdenkfe8c2802002-11-03 00:38:21 +0000345 irq_restore_user_regs
346
347#else
348
349 .align 5
350irq:
351 get_bad_stack
352 bad_save_user_regs
Wolfgang Denka1be4762008-05-20 16:00:29 +0200353 bl do_irq
wdenkfe8c2802002-11-03 00:38:21 +0000354
355 .align 5
356fiq:
357 get_bad_stack
358 bad_save_user_regs
Wolfgang Denka1be4762008-05-20 16:00:29 +0200359 bl do_fiq
wdenkfe8c2802002-11-03 00:38:21 +0000360
361#endif