1/* $NetBSD: locore.S,v 1.8 2001/06/23 02:17:14 matt 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#include <powerpc/spr.h> 52 53/* 54 * Some instructions gas doesn't understand (yet?) 55 */ 56#define bdneq bdnzf 2, 57 58#define INTSTK (8*1024) /* 8K interrupt stack */ 59#define SPILLSTK 1024 /* 1K spill stack */ 60 61/* 62 * Globals 63 */ 64GLOBAL(startsym) 65 .long 0 /* start symbol table */ 66GLOBAL(endsym) 67 .long 0 /* end symbol table */ 68GLOBAL(proc0paddr) 69 .long 0 /* proc0 p_addr */ 70 71GLOBAL(intrnames) 72 .asciz "clock", "irq1", "irq2", "irq3" 73 .asciz "irq4", "irq5", "irq6", "irq7" 74 .asciz "irq8", "irq9", "irq10", "irq11" 75 .asciz "irq12", "irq13", "irq14", "irq15" 76 .asciz "irq16", "irq17", "irq18", "irq19" 77 .asciz "irq20", "irq21", "irq22", "irq23" 78 .asciz "irq24", "irq25", "irq26", "irq27" 79 .asciz "irq28", "softnet", "softclock", "softserial" 80GLOBAL(eintrnames) 81 .align 4 82GLOBAL(intrcnt) 83 .long 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 84 .long 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 85GLOBAL(eintrcnt) 86 87/* 88 * File-scope for locore.S 89 */ 90 .data 91idle_u: 92 .long 0 /* fake uarea during idle after exit */ 93 94/* 95 * This symbol is here for the benefit of kvm_mkdb, and is supposed to 96 * mark the start of kernel text. 97 */ 98 .text 99 .globl _C_LABEL(kernel_text) 100_C_LABEL(kernel_text): 101 102/* 103 * Startup entry. Note, this must be the first thing in the text 104 * segment! 105 */ 106 .text 107 .globl __start 108__start: 109 li 0,0 110 mtmsr 0 /* Disable FPU/MMU/exceptions */ 111 isync 112 113/* 114 * Cpu detect. 115 * 116 */ 117 lis 8, 0x7FFF 118 ori 8, 8, 0xF3F0 119 lwz 9, 0(8) /* read processor ID */ 120 andis. 9, 9, 0x0200 /* bit 6: */ 121 cmpwi 0, 9, 0 /* 0 if read by CPU 0, 1 if read by CPU 1 */ 122 bne __start_cpu1 123 b __start_cpu0 124 125__start_cpu1: 126#ifdef CPU1_SLEEP 127 lis 8, 0x0020 /* SLEEP */ 128 mfspr 7, SPR_HID0 /* get HID0 */ 129 or 7, 7, 8 130 mtspr SPR_HID0, 7 /* set HID0 */ 131 lis 8, 0x0004 /* POW */ 132 sync 133 mtmsr 8 134 isync /* zzz... */ 135#else 136 addi 9, 9, 1 137 lis 7, 0x100 138__start_cpu1_loop: 139 subi 7, 7, 1 140 cmpi 0, 7, 0 141 bne __start_cpu1_loop 142 lis 8, 0x8000 143 ori 8, 8, 0x0c00 144 lis 9,_C_LABEL(cpl)@ha 145 lwz 9,_C_LABEL(cpl)@l(9) 146 stb 9, 0(8) 147#endif 148 b __start_cpu1 149 150__start_cpu0: 151 152/* compute end of kernel memory */ 153 lis 8,_C_LABEL(end)@ha 154 addi 8,8,_C_LABEL(end)@l 155#if defined(DDB) || defined(KERNFS) 156 lis 7,_C_LABEL(startsym)@ha 157 addi 7,7,_C_LABEL(startsym)@l 158 stw 3,0(7) 159 lis 7,_C_LABEL(endsym)@ha 160 addi 7,7,_C_LABEL(endsym)@l 161 stw 4,0(7) 162 mr 8,4 /* end of sysbol table */ 163#endif 164 li 9,PGOFSET 165 add 8,8,9 166 andc 8,8,9 167 addi 8,8,NBPG 168 lis 9,idle_u@ha 169 stw 8,idle_u@l(9) 170 addi 8,8,USPACE /* space for idle_u */ 171 lis 9,_C_LABEL(proc0paddr)@ha 172 stw 8,_C_LABEL(proc0paddr)@l(9) 173 addi 1,8,USPACE-FRAMELEN /* stackpointer for proc0 */ 174 mr 4,1 /* end of mem reserved for kernel */ 175 xor 0,0,0 176 stwu 0,-16(1) /* end of stack chain */ 177 178 lis 3,__start@ha 179 addi 3,3,__start@l 180 181 bl _C_LABEL(initppc) 182 bl _C_LABEL(main) 183 184loop: b loop /* XXX not reached */ 185 186 .globl _C_LABEL(enable_intr) 187_C_LABEL(enable_intr): 188 mfmsr 3 189 ori 3,3,PSL_EE@l 190 mtmsr 3 191 blr 192 193 .globl _C_LABEL(disable_intr) 194_C_LABEL(disable_intr): 195 mfmsr 3 196 andi. 3,3,~PSL_EE@l 197 mtmsr 3 198 blr 199 200 .globl _C_LABEL(debug_led) 201_C_LABEL(debug_led): 202 lis 4, 0x8000 203 ori 4, 4, 0x0c00 204 stb 3, 0(4) 205 blr 206/* 207 * Pull in common switch & setfault code. 208 */ 209#include <powerpc/powerpc/locore_subr.S> 210 211/* 212 * Pull in common trap vector code. 213 */ 214#include <powerpc/powerpc/trap_subr.S> 215 216