blob: e16b0881410ee5b2463c2b978e83d4c8f813f7ae [file] [log] [blame]
Wolfgang Denkadf20a12005-09-25 01:48:28 +02001/*
2 * armboot - Startup Code for ARM926EJS CPU-core
3 *
4 * Copyright (c) 2003 Texas Instruments
5 *
6 * ----- Adapted for OMAP1610 OMAP730 from ARM925t code ------
7 *
Albert ARIBAUD60fbc8d2011-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 Zundelf1b3f2b2009-05-13 10:54:10 +020010 * Copyright (c) 2002 Gary Jennejohn <garyj@denx.de>
Wolfgang Denkadf20a12005-09-25 01:48:28 +020011 * Copyright (c) 2003 Richard Woodruff <r-woodruff2@ti.com>
12 * Copyright (c) 2003 Kshitij <kshitij@ti.com>
Albert ARIBAUD340983d2011-04-22 19:41:02 +020013 * Copyright (c) 2010 Albert Aribaud <albert.u.boot@aribaud.net>
Wolfgang Denkadf20a12005-09-25 01:48:28 +020014 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +020015 * SPDX-License-Identifier: GPL-2.0+
Wolfgang Denkadf20a12005-09-25 01:48:28 +020016 */
17
Wolfgang Denk0191e472010-10-26 14:34:52 +020018#include <asm-offsets.h>
Wolfgang Denkadf20a12005-09-25 01:48:28 +020019#include <config.h>
20#include <version.h>
21
22/*
23 *************************************************************************
24 *
25 * Jump vector table as in table 3.1 in [1]
26 *
27 *************************************************************************
28 */
29
30
31.globl _start
32_start:
33 b reset
34 ldr pc, _undefined_instruction
35 ldr pc, _software_interrupt
36 ldr pc, _prefetch_abort
37 ldr pc, _data_abort
38 ldr pc, _not_used
39 ldr pc, _irq
40 ldr pc, _fiq
41
42_undefined_instruction:
43 .word undefined_instruction
44_software_interrupt:
45 .word software_interrupt
46_prefetch_abort:
47 .word prefetch_abort
48_data_abort:
49 .word data_abort
50_not_used:
51 .word not_used
52_irq:
53 .word irq
54_fiq:
55 .word fiq
56
57 .balignl 16,0xdeadbeef
58
Albert Aribaud126897e2010-11-25 22:45:02 +010059_vectors_end:
Wolfgang Denkadf20a12005-09-25 01:48:28 +020060
61/*
62 *************************************************************************
63 *
64 * Startup Code (reset vector)
65 *
66 * do important init only if we don't start from memory!
67 * setup Memory and board specific bits prior to relocation.
68 * relocate armboot to ram
69 * setup stack
70 *
71 *************************************************************************
72 */
73
Heiko Schocher68c4d2e2010-09-17 13:10:45 +020074.globl _TEXT_BASE
Wolfgang Denkadf20a12005-09-25 01:48:28 +020075_TEXT_BASE:
Benoît Thébaudeaua402da32013-04-11 09:35:42 +000076#if defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_TEXT_BASE)
77 .word CONFIG_SPL_TEXT_BASE
78#else
Wolfgang Denk0708bc62010-10-07 21:51:12 +020079 .word CONFIG_SYS_TEXT_BASE
Benoît Thébaudeaua402da32013-04-11 09:35:42 +000080#endif
Wolfgang Denkadf20a12005-09-25 01:48:28 +020081
Wolfgang Denkadf20a12005-09-25 01:48:28 +020082/*
83 * These are defined in the board-specific linker script.
Albert Aribaud126897e2010-11-25 22:45:02 +010084 * Subtracting _start from them lets the linker put their
85 * relative position in the executable instead of leaving
86 * them null.
Wolfgang Denkadf20a12005-09-25 01:48:28 +020087 */
Albert Aribaud126897e2010-11-25 22:45:02 +010088.globl _bss_start_ofs
89_bss_start_ofs:
90 .word __bss_start - _start
Wolfgang Denkadf20a12005-09-25 01:48:28 +020091
Albert Aribaud126897e2010-11-25 22:45:02 +010092.globl _bss_end_ofs
93_bss_end_ofs:
Simon Glassed70c8f2013-03-14 06:54:53 +000094 .word __bss_end - _start
Wolfgang Denkadf20a12005-09-25 01:48:28 +020095
Po-Yu Chuang1864b002011-03-01 23:02:04 +000096.globl _end_ofs
97_end_ofs:
98 .word _end - _start
99
Wolfgang Denkadf20a12005-09-25 01:48:28 +0200100#ifdef CONFIG_USE_IRQ
101/* IRQ stack memory (calculated at run-time) */
102.globl IRQ_STACK_START
103IRQ_STACK_START:
104 .word 0x0badc0de
105
106/* IRQ stack memory (calculated at run-time) */
107.globl FIQ_STACK_START
108FIQ_STACK_START:
109 .word 0x0badc0de
110#endif
111
Heiko Schocher68c4d2e2010-09-17 13:10:45 +0200112/* IRQ stack memory (calculated at run-time) + 8 bytes */
113.globl IRQ_STACK_START_IN
114IRQ_STACK_START_IN:
115 .word 0x0badc0de
116
Heiko Schocher68c4d2e2010-09-17 13:10:45 +0200117/*
118 * the actual reset code
119 */
120
121reset:
122 /*
123 * set the cpu to SVC32 mode
124 */
125 mrs r0,cpsr
126 bic r0,r0,#0x1f
127 orr r0,r0,#0xd3
128 msr cpsr,r0
129
130 /*
131 * we do sys-critical inits only at reboot,
132 * not when booting from ram!
133 */
134#ifndef CONFIG_SKIP_LOWLEVEL_INIT
135 bl cpu_init_crit
136#endif
137
Albert ARIBAUDfacdae52013-01-08 10:18:02 +0000138 bl _main
Heiko Schocher68c4d2e2010-09-17 13:10:45 +0200139
140/*------------------------------------------------------------------------------*/
141
Albert ARIBAUDfacdae52013-01-08 10:18:02 +0000142 .globl c_runtime_cpu_setup
143c_runtime_cpu_setup:
144
145 mov pc, lr
146
Wolfgang Denkadf20a12005-09-25 01:48:28 +0200147/*
148 *************************************************************************
149 *
150 * CPU_init_critical registers
151 *
152 * setup important registers
153 * setup memory timing
154 *
155 *************************************************************************
156 */
157
158
Jean-Christophe PLAGNIOL-VILLARD314b7282009-05-15 23:45:20 +0200159#ifndef CONFIG_SKIP_LOWLEVEL_INIT
Wolfgang Denkadf20a12005-09-25 01:48:28 +0200160cpu_init_crit:
161 /*
162 * flush v4 I/D caches
163 */
164 mov r0, #0
165 mcr p15, 0, r0, c7, c5, 0 /* flush v4 I-cache */
166 mcr p15, 0, r0, c7, c6, 0 /* flush v4 D-cache */
167
168 /*
169 * disable MMU stuff and caches
170 */
171 mrc p15, 0, r0, c1, c0, 0
172 bic r0, r0, #0x00002300 /* clear bits 13, 9:8 (--V- --RS) */
173 bic r0, r0, #0x00000087 /* clear bits 7, 2:0 (B--- -CAM) */
174 orr r0, r0, #0x00000002 /* set bit 2 (A) Align */
175 orr r0, r0, #0x00001000 /* set bit 12 (I) I-Cache */
176 mcr p15, 0, r0, c1, c0, 0
177
178 /*
179 * Go setup Memory and board specific bits prior to relocation.
180 */
181 mov ip, lr /* perserve link reg across call */
Wolfgang Denk7f88a5e2005-10-06 17:08:18 +0200182 bl lowlevel_init /* go setup memory */
Wolfgang Denkadf20a12005-09-25 01:48:28 +0200183 mov lr, ip /* restore link */
184 mov pc, lr /* back to my caller */
Jean-Christophe PLAGNIOL-VILLARD314b7282009-05-15 23:45:20 +0200185#endif
Wolfgang Denkadf20a12005-09-25 01:48:28 +0200186/*
187 *************************************************************************
188 *
189 * Interrupt handling
190 *
191 *************************************************************************
192 */
193
194@
195@ IRQ stack frame.
196@
197#define S_FRAME_SIZE 72
198
199#define S_OLD_R0 68
200#define S_PSR 64
201#define S_PC 60
202#define S_LR 56
203#define S_SP 52
204
205#define S_IP 48
206#define S_FP 44
207#define S_R10 40
208#define S_R9 36
209#define S_R8 32
210#define S_R7 28
211#define S_R6 24
212#define S_R5 20
213#define S_R4 16
214#define S_R3 12
215#define S_R2 8
216#define S_R1 4
217#define S_R0 0
218
219#define MODE_SVC 0x13
220#define I_BIT 0x80
221
222/*
223 * use bad_save_user_regs for abort/prefetch/undef/swi ...
224 * use irq_save_user_regs / irq_restore_user_regs for IRQ/FIQ handling
225 */
226
227 .macro bad_save_user_regs
228 @ carve out a frame on current user stack
229 sub sp, sp, #S_FRAME_SIZE
230 stmia sp, {r0 - r12} @ Save user registers (now in svc mode) r0-r12
231
Heiko Schocher68c4d2e2010-09-17 13:10:45 +0200232 ldr r2, IRQ_STACK_START_IN
Wolfgang Denkadf20a12005-09-25 01:48:28 +0200233 @ get values for "aborted" pc and cpsr (into parm regs)
234 ldmia r2, {r2 - r3}
235 add r0, sp, #S_FRAME_SIZE @ grab pointer to old stack
236 add r5, sp, #S_SP
237 mov r1, lr
238 stmia r5, {r0 - r3} @ save sp_SVC, lr_SVC, pc, cpsr
239 mov r0, sp @ save current stack into r0 (param register)
240 .endm
241
242 .macro irq_save_user_regs
243 sub sp, sp, #S_FRAME_SIZE
244 stmia sp, {r0 - r12} @ Calling r0-r12
245 @ !!!! R8 NEEDS to be saved !!!! a reserved stack spot would be good.
246 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
252 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 Schocher68c4d2e2010-09-17 13:10:45 +0200264 ldr r13, IRQ_STACK_START_IN @ setup our mode stack
Wolfgang Denkadf20a12005-09-25 01:48:28 +0200265
266 str lr, [r13] @ save caller lr in position 0 of saved stack
267 mrs lr, spsr @ get the spsr
268 str lr, [r13, #4] @ save spsr in position 1 of saved stack
269 mov r13, #MODE_SVC @ prepare SVC-Mode
270 @ msr spsr_c, r13
271 msr spsr, r13 @ switch modes, make sure moves will execute
272 mov lr, pc @ capture return pc
273 movs pc, lr @ jump to next instruction & switch modes.
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 */
287 .align 5
288undefined_instruction:
289 get_bad_stack
290 bad_save_user_regs
291 bl do_undefined_instruction
292
293 .align 5
294software_interrupt:
295 get_bad_stack
296 bad_save_user_regs
297 bl do_software_interrupt
298
299 .align 5
300prefetch_abort:
301 get_bad_stack
302 bad_save_user_regs
303 bl do_prefetch_abort
304
305 .align 5
306data_abort:
307 get_bad_stack
308 bad_save_user_regs
309 bl do_data_abort
310
311 .align 5
312not_used:
313 get_bad_stack
314 bad_save_user_regs
315 bl do_not_used
316
317#ifdef CONFIG_USE_IRQ
318
319 .align 5
320irq:
321 get_irq_stack
322 irq_save_user_regs
Wolfgang Denka1be4762008-05-20 16:00:29 +0200323 bl do_irq
Wolfgang Denkadf20a12005-09-25 01:48:28 +0200324 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
Wolfgang Denka1be4762008-05-20 16:00:29 +0200331 bl do_fiq
Wolfgang Denkadf20a12005-09-25 01:48:28 +0200332 irq_restore_user_regs
333
334#else
335
336 .align 5
337irq:
338 get_bad_stack
339 bad_save_user_regs
340 bl do_irq
341
342 .align 5
343fiq:
344 get_bad_stack
345 bad_save_user_regs
346 bl do_fiq
347
348#endif
349
350# ifdef CONFIG_INTEGRATOR
351
352 /* Satisfied by general board level routine */
353
354#else
355
356 .align 5
357.globl reset_cpu
358reset_cpu:
359
360 ldr r1, rstctl1 /* get clkm1 reset ctl */
361 mov r3, #0x0
362 strh r3, [r1] /* clear it */
363 mov r3, #0x8
364 strh r3, [r1] /* force dsp+arm reset */
365_loop_forever:
366 b _loop_forever
367
368rstctl1:
369 .word 0xfffece10
370
371#endif /* #ifdef CONFIG_INTEGRATOR */