1 1.21 thorpej /* $NetBSD: locore.S,v 1.21 2021/02/26 02:18:56 thorpej 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 "opt_lockdebug.h" 37 1.12 apb #include "opt_modular.h" 38 1.1 simonb #include "opt_multiprocessor.h" 39 1.4 matt #include "opt_ppcparam.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.1 simonb #include <machine/psl.h> 46 1.1 simonb #include <machine/trap.h> 47 1.1 simonb #include <machine/asm.h> 48 1.1 simonb 49 1.3 matt #include <powerpc/spr.h> 50 1.14 matt #include <powerpc/oea/spr.h> 51 1.3 matt 52 1.6 ragge #include "ksyms.h" 53 1.6 ragge 54 1.1 simonb /* 55 1.1 simonb * Some instructions gas doesn't understand (yet?) 56 1.1 simonb */ 57 1.1 simonb #define bdneq bdnzf 2, 58 1.1 simonb 59 1.1 simonb /* 60 1.1 simonb * cache bit 61 1.1 simonb */ 62 1.1 simonb #define HID0_BTCD (1<<1) 63 1.1 simonb #define HID0_BHTE (1<<2) 64 1.1 simonb #define HID0_SIED (1<<7) 65 1.1 simonb #define HID0_DCI (1<<10) 66 1.1 simonb #define HID0_ICFI (1<<11) 67 1.1 simonb #define HID0_DCE (1<<14) 68 1.1 simonb #define HID0_ICE (1<<15) 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 78 1.1 simonb /* 79 1.1 simonb * This symbol is here for the benefit of kvm_mkdb, and is supposed to 80 1.1 simonb * mark the start of kernel text. 81 1.1 simonb */ 82 1.1 simonb .text 83 1.1 simonb .globl _C_LABEL(kernel_text) 84 1.1 simonb _C_LABEL(kernel_text): 85 1.1 simonb 86 1.1 simonb /* 87 1.1 simonb * Startup entry. Note, this must be the first thing in the text 88 1.1 simonb * segment! 89 1.1 simonb */ 90 1.1 simonb .text 91 1.1 simonb .globl __start 92 1.1 simonb __start: 93 1.1 simonb li 0,0 94 1.1 simonb mtmsr 0 /* Disable FPU/MMU/exceptions */ 95 1.1 simonb isync 96 1.1 simonb 97 1.1 simonb /* compute end of kernel memory */ 98 1.15 pooka #if NKSYMS || defined(DDB) || defined(MODULAR) 99 1.1 simonb lis 7,_C_LABEL(startsym)@ha 100 1.1 simonb addi 7,7,_C_LABEL(startsym)@l 101 1.1 simonb stw 3,0(7) 102 1.1 simonb lis 7,_C_LABEL(endsym)@ha 103 1.1 simonb addi 7,7,_C_LABEL(endsym)@l 104 1.1 simonb stw 4,0(7) 105 1.4 matt #else 106 1.4 matt lis 4,_C_LABEL(end)@ha 107 1.4 matt addi 4,4,_C_LABEL(end)@l 108 1.1 simonb #endif 109 1.4 matt 110 1.4 matt INIT_CPUINFO(4,1,9,0) 111 1.1 simonb 112 1.1 simonb lis 3,__start@ha 113 1.1 simonb addi 3,3,__start@l 114 1.1 simonb 115 1.1 simonb bl _C_LABEL(initppc) 116 1.1 simonb 117 1.1 simonb /* enable internal i/d-cache */ 118 1.1 simonb mfpvr 9 119 1.1 simonb rlwinm 9,9,16,16,31 120 1.19 joerg cmpwi %r9,1 121 1.1 simonb beq 3f /* not needed for 601 */ 122 1.3 matt mfspr 11,SPR_HID0 123 1.1 simonb andi. 0,11,HID0_DCE 124 1.1 simonb ori 11,11,HID0_ICE|HID0_DCE 125 1.1 simonb ori 8,11,HID0_ICFI 126 1.1 simonb bne 1f /* don't invalidate the D-cache */ 127 1.1 simonb ori 8,8,HID0_DCI /* unless it wasn't enabled */ 128 1.1 simonb 1: 129 1.1 simonb sync 130 1.3 matt mtspr SPR_HID0,8 /* enable and invalidate caches */ 131 1.1 simonb sync 132 1.3 matt mtspr SPR_HID0,11 /* enable caches */ 133 1.1 simonb sync 134 1.1 simonb isync 135 1.19 joerg cmpwi %r9,4 /* check for 604 */ 136 1.19 joerg cmpwi %cr1,%r9,9 /* or 604e */ 137 1.19 joerg cmpwi %cr2,%r9,10 /* or mach5 */ 138 1.1 simonb cror 2,2,6 139 1.1 simonb cror 2,2,10 140 1.1 simonb bne 3f 141 1.1 simonb ori 11,11,HID0_SIED|HID0_BHTE /* for 604[e], enable */ 142 1.1 simonb bne 2,2f 143 1.1 simonb ori 11,11,HID0_BTCD 144 1.1 simonb 2: 145 1.3 matt mtspr SPR_HID0,11 146 1.1 simonb 3: 147 1.1 simonb sync 148 1.1 simonb isync 149 1.1 simonb 150 1.1 simonb bl _C_LABEL(main) 151 1.1 simonb 152 1.1 simonb loop: 153 1.1 simonb b loop /* not reached */ 154 1.1 simonb 155 1.1 simonb .globl _C_LABEL(enable_intr) 156 1.1 simonb _C_LABEL(enable_intr): 157 1.1 simonb mfmsr 3 158 1.5 matt ori 4,3,PSL_EE@l 159 1.5 matt mtmsr 4 160 1.1 simonb blr 161 1.1 simonb 162 1.1 simonb .globl _C_LABEL(disable_intr) 163 1.1 simonb _C_LABEL(disable_intr): 164 1.1 simonb mfmsr 3 165 1.5 matt andi. 4,3,~PSL_EE@l 166 1.5 matt mtmsr 4 167 1.1 simonb blr 168 1.1 simonb 169 1.1 simonb /* 170 1.1 simonb * Pull in common switch / setfault code. 171 1.1 simonb */ 172 1.1 simonb #include <powerpc/powerpc/locore_subr.S> 173 1.1 simonb 174 1.1 simonb /* 175 1.1 simonb * Pull in common trap vector code. 176 1.1 simonb */ 177 1.1 simonb #include <powerpc/powerpc/trap_subr.S> 178 1.5 matt 179 1.5 matt /* 180 1.5 matt * Pull in common pio / bus_space code. 181 1.5 matt */ 182 1.5 matt #include <powerpc/powerpc/pio_subr.S> 183