blob: 5360f55bc1a4251e9e3d56ba133854ec788b3153 [file] [log] [blame]
wdenk6f213472003-08-29 22:00:43 +00001/*
2 * armboot - Startup Code for ARM926EJS CPU-core
3 *
4 * Copyright (c) 2003 Texas Instruments
5 *
wdenka56bd922004-06-06 23:13:55 +00006 * ----- Adapted for OMAP1610 OMAP730 from ARM925t code ------
wdenk6f213472003-08-29 22:00:43 +00007 *
Albert ARIBAUDfa82f872011-08-04 18:45:45 +02008 * Copyright (c) 2001 Marius Gröger <mag@sysgo.de>
9 * Copyright (c) 2002 Alex Züpke <azu@sysgo.de>
Detlev Zundel792a09e2009-05-13 10:54:10 +020010 * Copyright (c) 2002 Gary Jennejohn <garyj@denx.de>
wdenk6f213472003-08-29 22:00:43 +000011 * Copyright (c) 2003 Richard Woodruff <r-woodruff2@ti.com>
12 * Copyright (c) 2003 Kshitij <kshitij@ti.com>
Albert ARIBAUD57b4bce2011-04-22 19:41:02 +020013 * Copyright (c) 2010 Albert Aribaud <albert.u.boot@aribaud.net>
wdenk6f213472003-08-29 22:00:43 +000014 *
Wolfgang Denk1a459662013-07-08 09:37:19 +020015 * SPDX-License-Identifier: GPL-2.0+
wdenk6f213472003-08-29 22:00:43 +000016 */
17
Wolfgang Denk25ddd1f2010-10-26 14:34:52 +020018#include <asm-offsets.h>
wdenk6f213472003-08-29 22:00:43 +000019#include <config.h>
Wolfgang Denkfcd3c872009-07-24 00:17:48 +020020#include <common.h>
wdenk6f213472003-08-29 22:00:43 +000021#include <version.h>
22
wdenk6f213472003-08-29 22:00:43 +000023/*
24 *************************************************************************
25 *
26 * Jump vector table as in table 3.1 in [1]
27 *
28 *************************************************************************
29 */
30
31
Heiko Schocher337c4332011-09-14 19:59:37 +000032#ifdef CONFIG_SYS_DV_NOR_BOOT_CFG
33.globl _start
34_start:
35.globl _NOR_BOOT_CFG
36_NOR_BOOT_CFG:
37 .word CONFIG_SYS_DV_NOR_BOOT_CFG
38 b reset
39#else
wdenk6f213472003-08-29 22:00:43 +000040.globl _start
41_start:
42 b reset
Heiko Schocher337c4332011-09-14 19:59:37 +000043#endif
Aneesh V401bb302011-07-13 05:11:07 +000044#ifdef CONFIG_SPL_BUILD
John Rigbyef22b502010-01-25 23:12:52 -070045/* No exception handlers in preloader */
46 ldr pc, _hang
47 ldr pc, _hang
48 ldr pc, _hang
49 ldr pc, _hang
50 ldr pc, _hang
51 ldr pc, _hang
52 ldr pc, _hang
53
54_hang:
55 .word do_hang
56/* pad to 64 byte boundary */
57 .word 0x12345678
58 .word 0x12345678
59 .word 0x12345678
60 .word 0x12345678
61 .word 0x12345678
62 .word 0x12345678
63 .word 0x12345678
64#else
wdenk6f213472003-08-29 22:00:43 +000065 ldr pc, _undefined_instruction
66 ldr pc, _software_interrupt
67 ldr pc, _prefetch_abort
68 ldr pc, _data_abort
69 ldr pc, _not_used
70 ldr pc, _irq
71 ldr pc, _fiq
72
73_undefined_instruction:
74 .word undefined_instruction
75_software_interrupt:
76 .word software_interrupt
77_prefetch_abort:
78 .word prefetch_abort
79_data_abort:
80 .word data_abort
81_not_used:
82 .word not_used
83_irq:
84 .word irq
85_fiq:
86 .word fiq
87
Aneesh V401bb302011-07-13 05:11:07 +000088#endif /* CONFIG_SPL_BUILD */
wdenk6f213472003-08-29 22:00:43 +000089 .balignl 16,0xdeadbeef
90
91
92/*
93 *************************************************************************
94 *
95 * Startup Code (reset vector)
96 *
97 * do important init only if we don't start from memory!
98 * setup Memory and board specific bits prior to relocation.
99 * relocate armboot to ram
100 * setup stack
101 *
102 *************************************************************************
103 */
104
Heiko Schocherab86f722010-09-17 13:10:42 +0200105.globl _TEXT_BASE
wdenk6f213472003-08-29 22:00:43 +0000106_TEXT_BASE:
Benoît Thébaudeau508611b2013-04-11 09:35:42 +0000107#if defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_TEXT_BASE)
Heiko Schocher435199f2011-11-01 20:00:29 +0000108 .word CONFIG_SPL_TEXT_BASE
109#else
110 .word CONFIG_SYS_TEXT_BASE
111#endif
wdenk6f213472003-08-29 22:00:43 +0000112
wdenk6f213472003-08-29 22:00:43 +0000113/*
wdenkf6e20fc2004-02-08 19:38:38 +0000114 * These are defined in the board-specific linker script.
Albert Aribaud92d5ecb2010-10-11 13:13:28 +0200115 * Subtracting _start from them lets the linker put their
116 * relative position in the executable instead of leaving
117 * them null.
wdenk6f213472003-08-29 22:00:43 +0000118 */
Albert Aribaud92d5ecb2010-10-11 13:13:28 +0200119.globl _bss_start_ofs
120_bss_start_ofs:
121 .word __bss_start - _start
wdenkf6e20fc2004-02-08 19:38:38 +0000122
Albert Aribaud92d5ecb2010-10-11 13:13:28 +0200123.globl _bss_end_ofs
124_bss_end_ofs:
Simon Glass3929fb02013-03-14 06:54:53 +0000125 .word __bss_end - _start
wdenk6f213472003-08-29 22:00:43 +0000126
Po-Yu Chuangf326cbb2011-03-01 23:02:04 +0000127.globl _end_ofs
128_end_ofs:
129 .word _end - _start
130
wdenk6f213472003-08-29 22:00:43 +0000131#ifdef CONFIG_USE_IRQ
132/* IRQ stack memory (calculated at run-time) */
133.globl IRQ_STACK_START
134IRQ_STACK_START:
135 .word 0x0badc0de
136
137/* IRQ stack memory (calculated at run-time) */
138.globl FIQ_STACK_START
139FIQ_STACK_START:
140 .word 0x0badc0de
141#endif
142
Heiko Schocherab86f722010-09-17 13:10:42 +0200143/* IRQ stack memory (calculated at run-time) + 8 bytes */
144.globl IRQ_STACK_START_IN
145IRQ_STACK_START_IN:
146 .word 0x0badc0de
wdenk6f213472003-08-29 22:00:43 +0000147
Heiko Schocherab86f722010-09-17 13:10:42 +0200148/*
149 * the actual reset code
150 */
151
152reset:
153 /*
154 * set the cpu to SVC32 mode
155 */
156 mrs r0,cpsr
157 bic r0,r0,#0x1f
158 orr r0,r0,#0xd3
159 msr cpsr,r0
160
161 /*
162 * we do sys-critical inits only at reboot,
163 * not when booting from ram!
164 */
Christian Riesch27b66622012-02-02 00:44:37 +0000165#ifndef CONFIG_SKIP_LOWLEVEL_INIT
Heiko Schocherab86f722010-09-17 13:10:42 +0200166 bl cpu_init_crit
Christian Riesch27b66622012-02-02 00:44:37 +0000167#endif
Heiko Schocherab86f722010-09-17 13:10:42 +0200168
Albert ARIBAUDe05e5de2013-01-08 10:18:02 +0000169 bl _main
Heiko Schocherab86f722010-09-17 13:10:42 +0200170
171/*------------------------------------------------------------------------------*/
172
Albert ARIBAUDe05e5de2013-01-08 10:18:02 +0000173 .globl c_runtime_cpu_setup
174c_runtime_cpu_setup:
175
176 bx lr
177
wdenk6f213472003-08-29 22:00:43 +0000178/*
179 *************************************************************************
180 *
181 * CPU_init_critical registers
182 *
183 * setup important registers
184 * setup memory timing
185 *
186 *************************************************************************
187 */
Christian Riesch27b66622012-02-02 00:44:37 +0000188#ifndef CONFIG_SKIP_LOWLEVEL_INIT
wdenk6f213472003-08-29 22:00:43 +0000189cpu_init_crit:
190 /*
Sughosh Ganuda104e02012-02-02 00:44:38 +0000191 * flush D cache before disabling it
wdenk6f213472003-08-29 22:00:43 +0000192 */
193 mov r0, #0
Sughosh Ganuda104e02012-02-02 00:44:38 +0000194flush_dcache:
195 mrc p15, 0, r15, c7, c10, 3
196 bne flush_dcache
197
198 mcr p15, 0, r0, c8, c7, 0 /* invalidate TLB */
199 mcr p15, 0, r0, c7, c5, 0 /* invalidate I Cache */
wdenk6f213472003-08-29 22:00:43 +0000200
201 /*
Christian Rieschd735a992012-02-02 00:44:40 +0000202 * disable MMU and D cache
203 * enable I cache if CONFIG_SYS_ICACHE_OFF is not defined
wdenk6f213472003-08-29 22:00:43 +0000204 */
205 mrc p15, 0, r0, c1, c0, 0
Christian Rieschb67d8812012-02-02 00:44:39 +0000206 bic r0, r0, #0x00000300 /* clear bits 9:8 (---- --RS) */
wdenk6f213472003-08-29 22:00:43 +0000207 bic r0, r0, #0x00000087 /* clear bits 7, 2:0 (B--- -CAM) */
Christian Rieschb67d8812012-02-02 00:44:39 +0000208#ifdef CONFIG_SYS_EXCEPTION_VECTORS_HIGH
209 orr r0, r0, #0x00002000 /* set bit 13 (--V- ----) */
210#else
211 bic r0, r0, #0x00002000 /* clear bit 13 (--V- ----) */
212#endif
wdenk6f213472003-08-29 22:00:43 +0000213 orr r0, r0, #0x00000002 /* set bit 2 (A) Align */
Christian Rieschd735a992012-02-02 00:44:40 +0000214#ifndef CONFIG_SYS_ICACHE_OFF
wdenk6f213472003-08-29 22:00:43 +0000215 orr r0, r0, #0x00001000 /* set bit 12 (I) I-Cache */
Christian Rieschd735a992012-02-02 00:44:40 +0000216#endif
wdenk6f213472003-08-29 22:00:43 +0000217 mcr p15, 0, r0, c1, c0, 0
218
219 /*
220 * Go setup Memory and board specific bits prior to relocation.
221 */
222 mov ip, lr /* perserve link reg across call */
Wolfgang Denk87cb6862005-10-06 17:08:18 +0200223 bl lowlevel_init /* go setup pll,mux,memory */
wdenk6f213472003-08-29 22:00:43 +0000224 mov lr, ip /* restore link */
Heiko Schocherca4b5582011-11-09 20:06:23 +0000225 mov pc, lr /* back to my caller */
Christian Riesch27b66622012-02-02 00:44:37 +0000226#endif /* CONFIG_SKIP_LOWLEVEL_INIT */
Stelian Popa6cdd212008-01-19 21:09:35 +0000227
Aneesh V401bb302011-07-13 05:11:07 +0000228#ifndef CONFIG_SPL_BUILD
wdenk6f213472003-08-29 22:00:43 +0000229/*
230 *************************************************************************
231 *
232 * Interrupt handling
233 *
234 *************************************************************************
235 */
236
237@
238@ IRQ stack frame.
239@
240#define S_FRAME_SIZE 72
241
242#define S_OLD_R0 68
243#define S_PSR 64
244#define S_PC 60
245#define S_LR 56
246#define S_SP 52
247
248#define S_IP 48
249#define S_FP 44
250#define S_R10 40
251#define S_R9 36
252#define S_R8 32
253#define S_R7 28
254#define S_R6 24
255#define S_R5 20
256#define S_R4 16
257#define S_R3 12
258#define S_R2 8
259#define S_R1 4
260#define S_R0 0
261
262#define MODE_SVC 0x13
263#define I_BIT 0x80
264
265/*
266 * use bad_save_user_regs for abort/prefetch/undef/swi ...
267 * use irq_save_user_regs / irq_restore_user_regs for IRQ/FIQ handling
268 */
269
270 .macro bad_save_user_regs
271 @ carve out a frame on current user stack
272 sub sp, sp, #S_FRAME_SIZE
273 stmia sp, {r0 - r12} @ Save user registers (now in svc mode) r0-r12
Heiko Schocherab86f722010-09-17 13:10:42 +0200274 ldr r2, IRQ_STACK_START_IN
wdenk6f213472003-08-29 22:00:43 +0000275 @ get values for "aborted" pc and cpsr (into parm regs)
276 ldmia r2, {r2 - r3}
277 add r0, sp, #S_FRAME_SIZE @ grab pointer to old stack
278 add r5, sp, #S_SP
279 mov r1, lr
280 stmia r5, {r0 - r3} @ save sp_SVC, lr_SVC, pc, cpsr
281 mov r0, sp @ save current stack into r0 (param register)
282 .endm
283
284 .macro irq_save_user_regs
285 sub sp, sp, #S_FRAME_SIZE
286 stmia sp, {r0 - r12} @ Calling r0-r12
287 @ !!!! R8 NEEDS to be saved !!!! a reserved stack spot would be good.
288 add r8, sp, #S_PC
289 stmdb r8, {sp, lr}^ @ Calling SP, LR
290 str lr, [r8, #0] @ Save calling PC
291 mrs r6, spsr
292 str r6, [r8, #4] @ Save CPSR
293 str r0, [r8, #8] @ Save OLD_R0
294 mov r0, sp
295 .endm
296
297 .macro irq_restore_user_regs
298 ldmia sp, {r0 - lr}^ @ Calling r0 - lr
299 mov r0, r0
300 ldr lr, [sp, #S_PC] @ Get PC
301 add sp, sp, #S_FRAME_SIZE
302 subs pc, lr, #4 @ return & move spsr_svc into cpsr
303 .endm
304
305 .macro get_bad_stack
Heiko Schocherab86f722010-09-17 13:10:42 +0200306 ldr r13, IRQ_STACK_START_IN @ setup our mode stack
wdenk6f213472003-08-29 22:00:43 +0000307
308 str lr, [r13] @ save caller lr in position 0 of saved stack
309 mrs lr, spsr @ get the spsr
310 str lr, [r13, #4] @ save spsr in position 1 of saved stack
311 mov r13, #MODE_SVC @ prepare SVC-Mode
312 @ msr spsr_c, r13
313 msr spsr, r13 @ switch modes, make sure moves will execute
314 mov lr, pc @ capture return pc
315 movs pc, lr @ jump to next instruction & switch modes.
316 .endm
317
318 .macro get_irq_stack @ setup IRQ stack
319 ldr sp, IRQ_STACK_START
320 .endm
321
322 .macro get_fiq_stack @ setup FIQ stack
323 ldr sp, FIQ_STACK_START
324 .endm
Aneesh V401bb302011-07-13 05:11:07 +0000325#endif /* CONFIG_SPL_BUILD */
wdenk6f213472003-08-29 22:00:43 +0000326
327/*
328 * exception handlers
329 */
Aneesh V401bb302011-07-13 05:11:07 +0000330#ifdef CONFIG_SPL_BUILD
John Rigbyef22b502010-01-25 23:12:52 -0700331 .align 5
332do_hang:
333 ldr sp, _TEXT_BASE /* switch to abort stack */
3341:
335 bl 1b /* hang and never return */
Aneesh V401bb302011-07-13 05:11:07 +0000336#else /* !CONFIG_SPL_BUILD */
wdenk6f213472003-08-29 22:00:43 +0000337 .align 5
338undefined_instruction:
339 get_bad_stack
340 bad_save_user_regs
341 bl do_undefined_instruction
342
343 .align 5
344software_interrupt:
345 get_bad_stack
346 bad_save_user_regs
347 bl do_software_interrupt
348
349 .align 5
350prefetch_abort:
351 get_bad_stack
352 bad_save_user_regs
353 bl do_prefetch_abort
354
355 .align 5
356data_abort:
357 get_bad_stack
358 bad_save_user_regs
359 bl do_data_abort
360
361 .align 5
362not_used:
363 get_bad_stack
364 bad_save_user_regs
365 bl do_not_used
366
367#ifdef CONFIG_USE_IRQ
368
369 .align 5
370irq:
371 get_irq_stack
372 irq_save_user_regs
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200373 bl do_irq
wdenk6f213472003-08-29 22:00:43 +0000374 irq_restore_user_regs
375
376 .align 5
377fiq:
378 get_fiq_stack
379 /* someone ought to write a more effiction fiq_save_user_regs */
380 irq_save_user_regs
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200381 bl do_fiq
wdenk6f213472003-08-29 22:00:43 +0000382 irq_restore_user_regs
383
384#else
385
386 .align 5
387irq:
388 get_bad_stack
389 bad_save_user_regs
390 bl do_irq
391
392 .align 5
393fiq:
394 get_bad_stack
395 bad_save_user_regs
396 bl do_fiq
397
398#endif
Aneesh V401bb302011-07-13 05:11:07 +0000399#endif /* CONFIG_SPL_BUILD */