blob: ffd7dd0dcd093c38a54c1b371045a015e5508372 [file] [log] [blame]
Guennadi Liakhovetski8c170c52008-08-31 00:39:46 +02001/*
Cyril Chemparathy4e3ad932010-06-07 14:13:27 -04002 * armboot - Startup Code for ARM1176 CPU-core
Guennadi Liakhovetski8c170c52008-08-31 00:39:46 +02003 *
4 * Copyright (c) 2007 Samsung Electronics
5 *
6 * Copyright (C) 2008
7 * Guennadi Liakhovetki, DENX Software Engineering, <lg@denx.de>
8 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02009 * SPDX-License-Identifier: GPL-2.0+
Guennadi Liakhovetski8c170c52008-08-31 00:39:46 +020010 *
11 * 2007-09-21 - Restructured codes by jsgood (jsgood.yang@samsung.com)
12 * 2007-09-21 - Added MoviNAND and OneNAND boot codes by
13 * jsgood (jsgood.yang@samsung.com)
14 * Base codes by scsuh (sc.suh)
15 */
16
Wolfgang Denk0191e472010-10-26 14:34:52 +020017#include <asm-offsets.h>
Guennadi Liakhovetski8c170c52008-08-31 00:39:46 +020018#include <config.h>
19#include <version.h>
Guennadi Liakhovetski8c170c52008-08-31 00:39:46 +020020
Benoît Thébaudeau62dd75c2013-04-11 09:36:02 +000021#ifndef CONFIG_SYS_PHY_UBOOT_BASE
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020022#define CONFIG_SYS_PHY_UBOOT_BASE CONFIG_SYS_UBOOT_BASE
Guennadi Liakhovetski8c170c52008-08-31 00:39:46 +020023#endif
24
25/*
26 *************************************************************************
27 *
28 * Jump vector table as in table 3.1 in [1]
29 *
30 *************************************************************************
31 */
32
33.globl _start
34_start: b reset
Benoît Thébaudeau80f2f932013-04-11 09:36:01 +000035#ifndef CONFIG_SPL_BUILD
Guennadi Liakhovetski8c170c52008-08-31 00:39:46 +020036 ldr pc, _undefined_instruction
37 ldr pc, _software_interrupt
38 ldr pc, _prefetch_abort
39 ldr pc, _data_abort
40 ldr pc, _not_used
41 ldr pc, _irq
42 ldr pc, _fiq
43
44_undefined_instruction:
45 .word undefined_instruction
46_software_interrupt:
47 .word software_interrupt
48_prefetch_abort:
49 .word prefetch_abort
50_data_abort:
51 .word data_abort
52_not_used:
53 .word not_used
54_irq:
55 .word irq
56_fiq:
57 .word fiq
58_pad:
59 .word 0x12345678 /* now 16*4=64 */
60#else
61 . = _start + 64
62#endif
63
64.global _end_vect
65_end_vect:
66 .balignl 16,0xdeadbeef
67/*
68 *************************************************************************
69 *
70 * Startup Code (reset vector)
71 *
72 * do important init only if we don't start from memory!
73 * setup Memory and board specific bits prior to relocation.
74 * relocate armboot to ram
75 * setup stack
76 *
77 *************************************************************************
78 */
79
Heiko Schocher55f965a2010-09-17 13:10:53 +020080.globl _TEXT_BASE
Guennadi Liakhovetski8c170c52008-08-31 00:39:46 +020081_TEXT_BASE:
Benoît Thébaudeaua402da32013-04-11 09:35:42 +000082#if defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_TEXT_BASE)
83 .word CONFIG_SPL_TEXT_BASE
84#else
Wolfgang Denk0708bc62010-10-07 21:51:12 +020085 .word CONFIG_SYS_TEXT_BASE
Benoît Thébaudeaua402da32013-04-11 09:35:42 +000086#endif
Guennadi Liakhovetski8c170c52008-08-31 00:39:46 +020087
88/*
Guennadi Liakhovetski8c170c52008-08-31 00:39:46 +020089 * These are defined in the board-specific linker script.
Darius Augulis5e870f12010-10-25 13:48:03 +030090 * Subtracting _start from them lets the linker put their
91 * relative position in the executable instead of leaving
92 * them null.
Guennadi Liakhovetski8c170c52008-08-31 00:39:46 +020093 */
Guennadi Liakhovetski8c170c52008-08-31 00:39:46 +020094
Darius Augulis5e870f12010-10-25 13:48:03 +030095.globl _bss_start_ofs
96_bss_start_ofs:
97 .word __bss_start - _start
Guennadi Liakhovetski8c170c52008-08-31 00:39:46 +020098
Darius Augulis5e870f12010-10-25 13:48:03 +030099.globl _bss_end_ofs
100_bss_end_ofs:
Simon Glassed70c8f2013-03-14 06:54:53 +0000101 .word __bss_end - _start
Heiko Schocher55f965a2010-09-17 13:10:53 +0200102
Po-Yu Chuang1864b002011-03-01 23:02:04 +0000103.globl _end_ofs
104_end_ofs:
105 .word _end - _start
106
Darius Augulis5e870f12010-10-25 13:48:03 +0300107/* IRQ stack memory (calculated at run-time) + 8 bytes */
108.globl IRQ_STACK_START_IN
109IRQ_STACK_START_IN:
110 .word 0x0badc0de
Heiko Schocher55f965a2010-09-17 13:10:53 +0200111
Guennadi Liakhovetski8c170c52008-08-31 00:39:46 +0200112/*
113 * the actual reset code
114 */
115
116reset:
117 /*
118 * set the cpu to SVC32 mode
119 */
120 mrs r0, cpsr
121 bic r0, r0, #0x3f
122 orr r0, r0, #0xd3
123 msr cpsr, r0
124
125/*
126 *************************************************************************
127 *
128 * CPU_init_critical registers
129 *
130 * setup important registers
131 * setup memory timing
132 *
133 *************************************************************************
134 */
135 /*
136 * we do sys-critical inits only at reboot,
137 * not when booting from ram!
138 */
139cpu_init_crit:
140 /*
141 * When booting from NAND - it has definitely been a reset, so, no need
142 * to flush caches and disable the MMU
143 */
Benoît Thébaudeau80f2f932013-04-11 09:36:01 +0000144#ifndef CONFIG_SPL_BUILD
Guennadi Liakhovetski8c170c52008-08-31 00:39:46 +0200145 /*
146 * flush v4 I/D caches
147 */
148 mov r0, #0
149 mcr p15, 0, r0, c7, c7, 0 /* flush v3/v4 cache */
150 mcr p15, 0, r0, c8, c7, 0 /* flush v4 TLB */
151
152 /*
153 * disable MMU stuff and caches
154 */
155 mrc p15, 0, r0, c1, c0, 0
156 bic r0, r0, #0x00002300 @ clear bits 13, 9:8 (--V- --RS)
157 bic r0, r0, #0x00000087 @ clear bits 7, 2:0 (B--- -CAM)
158 orr r0, r0, #0x00000002 @ set bit 2 (A) Align
159 orr r0, r0, #0x00001000 @ set bit 12 (I) I-Cache
Cyril Chemparathy4e3ad932010-06-07 14:13:27 -0400160
Guennadi Liakhovetski8c170c52008-08-31 00:39:46 +0200161 /* Prepare to disable the MMU */
Cyril Chemparathy4e3ad932010-06-07 14:13:27 -0400162 adr r2, mmu_disable_phys
Wolfgang Denk0708bc62010-10-07 21:51:12 +0200163 sub r2, r2, #(CONFIG_SYS_PHY_UBOOT_BASE - CONFIG_SYS_TEXT_BASE)
Guennadi Liakhovetski8c170c52008-08-31 00:39:46 +0200164 b mmu_disable
165
166 .align 5
167 /* Run in a single cache-line */
168mmu_disable:
169 mcr p15, 0, r0, c1, c0, 0
170 nop
171 nop
172 mov pc, r2
Cyril Chemparathy4e3ad932010-06-07 14:13:27 -0400173mmu_disable_phys:
174
175#ifdef CONFIG_DISABLE_TCM
176 /*
177 * Disable the TCMs
178 */
179 mrc p15, 0, r0, c0, c0, 2 /* Return TCM details */
180 cmp r0, #0
181 beq skip_tcmdisable
182 mov r1, #0
183 mov r2, #1
184 tst r0, r2
185 mcrne p15, 0, r1, c9, c1, 1 /* Disable Instruction TCM if present*/
186 tst r0, r2, LSL #16
187 mcrne p15, 0, r1, c9, c1, 0 /* Disable Data TCM if present*/
188skip_tcmdisable:
189#endif
Guennadi Liakhovetski8c170c52008-08-31 00:39:46 +0200190#endif
191
Cyril Chemparathy4e3ad932010-06-07 14:13:27 -0400192#ifdef CONFIG_PERIPORT_REMAP
Guennadi Liakhovetski8c170c52008-08-31 00:39:46 +0200193 /* Peri port setup */
Cyril Chemparathy4e3ad932010-06-07 14:13:27 -0400194 ldr r0, =CONFIG_PERIPORT_BASE
195 orr r0, r0, #CONFIG_PERIPORT_SIZE
196 mcr p15,0,r0,c15,c2,4
Joonyoung Shimce0cdc52010-02-08 22:00:52 +0900197#endif
Guennadi Liakhovetski8c170c52008-08-31 00:39:46 +0200198
199 /*
200 * Go setup Memory and board specific bits prior to relocation.
201 */
202 bl lowlevel_init /* go setup pll,mux,memory */
203
Albert ARIBAUDfacdae52013-01-08 10:18:02 +0000204 bl _main
Heiko Schocher55f965a2010-09-17 13:10:53 +0200205
206/*------------------------------------------------------------------------------*/
207
Albert ARIBAUDfacdae52013-01-08 10:18:02 +0000208 .globl c_runtime_cpu_setup
209c_runtime_cpu_setup:
210
211 mov pc, lr
212
Benoît Thébaudeau80f2f932013-04-11 09:36:01 +0000213#ifndef CONFIG_SPL_BUILD
Guennadi Liakhovetski8c170c52008-08-31 00:39:46 +0200214/*
Guennadi Liakhovetski8c170c52008-08-31 00:39:46 +0200215 *************************************************************************
216 *
217 * Interrupt handling
218 *
219 *************************************************************************
220 */
221@
222@ IRQ stack frame.
223@
224#define S_FRAME_SIZE 72
225
226#define S_OLD_R0 68
227#define S_PSR 64
228#define S_PC 60
229#define S_LR 56
230#define S_SP 52
231
232#define S_IP 48
233#define S_FP 44
234#define S_R10 40
235#define S_R9 36
236#define S_R8 32
237#define S_R7 28
238#define S_R6 24
239#define S_R5 20
240#define S_R4 16
241#define S_R3 12
242#define S_R2 8
243#define S_R1 4
244#define S_R0 0
245
246#define MODE_SVC 0x13
247#define I_BIT 0x80
248
249/*
250 * use bad_save_user_regs for abort/prefetch/undef/swi ...
251 */
252
253 .macro bad_save_user_regs
254 /* carve out a frame on current user stack */
255 sub sp, sp, #S_FRAME_SIZE
256 /* Save user registers (now in svc mode) r0-r12 */
257 stmia sp, {r0 - r12}
258
Heiko Schocher55f965a2010-09-17 13:10:53 +0200259 ldr r2, IRQ_STACK_START_IN
Guennadi Liakhovetski8c170c52008-08-31 00:39:46 +0200260 /* get values for "aborted" pc and cpsr (into parm regs) */
261 ldmia r2, {r2 - r3}
262 /* grab pointer to old stack */
263 add r0, sp, #S_FRAME_SIZE
264
265 add r5, sp, #S_SP
266 mov r1, lr
267 /* save sp_SVC, lr_SVC, pc, cpsr */
268 stmia r5, {r0 - r3}
269 /* save current stack into r0 (param register) */
270 mov r0, sp
271 .endm
272
273 .macro get_bad_stack
Heiko Schocher55f965a2010-09-17 13:10:53 +0200274 ldr r13, IRQ_STACK_START_IN @ setup our mode stack
Guennadi Liakhovetski8c170c52008-08-31 00:39:46 +0200275
276 /* save caller lr in position 0 of saved stack */
277 str lr, [r13]
278 /* get the spsr */
279 mrs lr, spsr
280 /* save spsr in position 1 of saved stack */
281 str lr, [r13, #4]
282
283 /* prepare SVC-Mode */
284 mov r13, #MODE_SVC
285 @ msr spsr_c, r13
286 /* switch modes, make sure moves will execute */
287 msr spsr, r13
288 /* capture return pc */
289 mov lr, pc
290 /* jump to next instruction & switch modes. */
291 movs pc, lr
292 .endm
293
294 .macro get_bad_stack_swi
295 /* space on current stack for scratch reg. */
296 sub r13, r13, #4
297 /* save R0's value. */
298 str r0, [r13]
Heiko Schocher55f965a2010-09-17 13:10:53 +0200299 ldr r13, IRQ_STACK_START_IN @ setup our mode stack
Guennadi Liakhovetski8c170c52008-08-31 00:39:46 +0200300 /* save caller lr in position 0 of saved stack */
301 str lr, [r0]
302 /* get the spsr */
Tetsuyuki Kobayashib023a952013-04-05 00:12:51 +0000303 mrs lr, spsr
Guennadi Liakhovetski8c170c52008-08-31 00:39:46 +0200304 /* save spsr in position 1 of saved stack */
305 str lr, [r0, #4]
Tetsuyuki Kobayashib023a952013-04-05 00:12:51 +0000306 /* restore lr */
307 ldr lr, [r0]
Guennadi Liakhovetski8c170c52008-08-31 00:39:46 +0200308 /* restore r0 */
309 ldr r0, [r13]
310 /* pop stack entry */
311 add r13, r13, #4
312 .endm
313
314/*
315 * exception handlers
316 */
317 .align 5
318undefined_instruction:
319 get_bad_stack
320 bad_save_user_regs
321 bl do_undefined_instruction
322
323 .align 5
324software_interrupt:
325 get_bad_stack_swi
326 bad_save_user_regs
327 bl do_software_interrupt
328
329 .align 5
330prefetch_abort:
331 get_bad_stack
332 bad_save_user_regs
333 bl do_prefetch_abort
334
335 .align 5
336data_abort:
337 get_bad_stack
338 bad_save_user_regs
339 bl do_data_abort
340
341 .align 5
342not_used:
343 get_bad_stack
344 bad_save_user_regs
345 bl do_not_used
346
347 .align 5
348irq:
349 get_bad_stack
350 bad_save_user_regs
351 bl do_irq
352
353 .align 5
354fiq:
355 get_bad_stack
356 bad_save_user_regs
357 bl do_fiq
Benoît Thébaudeau80f2f932013-04-11 09:36:01 +0000358#endif /* CONFIG_SPL_BUILD */