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