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