blob: ac1e55a708d7edb8a9e3d65202867b472aaf5096 [file] [log] [blame]
Dirk Behme7d75a102008-12-14 09:47:13 +01001/*
2 * armboot - Startup Code for OMAP3530/ARM Cortex CPU-core
3 *
4 * Copyright (c) 2004 Texas Instruments <r-woodruff2@ti.com>
5 *
6 * Copyright (c) 2001 Marius Gröger <mag@sysgo.de>
7 * Copyright (c) 2002 Alex Züpke <azu@sysgo.de>
Detlev Zundelf1b3f2b2009-05-13 10:54:10 +02008 * Copyright (c) 2002 Gary Jennejohn <garyj@denx.de>
Dirk Behme7d75a102008-12-14 09:47:13 +01009 * Copyright (c) 2003 Richard Woodruff <r-woodruff2@ti.com>
10 * Copyright (c) 2003 Kshitij <kshitij@ti.com>
11 * Copyright (c) 2006-2008 Syed Mohammed Khasim <x0khasim@ti.com>
12 *
Wolfgang Denkbd8ec7e2013-10-07 13:07:26 +020013 * SPDX-License-Identifier: GPL-2.0+
Dirk Behme7d75a102008-12-14 09:47:13 +010014 */
15
Wolfgang Denk0191e472010-10-26 14:34:52 +020016#include <asm-offsets.h>
Dirk Behme7d75a102008-12-14 09:47:13 +010017#include <config.h>
18#include <version.h>
Aneesh V688ee132011-11-21 23:34:00 +000019#include <asm/system.h>
Aneesh Vfd8798b2012-03-08 07:20:18 +000020#include <linux/linkage.h>
Dirk Behme7d75a102008-12-14 09:47:13 +010021
22.globl _start
23_start: b reset
24 ldr pc, _undefined_instruction
25 ldr pc, _software_interrupt
26 ldr pc, _prefetch_abort
27 ldr pc, _data_abort
28 ldr pc, _not_used
29 ldr pc, _irq
30 ldr pc, _fiq
Aneesh Vef0f76e2011-07-21 09:10:18 -040031#ifdef CONFIG_SPL_BUILD
32_undefined_instruction: .word _undefined_instruction
33_software_interrupt: .word _software_interrupt
34_prefetch_abort: .word _prefetch_abort
35_data_abort: .word _data_abort
36_not_used: .word _not_used
37_irq: .word _irq
38_fiq: .word _fiq
39_pad: .word 0x12345678 /* now 16*4=64 */
40#else
Marek Vasuteb54c6b2013-12-14 05:55:26 +010041.globl _undefined_instruction
Dirk Behme7d75a102008-12-14 09:47:13 +010042_undefined_instruction: .word undefined_instruction
Marek Vasuteb54c6b2013-12-14 05:55:26 +010043.globl _software_interrupt
Dirk Behme7d75a102008-12-14 09:47:13 +010044_software_interrupt: .word software_interrupt
Marek Vasuteb54c6b2013-12-14 05:55:26 +010045.globl _prefetch_abort
Dirk Behme7d75a102008-12-14 09:47:13 +010046_prefetch_abort: .word prefetch_abort
Marek Vasuteb54c6b2013-12-14 05:55:26 +010047.globl _data_abort
Dirk Behme7d75a102008-12-14 09:47:13 +010048_data_abort: .word data_abort
Marek Vasuteb54c6b2013-12-14 05:55:26 +010049.globl _not_used
Dirk Behme7d75a102008-12-14 09:47:13 +010050_not_used: .word not_used
Marek Vasuteb54c6b2013-12-14 05:55:26 +010051.globl _irq
Dirk Behme7d75a102008-12-14 09:47:13 +010052_irq: .word irq
Marek Vasuteb54c6b2013-12-14 05:55:26 +010053.globl _fiq
Dirk Behme7d75a102008-12-14 09:47:13 +010054_fiq: .word fiq
55_pad: .word 0x12345678 /* now 16*4=64 */
Aneesh Vef0f76e2011-07-21 09:10:18 -040056#endif /* CONFIG_SPL_BUILD */
57
Dirk Behme7d75a102008-12-14 09:47:13 +010058.global _end_vect
59_end_vect:
60
61 .balignl 16,0xdeadbeef
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
Dirk Behme7d75a102008-12-14 09:47:13 +010073#ifdef CONFIG_USE_IRQ
74/* IRQ stack memory (calculated at run-time) */
75.globl IRQ_STACK_START
76IRQ_STACK_START:
77 .word 0x0badc0de
78
79/* IRQ stack memory (calculated at run-time) */
80.globl FIQ_STACK_START
81FIQ_STACK_START:
82 .word 0x0badc0de
83#endif
84
Heiko Schocher56d0a4d2010-09-17 13:10:41 +020085/* IRQ stack memory (calculated at run-time) + 8 bytes */
86.globl IRQ_STACK_START_IN
87IRQ_STACK_START_IN:
88 .word 0x0badc0de
89
Dirk Behme7d75a102008-12-14 09:47:13 +010090/*
91 * the actual reset code
92 */
93
94reset:
Aneesh V13a74c12011-07-21 09:10:27 -040095 bl save_boot_params
Dirk Behme7d75a102008-12-14 09:47:13 +010096 /*
Andre Przywara7acb96b2013-04-02 05:43:36 +000097 * disable interrupts (FIQ and IRQ), also set the cpu to SVC32 mode,
98 * except if in HYP mode already
Dirk Behme7d75a102008-12-14 09:47:13 +010099 */
100 mrs r0, cpsr
Andre Przywara7acb96b2013-04-02 05:43:36 +0000101 and r1, r0, #0x1f @ mask mode bits
102 teq r1, #0x1a @ test for HYP mode
103 bicne r0, r0, #0x1f @ clear all mode bits
104 orrne r0, r0, #0x13 @ set SVC mode
105 orr r0, r0, #0xc0 @ disable FIQ and IRQ
Dirk Behme7d75a102008-12-14 09:47:13 +0100106 msr cpsr,r0
107
Aneesh V688ee132011-11-21 23:34:00 +0000108/*
109 * Setup vector:
110 * (OMAP4 spl TEXT_BASE is not 32 byte aligned.
111 * Continue to use ROM code vector only in OMAP4 spl)
112 */
113#if !(defined(CONFIG_OMAP44XX) && defined(CONFIG_SPL_BUILD))
114 /* Set V=0 in CP15 SCTRL register - for VBAR to point to vector */
115 mrc p15, 0, r0, c1, c0, 0 @ Read CP15 SCTRL Register
116 bic r0, #CR_V @ V = 0
117 mcr p15, 0, r0, c1, c0, 0 @ Write CP15 SCTRL Register
118
119 /* Set vector address in CP15 VBAR register */
120 ldr r0, =_start
121 mcr p15, 0, r0, c12, c0, 0 @Set VBAR
122#endif
123
Dirk Behme7d75a102008-12-14 09:47:13 +0100124 /* the mask ROM code should have PLL and others stable */
125#ifndef CONFIG_SKIP_LOWLEVEL_INIT
Simon Glass277e3082011-11-05 03:56:51 +0000126 bl cpu_init_cp15
Dirk Behme7d75a102008-12-14 09:47:13 +0100127 bl cpu_init_crit
128#endif
129
Albert ARIBAUDfacdae52013-01-08 10:18:02 +0000130 bl _main
Heiko Schocher56d0a4d2010-09-17 13:10:41 +0200131
132/*------------------------------------------------------------------------------*/
133
Albert ARIBAUDfacdae52013-01-08 10:18:02 +0000134ENTRY(c_runtime_cpu_setup)
Aneesh V3e3bc1e2011-06-16 23:30:49 +0000135/*
136 * If I-cache is enabled invalidate it
137 */
138#ifndef CONFIG_SYS_ICACHE_OFF
139 mcr p15, 0, r0, c7, c5, 0 @ invalidate icache
140 mcr p15, 0, r0, c7, c10, 4 @ DSB
141 mcr p15, 0, r0, c7, c5, 4 @ ISB
142#endif
Tetsuyuki Kobayashi61c70db2012-06-25 02:40:57 +0000143/*
144 * Move vector table
145 */
Tetsuyuki Kobayashi61c70db2012-06-25 02:40:57 +0000146 /* Set vector address in CP15 VBAR register */
147 ldr r0, =_start
Tetsuyuki Kobayashi61c70db2012-06-25 02:40:57 +0000148 mcr p15, 0, r0, c12, c0, 0 @Set VBAR
Tetsuyuki Kobayashi61c70db2012-06-25 02:40:57 +0000149
Albert ARIBAUDfacdae52013-01-08 10:18:02 +0000150 bx lr
Heiko Schocher56d0a4d2010-09-17 13:10:41 +0200151
Albert ARIBAUDfacdae52013-01-08 10:18:02 +0000152ENDPROC(c_runtime_cpu_setup)
Heiko Schocher661a29e2010-10-11 14:08:15 +0200153
Dirk Behme7d75a102008-12-14 09:47:13 +0100154/*************************************************************************
155 *
Tetsuyuki Kobayashi153ba382012-07-06 21:14:20 +0000156 * void save_boot_params(u32 r0, u32 r1, u32 r2, u32 r3)
157 * __attribute__((weak));
158 *
159 * Stack pointer is not yet initialized at this moment
160 * Don't save anything to stack even if compiled with -O0
161 *
162 *************************************************************************/
163ENTRY(save_boot_params)
164 bx lr @ back to my caller
165ENDPROC(save_boot_params)
166 .weak save_boot_params
167
168/*************************************************************************
169 *
Simon Glass277e3082011-11-05 03:56:51 +0000170 * cpu_init_cp15
Dirk Behme7d75a102008-12-14 09:47:13 +0100171 *
Simon Glass277e3082011-11-05 03:56:51 +0000172 * Setup CP15 registers (cache, MMU, TLBs). The I-cache is turned on unless
173 * CONFIG_SYS_ICACHE_OFF is defined.
Dirk Behme7d75a102008-12-14 09:47:13 +0100174 *
175 *************************************************************************/
Aneesh Vfd8798b2012-03-08 07:20:18 +0000176ENTRY(cpu_init_cp15)
Dirk Behme7d75a102008-12-14 09:47:13 +0100177 /*
178 * Invalidate L1 I/D
179 */
180 mov r0, #0 @ set up for MCR
181 mcr p15, 0, r0, c8, c7, 0 @ invalidate TLBs
182 mcr p15, 0, r0, c7, c5, 0 @ invalidate icache
Aneesh V3e3bc1e2011-06-16 23:30:49 +0000183 mcr p15, 0, r0, c7, c5, 6 @ invalidate BP array
184 mcr p15, 0, r0, c7, c10, 4 @ DSB
185 mcr p15, 0, r0, c7, c5, 4 @ ISB
Dirk Behme7d75a102008-12-14 09:47:13 +0100186
187 /*
188 * disable MMU stuff and caches
189 */
190 mrc p15, 0, r0, c1, c0, 0
191 bic r0, r0, #0x00002000 @ clear bits 13 (--V-)
192 bic r0, r0, #0x00000007 @ clear bits 2:0 (-CAM)
193 orr r0, r0, #0x00000002 @ set bit 1 (--A-) Align
Aneesh V3e3bc1e2011-06-16 23:30:49 +0000194 orr r0, r0, #0x00000800 @ set bit 11 (Z---) BTB
195#ifdef CONFIG_SYS_ICACHE_OFF
196 bic r0, r0, #0x00001000 @ clear bit 12 (I) I-cache
197#else
198 orr r0, r0, #0x00001000 @ set bit 12 (I) I-cache
199#endif
Dirk Behme7d75a102008-12-14 09:47:13 +0100200 mcr p15, 0, r0, c1, c0, 0
Stephen Warrene9d59c92013-02-26 12:28:27 +0000201
Stephen Warrenc63c3502013-03-04 13:29:40 +0000202#ifdef CONFIG_ARM_ERRATA_716044
203 mrc p15, 0, r0, c1, c0, 0 @ read system control register
204 orr r0, r0, #1 << 11 @ set bit #11
205 mcr p15, 0, r0, c1, c0, 0 @ write system control register
206#endif
207
Stephen Warrene9d59c92013-02-26 12:28:27 +0000208#ifdef CONFIG_ARM_ERRATA_742230
209 mrc p15, 0, r0, c15, c0, 1 @ read diagnostic register
210 orr r0, r0, #1 << 4 @ set bit #4
211 mcr p15, 0, r0, c15, c0, 1 @ write diagnostic register
212#endif
213
214#ifdef CONFIG_ARM_ERRATA_743622
215 mrc p15, 0, r0, c15, c0, 1 @ read diagnostic register
216 orr r0, r0, #1 << 6 @ set bit #6
217 mcr p15, 0, r0, c15, c0, 1 @ write diagnostic register
218#endif
219
220#ifdef CONFIG_ARM_ERRATA_751472
221 mrc p15, 0, r0, c15, c0, 1 @ read diagnostic register
222 orr r0, r0, #1 << 11 @ set bit #11
223 mcr p15, 0, r0, c15, c0, 1 @ write diagnostic register
224#endif
225
Simon Glass277e3082011-11-05 03:56:51 +0000226 mov pc, lr @ back to my caller
Aneesh Vfd8798b2012-03-08 07:20:18 +0000227ENDPROC(cpu_init_cp15)
Dirk Behme7d75a102008-12-14 09:47:13 +0100228
Simon Glass277e3082011-11-05 03:56:51 +0000229#ifndef CONFIG_SKIP_LOWLEVEL_INIT
230/*************************************************************************
231 *
232 * CPU_init_critical registers
233 *
234 * setup important registers
235 * setup memory timing
236 *
237 *************************************************************************/
Aneesh Vfd8798b2012-03-08 07:20:18 +0000238ENTRY(cpu_init_crit)
Dirk Behme7d75a102008-12-14 09:47:13 +0100239 /*
240 * Jump to board specific initialization...
241 * The Mask ROM will have already initialized
242 * basic memory. Go here to bump up clock rate and handle
243 * wake up conditions.
244 */
Benoît Thébaudeau0a167902012-08-10 12:05:16 +0000245 b lowlevel_init @ go setup pll,mux,memory
Aneesh Vfd8798b2012-03-08 07:20:18 +0000246ENDPROC(cpu_init_crit)
Rob Herringa6932872011-06-28 05:39:38 +0000247#endif
Aneesh Vef0f76e2011-07-21 09:10:18 -0400248
249#ifndef CONFIG_SPL_BUILD
Dirk Behme7d75a102008-12-14 09:47:13 +0100250/*
251 *************************************************************************
252 *
253 * Interrupt handling
254 *
255 *************************************************************************
256 */
257@
258@ IRQ stack frame.
259@
260#define S_FRAME_SIZE 72
261
262#define S_OLD_R0 68
263#define S_PSR 64
264#define S_PC 60
265#define S_LR 56
266#define S_SP 52
267
268#define S_IP 48
269#define S_FP 44
270#define S_R10 40
271#define S_R9 36
272#define S_R8 32
273#define S_R7 28
274#define S_R6 24
275#define S_R5 20
276#define S_R4 16
277#define S_R3 12
278#define S_R2 8
279#define S_R1 4
280#define S_R0 0
281
282#define MODE_SVC 0x13
283#define I_BIT 0x80
284
285/*
286 * use bad_save_user_regs for abort/prefetch/undef/swi ...
287 * use irq_save_user_regs / irq_restore_user_regs for IRQ/FIQ handling
288 */
289
290 .macro bad_save_user_regs
291 sub sp, sp, #S_FRAME_SIZE @ carve out a frame on current
292 @ user stack
293 stmia sp, {r0 - r12} @ Save user registers (now in
294 @ svc mode) r0-r12
Heiko Schocher56d0a4d2010-09-17 13:10:41 +0200295 ldr r2, IRQ_STACK_START_IN @ set base 2 words into abort
Dirk Behme7d75a102008-12-14 09:47:13 +0100296 @ stack
297 ldmia r2, {r2 - r3} @ get values for "aborted" pc
298 @ and cpsr (into parm regs)
299 add r0, sp, #S_FRAME_SIZE @ grab pointer to old stack
300
301 add r5, sp, #S_SP
302 mov r1, lr
303 stmia r5, {r0 - r3} @ save sp_SVC, lr_SVC, pc, cpsr
304 mov r0, sp @ save current stack into r0
305 @ (param register)
306 .endm
307
308 .macro irq_save_user_regs
309 sub sp, sp, #S_FRAME_SIZE
310 stmia sp, {r0 - r12} @ Calling r0-r12
311 add r8, sp, #S_PC @ !! R8 NEEDS to be saved !!
312 @ a reserved stack spot would
313 @ be good.
314 stmdb r8, {sp, lr}^ @ Calling SP, LR
315 str lr, [r8, #0] @ Save calling PC
316 mrs r6, spsr
317 str r6, [r8, #4] @ Save CPSR
318 str r0, [r8, #8] @ Save OLD_R0
319 mov r0, sp
320 .endm
321
322 .macro irq_restore_user_regs
323 ldmia sp, {r0 - lr}^ @ Calling r0 - lr
324 mov r0, r0
325 ldr lr, [sp, #S_PC] @ Get PC
326 add sp, sp, #S_FRAME_SIZE
327 subs pc, lr, #4 @ return & move spsr_svc into
328 @ cpsr
329 .endm
330
331 .macro get_bad_stack
Heiko Schocher56d0a4d2010-09-17 13:10:41 +0200332 ldr r13, IRQ_STACK_START_IN @ setup our mode stack (enter
333 @ in banked mode)
Dirk Behme7d75a102008-12-14 09:47:13 +0100334
335 str lr, [r13] @ save caller lr in position 0
336 @ of saved stack
337 mrs lr, spsr @ get the spsr
338 str lr, [r13, #4] @ save spsr in position 1 of
339 @ saved stack
340
341 mov r13, #MODE_SVC @ prepare SVC-Mode
342 @ msr spsr_c, r13
343 msr spsr, r13 @ switch modes, make sure
344 @ moves will execute
345 mov lr, pc @ capture return pc
346 movs pc, lr @ jump to next instruction &
347 @ switch modes.
348 .endm
349
350 .macro get_bad_stack_swi
351 sub r13, r13, #4 @ space on current stack for
352 @ scratch reg.
353 str r0, [r13] @ save R0's value.
Heiko Schocher56d0a4d2010-09-17 13:10:41 +0200354 ldr r0, IRQ_STACK_START_IN @ get data regions start
Dirk Behme7d75a102008-12-14 09:47:13 +0100355 @ spots for abort stack
356 str lr, [r0] @ save caller lr in position 0
357 @ of saved stack
Tetsuyuki Kobayashib023a952013-04-05 00:12:51 +0000358 mrs lr, spsr @ get the spsr
Dirk Behme7d75a102008-12-14 09:47:13 +0100359 str lr, [r0, #4] @ save spsr in position 1 of
360 @ saved stack
Tetsuyuki Kobayashib023a952013-04-05 00:12:51 +0000361 ldr lr, [r0] @ restore lr
Dirk Behme7d75a102008-12-14 09:47:13 +0100362 ldr r0, [r13] @ restore r0
363 add r13, r13, #4 @ pop stack entry
364 .endm
365
366 .macro get_irq_stack @ setup IRQ stack
367 ldr sp, IRQ_STACK_START
368 .endm
369
370 .macro get_fiq_stack @ setup FIQ stack
371 ldr sp, FIQ_STACK_START
372 .endm
373
374/*
375 * exception handlers
376 */
377 .align 5
378undefined_instruction:
379 get_bad_stack
380 bad_save_user_regs
381 bl do_undefined_instruction
382
383 .align 5
384software_interrupt:
385 get_bad_stack_swi
386 bad_save_user_regs
387 bl do_software_interrupt
388
389 .align 5
390prefetch_abort:
391 get_bad_stack
392 bad_save_user_regs
393 bl do_prefetch_abort
394
395 .align 5
396data_abort:
397 get_bad_stack
398 bad_save_user_regs
399 bl do_data_abort
400
401 .align 5
402not_used:
403 get_bad_stack
404 bad_save_user_regs
405 bl do_not_used
406
407#ifdef CONFIG_USE_IRQ
408
409 .align 5
410irq:
411 get_irq_stack
412 irq_save_user_regs
413 bl do_irq
414 irq_restore_user_regs
415
416 .align 5
417fiq:
418 get_fiq_stack
419 /* someone ought to write a more effective fiq_save_user_regs */
420 irq_save_user_regs
421 bl do_fiq
422 irq_restore_user_regs
423
424#else
425
426 .align 5
427irq:
428 get_bad_stack
429 bad_save_user_regs
430 bl do_irq
431
432 .align 5
433fiq:
434 get_bad_stack
435 bad_save_user_regs
436 bl do_fiq
437
Aneesh Vef0f76e2011-07-21 09:10:18 -0400438#endif /* CONFIG_USE_IRQ */
439#endif /* CONFIG_SPL_BUILD */