1 /* -*-C++-*- $NetBSD: mips_arch.cpp,v 1.6 2006/03/05 04:05:39 uwe Exp $ */
4 * Copyright (c) 2001 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
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.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
31 #undef DEBUG_KERNADDR_ACCESS
32 #undef DEBUG_CP0_ACCESS
35 #include <mips/mips_arch.h>
39 MIPSArchitecture::MIPSArchitecture(Console
*&cons
, MemoryManager
*&mem
)
40 : Architecture(cons
, mem
)
45 MIPSArchitecture::~MIPSArchitecture(void)
51 MIPSArchitecture::systemInfo()
54 Architecture::systemInfo();
57 #ifdef DEBUG_CP0_ACCESS
61 DPRINTF((TEXT("status register test\n")));
63 DPRINTF((TEXT("current value: 0x%08x\n"), r0
));
66 DPRINTF((TEXT("write test: 0x%08x\n"), r1
));
70 #endif // DEBUG_CP0_ACCESS
74 MIPSArchitecture::init()
77 DPRINTF((TEXT("can't initialize memory manager.\n")));
85 MIPSArchitecture::setupLoader()
89 #ifdef DEBUG_KERNADDR_ACCESS // kernel address access test
90 #define TEST_MAGIC 0xac1dcafe
96 VOLATILE_REF(ptokv(p
)) = TEST_MAGIC
;
99 DPRINTF((TEXT("kernel address access test: %S\n"),
100 r0
== TEST_MAGIC
? "OK" : "NG"));
102 #endif // DEBUG_KERNADDR_ACCESS
104 if (!_mem
->getPage(v
, _loader_addr
)) {
105 DPRINTF((TEXT("can't get page for 2nd loader.\n")));
108 DPRINTF((TEXT("2nd bootloader vaddr=0x%08x paddr=0x%08x\n"),
109 (unsigned)v
,(unsigned)_loader_addr
));
111 memcpy(LPVOID(v
), LPVOID(_boot_func
), _mem
->getPageSize());
112 DPRINTF((TEXT("2nd bootloader copy done.\n")));
118 MIPSArchitecture::jump(paddr_t info
, paddr_t pvec
)
124 // stack for bootloader(but mips loader don't use stack)
126 sp
= ptokv(p
+ _mem
->getPageSize() - 0x10);
130 _loader_addr
= ptokv(_loader_addr
);
132 // switch kernel mode.
134 if (SetKMode(1) != 1) {
135 DPRINTF((TEXT("SetKMode(1) failed.\n")));
138 DPRINTF((TEXT("jump to 0x%08x (info=0x%08x, pvec=0x%08x)\n"),
139 _loader_addr
, info
, pvec
));
141 // writeback whole D-cache and invalidate whole I-cache.
142 // 2nd boot-loader access data via kseg0 which were writed via kuseg,
145 // jump to 2nd-loader(run kseg0)
146 __asm(".set noreorder;"
149 ".set reorder", info
, pvec
, sp
, _loader_addr
);