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