Home | History | Annotate | Line # | Download | only in explora
explora_start.S revision 1.6
      1 /*	$NetBSD: explora_start.S,v 1.6 2009/11/26 00:19:16 matt Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 2003 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Juergen Hannken-Illjes.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  *
     19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  * POSSIBILITY OF SUCH DAMAGE.
     30  */
     31 
     32 /*
     33  * Initial state:
     34  *
     35  * iccr = 0x00008001 0x80000000-0x87ffffff 0xf80000000-0xffffffff
     36  * dccr = 0x00008001 0x80000000-0x87ffffff 0xf80000000-0xffffffff
     37  * dcwr = 0x00000000
     38  * msr  = 0x00001000 ME=machine check enable
     39  *
     40  */
     41 
     42 #include "assym.h"
     43 
     44 #define _NOREGNAMES
     45 
     46 #include <machine/param.h>
     47 #include <machine/psl.h>
     48 #include <machine/trap.h>
     49 #include <machine/asm.h>
     50 
     51 #include <powerpc/spr.h>
     52 #include <powerpc/ibm4xx/dcr403cgx.h>
     53 #include <powerpc/ibm4xx/pmap.h>
     54 
     55 #include "opt_ddb.h"
     56 #include "opt_ppcparam.h"
     57 
     58 /*
     59  * Initially the dram starts at 0x01000000. This is way too high.
     60  * We relocate dram to 0x00000000. We use the video ram at 0xf0000000
     61  * as a temporary staging area.
     62  */
     63 
     64 #define STAGE1_BASE	0xf0000000
     65 
     66 	.text
     67 	.globl	__start
     68 __start:
     69 	b	1f
     70 	nop
     71 	nop
     72 	.long	0
     73 	.ascii	"XncdPPC\0"
     74 	.long	0
     75 	.long	0
     76 
     77 1:
     78 	/* Disable exceptions, caches, invalidate all TLB's. */
     79 
     80 	li	0,0
     81 	mtmsr	0
     82 	mttcr	0
     83 	mtdccr	0
     84 	mticcr	0
     85 	sync
     86 	isync
     87 
     88 /* Clear caches and invalidate tlbs */
     89 	li	7,256
     90 	mtctr	7
     91 	li	6,0
     92 1:
     93 	dccci	0,6
     94 	addi	6,6,16
     95 	bdnz	1b
     96 
     97 	li	7,512
     98 	mtctr	7
     99 	li	6,0
    100 1:
    101 	iccci	0,6
    102 	addi	6,6,16
    103 	bdnz	1b
    104 
    105 	tlbia
    106 	sync
    107 	isync
    108 
    109 /* Get current address -- NOT the same as . */
    110 
    111 	bl	_next
    112 _next:
    113 	mflr	3
    114 	subi	3,3,_next-__start
    115 	lis	4,STAGE1_BASE@h
    116 	ori	4,4,STAGE1_BASE@l
    117 	li	5,stage1size
    118 
    119 1:
    120 	lbz	1,0(3)
    121 	mr	0,5
    122 	cmpwi	0,0
    123 	stb	1,0(4)
    124 	addi	3,3,1
    125 	addi	4,4,1
    126 	addi	5,5,-1
    127 	bgt	1b
    128 
    129 /* Jump into the staging area so we can remap the dram. */
    130 
    131 	lis	0,stage1reloc@h
    132 	ori	0,0,stage1reloc@l
    133 	mtlr	0
    134 	blr
    135 
    136 stage1reloc = .-__start+STAGE1_BASE
    137 
    138 /* Remap the dram from 0x01000000 to 0x00000000. */
    139 
    140 #define REMAP(r, tmp1, tmp2) \
    141 	mfbr##r	tmp1 ; \
    142 	lis	tmp2,0xff ; \
    143 	ori	tmp2,tmp2,0xffff ; \
    144 	cmplw	tmp1,tmp2 ; \
    145 	ble	1f ; \
    146 	addis	tmp1,tmp1,0xf000 ; \
    147 	mtbr##r	tmp1 ; \
    148 1:
    149 
    150 	REMAP(4, 1, 2)
    151 	REMAP(5, 1, 2)
    152 	REMAP(6, 1, 2)
    153 	REMAP(7, 1, 2)
    154 
    155 #undef REMAP
    156 
    157 /* Initial setup. */
    158 
    159 	ba	stage2
    160 
    161 stage2:
    162 
    163 #ifdef PPC_4XX_NOCACHE
    164 	li	0,0
    165 #else
    166 	lis	0,0xfffc
    167 #endif
    168 	mtdccr	0
    169 	mticcr	0
    170 	sync
    171 	isync
    172 
    173 /* get start of bss */
    174 	lis	7,_C_LABEL(edata)-4@h
    175 	ori	7,7,_C_LABEL(edata)-4@l
    176 /* get end of kernel */
    177 	lis	4,_C_LABEL(end)@h
    178 	ori	4,4,_C_LABEL(end)@l
    179 /* clear bss */
    180 	li	3,0
    181 1:
    182 	stwu	3,4(7)
    183 	cmpw	7,4
    184 	bne+	1b
    185 
    186 	INIT_CPUINFO(4,1,9,0)
    187 
    188 	lis	3,__start@h
    189 	ori	3,3,__start@l
    190 
    191 /* Run the remaining setup in C. */
    192 	bl	_C_LABEL(bootstrap)
    193 
    194 	bl	_C_LABEL(main)
    195 
    196 	/* NOTREACHED */
    197 2:	nop
    198 	b	2b
    199 
    200 stage1size = .-__start
    201 
    202 #include <powerpc/ibm4xx/4xx_locore.S>
    203