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>
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 #ifdef CONFIG_MEMORY_UPPER_CODE
245 ldr sp, =(CONFIG_SYS_UBOOT_BASE + CONFIG_SYS_UBOOT_SIZE - 0xc)
247 ldr r0, _TEXT_BASE /* upper 128 KiB: relocated uboot */
248 sub r0, r0, #CONFIG_SYS_MALLOC_LEN /* malloc area */
249 sub r0, r0, #CONFIG_SYS_GBL_DATA_SIZE /* bdinfo */
250 sub sp, r0, #12 /* leave 3 words for abort-stack */
255 ldr r0, _bss_start /* find start of bss segment */
256 ldr r1, _bss_end /* stop here */
257 mov r2, #0 /* clear */
260 str r2, [r0] /* clear loop... */
265 #ifndef CONFIG_NAND_SPL
266 ldr pc, _start_armboot
275 #ifdef CONFIG_ENABLE_MMU
280 #ifndef CONFIG_NAND_SPL
282 * we assume that cache operation is done before. (eg. cleanup_before_linux())
283 * actually, we don't need to do anything about cache if not use d-cache in
284 * U-Boot. So, in this function we clean only MMU. by scsuh
286 * void theLastJump(void *kernel, int arch_num, uint boot_params);
288 #ifdef CONFIG_ENABLE_MMU
293 ldr r4, _TEXT_PHY_BASE
294 adr r5, phy_last_jump
302 mrc p15, 0, r0, c1, c0, 0
303 bic r0, r0, #0x00002300 /* clear bits 13, 9:8 (--V- --RS) */
304 bic r0, r0, #0x00000087 /* clear bits 7, 2:0 (B--- -CAM) */
305 orr r0, r0, #0x00000002 /* set bit 2 (A) Align */
306 orr r0, r0, #0x00001000 /* set bit 12 (I) I-Cache */
307 mcr p15, 0, r0, c1, c0, 0
309 mcr p15, 0, r0, c8, c7, 0 /* flush v4 TLB */
315 *************************************************************************
319 *************************************************************************
324 #define S_FRAME_SIZE 72
346 #define MODE_SVC 0x13
350 * use bad_save_user_regs for abort/prefetch/undef/swi ...
353 .macro bad_save_user_regs
354 /* carve out a frame on current user stack */
355 sub sp, sp, #S_FRAME_SIZE
356 /* Save user registers (now in svc mode) r0-r12 */
359 ldr r2, _armboot_start
360 sub r2, r2, #(CONFIG_SYS_MALLOC_LEN)
361 /* set base 2 words into abort stack */
362 sub r2, r2, #(CONFIG_SYS_GBL_DATA_SIZE+8)
363 /* get values for "aborted" pc and cpsr (into parm regs) */
365 /* grab pointer to old stack */
366 add r0, sp, #S_FRAME_SIZE
370 /* save sp_SVC, lr_SVC, pc, cpsr */
372 /* save current stack into r0 (param register) */
377 /* setup our mode stack (enter in banked mode) */
378 ldr r13, _armboot_start
379 /* move past malloc pool */
380 sub r13, r13, #(CONFIG_SYS_MALLOC_LEN)
381 /* move to reserved a couple spots for abort stack */
382 sub r13, r13, #(CONFIG_SYS_GBL_DATA_SIZE + 8)
384 /* save caller lr in position 0 of saved stack */
388 /* save spsr in position 1 of saved stack */
391 /* prepare SVC-Mode */
394 /* switch modes, make sure moves will execute */
396 /* capture return pc */
398 /* jump to next instruction & switch modes. */
402 .macro get_bad_stack_swi
403 /* space on current stack for scratch reg. */
405 /* save R0's value. */
407 /* get data regions start */
408 ldr r0, _armboot_start
409 /* move past malloc pool */
410 sub r0, r0, #(CONFIG_SYS_MALLOC_LEN)
411 /* move past gbl and a couple spots for abort stack */
412 sub r0, r0, #(CONFIG_SYS_GBL_DATA_SIZE + 8)
413 /* save caller lr in position 0 of saved stack */
417 /* save spsr in position 1 of saved stack */
421 /* pop stack entry */
429 undefined_instruction:
432 bl do_undefined_instruction
438 bl do_software_interrupt
469 #endif /* CONFIG_NAND_SPL */