blob: a396ebcb715ebc121d8b4e13c7b28fecc2ea2675 [file] [log] [blame]
wdenkfe8c2802002-11-03 00:38:21 +00001/*
2 * armboot - Startup Code for ARM720 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>
wdenkfe8c2802002-11-03 00:38:21 +00006 *
7 * See file CREDITS for list of people who contributed to this
8 * project.
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License as
12 * published by the Free Software Foundation; either version 2 of
13 * the License, or (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
wdenkfa366cc2004-07-11 22:27:55 +000017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
wdenkfe8c2802002-11-03 00:38:21 +000018 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
23 * MA 02111-1307 USA
24 */
25
Wolfgang Denk0191e472010-10-26 14:34:52 +020026#include <asm-offsets.h>
wdenkfe8c2802002-11-03 00:38:21 +000027#include <config.h>
28#include <version.h>
wdenkf2140d52004-07-01 16:30:44 +000029#include <asm/hardware.h>
wdenkfe8c2802002-11-03 00:38:21 +000030
31/*
32 *************************************************************************
33 *
34 * Jump vector table as in table 3.1 in [1]
35 *
36 *************************************************************************
37 */
38
39
40.globl _start
wdenkfa366cc2004-07-11 22:27:55 +000041_start: b reset
wdenkfe8c2802002-11-03 00:38:21 +000042 ldr pc, _undefined_instruction
43 ldr pc, _software_interrupt
44 ldr pc, _prefetch_abort
45 ldr pc, _data_abort
46 ldr pc, _not_used
47 ldr pc, _irq
48 ldr pc, _fiq
49
Allen Martinb9690f12012-08-31 08:30:07 +000050#ifdef CONFIG_SPL_BUILD
51_undefined_instruction: .word _undefined_instruction
52_software_interrupt: .word _software_interrupt
53_prefetch_abort: .word _prefetch_abort
54_data_abort: .word _data_abort
55_not_used: .word _not_used
56_irq: .word _irq
57_fiq: .word _fiq
Allen Martine60ab6e2012-08-31 08:30:09 +000058_pad: .word 0x12345678 /* now 16*4=64 */
Allen Martinb9690f12012-08-31 08:30:07 +000059#else
wdenkfa366cc2004-07-11 22:27:55 +000060_undefined_instruction: .word undefined_instruction
wdenkfe8c2802002-11-03 00:38:21 +000061_software_interrupt: .word software_interrupt
62_prefetch_abort: .word prefetch_abort
63_data_abort: .word data_abort
64_not_used: .word not_used
65_irq: .word irq
66_fiq: .word fiq
Allen Martine60ab6e2012-08-31 08:30:09 +000067_pad: .word 0x12345678 /* now 16*4=64 */
Allen Martinb9690f12012-08-31 08:30:07 +000068#endif /* CONFIG_SPL_BUILD */
wdenkfe8c2802002-11-03 00:38:21 +000069
70 .balignl 16,0xdeadbeef
71
72
73/*
74 *************************************************************************
75 *
76 * Startup Code (reset vector)
77 *
wdenk927034e2004-02-08 19:38:38 +000078 * do important init only if we don't start from RAM!
wdenkfe8c2802002-11-03 00:38:21 +000079 * relocate armboot to ram
80 * setup stack
81 * jump to second stage
82 *
83 *************************************************************************
84 */
85
Heiko Schochercad80e12010-09-17 13:10:52 +020086.globl _TEXT_BASE
wdenkfe8c2802002-11-03 00:38:21 +000087_TEXT_BASE:
Benoît Thébaudeaua402da32013-04-11 09:35:42 +000088#if defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_TEXT_BASE)
Allen Martine60ab6e2012-08-31 08:30:09 +000089 .word CONFIG_SPL_TEXT_BASE
90#else
Wolfgang Denk0708bc62010-10-07 21:51:12 +020091 .word CONFIG_SYS_TEXT_BASE
Allen Martine60ab6e2012-08-31 08:30:09 +000092#endif
wdenkfe8c2802002-11-03 00:38:21 +000093
wdenkfe8c2802002-11-03 00:38:21 +000094/*
wdenk927034e2004-02-08 19:38:38 +000095 * These are defined in the board-specific linker script.
Albert Aribaud126897e2010-11-25 22:45:02 +010096 * Subtracting _start from them lets the linker put their
97 * relative position in the executable instead of leaving
98 * them null.
wdenkfe8c2802002-11-03 00:38:21 +000099 */
Albert Aribaud126897e2010-11-25 22:45:02 +0100100.globl _bss_start_ofs
101_bss_start_ofs:
102 .word __bss_start - _start
wdenk927034e2004-02-08 19:38:38 +0000103
Albert Aribaud126897e2010-11-25 22:45:02 +0100104.globl _bss_end_ofs
105_bss_end_ofs:
Simon Glassed70c8f2013-03-14 06:54:53 +0000106 .word __bss_end - _start
wdenkfe8c2802002-11-03 00:38:21 +0000107
Po-Yu Chuang1864b002011-03-01 23:02:04 +0000108.globl _end_ofs
109_end_ofs:
110 .word _end - _start
111
wdenkfe8c2802002-11-03 00:38:21 +0000112#ifdef CONFIG_USE_IRQ
113/* IRQ stack memory (calculated at run-time) */
114.globl IRQ_STACK_START
115IRQ_STACK_START:
116 .word 0x0badc0de
117
118/* IRQ stack memory (calculated at run-time) */
119.globl FIQ_STACK_START
120FIQ_STACK_START:
121 .word 0x0badc0de
122#endif
Heiko Schochercad80e12010-09-17 13:10:52 +0200123
Heiko Schochercad80e12010-09-17 13:10:52 +0200124/* IRQ stack memory (calculated at run-time) + 8 bytes */
125.globl IRQ_STACK_START_IN
126IRQ_STACK_START_IN:
127 .word 0x0badc0de
128
Heiko Schochercad80e12010-09-17 13:10:52 +0200129/*
130 * the actual reset code
131 */
132
133reset:
134 /*
135 * set the cpu to SVC32 mode
136 */
137 mrs r0,cpsr
138 bic r0,r0,#0x1f
139 orr r0,r0,#0xd3
140 msr cpsr,r0
141
142 /*
143 * we do sys-critical inits only at reboot,
144 * not when booting from ram!
145 */
146#ifndef CONFIG_SKIP_LOWLEVEL_INIT
147 bl cpu_init_crit
148#endif
149
Albert ARIBAUDfacdae52013-01-08 10:18:02 +0000150 bl _main
Heiko Schochercad80e12010-09-17 13:10:52 +0200151
152/*------------------------------------------------------------------------------*/
153
Albert ARIBAUDfacdae52013-01-08 10:18:02 +0000154 .globl c_runtime_cpu_setup
155c_runtime_cpu_setup:
156
157 mov pc, lr
158
wdenkfe8c2802002-11-03 00:38:21 +0000159/*
160 *************************************************************************
161 *
162 * CPU_init_critical registers
163 *
164 * setup important registers
165 * setup memory timing
166 *
167 *************************************************************************
168 */
169
Axel Lin89a8f7a2013-05-21 13:44:10 +0000170#ifndef CONFIG_SKIP_LOWLEVEL_INIT
wdenkfe8c2802002-11-03 00:38:21 +0000171cpu_init_crit:
wdenkfe8c2802002-11-03 00:38:21 +0000172
Wolfgang Denk7f88a5e2005-10-06 17:08:18 +0200173 mov ip, lr
wdenkfe8c2802002-11-03 00:38:21 +0000174 /*
175 * before relocating, we have to setup RAM timing
wdenk927034e2004-02-08 19:38:38 +0000176 * because memory timing is board-dependent, you will
wdenk336b2bc2005-04-02 23:52:25 +0000177 * find a lowlevel_init.S in your board directory.
wdenkfe8c2802002-11-03 00:38:21 +0000178 */
wdenk336b2bc2005-04-02 23:52:25 +0000179 bl lowlevel_init
wdenkfe8c2802002-11-03 00:38:21 +0000180 mov lr, ip
181
182 mov pc, lr
Axel Lin89a8f7a2013-05-21 13:44:10 +0000183#endif /* CONFIG_SKIP_LOWLEVEL_INIT */
wdenkfe8c2802002-11-03 00:38:21 +0000184
185
Allen Martinb9690f12012-08-31 08:30:07 +0000186#ifndef CONFIG_SPL_BUILD
wdenkfe8c2802002-11-03 00:38:21 +0000187/*
188 *************************************************************************
189 *
190 * Interrupt handling
191 *
192 *************************************************************************
193 */
194
195@
196@ IRQ stack frame.
197@
198#define S_FRAME_SIZE 72
199
200#define S_OLD_R0 68
201#define S_PSR 64
202#define S_PC 60
203#define S_LR 56
204#define S_SP 52
205
206#define S_IP 48
207#define S_FP 44
208#define S_R10 40
209#define S_R9 36
210#define S_R8 32
211#define S_R7 28
212#define S_R6 24
213#define S_R5 20
214#define S_R4 16
215#define S_R3 12
216#define S_R2 8
217#define S_R1 4
218#define S_R0 0
219
220#define MODE_SVC 0x13
221#define I_BIT 0x80
222
223/*
224 * use bad_save_user_regs for abort/prefetch/undef/swi ...
225 * use irq_save_user_regs / irq_restore_user_regs for IRQ/FIQ handling
226 */
227
228 .macro bad_save_user_regs
229 sub sp, sp, #S_FRAME_SIZE
230 stmia sp, {r0 - r12} @ Calling r0-r12
wdenkfa366cc2004-07-11 22:27:55 +0000231 add r8, sp, #S_PC
wdenkfe8c2802002-11-03 00:38:21 +0000232
Heiko Schochercad80e12010-09-17 13:10:52 +0200233 ldr r2, IRQ_STACK_START_IN
wdenkfa366cc2004-07-11 22:27:55 +0000234 ldmia r2, {r2 - r4} @ get pc, cpsr, old_r0
wdenkfe8c2802002-11-03 00:38:21 +0000235 add r0, sp, #S_FRAME_SIZE @ restore sp_SVC
236
237 add r5, sp, #S_SP
238 mov r1, lr
wdenkfa366cc2004-07-11 22:27:55 +0000239 stmia r5, {r0 - r4} @ save sp_SVC, lr_SVC, pc, cpsr, old_r
wdenkfe8c2802002-11-03 00:38:21 +0000240 mov r0, sp
241 .endm
242
243 .macro irq_save_user_regs
244 sub sp, sp, #S_FRAME_SIZE
245 stmia sp, {r0 - r12} @ Calling r0-r12
wdenkfa366cc2004-07-11 22:27:55 +0000246 add r8, sp, #S_PC
247 stmdb r8, {sp, lr}^ @ Calling SP, LR
248 str lr, [r8, #0] @ Save calling PC
249 mrs r6, spsr
250 str r6, [r8, #4] @ Save CPSR
251 str r0, [r8, #8] @ Save OLD_R0
wdenkfe8c2802002-11-03 00:38:21 +0000252 mov r0, sp
253 .endm
254
255 .macro irq_restore_user_regs
256 ldmia sp, {r0 - lr}^ @ Calling r0 - lr
257 mov r0, r0
258 ldr lr, [sp, #S_PC] @ Get PC
259 add sp, sp, #S_FRAME_SIZE
260 subs pc, lr, #4 @ return & move spsr_svc into cpsr
261 .endm
262
263 .macro get_bad_stack
Heiko Schochercad80e12010-09-17 13:10:52 +0200264 ldr r13, IRQ_STACK_START_IN @ setup our mode stack
wdenkfe8c2802002-11-03 00:38:21 +0000265
266 str lr, [r13] @ save caller lr / spsr
267 mrs lr, spsr
wdenkfa366cc2004-07-11 22:27:55 +0000268 str lr, [r13, #4]
wdenkfe8c2802002-11-03 00:38:21 +0000269
270 mov r13, #MODE_SVC @ prepare SVC-Mode
271 msr spsr_c, r13
272 mov lr, pc
273 movs pc, lr
274 .endm
275
276 .macro get_irq_stack @ setup IRQ stack
277 ldr sp, IRQ_STACK_START
278 .endm
279
280 .macro get_fiq_stack @ setup FIQ stack
281 ldr sp, FIQ_STACK_START
282 .endm
283
284/*
285 * exception handlers
286 */
wdenkfa366cc2004-07-11 22:27:55 +0000287 .align 5
wdenkfe8c2802002-11-03 00:38:21 +0000288undefined_instruction:
289 get_bad_stack
290 bad_save_user_regs
wdenkfa366cc2004-07-11 22:27:55 +0000291 bl do_undefined_instruction
wdenkfe8c2802002-11-03 00:38:21 +0000292
293 .align 5
294software_interrupt:
295 get_bad_stack
296 bad_save_user_regs
wdenkfa366cc2004-07-11 22:27:55 +0000297 bl do_software_interrupt
wdenkfe8c2802002-11-03 00:38:21 +0000298
299 .align 5
300prefetch_abort:
301 get_bad_stack
302 bad_save_user_regs
wdenkfa366cc2004-07-11 22:27:55 +0000303 bl do_prefetch_abort
wdenkfe8c2802002-11-03 00:38:21 +0000304
305 .align 5
306data_abort:
307 get_bad_stack
308 bad_save_user_regs
wdenkfa366cc2004-07-11 22:27:55 +0000309 bl do_data_abort
wdenkfe8c2802002-11-03 00:38:21 +0000310
311 .align 5
312not_used:
313 get_bad_stack
314 bad_save_user_regs
wdenkfa366cc2004-07-11 22:27:55 +0000315 bl do_not_used
wdenkfe8c2802002-11-03 00:38:21 +0000316
317#ifdef CONFIG_USE_IRQ
318
319 .align 5
320irq:
321 get_irq_stack
322 irq_save_user_regs
wdenkfa366cc2004-07-11 22:27:55 +0000323 bl do_irq
wdenkfe8c2802002-11-03 00:38:21 +0000324 irq_restore_user_regs
325
326 .align 5
327fiq:
328 get_fiq_stack
329 /* someone ought to write a more effiction fiq_save_user_regs */
330 irq_save_user_regs
wdenkfa366cc2004-07-11 22:27:55 +0000331 bl do_fiq
wdenkfe8c2802002-11-03 00:38:21 +0000332 irq_restore_user_regs
333
334#else
335
336 .align 5
337irq:
338 get_bad_stack
339 bad_save_user_regs
wdenkfa366cc2004-07-11 22:27:55 +0000340 bl do_irq
wdenkfe8c2802002-11-03 00:38:21 +0000341
342 .align 5
343fiq:
344 get_bad_stack
345 bad_save_user_regs
wdenkfa366cc2004-07-11 22:27:55 +0000346 bl do_fiq
wdenkfe8c2802002-11-03 00:38:21 +0000347
348#endif
Allen Martinb9690f12012-08-31 08:30:07 +0000349#endif /* CONFIG_SPL_BUILD */