Home | History | Annotate | Line # | Download | only in prep
locore.S revision 1.2
      1 /*	$NetBSD: locore.S,v 1.2 2001/06/17 16:01:28 nonaka 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 "assym.h"
     41 
     42 #include <sys/syscall.h>
     43 
     44 #include <machine/param.h>
     45 #include <machine/vmparam.h>
     46 #include <machine/pmap.h>
     47 #include <machine/psl.h>
     48 #include <machine/trap.h>
     49 #include <machine/asm.h>
     50 
     51 /*
     52  * Some instructions gas doesn't understand (yet?)
     53  */
     54 #define	bdneq	bdnzf 2,
     55 
     56 /*
     57  * cache bit
     58  */
     59 #define	HID0_BTCD	(1<<1)
     60 #define	HID0_BHTE	(1<<2)
     61 #define	HID0_SIED	(1<<7)
     62 #define	HID0_DCI	(1<<10)
     63 #define	HID0_ICFI	(1<<11)
     64 #define	HID0_DCE	(1<<14)
     65 #define	HID0_ICE	(1<<15)
     66 
     67 #define	INTSTK	(8*1024)	/* 8K interrupt stack */
     68 #define	SPILLSTK 1024		/* 1K spill stack */
     69 
     70 /*
     71  * Globals
     72  */
     73 GLOBAL(startsym)
     74 	.long	0			/* start symbol table */
     75 GLOBAL(endsym)
     76 	.long	0			/* end symbol table */
     77 GLOBAL(proc0paddr)
     78 	.long	0			/* proc0 p_addr */
     79 
     80 GLOBAL(intrnames)
     81 	.asciz	"clock", "irq1", "irq2", "irq3"
     82 	.asciz	"irq4", "irq5", "irq6", "irq7"
     83 	.asciz	"irq8", "irq9", "irq10", "irq11"
     84 	.asciz	"irq12", "irq13", "irq14", "irq15"
     85 	.asciz	"irq16", "irq17", "irq18", "irq19"
     86 	.asciz	"irq20", "irq21", "irq22", "irq23"
     87 	.asciz	"irq24", "irq25", "irq26", "irq27"
     88 	.asciz	"irq28", "softnet", "softclock", "softserial"
     89 GLOBAL(eintrnames)
     90 	.align	4
     91 GLOBAL(intrcnt)
     92 	.long	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
     93 	.long	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
     94 GLOBAL(eintrcnt)
     95 
     96 /*
     97  * File-scope for locore.S
     98  */
     99 	.data
    100 idle_u:
    101 	.long	0			/* fake uarea during idle after exit */
    102 
    103 /*
    104  * This symbol is here for the benefit of kvm_mkdb, and is supposed to
    105  * mark the start of kernel text.
    106  */
    107 	.text
    108 	.globl	_C_LABEL(kernel_text)
    109 _C_LABEL(kernel_text):
    110 
    111 /*
    112  * Startup entry.  Note, this must be the first thing in the text
    113  * segment!
    114  */
    115 	.text
    116 	.globl	__start
    117 __start:
    118 	li	0,0
    119 	mtmsr	0			/* Disable FPU/MMU/exceptions */
    120 	isync
    121 
    122 /* compute end of kernel memory */
    123 	lis	8,_C_LABEL(end)@ha
    124 	addi	8,8,_C_LABEL(end)@l
    125 #if defined(DDB) || defined(KERNFS)
    126 	lis	7,_C_LABEL(startsym)@ha
    127 	addi	7,7,_C_LABEL(startsym)@l
    128 	stw	3,0(7)
    129 	lis	7,_C_LABEL(endsym)@ha
    130 	addi	7,7,_C_LABEL(endsym)@l
    131 	stw	4,0(7)
    132 	mr	8,4			/* end of sysbol table */
    133 #endif
    134 	li	9,PGOFSET
    135 	add	8,8,9
    136 	andc	8,8,9
    137 	addi	8,8,NBPG
    138 	lis	9,idle_u@ha
    139 	stw	8,idle_u@l(9)
    140 	addi	8,8,USPACE		/* space for idle_u */
    141 	lis	9,_C_LABEL(proc0paddr)@ha
    142 	stw	8,_C_LABEL(proc0paddr)@l(9)
    143 	addi	1,8,USPACE-FRAMELEN	/* stackpointer for proc0 */
    144 	mr	4,1			/* end of mem reserved for kernel */
    145 	xor	0,0,0
    146 	stwu	0,-16(1)		/* end of stack chain */
    147 
    148 	lis	3,__start@ha
    149 	addi	3,3,__start@l
    150 
    151 	bl	_C_LABEL(initppc)
    152 
    153 /* enable internal i/d-cache */
    154 	mfpvr	9
    155 	rlwinm	9,9,16,16,31
    156 	cmpi	0,9,1
    157 	beq	3f			/* not needed for 601 */
    158 	mfspr	11,1008
    159 	andi.	0,11,HID0_DCE
    160 	ori	11,11,HID0_ICE|HID0_DCE
    161 	ori	8,11,HID0_ICFI
    162 	bne	1f			/* don't invalidate the D-cache */
    163 	ori	8,8,HID0_DCI		/* unless it wasn't enabled */
    164 1:
    165 	sync
    166 	mtspr	1008,8			/* enable and invalidate caches */
    167 	sync
    168 	mtspr	1008,11			/* enable caches */
    169 	sync
    170 	isync
    171 	cmpi	0,9,4			/* check for 604 */
    172 	cmpi	1,9,9			/* or 604e */
    173 	cmpi	2,9,10			/* or mach5 */
    174 	cror	2,2,6
    175 	cror	2,2,10
    176 	bne	3f
    177 	ori	11,11,HID0_SIED|HID0_BHTE /* for 604[e], enable */
    178 	bne	2,2f
    179 	ori	11,11,HID0_BTCD
    180 2:
    181 	mtspr	1008,11
    182 3:
    183 	sync
    184 	isync
    185 
    186 	bl	_C_LABEL(main)
    187 
    188 loop:
    189 	b	loop			/* not reached */
    190 
    191 	.globl	_C_LABEL(enable_intr)
    192 _C_LABEL(enable_intr):
    193 	mfmsr	3
    194 	ori	3,3,PSL_EE@l
    195 	mtmsr	3
    196 	blr
    197 
    198 	.globl	_C_LABEL(disable_intr)
    199 _C_LABEL(disable_intr):
    200 	mfmsr	3
    201 	andi.	3,3,~PSL_EE@l
    202 	mtmsr	3
    203 	blr
    204 
    205 /*
    206  * Pull in common switch / setfault code.
    207  */
    208 #include <powerpc/powerpc/locore_subr.S>
    209 
    210 /*
    211  * Pull in common trap vector code.
    212  */
    213 #include <powerpc/powerpc/trap_subr.S>
    214