Home | History | Annotate | Line # | Download | only in nslu2
nslu2_start.S revision 1.2.30.1
      1  1.2.30.1  bouyer /*	$NetBSD: nslu2_start.S,v 1.2.30.1 2011/02/08 16:19:18 bouyer Exp $	*/
      2       1.1     scw 
      3       1.1     scw /*
      4       1.1     scw  * Copyright (c) 2006 The NetBSD Foundation, Inc.
      5       1.1     scw  * All rights reserved.
      6       1.1     scw  *
      7       1.1     scw  * This code is derived from software contributed to The NetBSD Foundation
      8       1.1     scw  * by Ichiro FUKUHARA, Jason R. Thorpe, and Steve C. Woodford.
      9       1.1     scw  *
     10       1.1     scw  * Redistribution and use in source and binary forms, with or without
     11       1.1     scw  * modification, are permitted provided that the following conditions
     12       1.1     scw  * are met:
     13       1.1     scw  * 1. Redistributions of source code must retain the above copyright
     14       1.1     scw  *    notice, this list of conditions and the following disclaimer.
     15       1.1     scw  * 2. Redistributions in binary form must reproduce the above copyright
     16       1.1     scw  *    notice, this list of conditions and the following disclaimer in the
     17       1.1     scw  *    documentation and/or other materials provided with the distribution.
     18       1.1     scw  *
     19       1.1     scw  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20       1.1     scw  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21       1.1     scw  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22       1.1     scw  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23       1.1     scw  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24       1.1     scw  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25       1.1     scw  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26       1.1     scw  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27       1.1     scw  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28       1.1     scw  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29       1.1     scw  * POSSIBILITY OF SUCH DAMAGE.
     30       1.1     scw  */
     31       1.1     scw 
     32       1.1     scw #include <machine/asm.h>
     33       1.1     scw #include <arm/armreg.h>
     34  1.2.30.1  bouyer #include "assym.h"
     35       1.1     scw 
     36       1.1     scw #include <arm/xscale/ixp425reg.h>
     37       1.1     scw 
     38  1.2.30.1  bouyer RCSID("$NetBSD: nslu2_start.S,v 1.2.30.1 2011/02/08 16:19:18 bouyer Exp $")
     39  1.2.30.1  bouyer 
     40       1.1     scw 	.section .start,"ax",%progbits
     41       1.1     scw 
     42       1.1     scw 	.global	_C_LABEL(nslu2_start)
     43       1.1     scw _C_LABEL(nslu2_start):
     44       1.1     scw         /*
     45       1.1     scw          * We will go ahead and disable the MMU here so that we don't
     46       1.1     scw          * have to worry about flushing caches, etc.
     47       1.1     scw          *
     48       1.1     scw          * Note that we may not currently be running VA==PA, which means
     49       1.1     scw          * we'll need to leap to the next insn after disabing the MMU.
     50       1.1     scw          */
     51       1.1     scw         adr     r8, Lunmapped
     52       1.1     scw         bic     r8, r8, #0xff000000     /* clear upper 8 bits */
     53       1.1     scw         orr     r8, r8, #0x10000000     /* OR in physical base address */
     54       1.1     scw 
     55       1.1     scw         mrc     p15, 0, r2, c1, c0, 0
     56       1.1     scw         bic     r2, r2, #CPU_CONTROL_MMU_ENABLE
     57       1.1     scw 	orr	r2, r2, #CPU_CONTROL_BEND_ENABLE
     58       1.1     scw         mcr     p15, 0, r2, c1, c0, 0
     59       1.1     scw 
     60       1.1     scw         nop
     61       1.1     scw         nop
     62       1.1     scw         nop
     63       1.1     scw 
     64       1.1     scw         mov     pc, r8                  /* Heave-ho! */
     65       1.1     scw 
     66       1.1     scw Lunmapped:
     67       1.1     scw 	/*
     68       1.1     scw 	 * We want to construct a memory map that maps us
     69       1.1     scw 	 * VA==PA (SDRAM at 0x10000000). We create these
     70       1.1     scw 	 * mappings uncached and unbuffered to be safe.
     71       1.1     scw 	 */
     72       1.1     scw 
     73       1.1     scw 	/*
     74       1.1     scw 	 * Step 1: Map the entire address space VA==PA.
     75       1.1     scw 	 */
     76       1.1     scw 	adr	r0, Ltable
     77       1.1     scw 	ldr	r0, [r0]			/* r0 = &l1table */
     78       1.1     scw 
     79       1.1     scw 	mov	r1, #(L1_TABLE_SIZE / 4)	/* 4096 entry */
     80       1.1     scw 	mov	r2, #(L1_S_SIZE)		/* 1MB / section */
     81  1.2.30.1  bouyer 	mov	r3, #(L1_S_AP_KRW)		/* kernel read/write */
     82       1.1     scw 	orr	r3, r3, #(L1_TYPE_S)		/* L1 entry is section */
     83       1.1     scw 1:
     84       1.1     scw 	str	r3, [r0], #0x04
     85       1.1     scw 	add	r3, r3, r2
     86       1.1     scw 	subs	r1, r1, #1
     87       1.1     scw 	bgt	1b
     88       1.1     scw 
     89       1.1     scw         /*
     90       1.1     scw          * Step 2: Map VA 0xc0000000->0xc3ffffff to PA 0x10000000->0x13ffffff.
     91       1.1     scw          */
     92       1.1     scw         adr     r0, Ltable                      /* r0 = &l1table */
     93       1.1     scw         ldr     r0, [r0]
     94       1.1     scw 
     95  1.2.30.1  bouyer         mov     r3, #(L1_S_AP_KRW)
     96       1.1     scw         orr     r3, r3, #(L1_TYPE_S)
     97       1.1     scw         orr     r3, r3, #0x10000000
     98       1.1     scw         add     r0, r0, #(0xc00 * 4)            /* offset to 0xc00xxxxx */
     99       1.1     scw         mov     r1, #0x40                       /* 64MB */
    100       1.1     scw 1:
    101       1.1     scw         str     r3, [r0], #0x04
    102       1.1     scw         add     r3, r3, r2
    103       1.1     scw         subs    r1, r1, #1
    104       1.1     scw         bgt     1b
    105       1.1     scw 
    106       1.1     scw 	/*
    107       1.1     scw 	 * Step 3: Map VA 0xf0000000->0xf0100000 to PA 0xc8000000->0xc8100000.
    108       1.1     scw 	 */
    109       1.1     scw 	adr	r0, Ltable			/* r0 = &l1table */
    110       1.1     scw 	ldr	r0, [r0]
    111       1.1     scw 
    112       1.1     scw 	add	r0, r0, #(0xf00 * 4)		/* offset to 0xf0000000 */
    113       1.1     scw 	mov	r3, #0xc8000000
    114       1.1     scw 	add	r3, r3, #0x00100000
    115  1.2.30.1  bouyer 	orr	r3, r3, #(L1_S_AP_KRW)
    116       1.1     scw 	orr	r3, r3, #(L1_TYPE_S)
    117       1.1     scw 	str	r3, [r0]
    118       1.1     scw 
    119       1.1     scw 	/*
    120       1.1     scw 	 * Step 4: Map VA 0xf0200000->0xf0300000 to PA 0xcc000000->0xcc100000.
    121       1.1     scw 	 */
    122       1.1     scw 	adr	r0, Ltable			/* r0 = &l1table */
    123       1.1     scw 	ldr	r0, [r0]
    124       1.1     scw 
    125       1.1     scw 	add	r0, r0, #(0xf00 * 4)		/* offset to 0xf0200000 */
    126       1.1     scw 	add	r0, r0, #(0x002 * 4)
    127       1.1     scw 	mov	r3, #0xcc000000
    128       1.1     scw 	add	r3, r3, #0x00100000
    129  1.2.30.1  bouyer 	orr	r3, r3, #(L1_S_AP_KRW)
    130       1.1     scw 	orr	r3, r3, #(L1_TYPE_S)
    131       1.1     scw 	str	r3, [r0]
    132       1.1     scw 
    133       1.1     scw 	/* OK!  Page table is set up.  Give it to the CPU. */
    134       1.1     scw 	adr	r0, Ltable
    135       1.1     scw 	ldr	r0, [r0]
    136       1.1     scw 	mcr	p15, 0, r0, c2, c0, 0
    137       1.1     scw 
    138       1.1     scw 	/* Flush the old TLBs, just in case. */
    139       1.1     scw 	mcr	p15, 0, r0, c8, c7, 0
    140       1.1     scw 
    141       1.1     scw 	/* Set the Domain Access register.  Very important! */
    142       1.1     scw 	mov	r0, #1
    143       1.1     scw 	mcr	p15, 0, r0, c3, c0, 0
    144       1.1     scw 
    145       1.1     scw 	/* Get ready to jump to the "real" kernel entry point... */
    146       1.1     scw 	ldr	r1, Lstart
    147       1.1     scw 	mov	r1, r1			/* Make sure the load completes! */
    148       1.1     scw 
    149       1.1     scw 	/* OK, let's enable the MMU. */
    150       1.1     scw 	mrc	p15, 0, r2, c1, c0, 0
    151       1.1     scw 	orr	r2, r2, #CPU_CONTROL_MMU_ENABLE
    152       1.1     scw 	orr	r2, r2, #CPU_CONTROL_BEND_ENABLE
    153       1.1     scw 	mcr	p15, 0, r2, c1, c0, 0
    154       1.1     scw 
    155       1.1     scw 	nop
    156       1.1     scw 	nop
    157       1.1     scw 	nop
    158       1.1     scw 
    159       1.1     scw 	/* CPWAIT sequence to make sure the MMU is on... */
    160       1.1     scw 	mrc	p15, 0, r2, c2, c0, 0	/* arbitrary read of CP15 */
    161       1.1     scw 	mov	r2, r2			/* force it to complete */
    162       1.1     scw 	mov	pc, r1			/* leap to kernel entry point! */
    163       1.1     scw 
    164       1.1     scw Ltable:
    165       1.1     scw 	.word	0x10200000 - 0x4000
    166       1.1     scw 
    167       1.1     scw Lstart:
    168       1.1     scw 	.word	start
    169