Home | History | Annotate | Line # | Download | only in viper
viper_start.S revision 1.1
      1  1.1  pooka /*	$NetBSD: viper_start.S,v 1.1 2005/06/06 20:24:11 pooka Exp $	*/
      2  1.1  pooka 
      3  1.1  pooka /*
      4  1.1  pooka  * Copyright (c) 2005 Antti Kantee.  All Rights Reserved.
      5  1.1  pooka  *
      6  1.1  pooka  * Redistribution and use in source and binary forms, with or without
      7  1.1  pooka  * modification, are permitted provided that the following conditions
      8  1.1  pooka  * are met:
      9  1.1  pooka  * 1. Redistributions of source code must retain the above copyright
     10  1.1  pooka  *    notice, this list of conditions and the following disclaimer.
     11  1.1  pooka  * 2. Redistributions in binary form must reproduce the above copyright
     12  1.1  pooka  *    notice, this list of conditions and the following disclaimer in the
     13  1.1  pooka  *    documentation and/or other materials provided with the distribution.
     14  1.1  pooka  * 3. All advertising materials mentioning features or use of this software
     15  1.1  pooka  *    must display the following acknowledgement:
     16  1.1  pooka  *        This product includes software developed by The NetBSD
     17  1.1  pooka  *        Foundation, Inc. and its contributors.
     18  1.1  pooka  * 4. The name of the company nor the name of the author may be used to
     19  1.1  pooka  *    endorse or promote products derived from this software without specific
     20  1.1  pooka  *    prior written permission.
     21  1.1  pooka  *
     22  1.1  pooka  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
     23  1.1  pooka  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     24  1.1  pooka  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     25  1.1  pooka  * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     26  1.1  pooka  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     27  1.1  pooka  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     28  1.1  pooka  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     29  1.1  pooka  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     30  1.1  pooka  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     31  1.1  pooka  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     32  1.1  pooka  * SUCH DAMAGE.
     33  1.1  pooka  */
     34  1.1  pooka 
     35  1.1  pooka #include <machine/asm.h>
     36  1.1  pooka #include <arm/armreg.h>
     37  1.1  pooka #include <arm/arm32/pmap.h>
     38  1.1  pooka #include <arm/arm32/pte.h>
     39  1.1  pooka 
     40  1.1  pooka /*
     41  1.1  pooka  * We start out with RAM mapped to the bottom 64MB.  We are jogging
     42  1.1  pooka  * happily there with the MMU on.  Our mission: map some important
     43  1.1  pooka  * bootstrap devices (such as console port) in addition to mapping
     44  1.1  pooka  * the physical RAM to 0xc0...
     45  1.1  pooka  *
     46  1.1  pooka  * If I try to create a mapping from scratch, something important gets
     47  1.1  pooka  * wiped out (never could figure out exactly what), so we do this with
     48  1.1  pooka  * the MMU on adding to the existing translation table.
     49  1.1  pooka  */
     50  1.1  pooka 
     51  1.1  pooka #define CPWAIT_BRANCH							 \
     52  1.1  pooka 	sub	pc, pc, #4
     53  1.1  pooka 
     54  1.1  pooka #define CPWAIT(tmp)							 \
     55  1.1  pooka 	mrc	p15, 0, tmp, c2, c0, 0  /* arbitrary read of CP15 */	;\
     56  1.1  pooka 	mov	tmp, tmp		/* wait for it to complete */	;\
     57  1.1  pooka 	CPWAIT_BRANCH			/* branch to next insn */
     58  1.1  pooka 
     59  1.1  pooka #ifndef SDRAM_START
     60  1.1  pooka #define SDRAM_START 0xa0000000
     61  1.1  pooka #endif
     62  1.1  pooka 
     63  1.1  pooka 	.text
     64  1.1  pooka 
     65  1.1  pooka 	.global _C_LABEL(viper_start)
     66  1.1  pooka _C_LABEL(viper_start):
     67  1.1  pooka 
     68  1.1  pooka 	/* Figure out where we want to jump to when the time comes */
     69  1.1  pooka 	adr	r8, .Linva
     70  1.1  pooka 	ldr	r8, [r8]
     71  1.1  pooka 
     72  1.1  pooka 	/*
     73  1.1  pooka 	 * Start playing with the virtual address space mapping
     74  1.1  pooka 	 * for initial bootstrap.
     75  1.1  pooka 	 *
     76  1.1  pooka 	 * Load registers, which will remain constant throughout
     77  1.1  pooka 	 * building the VA mapping.
     78  1.1  pooka 	 */
     79  1.1  pooka 	mov     r2, #(L1_S_SIZE)		/* 1MB chunks */
     80  1.1  pooka 
     81  1.1  pooka 	/*
     82  1.1  pooka 	 * First map SDRAM VA == PA.  This enables us to cut&waste
     83  1.1  pooka 	 * some existing initarm() code without modification
     84  1.1  pooka 	 * (and, if, god forbid, someone would like to unify them
     85  1.1  pooka 	 * some day, this'll make that job easier)
     86  1.1  pooka 	 */
     87  1.1  pooka 	mrc	p15, 0, r0, c2, c0, 0		/* Get L1 */
     88  1.1  pooka 	bic	r0, r0, #0xff000000
     89  1.1  pooka 	add	r0, r0, #(0xa00 * 4)		/* offset to 0xa0.. */
     90  1.1  pooka 
     91  1.1  pooka 	mov	r3, #SDRAM_START		/* map to 0xa00.. */
     92  1.1  pooka 	orr	r3, r3, #(L1_S_AP(AP_KRW))	/* the usual perms & stuff */
     93  1.1  pooka 	orr	r3, r3, #(L1_TYPE_S)
     94  1.1  pooka 	orr	r3, r3, #(L1_S_DOM(PMAP_DOMAIN_KERNEL))
     95  1.1  pooka 	mov	r1, #0x40			/* 64 1MB entries */
     96  1.1  pooka 
     97  1.1  pooka 1:
     98  1.1  pooka 	/* and looplooploop */
     99  1.1  pooka 	str	r3, [r0], #4
    100  1.1  pooka 	add	r3, r3, r2
    101  1.1  pooka 	subs	r1, r1, #1
    102  1.1  pooka 	bgt	1b
    103  1.1  pooka 
    104  1.1  pooka 	/*
    105  1.1  pooka 	 * Map SDRAM also to VA 0xc00...
    106  1.1  pooka 	 */
    107  1.1  pooka 	mrc	p15, 0, r0, c2, c0, 0		/* Get L1 */
    108  1.1  pooka 	bic	r0, r0, #0xff000000
    109  1.1  pooka 	add	r0, r0, #(0xc00 * 4)		/* start from 0xc00.. */
    110  1.1  pooka 
    111  1.1  pooka 	mov	r3, #SDRAM_START		/* map to 0xa00.. */
    112  1.1  pooka 	orr	r3, r3, #(L1_S_AP(AP_KRW))	/* the usual perms & stuff */
    113  1.1  pooka 	orr	r3, r3, #(L1_TYPE_S)
    114  1.1  pooka 	orr	r3, r3, #(L1_S_DOM(PMAP_DOMAIN_KERNEL))
    115  1.1  pooka 	mov	r1, #0x40			/* 64 1MB entries */
    116  1.1  pooka 
    117  1.1  pooka 1:
    118  1.1  pooka 	/* and looplooploop */
    119  1.1  pooka 	str	r3, [r0], #4
    120  1.1  pooka 	add	r3, r3, r2
    121  1.1  pooka 	subs	r1, r1, #1
    122  1.1  pooka 	bgt	1b
    123  1.1  pooka 
    124  1.1  pooka 	/*
    125  1.1  pooka 	 * Here come the devices.  Map an L1 section for each device
    126  1.1  pooka 	 * to make this easy.
    127  1.1  pooka 	 */
    128  1.1  pooka 
    129  1.1  pooka 	/* INTCTL */
    130  1.1  pooka 	mrc	p15, 0, r0, c2, c0, 0		/* Get L1 */
    131  1.1  pooka 	bic	r0, r0, #0xff000000
    132  1.1  pooka 	add	r0, r0, #(0xfd0 * 4)		/* offset to 0xfd000000 */
    133  1.1  pooka 
    134  1.1  pooka 	mov	r3,	#0x40000000
    135  1.1  pooka 	orr	r3, r3,	#0x00d00000
    136  1.1  pooka 	orr	r3, r3, #(L1_S_AP(AP_KRW))
    137  1.1  pooka 	orr	r3, r3, #(L1_TYPE_S)
    138  1.1  pooka 	orr	r3, r3, #(L1_S_DOM(PMAP_DOMAIN_KERNEL))
    139  1.1  pooka 	str	r3, [r0], #4
    140  1.1  pooka 
    141  1.1  pooka 	/* GPIO */
    142  1.1  pooka 	mov	r3,	#0x40000000
    143  1.1  pooka 	orr	r3, r3,	#0x00e00000
    144  1.1  pooka 	orr	r3, r3, #(L1_S_AP(AP_KRW))
    145  1.1  pooka 	orr	r3, r3, #(L1_TYPE_S)
    146  1.1  pooka 	orr	r3, r3, #(L1_S_DOM(PMAP_DOMAIN_KERNEL))
    147  1.1  pooka 	str	r3, [r0], #4
    148  1.1  pooka 
    149  1.1  pooka 	/* CLKMAN */
    150  1.1  pooka 	mov	r3,	#0x41000000
    151  1.1  pooka 	orr	r3, r3, #0x00300000
    152  1.1  pooka 	orr	r3, r3, #(L1_S_AP(AP_KRW))
    153  1.1  pooka 	orr	r3, r3, #(L1_TYPE_S)
    154  1.1  pooka 	orr	r3, r3, #(L1_S_DOM(PMAP_DOMAIN_KERNEL))
    155  1.1  pooka 	str	r3, [r0], #4
    156  1.1  pooka 
    157  1.1  pooka 	/* FFUART */
    158  1.1  pooka 	mov	r3,	#0x40000000
    159  1.1  pooka 	orr	r3, r3, #0x00100000
    160  1.1  pooka 	orr	r3, r3, #(L1_S_AP(AP_KRW))
    161  1.1  pooka 	orr	r3, r3, #(L1_TYPE_S)
    162  1.1  pooka 	orr	r3, r3, #(L1_S_DOM(PMAP_DOMAIN_KERNEL))
    163  1.1  pooka 	str	r3, [r0], #4
    164  1.1  pooka 
    165  1.1  pooka 	/* BTUART */
    166  1.1  pooka 	mov	r3,	#0x40000000
    167  1.1  pooka 	orr	r3, r3, #0x00200000
    168  1.1  pooka 	orr	r3, r3, #(L1_S_AP(AP_KRW))
    169  1.1  pooka 	orr	r3, r3, #(L1_TYPE_S)
    170  1.1  pooka 	orr	r3, r3, #(L1_S_DOM(PMAP_DOMAIN_KERNEL))
    171  1.1  pooka 	str	r3, [r0], #4
    172  1.1  pooka 
    173  1.1  pooka #if 0
    174  1.1  pooka 	/*
    175  1.1  pooka 	 * Cache cleanup.  Not needed here?  Slight speedup in booting.
    176  1.1  pooka 	 */
    177  1.1  pooka 	mov	r3, #(DCACHE_SIZE)
    178  1.1  pooka 	subs	r3, r3, #32
    179  1.1  pooka 1:
    180  1.1  pooka 	mcr	p15, 0, r3, c7, c10, 2
    181  1.1  pooka 	subs	r3, r3, #32
    182  1.1  pooka 	bne	1b
    183  1.1  pooka 	CPWAIT(r3)
    184  1.1  pooka 
    185  1.1  pooka 	/* Drain write buffer */
    186  1.1  pooka 	mcr	p15, 0, r6, c7, c10, 4
    187  1.1  pooka #endif
    188  1.1  pooka 
    189  1.1  pooka 	/*
    190  1.1  pooka 	 * Make domain control go ful fart.
    191  1.1  pooka 	 * We probably could be slightly more sensible about this,
    192  1.1  pooka 	 * but it'll be replaced soon anyway, so why bother.
    193  1.1  pooka 	 */
    194  1.1  pooka 	mov	r0, #0xffffffff
    195  1.1  pooka 	mcr	p15, 0, r0, c3, c0, 0
    196  1.1  pooka 
    197  1.1  pooka 	/*
    198  1.1  pooka 	 * Relocate the kernel to where we want it, not where Redboot
    199  1.1  pooka 	 * let's us load it.  Don't bother jumping after this stage,
    200  1.1  pooka 	 * we'll do that soon enough anyway, and to the correct virtual
    201  1.1  pooka 	 * address space region I might add.
    202  1.1  pooka 	 */
    203  1.1  pooka 	adr	r0, _C_LABEL(viper_start)	/* start copy from here */
    204  1.1  pooka 	add	r0, r0, #SDRAM_START		/* offset to SDRAM mapping */
    205  1.1  pooka 
    206  1.1  pooka 	ldr	r1, .Lcopy_size			/* copy this much (bytes) */
    207  1.1  pooka 	add	r1, r1, #3			/* prepare for roundup */
    208  1.1  pooka 	mov	r1, r1, LSR #2			/* make it words */
    209  1.1  pooka 
    210  1.1  pooka 	mov	r2, #SDRAM_START		/* target address, */
    211  1.1  pooka 	add	r2, r2, #0x00200000		/* kernel offsets by 2megs */
    212  1.1  pooka 
    213  1.1  pooka 	/* after this it's just a load-store-loop */
    214  1.1  pooka 1:
    215  1.1  pooka 	ldr	r3, [r0], #4
    216  1.1  pooka 	str	r3, [r2], #4
    217  1.1  pooka 	subs	r1, r1, #1
    218  1.1  pooka 	bgt	1b
    219  1.1  pooka 
    220  1.1  pooka 	/*
    221  1.1  pooka 	 * Now let's clean the cache again to make sure everything
    222  1.1  pooka 	 * is in place.
    223  1.1  pooka 	 *
    224  1.1  pooka 	 * XXX: should this take into account the XScale cache clean bug?
    225  1.1  pooka 	 */
    226  1.1  pooka 	mov	r3, #(DCACHE_SIZE)
    227  1.1  pooka 	subs	r3, r3, #32
    228  1.1  pooka 1:
    229  1.1  pooka 	mcr	p15, 0, r3, c7, c10, 2
    230  1.1  pooka 	subs	r3, r3, #32
    231  1.1  pooka 	bne	1b
    232  1.1  pooka 	CPWAIT(r3)
    233  1.1  pooka 
    234  1.1  pooka 	/* Drain write buffer */
    235  1.1  pooka 	mcr	p15, 0, r6, c7, c10, 4
    236  1.1  pooka 
    237  1.1  pooka 	/* Invalidate TLBs just to be sure */
    238  1.1  pooka 	mcr     p15, 0, r0, c8, c7, 0
    239  1.1  pooka 
    240  1.1  pooka 	/*
    241  1.1  pooka 	 * You are standing at the gate to NetBSD. --More--
    242  1.1  pooka 	 * Unspeakable cruelty and harm lurk down there. --More--
    243  1.1  pooka 	 * Are you sure you want to enter?
    244  1.1  pooka 	 */
    245  1.1  pooka 	mov	pc, r8				/* So be it */
    246  1.1  pooka 
    247  1.1  pooka /* symbol to use for address calculation in the right VA */
    248  1.1  pooka .Linva:
    249  1.1  pooka 	.word	start
    250  1.1  pooka 
    251  1.1  pooka /*
    252  1.1  pooka  * Calculate size of kernel to copy.  Don't bother to copy bss,
    253  1.1  pooka  * although I guess the CPU could use the warmup exercise ...
    254  1.1  pooka  */
    255  1.1  pooka .Lcopy_size:
    256  1.1  pooka 	.word _edata - _C_LABEL(viper_start)
    257