1 1.16 andvar /* $NetBSD: locore.S,v 1.16 2023/09/29 06:09:20 andvar Exp $ */ 2 1.6 agc 3 1.6 agc /*- 4 1.6 agc * Copyright (c) 1990 The Regents of the University of California. 5 1.6 agc * All rights reserved. 6 1.6 agc * 7 1.6 agc * This code is derived from software contributed to Berkeley by 8 1.6 agc * William Jolitz. 9 1.6 agc * 10 1.6 agc * Redistribution and use in source and binary forms, with or without 11 1.6 agc * modification, are permitted provided that the following conditions 12 1.6 agc * are met: 13 1.6 agc * 1. Redistributions of source code must retain the above copyright 14 1.6 agc * notice, this list of conditions and the following disclaimer. 15 1.6 agc * 2. Redistributions in binary form must reproduce the above copyright 16 1.6 agc * notice, this list of conditions and the following disclaimer in the 17 1.6 agc * documentation and/or other materials provided with the distribution. 18 1.6 agc * 3. Neither the name of the University nor the names of its contributors 19 1.6 agc * may be used to endorse or promote products derived from this software 20 1.6 agc * without specific prior written permission. 21 1.6 agc * 22 1.6 agc * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 23 1.6 agc * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 1.6 agc * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 1.6 agc * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 26 1.6 agc * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27 1.6 agc * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28 1.6 agc * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 1.6 agc * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 1.6 agc * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31 1.6 agc * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 1.6 agc * SUCH DAMAGE. 33 1.6 agc * 34 1.6 agc * @(#)locore.s 7.3 (Berkeley) 5/13/91 35 1.6 agc */ 36 1.1 uch 37 1.1 uch /*- 38 1.1 uch * Copyright (c) 1993, 1994, 1995, 1997 39 1.1 uch * Charles M. Hannum. All rights reserved. 40 1.1 uch * 41 1.1 uch * This code is derived from software contributed to Berkeley by 42 1.1 uch * William Jolitz. 43 1.1 uch * 44 1.1 uch * Redistribution and use in source and binary forms, with or without 45 1.1 uch * modification, are permitted provided that the following conditions 46 1.1 uch * are met: 47 1.1 uch * 1. Redistributions of source code must retain the above copyright 48 1.1 uch * notice, this list of conditions and the following disclaimer. 49 1.1 uch * 2. Redistributions in binary form must reproduce the above copyright 50 1.1 uch * notice, this list of conditions and the following disclaimer in the 51 1.1 uch * documentation and/or other materials provided with the distribution. 52 1.1 uch * 3. All advertising materials mentioning features or use of this software 53 1.1 uch * must display the following acknowledgement: 54 1.1 uch * This product includes software developed by the University of 55 1.1 uch * California, Berkeley and its contributors. 56 1.1 uch * 4. Neither the name of the University nor the names of its contributors 57 1.1 uch * may be used to endorse or promote products derived from this software 58 1.1 uch * without specific prior written permission. 59 1.1 uch * 60 1.1 uch * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 61 1.1 uch * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 62 1.1 uch * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 63 1.1 uch * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 64 1.1 uch * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 65 1.1 uch * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 66 1.1 uch * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 67 1.1 uch * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 68 1.1 uch * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 69 1.1 uch * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 70 1.1 uch * SUCH DAMAGE. 71 1.1 uch * 72 1.1 uch * @(#)locore.s 7.3 (Berkeley) 5/13/91 73 1.1 uch */ 74 1.1 uch 75 1.5 uch #include "opt_cputype.h" 76 1.2 uch #include "opt_memsize.h" 77 1.1 uch #include "assym.h" 78 1.1 uch 79 1.14 uwe #if defined(SH3) && defined(SH4) 80 1.14 uwe #error "evbsh3 port don't support SH3,SH4 common kernel." 81 1.2 uch #endif 82 1.1 uch 83 1.2 uch #include <sh3/asm.h> 84 1.16 andvar #include <sh3/cache_sh3.h> 85 1.16 andvar #include <sh3/cache_sh4.h> 86 1.4 uch #include <sh3/exception.h> 87 1.2 uch #include <sh3/locore.h> 88 1.2 uch #include <sh3/mmu_sh3.h> 89 1.2 uch #include <sh3/mmu_sh4.h> 90 1.16 andvar #include <sh3/psl.h> 91 1.1 uch 92 1.5 uch #define INIT_STACK \ 93 1.5 uch ((IOM_RAM_BEGIN + IOM_RAM_SIZE - 0x00001000) | 0x80000000) 94 1.1 uch 95 1.1 uch NENTRY(start) 96 1.11 tsutsui ALTENTRY(kernel_text) 97 1.1 uch /* Set SP to initial position */ 98 1.1 uch mov.l XLtmpstk, r15 99 1.1 uch 100 1.15 uwe /* Set Status Register */ 101 1.1 uch mov.l SR_init, r0 102 1.1 uch ldc r0, sr 103 1.1 uch 104 1.2 uch /* MMU off */ 105 1.1 uch xor r0, r0 106 1.2 uch MOV (MMUCR, r2) 107 1.2 uch mov.l r0, @r2 108 1.1 uch 109 1.1 uch bra start1 110 1.1 uch nop 111 1.1 uch .align 2 112 1.13 uwe SR_init: .long PSL_MD | PSL_BL | PSL_IMASK 113 1.2 uch REG_SYMBOL(MMUCR) 114 1.1 uch start1: 115 1.1 uch 116 1.1 uch #ifdef ROMIMAGE 117 1.1 uch /* Initialize BUS State Control Regs. */ 118 1.1 uch mov.l _ROM_START, r3 119 1.1 uch mov.l XL_ram_start, r4 120 1.1 uch mov.l @r4, r4 121 1.1 uch sub r3, r4 122 1.7 wiz /* Set Bus State Controller */ 123 1.1 uch mov.l XLInitializeBsc, r0 124 1.1 uch sub r4, r0 125 1.1 uch jsr @r0 126 1.1 uch nop 127 1.1 uch 128 1.1 uch /* Move kernel image from ROM area to RAM area */ 129 1.1 uch mov.l ___end, r0 130 1.1 uch mov.l ___start, r1 131 1.1 uch mov.l _KERNBASE, r2 132 1.1 uch sub r2, r0 133 1.1 uch sub r2, r1 134 1.1 uch sub r1, r0 135 1.1 uch add #4, r0 /* size of bytes to be copied */ 136 1.1 uch shlr2 r0 /* number of long word */ 137 1.1 uch mov.l _ROM_START, r3 138 1.1 uch add r3, r1 /* src address */ 139 1.1 uch mov.l ___start, r3 140 1.1 uch sub r2, r3 141 1.1 uch mov.l XL_ram_start, r4 142 1.14 uwe mov.l @r4, r4 143 1.1 uch add r4, r3 /* dest address */ 144 1.1 uch 1: 145 1.1 uch mov.l @r1+, r4 146 1.1 uch mov.l r4, @r3 147 1.1 uch add #4, r3 148 1.1 uch dt r0 /* decrement and Test */ 149 1.1 uch bf 1b 150 1.1 uch /* kernel image copy end */ 151 1.1 uch 152 1.1 uch mov.l LXstart_in_RAM, r0 153 1.1 uch jmp @r0 /* jump to RAM area */ 154 1.1 uch nop 155 1.1 uch 156 1.1 uch .align 2 157 1.1 uch LXstart_in_RAM: 158 1.1 uch .long start_in_RAM 159 1.14 uwe XL_ram_start: 160 1.1 uch .long _C_LABEL(ram_start) 161 1.2 uch #else /* ROMIMAGE */ 162 1.1 uch #ifndef DONT_INIT_BSC 163 1.7 wiz /* Set Bus State Controller */ 164 1.1 uch mov.l XLInitializeBsc, r0 165 1.1 uch jsr @r0 166 1.1 uch nop 167 1.2 uch #endif /* !DONT_INIT_BSC */ 168 1.2 uch #endif /* ROMIMAGE */ 169 1.1 uch 170 1.1 uch start_in_RAM: 171 1.1 uch mova 1f, r0 172 1.1 uch mov r0, r4 173 1.1 uch mov.l XLinitSH3, r0 174 1.1 uch jsr @r0 /* call initSH3() */ 175 1.1 uch nop 176 1.1 uch 177 1.1 uch .align 2 178 1.1 uch 1: 179 1.1 uch 180 1.1 uch #ifdef SH4 181 1.1 uch /* CCR must be accessed from P2 area */ 182 1.1 uch mova cache_on, r0 183 1.1 uch mov r0, r5 184 1.1 uch mov.l XLtoP2, r1 185 1.1 uch add r1, r5 186 1.1 uch mova main_label, r0 187 1.1 uch mov r0, r2 188 1.2 uch MOV (CCR, r3) 189 1.1 uch mov.l XL_CCRVAL, r4 190 1.1 uch jmp @r5 191 1.1 uch nop 192 1.1 uch 193 1.1 uch .align 2 194 1.1 uch cache_on: 195 1.1 uch mov.l r4, @r3 /* Write to CCR */ 196 1.1 uch nop 197 1.1 uch nop 198 1.1 uch nop 199 1.1 uch nop 200 1.1 uch nop 201 1.1 uch nop 202 1.1 uch nop 203 1.1 uch nop 204 1.1 uch jmp @r2 205 1.1 uch nop 206 1.14 uwe 207 1.1 uch .align 2 208 1.1 uch main_label: 209 1.2 uch #endif /* SH4 */ 210 1.1 uch mov.l XLmain, r0 211 1.1 uch jsr @r0 /* call main() */ 212 1.1 uch nop 213 1.1 uch 214 1.1 uch .align 2 215 1.1 uch 216 1.1 uch #ifndef DONT_INIT_BSC 217 1.1 uch XLInitializeBsc:.long _C_LABEL(InitializeBsc) 218 1.2 uch #endif /* DONT_INIT_BSC */ 219 1.1 uch ___start: .long start 220 1.10 uebayasi ___etext: .long _C_LABEL(etext) 221 1.10 uebayasi ___end: .long _C_LABEL(end) 222 1.1 uch XLtmpstk: .long INIT_STACK 223 1.2 uch _KERNBASE: .long 0x8c000000 224 1.12 uwe #ifdef ROMIMAGE 225 1.1 uch _ROM_START: .long IOM_ROM_BEGIN 226 1.12 uwe #endif 227 1.1 uch XLinitSH3: .long _C_LABEL(initSH3) 228 1.1 uch XLmain: .long _C_LABEL(main) 229 1.1 uch XLtoP2: .long 0x20000000 230 1.2 uch REG_SYMBOL(CCR) 231 1.13 uwe #ifdef SH4 /* invalidate and enable instruction and operand caches */ 232 1.13 uwe XL_CCRVAL: .long SH4_CCR_ICI | SH4_CCR_ICE | SH4_CCR_OCI | SH4_CCR_OCE 233 1.2 uch #endif /* SH4 */ 234 1.1 uch 235 1.1 uch load_and_reset: 236 1.1 uch mov.l XL_start_address, r0 237 1.1 uch mov r0, r8 238 1.1 uch mov.l @r4+, r1 /* r1 = osimage size */ 239 1.1 uch mov.l @r4+, r2 /* r2 = check sum */ 240 1.1 uch shlr2 r1 /* r1 = osimage size in dword */ 241 1.1 uch 1: 242 1.1 uch mov.l @r4+, r3 243 1.1 uch mov.l r3, @r0 244 1.1 uch add #4, r0 245 1.1 uch dt r1 246 1.1 uch bf 1b 247 1.1 uch 248 1.1 uch jmp @r8 /* jump to start address */ 249 1.1 uch nop 250 1.1 uch 251 1.1 uch .align 2 252 1.1 uch XL_start_address: 253 1.1 uch .long IOM_RAM_BEGIN + 0x00010000 254 1.1 uch load_and_reset_end: 255 1.1 uch 256 1.1 uch ENTRY(XLoadAndReset) 257 1.2 uch __INTR_MASK(r0, r1) 258 1.1 uch /* copy trampoline code to RAM area top */ 259 1.1 uch mov.l XL_load_and_reset, r0 260 1.1 uch mov.l XL_load_and_reset_end, r1 261 1.1 uch mov.l XL_load_trampoline_addr, r2 262 1.1 uch mov r2, r8 263 1.1 uch sub r0, r1 /* r1 = bytes to be copied */ 264 1.1 uch 1: mov.b @r0+, r3 265 1.1 uch mov.b r3, @r2 266 1.1 uch add #1, r2 267 1.1 uch dt r1 268 1.1 uch bf 1b 269 1.1 uch 270 1.1 uch jmp @r8 /* jump to trampoline code */ 271 1.1 uch nop 272 1.1 uch 273 1.1 uch .align 2 274 1.1 uch XL_load_trampoline_addr: 275 1.1 uch .long IOM_RAM_BEGIN + 0x00008000 276 1.1 uch XL_load_and_reset: 277 1.1 uch .long load_and_reset 278 1.1 uch XL_load_and_reset_end: 279 1.1 uch .long load_and_reset_end 280