1 /* $NetBSD: start.S,v 1.1.2.3 2004/09/21 13:16:12 skrll Exp $ */
4 * Copyright (c) 2003 Naoto Shimazaki.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY NAOTO SHIMAZAKI AND CONTRIBUTORS ``AS IS''
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
18 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE NAOTO OR CONTRIBUTORS BE
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
26 * THE POSSIBILITY OF SUCH DAMAGE.
31 * This code assumes some trick described below:
33 * - Located at 0x80000000 by linker
34 * - Placed at 0xbfc00000 (by ROM writer)
35 * - Executed at 0xbfc00000 by CPU
39 * - You cannot use 'j' and 'jal'. Instead, you must use 'b'.
40 * - If you want to jump to absolute address, you must load
41 * the target address to a register and jump to it with
43 * - You never be able to write any memory before
44 * the bus configuration completed.
48 #include <sys/cdefs.h>
49 #include <sys/errno.h>
50 #include <sys/syscall.h>
52 #include <machine/param.h>
54 #include <mips/cpuregs.h>
55 #include <mips/trap.h>
64 * macro ROMICE - support for Kyoto-micro's PARTNER-ETII ROM-ICE
66 * PARTNER-ETII by Kyoto-microcomputer is a ROM based emulater.
67 * This ICE initializes by itself the very early configurations of
68 * the target CPU. This macro skips that configurations.
72 * exception vector table
76 b start /* MUST relative jump */
101 * EP = 0, AD = 0, K0 = 2
108 * CU0 = 0, RE = 0, DS:BEV = 0, IM = 0, KX = SX = UX = 0,
109 * KSU = 0, IE = 0, others = untouch
118 mtc0 zero, $18 /* CP0 Watch Lo */
119 mtc0 zero, $11 /* CP0 compare */
124 li t0, 0xab000248 /* LEDCNTREG */
136 * initialize VR4181 bus controller
141 * ROMs = 10 (64Mbit), ROMWEN0 = 1, Rtype = 01 (flash)
142 * RSTOUT = 1 (inactive)
144 li t0, 0xaa000000 /* BCUCNTREG1 */
150 * BRF = refresh cycle x 1/TClock
151 * = 30.52usec x 32.768MHz
152 * = 0x3e8 (1000 TClock)
154 li t0, 0xaa000010 /* BCURFCNTREG */
160 * WPROM = 111 = 8.5TClock = 259ns
161 * WROMA = 1000 = 9.5TClock = 290ns
163 li t0, 0xaa00000c /* BCUSPEEDREG */
169 * BIT8 = 1 (always 1)
170 * TRAS = 01 = 5SDCLK (forced under 66, 50, 33MHz bus clock)
171 * TRC = 01 = 7SDCLK (forced under 66, 50, 33MHz bus clock)
172 * TRP = 10 = 3SDCLK (forced under 66, 50, 33MHz bus clock)
173 * TRCP = 01 = 2SDCLK (forced under 66, 50, 33MHz bus clock)
175 li t0, 0xaa00030c /* SDTIMINGREG */
180 * To initialize 64Mbit SDRAM properly, we have to take
183 * 1. set MEMCFG_REG for 16Mbit SDRAM
185 * 3. init SDRAM (setting MEMCFG_REG:Init to 1)
186 * 4. set MEMCFG_REG for 64Mbit SDRAM
188 * confirm to VR4181 users manual 6.5.2 MEMCFG_REG (page 142).
189 * (the page number is for Japanese edition. it might be
190 * at another page number for the English edition.)
194 * first, say MEMCFG_REG that SDRAM is 16Mbit
196 * B1Config = 01 (16Mbit)
197 * Bstreftype = 1 (all raw refresh)
198 * BstRefr = 0 (not allow burst refresh)
199 * EDOAsym = 0 (asymetric)
200 * B0Config = 01 (16Mbit)
201 * EDO/SDRAM = 1 (SDRAM)
203 li t0, 0xaa000304 /* MEMCFG_REG <- 503 (16Mbit) */
208 * second, setup MODE_REG
209 * Bit11 = 0 (always 0)
210 * Bit10 = 0 (always 0)
211 * BR-SW = 0 (always 0)
212 * TE-Ven = 00 (always 00)
213 * LTMode = 011 (3clock CAS latency)
215 * BL = 111 (always 111)
217 li t0, 0xaa000308 /* MODE_REG */
222 * third, kick SDRAM initialization
226 li t0, 0xaa000304 /* MEMCFG_REG:Init <- 1 */
231 * final, say MEMCFG_REG that SDRAM is 16Mbit
233 * B1Config = 10 (64Mbit)
234 * Bstreftype = 1 (all raw refresh)
235 * BstRefr = 0 (not allow burst refresh)
236 * EDOAsym = 0 (asymetric)
237 * B0Config = 10 (64Mbit)
238 * EDO/SDRAM = 1 (SDRAM)
240 li t0, 0xaa000304 /* MEMCFG_REG */
246 * EXTRESULT = 1 (1 is recommended)
247 * INTRESULT = 0 (0 is recommended)
248 * EXBUFEN = 0 (use SYSDIR and SYSEN)
249 * MEMWS = 00 (1.5 SYSCLK)
250 * IOWS = 10 (2.5 SYSCLK)
251 * SCLKDIV = 10 (PCLK/6)
253 li t0, 0xab0002c4 /* XISACTL */
265 or t0, t0, 0x00000003 /* K0 = 3 */
266 mtc0 t0, $16 /* config */
274 mtc0 zero, $28 /* TagLo */
276 lui t0, 0x8000 /* vaddr */
277 ori t1, zero, 0x1000 /* cache size = 4KB */
281 cache 0x00, (t0) /* Index_Invalidate */
282 cache 0x09, (t0) /* Index_Store_Tag */
286 addiu t0, t0, 0x10 /* increment of line size */
300 * now early bus configuration is done.
305 * copy bootloader ROM to RAM
307 li t1, LCBOOT_ROMSTARTADDR
325 li t1, LCBOOT_ROMSTARTADDR
343 /* panic. stop LED */
344 li t0, 0xab000248 /* LEDCNTREG */
363 * now we've got a working RAM with cache.
374 or t0, t0, 0x00000003 /* K0 = 3 */
375 mtc0 t0, $16 /* config */
396 sw zero, (t1) /* delay slot */
429 move a0, zero /* a0: argc = 0 */
430 move a1, zero /* a1 */
431 move a2, zero /* a2 */
432 move a3, zero /* a3 */
433 move k0, zero /* k0 */
434 move k1, zero /* k1 */
435 la gp, _C_LABEL(_gp) /* global pointer */
436 la sp, start /* stack pointer */
446 li t0, 0xab000248 /* LEDCNTREG */
455 * initialize registers
457 li a0, 1 /* a0: argc = 1 */
458 la a1, argv0 /* a1: argv */
459 la a2, bootinfo /* a2: bootinfo */
460 move a3, zero /* a3 */
461 move k0, zero /* k0 */
462 move k1, zero /* k1 */
463 /* no need to set grobal pointer. it set in locore.S */
464 la sp, NETBSD_STARTADDR /* stack pointer */
473 * arguments for mach_init()
484 .half 34 /* length */
485 .half 0 /* reserved */
486 .word 0x13536135 /* magic */
487 .word 0 /* fb_addr */
488 .half 0 /* fb_line_bytes */
489 .half 0 /* fb_width */
490 .half 0 /* fb_height */
491 .half 0 /* fb_type */
492 .half 2 /* BI_CNUSE_SERIAL */
493 .half 0 /* padding */
494 .word 0x04104400 /* PLATID_CPU_MIPS_VR_4181 */
495 .word 0x03810100 /* PLATID_MACH_LASER5_L_CARD */