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