Home | History | Annotate | Line # | Download | only in bebox
      1 /*	$NetBSD: locore.S,v 1.30 2021/02/26 02:18:55 thorpej 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 "opt_lockdebug.h"
     37 #include "opt_modular.h"
     38 #include "opt_multiprocessor.h"
     39 #include "opt_ppcparam.h"
     40 #include "assym.h"
     41 #include "ksyms.h"
     42 
     43 #include <sys/syscall.h>
     44 
     45 #include <machine/param.h>
     46 #include <machine/psl.h>
     47 #include <machine/trap.h>
     48 #include <machine/asm.h>
     49 
     50 #include <powerpc/spr.h>
     51 #include <powerpc/oea/hid.h>
     52 #include <powerpc/oea/spr.h>
     53 
     54 /*
     55  * Some instructions gas doesn't understand (yet?)
     56  */
     57 #define	bdneq	bdnzf 2,
     58 
     59 /*
     60  * Globals
     61  */
     62 GLOBAL(startsym)
     63 	.long	0			/* start symbol table */
     64 GLOBAL(endsym)
     65 	.long	0			/* end symbol table */
     66 
     67 /* XXX All of this should die */
     68 GLOBAL(intrnames)
     69 	.asciz	"clock", "irq1", "irq2", "irq3"
     70 	.asciz	"irq4", "irq5", "irq6", "irq7"
     71 	.asciz	"irq8", "irq9", "irq10", "irq11"
     72 	.asciz	"irq12", "irq13", "irq14", "irq15"
     73 	.asciz	"irq16", "irq17", "irq18", "irq19"
     74 	.asciz	"irq20", "irq21", "irq22", "irq23"
     75 	.asciz	"irq24", "irq25", "irq26", "irq27"
     76 	.asciz	"irq28", "softnet", "softclock", "softserial"
     77 GLOBAL(eintrnames)
     78 	.align	4
     79 GLOBAL(intrcnt)
     80 	.long	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
     81 	.long	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
     82 GLOBAL(eintrcnt)
     83 
     84 /*
     85  * File-scope for locore.S
     86  */
     87 	.data
     88 idle_u:
     89 	.long	0			/* fake uarea during idle after exit */
     90 
     91 /*
     92  * This symbol is here for the benefit of kvm_mkdb, and is supposed to
     93  * mark the start of kernel text.
     94  */
     95 	.text
     96 	.globl	_C_LABEL(kernel_text)
     97 _C_LABEL(kernel_text):
     98 
     99 /*
    100  * Startup entry.  Note, this must be the first thing in the text
    101  * segment!
    102  */
    103 	.text
    104 	.globl	__start
    105 __start:
    106 	li	0,0
    107 	mtmsr	0			/* Disable FPU/MMU/exceptions */
    108 	isync
    109 
    110 /*
    111  * CPU detect.
    112  *
    113  */
    114 	lis	8, 0x7FFF
    115 	ori	8, 8, 0xF3F0
    116 	lwz	9, 0(8)		/* read processor ID */
    117 	andis.	9, 9, 0x0200	/* bit 6: */
    118 	cmpwi	0, 9, 0		/* 0 if read by CPU 0, 1 if read by CPU 1 */
    119 	bne	__start_cpu1
    120 	b	__start_cpu0
    121 	nop
    122 
    123 __start_cpu1:
    124 	/* Disable data and instruction caches for spinup. */
    125 	li	8,0
    126 	mtspr	SPR_HID0,8
    127 	sync
    128 	isync
    129 
    130 #ifdef MULTIPROCESSOR
    131 	li	3, 0x1		/* CPU ID 1 */
    132 	ba	cpu_spinstart	/* cpu_spinstart(CPU ID) */
    133 #else
    134 1:
    135 	b	1b
    136 #endif
    137 	nop
    138 
    139 __start_cpu0:
    140 	/* Enable data and instruction caches */
    141 	mfspr	8,SPR_HID0
    142 	andi.	8,8,(HID0_ICE|HID0_DCE)@l
    143 	andi.	0,8,HID0_DCE
    144 	ori	7,8,HID0_ICFI
    145 	bne	1f
    146 	ori	7,7,HID0_DCFI
    147 1:
    148 	sync
    149 	mtspr	SPR_HID0,7
    150 	sync
    151 	mtspr	SPR_HID0,8
    152 	sync
    153 	isync
    154 
    155 /* compute end of kernel memory */
    156 #if defined(DDB) || NKSYMS || defined(MODULAR)
    157 	lis	7,_C_LABEL(startsym)@ha
    158 	addi	7,7,_C_LABEL(startsym)@l
    159 	stw	3,0(7)
    160 	lis	7,_C_LABEL(endsym)@ha
    161 	addi	7,7,_C_LABEL(endsym)@l
    162 	stw	4,0(7)			/* end of symbol table */
    163 #else
    164 	lis	4,_C_LABEL(end)@ha
    165 	addi	4,4,_C_LABEL(end)@l
    166 #endif
    167 
    168 	INIT_CPUINFO(4,1,9,0)
    169 
    170 	lis	3,__start@ha
    171 	addi	3,3,__start@l
    172 
    173 	bl	_C_LABEL(initppc)
    174 	bl	_C_LABEL(main)
    175 
    176 loop:	b	loop			/* XXX not reached */
    177 
    178 
    179 	.globl	_C_LABEL(cache_flush_invalidate_all)
    180 _C_LABEL(cache_flush_invalidate_all):
    181 	mtctr	3
    182 	li	4,0x0
    183 loop1:	lwz	5,0(4)
    184 	addi	4,4,32
    185 	bdnz	loop1
    186 
    187 	mtctr	3
    188 	li	4,0x0
    189 loop2:	dcbf	0,4
    190 	addi	4,4,32
    191 	bdnz	loop2
    192 
    193 	blr
    194 
    195 	.globl	_C_LABEL(debug_led)
    196 _C_LABEL(debug_led):
    197 	lis	4, 0x8000
    198 	ori	4, 4, 0x0c00
    199 	stb	3, 0(4)
    200 	blr
    201 /*
    202  * Pull in common switch & setfault code.
    203  */
    204 #include <powerpc/powerpc/locore_subr.S>
    205 
    206 /*
    207  * Pull in common trap vector code.
    208  */
    209 #include <powerpc/powerpc/trap_subr.S>
    210 
    211 /*
    212  * Pull in common pio / bus_space code.
    213  */
    214 #include <powerpc/powerpc/pio_subr.S>
    215