Home | History | Annotate | Line # | Download | only in mpc85xx
mpc85xx_start.S revision 1.1.4.1
      1 /*	$NetBSD: mpc85xx_start.S,v 1.1.4.1 2011/06/06 09:05:32 jruoho Exp $	*/
      2 /*-
      3  * Copyright (c) 2010, 2011 The NetBSD Foundation, Inc.
      4  * All rights reserved.
      5  *
      6  * This code is derived from software contributed to The NetBSD Foundation
      7  * by Raytheon BBN Technologies Corp and Defense Advanced Research Projects
      8  * Agency and which was developed by Matt Thomas of 3am Software Foundry.
      9  *
     10  * This material is based upon work supported by the Defense Advanced Research
     11  * Projects Agency and Space and Naval Warfare Systems Center, Pacific, under
     12  * Contract No. N66001-09-C-2073.
     13  * Approved for Public Release, Distribution Unlimited
     14  *
     15  * Redistribution and use in source and binary forms, with or without
     16  * modification, are permitted provided that the following conditions
     17  * are met:
     18  * 1. Redistributions of source code must retain the above copyright
     19  *    notice, this list of conditions and the following disclaimer.
     20  * 2. Redistributions in binary form must reproduce the above copyright
     21  *    notice, this list of conditions and the following disclaimer in the
     22  *    documentation and/or other materials provided with the distribution.
     23  *
     24  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     25  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     26  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     27  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     28  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     29  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     30  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     31  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     32  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     33  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     34  * POSSIBILITY OF SUCH DAMAGE.
     35  */
     36 
     37 #include <sys/cdefs.h>
     38 #include <powerpc/asm.h>
     39 
     40 RCSID("$NetBSD: mpc85xx_start.S,v 1.1.4.1 2011/06/06 09:05:32 jruoho Exp $")
     41 
     42 #include "opt_altivec.h"
     43 #include "opt_ddb.h"
     44 #include "opt_ipkdb.h"
     45 #include "opt_lockdebug.h"
     46 #include "opt_modular.h"
     47 #include "opt_multiprocessor.h"
     48 #include "opt_ppcarch.h"
     49 #include "opt_ppcparam.h"
     50 
     51 #include "ksyms.h"
     52 
     53 #include <sys/param.h>
     54 
     55 #include <powerpc/spr.h>
     56 #include <powerpc/trap.h>
     57 #include <powerpc/booke/pte.h>
     58 #include <powerpc/booke/spr.h>
     59 #define	LBC_PRIVATE
     60 #include <powerpc/booke/e500reg.h>
     61 
     62 #include "assym.h"
     63 
     64 #define	INTSTK	0
     65 
     66 	.machine e500
     67 /*
     68  * This symbol is here for the benefit of kvm_mkdb, and is supposed to
     69  * mark the start of kernel text.
     70  */
     71 	.text
     72 	.globl	_C_LABEL(kernel_text)
     73 _C_LABEL(kernel_text):
     74         .globl  __start
     75 __start:
     76 
     77 /*
     78  * Startup entry.  Note, this must be the first thing in the text segment!
     79  */
     80 	mr	%r8,%r6
     81 	mr	%r7,%r5
     82 	mr	%r6,%r4
     83 	mr	%r5,%r3
     84 #ifdef DEBUG
     85 	/*
     86 	 * Set all the registers we don't care about to a known junk value.
     87 	 */
     88 	lis	%r2,0xdeadbeef@ha
     89 	addi	%r2,%r2,0xdeadbeef@l
     90 	mr	%r9,%r2
     91 	mr	%r10,%r9
     92 	mr	%r11,%r9
     93 	mr	%r12,%r9
     94 	mr	%r13,%r9
     95 	mr	%r14,%r9
     96 	mr	%r15,%r9
     97 	mr	%r16,%r9
     98 	mr	%r17,%r9
     99 	mr	%r18,%r9
    100 	mr	%r19,%r9
    101 	mr	%r20,%r9
    102 	mr	%r21,%r9
    103 	mr	%r22,%r9
    104 	mr	%r23,%r9
    105 	mr	%r24,%r9
    106 	mr	%r25,%r9
    107 	mr	%r26,%r9
    108 	mr	%r27,%r9
    109 	mr	%r28,%r9
    110 	mr	%r29,%r9
    111 	mr	%r30,%r9
    112 	mr	%r31,%r9
    113 #endif /* DEBUG */
    114 
    115 	li	%r0,0
    116 	mtmsr	%r0			/* Disable FPU/MMU/exceptions */
    117 	isync
    118 
    119 /* get start of bss */
    120 	lis	%r15,_C_LABEL(_edata)-4@ha
    121 	addi	%r15,%r15,_C_LABEL(_edata)-4@l
    122 /* get end of kernel memory */
    123 	lis	%r16,_C_LABEL(end)@ha
    124 	addi	%r16,%r16,_C_LABEL(end)@l
    125 /* zero bss */
    126 	sub	%r17,%r16,%r15
    127 	addi	%r17,%r17,3+USPACE
    128 	rlwinm	%r3,%r17,32-2,2,31	/* srwl	%r0,%r0,2 */
    129 	mtctr	%r3
    130 	li	%r0,0
    131 2:	stwu	%r0,4(%r15)
    132 	bdnz	2b
    133 
    134 #if NKSYMS || defined(DDB) || defined(MODULAR)
    135 	/* If we had symbol table location we'd store it here and would've adjusted r8 here */
    136 	lis	%r7,_C_LABEL(startsym)@ha
    137 	addi	%r7,%r7,_C_LABEL(startsym)@l
    138 	stw	%r8,0(%r7)
    139 	lis	%r7,_C_LABEL(endsym)@ha
    140 	addi	%r7,%r7,_C_LABEL(endsym)@l
    141 	stw	%r8,0(%r7)
    142 #endif
    143 
    144 	/* Set kernel MMU context. */
    145 	li	%r0,KERNEL_PID
    146 	mtpid	%r0
    147 	isync
    148 
    149 	INIT_CPUINFO(16,1,9,20)
    150 	mr	%r4,%r16
    151 	mfsprg0	%r21
    152 	lwz	%r20,CI_CURLWP(%r21)
    153 	mtsprg2	%r20
    154 	stw	%r21,L_CPU(%r20)
    155 	addi	%r21,%r21,CI_SAVELIFO
    156 	mtsprg3 %r21
    157 	mr	%r20,%r31		/* make deadbeef again */
    158 	mr	%r21,%r31		/* make deadbeef again */
    159 
    160 #if defined(GXEMUL)
    161 	/*
    162 	 * This is used to step through the external interrupt vector
    163 	 * to validate it.
    164 	 */
    165 	lis	%r29,3f@ha
    166 	addi	%r29,%r29,3f@l
    167 	mtsrr0	%r29
    168 	mfmsr	%r0
    169 	mtsrr1	%r0
    170 	lis	%r31,0xdeadf231@ha
    171 	addi	%r31,%r31,0xdeadf231@l
    172 	mtlr	%r31
    173 	addi	%r31,%r31,-0x10
    174 	mtcr	%r31
    175 	addi	%r31,%r31,-0x10
    176 	mtctr	%r31
    177 	addi	%r31,%r31,-0x10
    178 	mtxer	%r31
    179 	addi	%r31,%r31,-0x10
    180 	addi	%r30,%r31,-0x10
    181 	addi	%r29,%r30,-0x10
    182 	addi	%r28,%r29,-0x10
    183 	addi	%r27,%r28,-0x10
    184 	addi	%r26,%r27,-0x10
    185 	addi	%r25,%r26,-0x10
    186 	addi	%r24,%r25,-0x10
    187 	addi	%r23,%r24,-0x10
    188 	addi	%r22,%r23,-0x10
    189 	addi	%r21,%r22,-0x10
    190 	addi	%r20,%r21,-0x10
    191 	addi	%r19,%r20,-0x10
    192 	addi	%r18,%r19,-0x10
    193 	addi	%r17,%r18,-0x10
    194 	addi	%r16,%r17,-0x10
    195 	addi	%r15,%r16,-0x10
    196 	addi	%r14,%r15,-0x10
    197 	addi	%r13,%r14,-0x10
    198 	addi	%r12,%r13,-0x10
    199 	addi	%r11,%r12,-0x10
    200 	addi	%r10,%r11,-0x10
    201 	addi	%r9,%r10,-0x10
    202 	addi	%r8,%r9,-0x10
    203 	addi	%r7,%r8,-0x10
    204 	addi	%r6,%r7,-0x10
    205 	addi	%r5,%r6,-0x10
    206 	addi	%r4,%r5,-0x10
    207 	addi	%r3,%r4,-0x10
    208 	addi	%r2,%r3,-0x10
    209 	/* leave r1 alone */
    210 	addi	%r0,%r2,-0x20
    211 	b	_C_LABEL(instruction_tlb_error_vector)
    212 	//b	_C_LABEL(program_vector)
    213 	//b	_C_LABEL(external_input_vector)
    214 3:
    215 #endif
    216 
    217 	/*
    218 	 * TB is 50Mhz, watchdog should be ~10 seconds which makes that
    219 	 * 500 million or 0x20000000.  Since it takes 3 bit transitions
    220 	 * we really want 0x10000000.   That's bit 63-28 or 35.  This
    221 	 * means we want WPEXT,WP to be 0b10_0011.
    222 	 */
    223 	lis	%r3,(TCR_WRC_RESET|TCR_WP_2_N(0x23))@ha
    224 	addi	%r3,%r3,(TCR_WRC_RESET|TCR_WP_2_N(0x23))@l
    225 	mtspr	SPR_TCR, %r3
    226 	li	%r0, 0
    227 	mtspr	SPR_TBL, %r0
    228 	mtspr	SPR_TBU, %r0
    229 	mtspr	SPR_DBCR0, %r0
    230 
    231 #if 0
    232 	/*
    233 	 * Force all dirty lines in the kernel area to memory.
    234 	 */
    235 	lis	%r8,kernel_text@ha
    236 	addi	%r8,%r8,kernel_text@l
    237 4:	dcbst	%r0,%r8
    238 	addi	%r8,%r8,32
    239 	cmplw	%r8,%r4
    240 	blt	%cr0,4b
    241 	mbar	1
    242 	msync
    243 
    244 	/*
    245 	 * Turn off the data cache, and then invalidate it.
    246 	 */
    247 	li	%r3, 0
    248 	mtspr	SPR_L1CSR0, %r3
    249 	li	%r3, L1CSR_CFI
    250 	mtspr	SPR_L1CSR0, %r3
    251 #endif
    252 
    253 #if 1
    254 	/*
    255 	 * Clear any locks from the data or instruction caches.
    256 	 */
    257 	mfspr	%r3, SPR_L1CSR0
    258 	ori	%r3, %r3, L1CSR_CLFR
    259 	mtspr	SPR_L1CSR0, %r3
    260 	mfspr	%r3, SPR_L1CSR1
    261 	ori	%r3, %r3, L1CSR_CLFR
    262 	mtspr	SPR_L1CSR1, %r3
    263 #endif
    264 
    265 	lis	%r3,__start@ha
    266 	addi	%r3,%r3,__start@l
    267 
    268 	bl	_C_LABEL(initppc)
    269 	bl	_C_LABEL(main)
    270 
    271 loop:	b	loop			/* XXX not reached */
    272 
    273 #include <powerpc/booke/trap_subr.S>
    274 #include <powerpc/powerpc/locore_subr.S>
    275 #include <powerpc/powerpc/pio_subr.S>
    276 #ifdef PPC_HAVE_SPE
    277 #include <powerpc/booke/spe_subr.S>
    278 #endif
    279 #if defined(MULTIPROCESSOR)
    280 #include <powerpc/booke/e500_mpsubr.S>
    281 #endif
    282 
    283 #if 0
    284 	.p2align 5
    285 ENTRY(tlbwe)
    286 	isync
    287 	tlbwe
    288 	isync
    289 	blr
    290 #endif
    291