arch.cpp revision 1.4 1 /* -*-C++-*- $NetBSD: arch.cpp,v 1.4 2002/02/04 17:31:34 uch Exp $ */
2
3 /*-
4 * Copyright (c) 2001, 2002 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by UCHIYAMA Yasushi.
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. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 #include <hpcboot.h>
40 #include <hpcmenu.h>
41
42 #include <menu/window.h>
43 #include <menu/rootwindow.h> // MessageBox
44
45 #include <console.h>
46 #include <memory.h>
47 #include <load.h>
48 #include <arch.h>
49 #include <framebuffer.h>
50
51 Architecture::Architecture(Console *&cons, MemoryManager *&mem)
52 :_cons(cons), _mem(mem)
53 {
54
55 _loader_addr = 0;
56 _debug = FALSE;
57 _dll = 0;
58 }
59
60 Architecture::~Architecture(void)
61 {
62
63 if (_dll)
64 FreeLibrary(_dll);
65 }
66
67 BOOL
68 Architecture::allocateMemory(size_t sz)
69 {
70 //binary image.
71 sz = _mem->estimateTaggedPageSize(sz);
72 //pvec + BootArgs + 2 nd bootloader + bootloader stack.
73 sz += _mem->getPageSize() * 4;
74 sz = _mem->roundRegion(sz);
75 return _mem->reservePage(sz);
76 }
77
78 paddr_t
79 Architecture::setupBootInfo(Loader &loader)
80 {
81 HpcMenuInterface &menu = HpcMenuInterface::Instance();
82 vaddr_t v;
83 paddr_t p;
84
85 _mem->getPage(v, p);
86 _boot_arg = reinterpret_cast <struct BootArgs *>(v);
87
88 _boot_arg->argc = menu.setup_kernel_args(v + sizeof(struct BootArgs),
89 p + sizeof(struct BootArgs));
90 _boot_arg->argv = ptokv(p + sizeof(struct BootArgs));
91 menu.setup_bootinfo(_boot_arg->bi);
92 _boot_arg->bi.bi_cnuse = _cons->getBootConsole();
93
94 _boot_arg->bootinfo = ptokv(p + offsetof(struct BootArgs, bi));
95 _boot_arg->kernel_entry = loader.jumpAddr();
96
97 struct bootinfo &bi = _boot_arg->bi;
98 DPRINTF((TEXT("framebuffer: %dx%d type=%d linebytes=%d addr=0x%08x\n"),
99 bi.fb_width, bi.fb_height, bi.fb_type, bi.fb_line_bytes,
100 bi.fb_addr));
101 DPRINTF((TEXT("console = %d\n"), bi.bi_cnuse));
102
103 return p;
104 }
105
106 void *
107 Architecture::_load_func(const TCHAR * name)
108 {
109
110 if (_dll == NULL)
111 _dll = LoadLibrary(TEXT("coredll.dll"));
112
113 if (_dll == NULL) {
114 MessageBox(HpcMenuInterface::Instance()._root->_window,
115 TEXT("Can't load Coredll.dll"), TEXT("WARNING"), 0);
116
117 return NULL;
118 }
119
120 return reinterpret_cast <void *>(GetProcAddress(_dll, name));
121 }
122
123 void
124 Architecture::systemInfo(void)
125 {
126 u_int32_t val = 0;
127 SYSTEM_INFO si;
128 HDC hdc;
129
130 GetSystemInfo(&si);
131 DPRINTF((TEXT("GetSystemInfo:\n")));
132 DPRINTF((TEXT("wProcessorArchitecture 0x%x\n"),
133 si.wProcessorArchitecture));
134 DPRINTF((TEXT("dwPageSize 0x%x\n"),
135 si.dwPageSize));
136 DPRINTF((TEXT("dwAllocationGranularity 0x%08x\n"),
137 si.dwAllocationGranularity));
138 DPRINTF((TEXT("dwProcessorType 0x%x\n"),
139 si.dwProcessorType));
140 DPRINTF((TEXT("wProcessorLevel 0x%x\n"),
141 si.wProcessorLevel));
142 DPRINTF((TEXT("wProcessorRevision 0x%x\n"),
143 si.wProcessorRevision));
144
145 // inquire default setting.
146 FrameBufferInfo fb(0, 0);
147 DPRINTF((TEXT("Display: %dx%d %dbpp\n"), fb.width(), fb.height(),
148 fb.bpp()));
149
150 ReleaseDC(0, hdc);
151 }
152
153 BOOL(*Architecture::_load_LockPages(void))(LPVOID, DWORD, PDWORD, int)
154 {
155
156 return reinterpret_cast <BOOL(*)(LPVOID, DWORD, PDWORD, int)>
157 (_load_func(TEXT("LockPages")));
158 }
159
160 BOOL(*Architecture::_load_UnlockPages(void))(LPVOID, DWORD)
161 {
162
163 return reinterpret_cast <BOOL(*)(LPVOID, DWORD)>
164 (_load_func(TEXT("UnlockPages")));
165 }
166
167 //
168 // Debug support.
169 //
170 void
171 Architecture::_bitdisp(u_int32_t a, int s, int e, int m, int c)
172 {
173 u_int32_t j, j1;
174 int i, n;
175
176 n = 31; // 32bit only.
177 j1 = 1 << n;
178 e = e ? e : n;
179 for (j = j1, i = n; j > 0; j >>=1, i--) {
180 if (i > e || i < s) {
181 DPRINTF((TEXT("%c"), a & j ? '+' : '-'));
182 } else {
183 DPRINTF((TEXT("%c"), a & j ? '|' : '.'));
184 }
185 }
186 if (m) {
187 DPRINTF((TEXT("[%s]"),(char*)m));
188 }
189 if (c) {
190 for (j = j1, i = n; j > 0; j >>=1, i--) {
191 if (!(i > e || i < s) &&(a & j)) {
192 DPRINTF((TEXT(" %d"), i));
193 }
194 }
195 }
196 DPRINTF((TEXT(" [0x%08x] %d"), a, a));
197 DPRINTF((TEXT("\n")));
198 }
199
200 void
201 Architecture::_dbg_bit_print(u_int32_t reg, u_int32_t mask, const char *name)
202 {
203 static const char onoff[3] = "_x";
204
205 DPRINTF((TEXT("%S[%c] "), name, onoff[reg & mask ? 1 : 0]));
206 }
207