mips_arch.cpp revision 1.1.2.2 1 1.1.2.2 bouyer /* -*-C++-*- $NetBSD: mips_arch.cpp,v 1.1.2.2 2001/02/11 19:10:06 bouyer Exp $ */
2 1.1.2.2 bouyer
3 1.1.2.2 bouyer /*-
4 1.1.2.2 bouyer * Copyright (c) 2001 The NetBSD Foundation, Inc.
5 1.1.2.2 bouyer * All rights reserved.
6 1.1.2.2 bouyer *
7 1.1.2.2 bouyer * This code is derived from software contributed to The NetBSD Foundation
8 1.1.2.2 bouyer * by UCHIYAMA Yasushi.
9 1.1.2.2 bouyer *
10 1.1.2.2 bouyer * Redistribution and use in source and binary forms, with or without
11 1.1.2.2 bouyer * modification, are permitted provided that the following conditions
12 1.1.2.2 bouyer * are met:
13 1.1.2.2 bouyer * 1. Redistributions of source code must retain the above copyright
14 1.1.2.2 bouyer * notice, this list of conditions and the following disclaimer.
15 1.1.2.2 bouyer * 2. Redistributions in binary form must reproduce the above copyright
16 1.1.2.2 bouyer * notice, this list of conditions and the following disclaimer in the
17 1.1.2.2 bouyer * documentation and/or other materials provided with the distribution.
18 1.1.2.2 bouyer * 3. All advertising materials mentioning features or use of this software
19 1.1.2.2 bouyer * must display the following acknowledgement:
20 1.1.2.2 bouyer * This product includes software developed by the NetBSD
21 1.1.2.2 bouyer * Foundation, Inc. and its contributors.
22 1.1.2.2 bouyer * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.1.2.2 bouyer * contributors may be used to endorse or promote products derived
24 1.1.2.2 bouyer * from this software without specific prior written permission.
25 1.1.2.2 bouyer *
26 1.1.2.2 bouyer * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.1.2.2 bouyer * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.1.2.2 bouyer * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.1.2.2 bouyer * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.1.2.2 bouyer * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.1.2.2 bouyer * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.1.2.2 bouyer * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.1.2.2 bouyer * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.1.2.2 bouyer * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.1.2.2 bouyer * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.1.2.2 bouyer * POSSIBILITY OF SUCH DAMAGE.
37 1.1.2.2 bouyer */
38 1.1.2.2 bouyer #undef DEBUG_KERNADDR_ACCESS
39 1.1.2.2 bouyer #undef DEBUG_CP0_ACCESS
40 1.1.2.2 bouyer
41 1.1.2.2 bouyer #include <hpcboot.h>
42 1.1.2.2 bouyer #include <mips/mips_arch.h>
43 1.1.2.2 bouyer #include <console.h>
44 1.1.2.2 bouyer #include <memory.h>
45 1.1.2.2 bouyer
46 1.1.2.2 bouyer MIPSArchitecture::MIPSArchitecture(Console *&cons, MemoryManager *&mem)
47 1.1.2.2 bouyer : Architecture(cons, mem)
48 1.1.2.2 bouyer {
49 1.1.2.2 bouyer /* NO-OP */
50 1.1.2.2 bouyer }
51 1.1.2.2 bouyer
52 1.1.2.2 bouyer MIPSArchitecture::~MIPSArchitecture(void)
53 1.1.2.2 bouyer {
54 1.1.2.2 bouyer /* NO-OP */
55 1.1.2.2 bouyer }
56 1.1.2.2 bouyer
57 1.1.2.2 bouyer void
58 1.1.2.2 bouyer MIPSArchitecture::systemInfo()
59 1.1.2.2 bouyer {
60 1.1.2.2 bouyer u_int32_t r0, r1;
61 1.1.2.2 bouyer Architecture::systemInfo();
62 1.1.2.2 bouyer r0 = r1 = 0;
63 1.1.2.2 bouyer
64 1.1.2.2 bouyer #ifdef DEBUG_CP0_ACCESS
65 1.1.2.2 bouyer /* CP0 access test */
66 1.1.2.2 bouyer _kmode = SetKMode(1);
67 1.1.2.2 bouyer
68 1.1.2.2 bouyer DPRINTF((TEXT("status register test\n")));
69 1.1.2.2 bouyer GET_SR(r0);
70 1.1.2.2 bouyer DPRINTF((TEXT("current value: 0x%08x\n"), r0));
71 1.1.2.2 bouyer SET_SR(r1);
72 1.1.2.2 bouyer GET_SR(r1);
73 1.1.2.2 bouyer DPRINTF((TEXT("write test: 0x%08x\n"), r1));
74 1.1.2.2 bouyer SET_SR(r0);
75 1.1.2.2 bouyer
76 1.1.2.2 bouyer SetKMode(_kmode);
77 1.1.2.2 bouyer #endif // DEBUG_CP0_ACCESS
78 1.1.2.2 bouyer }
79 1.1.2.2 bouyer
80 1.1.2.2 bouyer BOOL
81 1.1.2.2 bouyer MIPSArchitecture::init()
82 1.1.2.2 bouyer {
83 1.1.2.2 bouyer if (!_mem->init()) {
84 1.1.2.2 bouyer DPRINTF((TEXT("can't initialize memory manager.\n")));
85 1.1.2.2 bouyer return FALSE;
86 1.1.2.2 bouyer }
87 1.1.2.2 bouyer
88 1.1.2.2 bouyer return TRUE;
89 1.1.2.2 bouyer }
90 1.1.2.2 bouyer
91 1.1.2.2 bouyer BOOL
92 1.1.2.2 bouyer MIPSArchitecture::setupLoader()
93 1.1.2.2 bouyer {
94 1.1.2.2 bouyer vaddr_t v;
95 1.1.2.2 bouyer
96 1.1.2.2 bouyer #ifdef DEBUG_KERNADDR_ACCESS // kernel address access test
97 1.1.2.2 bouyer #define TEST_MAGIC 0xac1dcafe
98 1.1.2.2 bouyer paddr_t p;
99 1.1.2.2 bouyer u_int32_t r0;
100 1.1.2.2 bouyer
101 1.1.2.2 bouyer _kmode = SetKMode(1);
102 1.1.2.2 bouyer _mem->getPage(v, p);
103 1.1.2.2 bouyer VOLATILE_REF(ptokv(p)) = TEST_MAGIC;
104 1.1.2.2 bouyer cacheFlush();
105 1.1.2.2 bouyer r0 = VOLATILE_REF(v);
106 1.1.2.2 bouyer DPRINTF((TEXT("kernel address access test: %S\n"),
107 1.1.2.2 bouyer r0 == TEST_MAGIC ? "OK" : "NG"));
108 1.1.2.2 bouyer SetKMode(_kmode);
109 1.1.2.2 bouyer #endif // DEBUG_KERNADDR_ACCESS
110 1.1.2.2 bouyer
111 1.1.2.2 bouyer if (!_mem->getPage(v , _loader_addr)) {
112 1.1.2.2 bouyer DPRINTF((TEXT("can't get page for 2nd loader.\n")));
113 1.1.2.2 bouyer return FALSE;
114 1.1.2.2 bouyer }
115 1.1.2.2 bouyer DPRINTF((TEXT("2nd bootloader vaddr=0x%08x paddr=0x%08x\n"),
116 1.1.2.2 bouyer (unsigned)v,(unsigned)_loader_addr));
117 1.1.2.2 bouyer
118 1.1.2.2 bouyer memcpy(LPVOID(v), LPVOID(_boot_func), _mem->getPageSize());
119 1.1.2.2 bouyer DPRINTF((TEXT("2nd bootloader copy done.\n")));
120 1.1.2.2 bouyer
121 1.1.2.2 bouyer return TRUE;
122 1.1.2.2 bouyer }
123 1.1.2.2 bouyer
124 1.1.2.2 bouyer void
125 1.1.2.2 bouyer MIPSArchitecture::jump(paddr_t info, paddr_t pvec)
126 1.1.2.2 bouyer {
127 1.1.2.2 bouyer kaddr_t sp;
128 1.1.2.2 bouyer vaddr_t v;
129 1.1.2.2 bouyer paddr_t p;
130 1.1.2.2 bouyer
131 1.1.2.2 bouyer // stack for bootloader(but mips loader don't use stack)
132 1.1.2.2 bouyer _mem->getPage(v, p);
133 1.1.2.2 bouyer sp = ptokv(p + _mem->getPageSize() - 0x10);
134 1.1.2.2 bouyer
135 1.1.2.2 bouyer info = ptokv(info);
136 1.1.2.2 bouyer pvec = ptokv(pvec);
137 1.1.2.2 bouyer _loader_addr = ptokv(_loader_addr);
138 1.1.2.2 bouyer
139 1.1.2.2 bouyer // switch kernel mode.
140 1.1.2.2 bouyer SetKMode(1);
141 1.1.2.2 bouyer if (SetKMode(1) != 1) {
142 1.1.2.2 bouyer DPRINTF((TEXT("SetKMode(1) failed.\n")));
143 1.1.2.2 bouyer return;
144 1.1.2.2 bouyer }
145 1.1.2.2 bouyer DPRINTF((TEXT("jump to 0x%08x(info=0x%08x, pvec=0x%08x\n"),
146 1.1.2.2 bouyer _loader_addr, info, pvec));
147 1.1.2.2 bouyer
148 1.1.2.2 bouyer // writeback whole D-cache and invalidate whole I-cache.
149 1.1.2.2 bouyer // 2nd boot-loader access data via kseg0 which were writed via kuseg,
150 1.1.2.2 bouyer cacheFlush();
151 1.1.2.2 bouyer
152 1.1.2.2 bouyer // jump to 2nd-loader(run kseg0)
153 1.1.2.2 bouyer __asm(".set noreorder;"
154 1.1.2.2 bouyer "jr a3;"
155 1.1.2.2 bouyer "move sp, a2;"
156 1.1.2.2 bouyer ".set reorder", info, pvec, sp, _loader_addr);
157 1.1.2.2 bouyer // NOTREACHED
158 1.1.2.2 bouyer }
159