arch.cpp revision 1.1.4.2 1 /* -*-C++-*- $NetBSD: arch.cpp,v 1.1.4.2 2001/06/21 19:22:39 nathanw Exp $ */
2
3 /*-
4 * Copyright (c) 2001 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 <console.h>
43 #include <memory.h>
44 #include <load.h>
45 #include <arch.h>
46 #include <framebuffer.h>
47
48 Architecture::Architecture(Console *&cons, MemoryManager *&mem)
49 :_cons(cons), _mem(mem)
50 {
51 _loader_addr = 0;
52 _debug = FALSE;
53 _dll = 0;
54 }
55
56 Architecture::~Architecture(void)
57 {
58 if (_dll)
59 FreeLibrary(_dll);
60 }
61
62 BOOL
63 Architecture::allocateMemory(size_t sz)
64 {
65 //binary image.
66 sz = _mem->estimateTaggedPageSize(sz);
67 //pvec + BootArgs + 2 nd bootloader + bootloader stack.
68 sz += _mem->getPageSize() * 4;
69 sz = _mem->roundRegion(sz);
70 return _mem->reservePage(sz);
71 }
72
73 paddr_t
74 Architecture::setupBootInfo(Loader &loader)
75 {
76 HpcMenuInterface &menu = HpcMenuInterface::Instance();
77 vaddr_t v;
78 paddr_t p;
79
80 _mem->getPage(v, p);
81 _boot_arg = reinterpret_cast <struct BootArgs *>(v);
82
83 _boot_arg->argc = menu.setup_kernel_args(v + sizeof(struct BootArgs),
84 p + sizeof(struct BootArgs));
85 _boot_arg->argv = ptokv(p + sizeof(struct BootArgs));
86 menu.setup_bootinfo(_boot_arg->bi);
87 _boot_arg->bi.bi_cnuse = _cons->getBootConsole();
88
89 _boot_arg->bootinfo = ptokv(p + offsetof(struct BootArgs, bi));
90 _boot_arg->kernel_entry = loader.jumpAddr();
91
92 struct bootinfo &bi = _boot_arg->bi;
93 DPRINTF((TEXT("framebuffer: %dx%d type=%d linebytes=%d addr=0x%08x\n"),
94 bi.fb_width, bi.fb_height, bi.fb_type, bi.fb_line_bytes,
95 bi.fb_addr));
96 DPRINTF((TEXT("console = %d\n"), bi.bi_cnuse));
97
98 return p;
99 }
100
101 void *
102 Architecture::_load_func(const TCHAR * name)
103 {
104 if (_dll == 0)
105 _dll = LoadLibrary(TEXT("coredll.dll"));
106
107 return
108 _dll ? reinterpret_cast <void *>(GetProcAddress(_dll, name)) : 0;
109 }
110
111 void
112 Architecture::systemInfo(void)
113 {
114 int(*func)(HDC, int, int, LPCSTR, int, LPSTR);
115 u_int32_t val = 0;
116 int ret;
117 HDC hdc;
118
119 // inquire default setting.
120 FrameBufferInfo fb(0, 0);
121 DPRINTF((TEXT("[DISPLAY] %dx%d %dbpp\n"), fb.width(), fb.height(),
122 fb.bpp()));
123
124 func = reinterpret_cast <int(*)(HDC, int, int, LPCSTR, int, LPSTR)>
125 (_load_func(TEXT("ExtEscape")));
126 if (func == 0) {
127 DPRINTF((TEXT("ExtEscape not found.\n")));
128 return;
129 }
130 hdc = GetDC(0);
131 ret = func(hdc, GETVFRAMEPHYSICAL, 0, 0, sizeof(u_int32_t),
132 reinterpret_cast <char *>(&val));
133 if (ret == 0)
134 DPRINTF((TEXT("ExtEscape(GETVFRAMEPHYSICAL) not implemented.\n")));
135 else if (ret < 0)
136 DPRINTF((TEXT("ExtEscape(GETVFRAMEPHYSICAL) failure.\n")));
137 else
138 DPRINTF((TEXT("frame buffer physical address: 0x%08x\n"),
139 val));
140
141 ret = func(hdc, GETVFRAMELEN, 0, 0, sizeof(u_int32_t),
142 reinterpret_cast <char *>(&val));
143
144 if (ret == 0)
145 DPRINTF((TEXT("ExtEscape(GETVFRAMELEN) not implemented.\n")));
146 else if (ret < 0)
147 DPRINTF((TEXT("ExtEscape(GETVFRAMELEN) failure.\n")));
148 else
149 DPRINTF((TEXT("frame buffer length: 0x%08x\n"), val));
150
151 ReleaseDC(0, hdc);
152
153 }
154
155 BOOL(*Architecture::_load_LockPages(void))(LPVOID, DWORD, PDWORD, int)
156 {
157 return reinterpret_cast <BOOL(*)(LPVOID, DWORD, PDWORD, int)>
158 (_load_func(TEXT("LockPages")));
159 }
160
161 BOOL(*Architecture::_load_UnlockPages(void))(LPVOID, DWORD)
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 DPRINTF((TEXT("%S[%c] "), name, onoff[reg & mask ? 1 : 0]));
205 }
206