2 * armboot - Startup Code for S3C6400/ARM1176 CPU-core
4 * Copyright (c) 2007 Samsung Electronics
7 * Guennadi Liakhovetki, DENX Software Engineering, <lg@denx.de>
9 * See file CREDITS for list of people who contributed to this
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License as
14 * published by the Free Software Foundation; either version 2 of
15 * the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
27 * 2007-09-21 - Restructured codes by jsgood (jsgood.yang@samsung.com)
28 * 2007-09-21 - Added MoviNAND and OneNAND boot codes by
29 * jsgood (jsgood.yang@samsung.com)
30 * Base codes by scsuh (sc.suh)
35 #ifdef CONFIG_ENABLE_MMU
36 #include <asm/proc/domain.h>
38 #include <asm/arch/s3c6400.h>
40 #if !defined(CONFIG_ENABLE_MMU) && !defined(CONFIG_SYS_PHY_UBOOT_BASE)
41 #define CONFIG_SYS_PHY_UBOOT_BASE CONFIG_SYS_UBOOT_BASE
45 *************************************************************************
47 * Jump vector table as in table 3.1 in [1]
49 *************************************************************************
54 #ifndef CONFIG_NAND_SPL
55 ldr pc, _undefined_instruction
56 ldr pc, _software_interrupt
57 ldr pc, _prefetch_abort
63 _undefined_instruction:
64 .word undefined_instruction
66 .word software_interrupt
78 .word 0x12345678 /* now 16*4=64 */
85 .balignl 16,0xdeadbeef
87 *************************************************************************
89 * Startup Code (reset vector)
91 * do important init only if we don't start from memory!
92 * setup Memory and board specific bits prior to relocation.
93 * relocate armboot to ram
96 *************************************************************************
103 * Below variable is very important because we use MMU in U-Boot.
104 * Without it, we cannot run code correctly before MMU is ON.
108 .word CONFIG_SYS_PHY_UBOOT_BASE
110 .globl _armboot_start
115 * These are defined in the board-specific linker script.
126 * the actual reset code
131 * set the cpu to SVC32 mode
139 *************************************************************************
141 * CPU_init_critical registers
143 * setup important registers
144 * setup memory timing
146 *************************************************************************
149 * we do sys-critical inits only at reboot,
150 * not when booting from ram!
154 * When booting from NAND - it has definitely been a reset, so, no need
155 * to flush caches and disable the MMU
157 #ifndef CONFIG_NAND_SPL
159 * flush v4 I/D caches
162 mcr p15, 0, r0, c7, c7, 0 /* flush v3/v4 cache */
163 mcr p15, 0, r0, c8, c7, 0 /* flush v4 TLB */
166 * disable MMU stuff and caches
168 mrc p15, 0, r0, c1, c0, 0
169 bic r0, r0, #0x00002300 @ clear bits 13, 9:8 (--V- --RS)
170 bic r0, r0, #0x00000087 @ clear bits 7, 2:0 (B--- -CAM)
171 orr r0, r0, #0x00000002 @ set bit 2 (A) Align
172 orr r0, r0, #0x00001000 @ set bit 12 (I) I-Cache
173 /* Prepare to disable the MMU */
174 adr r1, mmu_disable_phys
175 /* We presume we're within the first 1024 bytes */
177 ldr r2, _TEXT_PHY_BASE
184 /* Run in a single cache-line */
186 mcr p15, 0, r0, c1, c0, 0
193 /* Peri port setup */
196 mcr p15,0,r0,c15,c2,4 @ 256M (0x70000000 - 0x7fffffff)
199 * Go setup Memory and board specific bits prior to relocation.
201 bl lowlevel_init /* go setup pll,mux,memory */
204 #ifdef CONFIG_ENABLE_MMU
206 /* enable domain access */
208 mcr p15, 0, r5, c3, c0, 0 /* load domain access register */
210 /* Set the TTB register */
211 ldr r0, _mmu_table_base
212 ldr r1, =CONFIG_SYS_PHY_UBOOT_BASE
216 mcr p15, 0, r1, c2, c0, 0
219 mrc p15, 0, r0, c1, c0, 0
220 orr r0, r0, #1 /* Set CR_M to enable MMU */
222 /* Prepare to enable the MMU */
232 /* Run in a single cache-line */
235 mcr p15, 0, r0, c1, c0, 0
242 /* Set up the stack */
244 ldr r0, =CONFIG_SYS_UBOOT_BASE /* base of copy in DRAM */
245 sub r0, r0, #CONFIG_SYS_MALLOC_LEN /* malloc area */
246 sub r0, r0, #CONFIG_SYS_GBL_DATA_SIZE /* bdinfo */
247 sub sp, r0, #12 /* leave 3 words for abort-stack */
250 ldr r0, _bss_start /* find start of bss segment */
251 ldr r1, _bss_end /* stop here */
252 mov r2, #0 /* clear */
255 str r2, [r0] /* clear loop... */
260 #ifndef CONFIG_NAND_SPL
261 ldr pc, _start_armboot
270 #ifdef CONFIG_ENABLE_MMU
275 #ifndef CONFIG_NAND_SPL
277 * we assume that cache operation is done before. (eg. cleanup_before_linux())
278 * actually, we don't need to do anything about cache if not use d-cache in
279 * U-Boot. So, in this function we clean only MMU. by scsuh
281 * void theLastJump(void *kernel, int arch_num, uint boot_params);
283 #ifdef CONFIG_ENABLE_MMU
288 ldr r4, _TEXT_PHY_BASE
289 adr r5, phy_last_jump
297 mrc p15, 0, r0, c1, c0, 0
298 bic r0, r0, #0x00002300 /* clear bits 13, 9:8 (--V- --RS) */
299 bic r0, r0, #0x00000087 /* clear bits 7, 2:0 (B--- -CAM) */
300 orr r0, r0, #0x00000002 /* set bit 2 (A) Align */
301 orr r0, r0, #0x00001000 /* set bit 12 (I) I-Cache */
302 mcr p15, 0, r0, c1, c0, 0
304 mcr p15, 0, r0, c8, c7, 0 /* flush v4 TLB */
310 *************************************************************************
314 *************************************************************************
319 #define S_FRAME_SIZE 72
341 #define MODE_SVC 0x13
345 * use bad_save_user_regs for abort/prefetch/undef/swi ...
348 .macro bad_save_user_regs
349 /* carve out a frame on current user stack */
350 sub sp, sp, #S_FRAME_SIZE
351 /* Save user registers (now in svc mode) r0-r12 */
354 ldr r2, _armboot_start
355 sub r2, r2, #(CONFIG_SYS_MALLOC_LEN)
356 /* set base 2 words into abort stack */
357 sub r2, r2, #(CONFIG_SYS_GBL_DATA_SIZE+8)
358 /* get values for "aborted" pc and cpsr (into parm regs) */
360 /* grab pointer to old stack */
361 add r0, sp, #S_FRAME_SIZE
365 /* save sp_SVC, lr_SVC, pc, cpsr */
367 /* save current stack into r0 (param register) */
372 /* setup our mode stack (enter in banked mode) */
373 ldr r13, _armboot_start
374 /* move past malloc pool */
375 sub r13, r13, #(CONFIG_SYS_MALLOC_LEN)
376 /* move to reserved a couple spots for abort stack */
377 sub r13, r13, #(CONFIG_SYS_GBL_DATA_SIZE + 8)
379 /* save caller lr in position 0 of saved stack */
383 /* save spsr in position 1 of saved stack */
386 /* prepare SVC-Mode */
389 /* switch modes, make sure moves will execute */
391 /* capture return pc */
393 /* jump to next instruction & switch modes. */
397 .macro get_bad_stack_swi
398 /* space on current stack for scratch reg. */
400 /* save R0's value. */
402 /* get data regions start */
403 ldr r0, _armboot_start
404 /* move past malloc pool */
405 sub r0, r0, #(CONFIG_SYS_MALLOC_LEN)
406 /* move past gbl and a couple spots for abort stack */
407 sub r0, r0, #(CONFIG_SYS_GBL_DATA_SIZE + 8)
408 /* save caller lr in position 0 of saved stack */
412 /* save spsr in position 1 of saved stack */
416 /* pop stack entry */
424 undefined_instruction:
427 bl do_undefined_instruction
433 bl do_software_interrupt
464 #endif /* CONFIG_NAND_SPL */