Home | History | Annotate | Line # | Download | only in viper
viper_start.S revision 1.2.4.1
      1  1.2.4.1  rpaulo /*	$NetBSD: viper_start.S,v 1.2.4.1 2006/09/09 02:38:55 rpaulo 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.2.4.1  rpaulo #define XSCALE_DCACHE_SIZE 0x8000
     63      1.1   pooka 
     64      1.1   pooka 	.text
     65      1.1   pooka 
     66      1.1   pooka 	.global _C_LABEL(viper_start)
     67      1.1   pooka _C_LABEL(viper_start):
     68      1.1   pooka 
     69      1.1   pooka 	/* Figure out where we want to jump to when the time comes */
     70      1.1   pooka 	adr	r8, .Linva
     71      1.1   pooka 	ldr	r8, [r8]
     72      1.1   pooka 
     73      1.1   pooka 	/*
     74      1.1   pooka 	 * Start playing with the virtual address space mapping
     75      1.1   pooka 	 * for initial bootstrap.
     76      1.1   pooka 	 *
     77      1.1   pooka 	 * Load registers, which will remain constant throughout
     78      1.1   pooka 	 * building the VA mapping.
     79      1.1   pooka 	 */
     80      1.1   pooka 	mov     r2, #(L1_S_SIZE)		/* 1MB chunks */
     81      1.1   pooka 
     82      1.1   pooka 	/*
     83      1.1   pooka 	 * First map SDRAM VA == PA.  This enables us to cut&waste
     84      1.1   pooka 	 * some existing initarm() code without modification
     85      1.1   pooka 	 * (and, if, god forbid, someone would like to unify them
     86      1.1   pooka 	 * some day, this'll make that job easier)
     87      1.1   pooka 	 */
     88      1.1   pooka 	mrc	p15, 0, r0, c2, c0, 0		/* Get L1 */
     89      1.1   pooka 	bic	r0, r0, #0xff000000
     90      1.1   pooka 	add	r0, r0, #(0xa00 * 4)		/* offset to 0xa0.. */
     91      1.1   pooka 
     92      1.1   pooka 	mov	r3, #SDRAM_START		/* map to 0xa00.. */
     93      1.1   pooka 	orr	r3, r3, #(L1_S_AP(AP_KRW))	/* the usual perms & stuff */
     94      1.1   pooka 	orr	r3, r3, #(L1_TYPE_S)
     95      1.1   pooka 	orr	r3, r3, #(L1_S_DOM(PMAP_DOMAIN_KERNEL))
     96      1.1   pooka 	mov	r1, #0x40			/* 64 1MB entries */
     97      1.1   pooka 
     98      1.1   pooka 1:
     99      1.1   pooka 	/* and looplooploop */
    100      1.1   pooka 	str	r3, [r0], #4
    101      1.1   pooka 	add	r3, r3, r2
    102      1.1   pooka 	subs	r1, r1, #1
    103      1.1   pooka 	bgt	1b
    104      1.1   pooka 
    105      1.1   pooka 	/*
    106      1.1   pooka 	 * Map SDRAM also to VA 0xc00...
    107      1.1   pooka 	 */
    108      1.1   pooka 	mrc	p15, 0, r0, c2, c0, 0		/* Get L1 */
    109      1.1   pooka 	bic	r0, r0, #0xff000000
    110      1.1   pooka 	add	r0, r0, #(0xc00 * 4)		/* start from 0xc00.. */
    111      1.1   pooka 
    112      1.1   pooka 	mov	r3, #SDRAM_START		/* map to 0xa00.. */
    113      1.1   pooka 	orr	r3, r3, #(L1_S_AP(AP_KRW))	/* the usual perms & stuff */
    114      1.1   pooka 	orr	r3, r3, #(L1_TYPE_S)
    115      1.1   pooka 	orr	r3, r3, #(L1_S_DOM(PMAP_DOMAIN_KERNEL))
    116      1.1   pooka 	mov	r1, #0x40			/* 64 1MB entries */
    117      1.1   pooka 
    118      1.1   pooka 1:
    119      1.1   pooka 	/* and looplooploop */
    120      1.1   pooka 	str	r3, [r0], #4
    121      1.1   pooka 	add	r3, r3, r2
    122      1.1   pooka 	subs	r1, r1, #1
    123      1.1   pooka 	bgt	1b
    124      1.1   pooka 
    125      1.1   pooka 	/*
    126      1.1   pooka 	 * Here come the devices.  Map an L1 section for each device
    127      1.1   pooka 	 * to make this easy.
    128      1.1   pooka 	 */
    129      1.1   pooka 
    130      1.1   pooka 	/* INTCTL */
    131      1.1   pooka 	mrc	p15, 0, r0, c2, c0, 0		/* Get L1 */
    132      1.1   pooka 	bic	r0, r0, #0xff000000
    133      1.1   pooka 	add	r0, r0, #(0xfd0 * 4)		/* offset to 0xfd000000 */
    134      1.1   pooka 
    135      1.1   pooka 	mov	r3,	#0x40000000
    136      1.1   pooka 	orr	r3, r3,	#0x00d00000
    137      1.1   pooka 	orr	r3, r3, #(L1_S_AP(AP_KRW))
    138      1.1   pooka 	orr	r3, r3, #(L1_TYPE_S)
    139      1.1   pooka 	orr	r3, r3, #(L1_S_DOM(PMAP_DOMAIN_KERNEL))
    140      1.1   pooka 	str	r3, [r0], #4
    141      1.1   pooka 
    142      1.1   pooka 	/* GPIO */
    143      1.1   pooka 	mov	r3,	#0x40000000
    144      1.1   pooka 	orr	r3, r3,	#0x00e00000
    145      1.1   pooka 	orr	r3, r3, #(L1_S_AP(AP_KRW))
    146      1.1   pooka 	orr	r3, r3, #(L1_TYPE_S)
    147      1.1   pooka 	orr	r3, r3, #(L1_S_DOM(PMAP_DOMAIN_KERNEL))
    148      1.1   pooka 	str	r3, [r0], #4
    149      1.1   pooka 
    150      1.1   pooka 	/* CLKMAN */
    151      1.1   pooka 	mov	r3,	#0x41000000
    152      1.1   pooka 	orr	r3, r3, #0x00300000
    153      1.1   pooka 	orr	r3, r3, #(L1_S_AP(AP_KRW))
    154      1.1   pooka 	orr	r3, r3, #(L1_TYPE_S)
    155      1.1   pooka 	orr	r3, r3, #(L1_S_DOM(PMAP_DOMAIN_KERNEL))
    156      1.1   pooka 	str	r3, [r0], #4
    157      1.1   pooka 
    158      1.1   pooka 	/* FFUART */
    159      1.1   pooka 	mov	r3,	#0x40000000
    160      1.1   pooka 	orr	r3, r3, #0x00100000
    161      1.1   pooka 	orr	r3, r3, #(L1_S_AP(AP_KRW))
    162      1.1   pooka 	orr	r3, r3, #(L1_TYPE_S)
    163      1.1   pooka 	orr	r3, r3, #(L1_S_DOM(PMAP_DOMAIN_KERNEL))
    164      1.1   pooka 	str	r3, [r0], #4
    165      1.1   pooka 
    166      1.1   pooka 	/* BTUART */
    167      1.1   pooka 	mov	r3,	#0x40000000
    168      1.1   pooka 	orr	r3, r3, #0x00200000
    169      1.1   pooka 	orr	r3, r3, #(L1_S_AP(AP_KRW))
    170      1.1   pooka 	orr	r3, r3, #(L1_TYPE_S)
    171      1.1   pooka 	orr	r3, r3, #(L1_S_DOM(PMAP_DOMAIN_KERNEL))
    172      1.1   pooka 	str	r3, [r0], #4
    173      1.1   pooka 
    174      1.1   pooka #if 0
    175      1.1   pooka 	/*
    176      1.1   pooka 	 * Cache cleanup.  Not needed here?  Slight speedup in booting.
    177      1.1   pooka 	 */
    178  1.2.4.1  rpaulo 	mov	r3, #(XSCALE_DCACHE_SIZE)
    179      1.1   pooka 	subs	r3, r3, #32
    180      1.1   pooka 1:
    181      1.1   pooka 	mcr	p15, 0, r3, c7, c10, 2
    182      1.1   pooka 	subs	r3, r3, #32
    183      1.1   pooka 	bne	1b
    184      1.1   pooka 	CPWAIT(r3)
    185      1.1   pooka 
    186      1.1   pooka 	/* Drain write buffer */
    187      1.1   pooka 	mcr	p15, 0, r6, c7, c10, 4
    188      1.1   pooka #endif
    189      1.1   pooka 
    190      1.1   pooka 	/*
    191      1.1   pooka 	 * Make domain control go ful fart.
    192      1.1   pooka 	 * We probably could be slightly more sensible about this,
    193      1.1   pooka 	 * but it'll be replaced soon anyway, so why bother.
    194      1.1   pooka 	 */
    195      1.1   pooka 	mov	r0, #0xffffffff
    196      1.1   pooka 	mcr	p15, 0, r0, c3, c0, 0
    197      1.1   pooka 
    198      1.1   pooka 	/*
    199      1.1   pooka 	 * Relocate the kernel to where we want it, not where Redboot
    200      1.1   pooka 	 * let's us load it.  Don't bother jumping after this stage,
    201      1.1   pooka 	 * we'll do that soon enough anyway, and to the correct virtual
    202      1.1   pooka 	 * address space region I might add.
    203      1.1   pooka 	 */
    204      1.1   pooka 	adr	r0, _C_LABEL(viper_start)	/* start copy from here */
    205      1.1   pooka 	add	r0, r0, #SDRAM_START		/* offset to SDRAM mapping */
    206      1.1   pooka 
    207      1.1   pooka 	ldr	r1, .Lcopy_size			/* copy this much (bytes) */
    208      1.1   pooka 	add	r1, r1, #3			/* prepare for roundup */
    209      1.1   pooka 	mov	r1, r1, LSR #2			/* make it words */
    210      1.1   pooka 
    211      1.1   pooka 	mov	r2, #SDRAM_START		/* target address, */
    212      1.1   pooka 	add	r2, r2, #0x00200000		/* kernel offsets by 2megs */
    213      1.1   pooka 
    214      1.1   pooka 	/* after this it's just a load-store-loop */
    215      1.1   pooka 1:
    216      1.1   pooka 	ldr	r3, [r0], #4
    217      1.1   pooka 	str	r3, [r2], #4
    218      1.1   pooka 	subs	r1, r1, #1
    219      1.1   pooka 	bgt	1b
    220      1.1   pooka 
    221      1.1   pooka 	/*
    222      1.1   pooka 	 * Now let's clean the cache again to make sure everything
    223      1.1   pooka 	 * is in place.
    224      1.1   pooka 	 *
    225      1.1   pooka 	 * XXX: should this take into account the XScale cache clean bug?
    226      1.1   pooka 	 */
    227  1.2.4.1  rpaulo 	mov	r3, #(XSCALE_DCACHE_SIZE)
    228      1.1   pooka 	subs	r3, r3, #32
    229      1.1   pooka 1:
    230      1.1   pooka 	mcr	p15, 0, r3, c7, c10, 2
    231      1.1   pooka 	subs	r3, r3, #32
    232      1.1   pooka 	bne	1b
    233      1.1   pooka 	CPWAIT(r3)
    234      1.1   pooka 
    235      1.1   pooka 	/* Drain write buffer */
    236      1.1   pooka 	mcr	p15, 0, r6, c7, c10, 4
    237      1.1   pooka 
    238      1.1   pooka 	/* Invalidate TLBs just to be sure */
    239      1.1   pooka 	mcr     p15, 0, r0, c8, c7, 0
    240      1.1   pooka 
    241      1.1   pooka 	/*
    242      1.1   pooka 	 * You are standing at the gate to NetBSD. --More--
    243      1.1   pooka 	 * Unspeakable cruelty and harm lurk down there. --More--
    244      1.1   pooka 	 * Are you sure you want to enter?
    245      1.1   pooka 	 */
    246      1.1   pooka 	mov	pc, r8				/* So be it */
    247      1.1   pooka 
    248      1.1   pooka /* symbol to use for address calculation in the right VA */
    249      1.1   pooka .Linva:
    250      1.1   pooka 	.word	start
    251      1.1   pooka 
    252      1.1   pooka /*
    253      1.1   pooka  * Calculate size of kernel to copy.  Don't bother to copy bss,
    254      1.1   pooka  * although I guess the CPU could use the warmup exercise ...
    255      1.1   pooka  */
    256      1.1   pooka .Lcopy_size:
    257      1.1   pooka 	.word _edata - _C_LABEL(viper_start)
    258