1/* $NetBSD: locore.S,v 1.1 2002/02/27 21:02:24 scw 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 * The bootloaded passes the following registers: 107 * 108 * r3 == start of symbol table 109 * r4 == end of symbol table 110 * r5 == boot parameters 111 */ 112 .text 113 .globl __start 114__start: 115 li r0,0 116 mtmsr r0 /* Disable FPU/MMU/exceptions */ 117 isync 118 119/* compute end of kernel memory */ 120 lis r8,_C_LABEL(end)@ha 121 addi r8,r8,_C_LABEL(end)@l 122#if defined(DDB) || defined(KERNFS) 123 lis r7,_C_LABEL(startsym)@ha 124 addi r7,r7,_C_LABEL(startsym)@l 125 stw r3,0(r7) 126 lis r7,_C_LABEL(endsym)@ha 127 addi r7,r7,_C_LABEL(endsym)@l 128 stw r4,0(r7) 129 mr r8,r4 /* end of symbol table */ 130#endif 131 li r9,PGOFSET 132 add r8,r8,r9 133 andc r8,r8,r9 134 addi r8,r8,NBPG 135 lis r9,idle_u@ha 136 stw r8,idle_u@l(r9) 137 addi r8,r8,USPACE /* space for idle_u */ 138 lis r9,_C_LABEL(proc0paddr)@ha 139 stw r8,_C_LABEL(proc0paddr)@l(r9) 140 addi r1,r8,USPACE-FRAMELEN /* stackpointer for proc0 */ 141 mr r4,r1 /* end of mem reserved for kernel */ 142 xor r0,r0,r0 143 stwu r0,-16(r1) /* end of stack chain */ 144 145 lis r3,__start@ha 146 addi r3,r3,__start@l 147 148 bl _C_LABEL(initppc) 149 150/* enable internal i/d-cache */ 151 mfpvr r9 152 rlwinm r9,r9,16,16,31 153 cmpi cr0,r9,1 154 beq 3f /* not needed for 601 */ 155 mfspr r11,SPR_HID0 156 andi. r0,r11,HID0_DCE 157 ori r11,r11,HID0_ICE|HID0_DCE 158 ori r8,r11,HID0_ICFI 159 bne 1f /* don't invalidate the D-cache */ 160 ori r8,r8,HID0_DCFI /* unless it wasn't enabled */ 1611: 162 sync 163 mtspr SPR_HID0,r8 /* enable and invalidate caches */ 164 sync 165 mtspr SPR_HID0,r11 /* enable caches */ 166 sync 167 isync 168 cmpi cr0,r9,4 /* check for 604 */ 169 cmpi cr1,r9,9 /* or 604e */ 170 cmpi cr2,r9,10 /* or mach5 */ 171 cror 2,2,6 172 cror 2,2,10 173 bne 3f 174 ori r11,r11,HID0_SIED|HID0_BHTE /* for 604[e], enable */ 175 bne cr2,2f 176 ori r11,r11,HID0_BTCD 1772: 178 mtspr SPR_HID0,r11 1793: 180 sync 181 isync 182 183 bl _C_LABEL(main) 184 b bugret 185 186/* 187 * void _mvmeppc_unsup_board(const char *msg, const char *msgend) 188 * 189 * Print the specified message using ppcbug's console output syscall 190 * before dropping back out to bug. 191 */ 192ENTRY(_mvmeppc_unsup_board) 193 addi r10,0,0x0022 194 sc 195bugret: addi r10,0,0x0063 196 sc 197 /* NOTREACHED */ 198 199 .globl _C_LABEL(enable_intr) 200_C_LABEL(enable_intr): 201 mfmsr r3 202 ori r3,r3,PSL_EE@l 203 mtmsr r3 204 blr 205 206 .globl _C_LABEL(disable_intr) 207_C_LABEL(disable_intr): 208 mfmsr r3 209 andi. r3,r3,~PSL_EE@l 210 mtmsr r3 211 blr 212 213/* 214 * Pull in common switch / setfault code. 215 */ 216#include <powerpc/powerpc/locore_subr.S> 217 218/* 219 * Pull in common trap vector code. 220 */ 221#include <powerpc/powerpc/trap_subr.S> 222