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