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