smdk2800_start.S revision 1.1
11.1Sbsh/*	$NetBSD: smdk2800_start.S,v 1.1 2002/11/20 18:06:26 bsh Exp $ */
21.1Sbsh
31.1Sbsh/*
41.1Sbsh * Copyright (c) 2002 Fujitsu Component Limited
51.1Sbsh * Copyright (c) 2002 Genetec Corporation
61.1Sbsh * All rights reserved.
71.1Sbsh *
81.1Sbsh * Redistribution and use in source and binary forms, with or without
91.1Sbsh * modification, are permitted provided that the following conditions
101.1Sbsh * are met:
111.1Sbsh * 1. Redistributions of source code must retain the above copyright
121.1Sbsh *    notice, this list of conditions and the following disclaimer.
131.1Sbsh * 2. Redistributions in binary form must reproduce the above copyright
141.1Sbsh *    notice, this list of conditions and the following disclaimer in the
151.1Sbsh *    documentation and/or other materials provided with the distribution.
161.1Sbsh * 3. Neither the name of The Fujitsu Component Limited nor the name of
171.1Sbsh *    Genetec corporation may not be used to endorse or promote products
181.1Sbsh *    derived from this software without specific prior written permission.
191.1Sbsh *
201.1Sbsh * THIS SOFTWARE IS PROVIDED BY FUJITSU COMPONENT LIMITED AND GENETEC
211.1Sbsh * CORPORATION ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
221.1Sbsh * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
231.1Sbsh * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
241.1Sbsh * DISCLAIMED.  IN NO EVENT SHALL FUJITSU COMPONENT LIMITED OR GENETEC
251.1Sbsh * CORPORATION BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
261.1Sbsh * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
271.1Sbsh * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
281.1Sbsh * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
291.1Sbsh * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
301.1Sbsh * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
311.1Sbsh * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
321.1Sbsh * SUCH DAMAGE.
331.1Sbsh */
341.1Sbsh
351.1Sbsh#include <machine/asm.h>
361.1Sbsh#include <arm/armreg.h>
371.1Sbsh#include <arm/arm32/pte.h>
381.1Sbsh
391.1Sbsh/*
401.1Sbsh * Kernel start routine for Samsung SMDK2800.
411.1Sbsh * This code is excuted at the very first after the kernel is loaded
421.1Sbsh * by boot program on ROM or gzboot.
431.1Sbsh */
441.1Sbsh	.text
451.1Sbsh
461.1Sbsh	.global	_C_LABEL(smdk2800_start)
471.1Sbsh_C_LABEL(smdk2800_start):
481.1Sbsh	/* Are we running on ROM ? */
491.1Sbsh	cmp	pc, #0x08200000
501.1Sbsh	bhs	smdk2800_start_ram
511.1Sbsh
521.1Sbsh	/* move me to RAM
531.1Sbsh	 * XXX: we can use memcpy if it is PIC
541.1Sbsh	 */
551.1Sbsh	ldr r1, Lcopy_size
561.1Sbsh	adr r0, _C_LABEL(smdk2800_start)
571.1Sbsh	add r1, r1, #3
581.1Sbsh	mov r1, r1, LSR #2
591.1Sbsh	mov r2, #0x08200000
601.1Sbsh	mov r4, r2
611.1Sbsh
621.1Sbsh	cmp r0, r2
631.1Sbsh	bhs 5f
641.1Sbsh
651.1Sbsh	/* src < dest. copy from top */
661.1Sbsh	add r0,r0,r1,LSL #2
671.1Sbsh	add r2,r2,r1,LSL #2
681.1Sbsh
691.1Sbsh3:	ldr r3,[r0,#-4]!
701.1Sbsh	str r3,[r2,#-4]!
711.1Sbsh	subs r1,r1,#1
721.1Sbsh	bhi 3b
731.1Sbsh	b 7f
741.1Sbsh
751.1Sbsh	/* src >= dest. copy from bottom */
761.1Sbsh5:	ldr r3,[r0],#4
771.1Sbsh	str r3,[r2],#4
781.1Sbsh	subs r1,r1,#1
791.1Sbsh	bhi 5b
801.1Sbsh
811.1Sbsh7:
821.1Sbsh	/* Jump to RAM */
831.1Sbsh	ldr r0, Lstart_off
841.1Sbsh	add pc, r4, r0
851.1Sbsh
861.1SbshLcopy_size:	.word _edata-_C_LABEL(smdk2800_start)
871.1SbshLstart_off:	.word smdk2800_start_ram-_C_LABEL(smdk2800_start)
881.1Sbsh
891.1Sbshsmdk2800_start_ram:
901.1Sbsh	/*
911.1Sbsh	 *  Kernel is loaded in SDRAM (0x08200000..), and is expected to run
921.1Sbsh	 *  in VA 0xc0200000..
931.1Sbsh	 */
941.1Sbsh
951.1Sbsh	/* get ttb prepared by boot program */
961.1Sbsh	mrc p15, 0, r0, c2, c0, 0
971.1Sbsh	/* Disable MMU for a while */
981.1Sbsh	mrc	p15, 0, r2, c1, c0, 0
991.1Sbsh	bic	r2, r2, #CPU_CONTROL_MMU_ENABLE
1001.1Sbsh	mcr	p15, 0, r2, c1, c0, 0
1011.1Sbsh
1021.1Sbsh	nop
1031.1Sbsh	nop
1041.1Sbsh	nop
1051.1Sbsh
1061.1Sbsh	/*
1071.1Sbsh	 * Map VA 0xc0000000..0xc3ffffff to PA 0x08000000..0x09ffffff
1081.1Sbsh	 */
1091.1Sbsh	mov	r1, #(L1_S_AP(AP_KRW))
1101.1Sbsh	orr	r1, r1, #(L1_TYPE_S)
1111.1Sbsh	orr	r1, r1, #0x08000000
1121.1Sbsh	mov	r2, #(0xc00 * 4)
1131.1Sbsh1:
1141.1Sbsh	str	r1, [r0, r2]
1151.1Sbsh	add	r2, r2, #4
1161.1Sbsh	add	r1, r1, #L1_S_SIZE
1171.1Sbsh	cmp	r2, #(0xc20 * 4)
1181.1Sbsh	blo	1b
1191.1Sbsh
1201.1Sbsh
1211.1Sbsh	mcr	p15, 0, r0, c2, c0, 0	/* Set TTB */
1221.1Sbsh	mcr	p15, 0, r0, c8, c7, 0	/* Flush TLB */
1231.1Sbsh
1241.1Sbsh	/* Set the Domain Access register.  Very important! */
1251.1Sbsh	mov	r0, #1
1261.1Sbsh	mcr	p15, 0, r0, c3, c0, 0
1271.1Sbsh
1281.1Sbsh	/* Enable MMU */
1291.1Sbsh	mrc	p15, 0, r0, c1, c0, 0
1301.1Sbsh	orr	r0, r0, #CPU_CONTROL_MMU_ENABLE
1311.1Sbsh	mcr	p15, 0, r0, c1, c0, 0
1321.1Sbsh
1331.1Sbsh	nop
1341.1Sbsh	nop
1351.1Sbsh	nop
1361.1Sbsh
1371.1Sbsh	/* Jump to kernel code in TRUE VA */
1381.1Sbsh	adr	r0, Lstart
1391.1Sbsh	ldr	pc, [r0]
1401.1Sbsh
1411.1SbshLstart:
1421.1Sbsh	.word	start
143