Home | History | Annotate | Line # | Download | only in prep
locore.S revision 1.6
      1 /*	$NetBSD: locore.S,v 1.6 2003/04/27 10:42:52 ragge Exp $	*/
      2 /*	$OpenBSD: locore.S,v 1.4 1997/01/26 09:06:38 rahnds Exp $	*/
      3 
      4 /*
      5  * Copyright (C) 1995, 1996 Wolfgang Solfrank.
      6  * Copyright (C) 1995, 1996 TooLs GmbH.
      7  * All rights reserved.
      8  *
      9  * Redistribution and use in source and binary forms, with or without
     10  * modification, are permitted provided that the following conditions
     11  * are met:
     12  * 1. Redistributions of source code must retain the above copyright
     13  *    notice, this list of conditions and the following disclaimer.
     14  * 2. Redistributions in binary form must reproduce the above copyright
     15  *    notice, this list of conditions and the following disclaimer in the
     16  *    documentation and/or other materials provided with the distribution.
     17  * 3. All advertising materials mentioning features or use of this software
     18  *    must display the following acknowledgement:
     19  *	This product includes software developed by TooLs GmbH.
     20  * 4. The name of TooLs GmbH may not be used to endorse or promote products
     21  *    derived from this software without specific prior written permission.
     22  *
     23  * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
     24  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     25  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     26  * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     27  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     28  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     29  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     30  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     31  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
     32  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     33  */
     34 
     35 #include "opt_ddb.h"
     36 #include "fs_kernfs.h"
     37 #include "opt_ipkdb.h"
     38 #include "opt_lockdebug.h"
     39 #include "opt_multiprocessor.h"
     40 #include "opt_ppcparam.h"
     41 #include "assym.h"
     42 
     43 #include <sys/syscall.h>
     44 
     45 #include <machine/param.h>
     46 #include <machine/vmparam.h>
     47 #include <machine/pmap.h>
     48 #include <machine/psl.h>
     49 #include <machine/trap.h>
     50 #include <machine/asm.h>
     51 
     52 #include <powerpc/spr.h>
     53 
     54 #include "ksyms.h"
     55 
     56 /*
     57  * Some instructions gas doesn't understand (yet?)
     58  */
     59 #define	bdneq	bdnzf 2,
     60 
     61 /*
     62  * cache bit
     63  */
     64 #define	HID0_BTCD	(1<<1)
     65 #define	HID0_BHTE	(1<<2)
     66 #define	HID0_SIED	(1<<7)
     67 #define	HID0_DCI	(1<<10)
     68 #define	HID0_ICFI	(1<<11)
     69 #define	HID0_DCE	(1<<14)
     70 #define	HID0_ICE	(1<<15)
     71 
     72 /*
     73  * Globals
     74  */
     75 GLOBAL(startsym)
     76 	.long	0			/* start symbol table */
     77 GLOBAL(endsym)
     78 	.long	0			/* end symbol table */
     79 GLOBAL(proc0paddr)
     80 	.long	0			/* proc0 p_addr */
     81 
     82 GLOBAL(intrnames)
     83 	.asciz	"clock", "irq1", "irq2", "irq3"
     84 	.asciz	"irq4", "irq5", "irq6", "irq7"
     85 	.asciz	"irq8", "irq9", "irq10", "irq11"
     86 	.asciz	"irq12", "irq13", "irq14", "irq15"
     87 	.asciz	"irq16", "irq17", "irq18", "irq19"
     88 	.asciz	"irq20", "irq21", "irq22", "irq23"
     89 	.asciz	"irq24", "irq25", "irq26", "irq27"
     90 	.asciz	"irq28", "softnet", "softclock", "softserial"
     91 GLOBAL(eintrnames)
     92 	.align	4
     93 GLOBAL(intrcnt)
     94 	.long	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
     95 	.long	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
     96 GLOBAL(eintrcnt)
     97 
     98 /*
     99  * This symbol is here for the benefit of kvm_mkdb, and is supposed to
    100  * mark the start of kernel text.
    101  */
    102 	.text
    103 	.globl	_C_LABEL(kernel_text)
    104 _C_LABEL(kernel_text):
    105 
    106 /*
    107  * Startup entry.  Note, this must be the first thing in the text
    108  * segment!
    109  */
    110 	.text
    111 	.globl	__start
    112 __start:
    113 	li	0,0
    114 	mtmsr	0			/* Disable FPU/MMU/exceptions */
    115 	isync
    116 
    117 /* compute end of kernel memory */
    118 #if NKSYMS || defined(DDB) || defined(LKM) || defined(KERNFS)
    119 	lis	7,_C_LABEL(startsym)@ha
    120 	addi	7,7,_C_LABEL(startsym)@l
    121 	stw	3,0(7)
    122 	lis	7,_C_LABEL(endsym)@ha
    123 	addi	7,7,_C_LABEL(endsym)@l
    124 	stw	4,0(7)
    125 #else
    126 	lis	4,_C_LABEL(end)@ha
    127 	addi	4,4,_C_LABEL(end)@l
    128 #endif
    129 
    130 	INIT_CPUINFO(4,1,9,0)
    131 
    132 	lis	3,__start@ha
    133 	addi	3,3,__start@l
    134 
    135 	bl	_C_LABEL(initppc)
    136 
    137 /* enable internal i/d-cache */
    138 	mfpvr	9
    139 	rlwinm	9,9,16,16,31
    140 	cmpi	0,9,1
    141 	beq	3f			/* not needed for 601 */
    142 	mfspr	11,SPR_HID0
    143 	andi.	0,11,HID0_DCE
    144 	ori	11,11,HID0_ICE|HID0_DCE
    145 	ori	8,11,HID0_ICFI
    146 	bne	1f			/* don't invalidate the D-cache */
    147 	ori	8,8,HID0_DCI		/* unless it wasn't enabled */
    148 1:
    149 	sync
    150 	mtspr	SPR_HID0,8		/* enable and invalidate caches */
    151 	sync
    152 	mtspr	SPR_HID0,11		/* enable caches */
    153 	sync
    154 	isync
    155 	cmpi	0,9,4			/* check for 604 */
    156 	cmpi	1,9,9			/* or 604e */
    157 	cmpi	2,9,10			/* or mach5 */
    158 	cror	2,2,6
    159 	cror	2,2,10
    160 	bne	3f
    161 	ori	11,11,HID0_SIED|HID0_BHTE /* for 604[e], enable */
    162 	bne	2,2f
    163 	ori	11,11,HID0_BTCD
    164 2:
    165 	mtspr	SPR_HID0,11
    166 3:
    167 	sync
    168 	isync
    169 
    170 	bl	_C_LABEL(main)
    171 
    172 loop:
    173 	b	loop			/* not reached */
    174 
    175 	.globl	_C_LABEL(enable_intr)
    176 _C_LABEL(enable_intr):
    177 	mfmsr	3
    178 	ori	4,3,PSL_EE@l
    179 	mtmsr	4
    180 	blr
    181 
    182 	.globl	_C_LABEL(disable_intr)
    183 _C_LABEL(disable_intr):
    184 	mfmsr	3
    185 	andi.	4,3,~PSL_EE@l
    186 	mtmsr	4
    187 	blr
    188 
    189 /*
    190  * Pull in common switch / setfault code.
    191  */
    192 #include <powerpc/powerpc/locore_subr.S>
    193 
    194 /*
    195  * Pull in common trap vector code.
    196  */
    197 #include <powerpc/powerpc/trap_subr.S>
    198 
    199 /*
    200  * Pull in common pio / bus_space code.
    201  */
    202 #include <powerpc/powerpc/pio_subr.S>
    203