arch.cpp revision 1.1 1 /* -*-C++-*- $NetBSD: arch.cpp,v 1.1 2001/02/09 18:34:33 uch 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
82 struct BootArgs *karg = reinterpret_cast < struct BootArgs *>(v);
83
84 karg->argc = menu.setup_kernel_args(v + sizeof(struct BootArgs),
85 p + sizeof(struct BootArgs));
86 karg->argv = ptokv(p + sizeof(struct BootArgs));
87 menu.setup_bootinfo(karg->bi);
88 karg->bootinfo = ptokv(p + offsetof(struct BootArgs, bi));
89 karg->kernel_entry = loader.jumpAddr();
90
91 DPRINTF((TEXT("frame buffer: %dx%d type=%d linebytes=%d addr=0x%08x\n"),
92 karg->bi.fb_width, karg->bi.fb_height, karg->bi.fb_type,
93 karg->bi.fb_line_bytes, karg->bi.fb_addr));
94
95 return p;
96 }
97
98 void *
99 Architecture::_load_func(const TCHAR * name)
100 {
101 if (_dll == 0)
102 _dll = LoadLibrary(TEXT("coredll.dll"));
103
104 return _dll
105 ? reinterpret_cast <void *>(GetProcAddress(_dll, name))
106 : 0;
107 }
108
109 void
110 Architecture::systemInfo(void)
111 {
112 int(*func)(HDC, int, int, LPCSTR, int, LPSTR);
113 u_int32_t val = 0;
114 int ret;
115 HDC hdc;
116
117 // inquire default setting.
118 FrameBufferInfo fb(0, 0);
119 DPRINTF((TEXT("[DISPLAY] %dx%d %dbpp\n"), fb.width(), fb.height(),
120 fb.bpp()));
121
122 func = reinterpret_cast <int(*)(HDC, int, int, LPCSTR, int, LPSTR)>
123 (_load_func(TEXT("ExtEscape")));
124 if (func == 0) {
125 DPRINTF((TEXT("ExtEscape not found.\n")));
126 return;
127 }
128 hdc = GetDC(0);
129 ret = func(hdc, GETVFRAMEPHYSICAL, 0, 0, sizeof(u_int32_t),
130 reinterpret_cast <char *>(&val));
131 if (ret == 0)
132 DPRINTF((TEXT("ExtEscape(GETVFRAMEPHYSICAL) not implemented.\n")));
133 else if (ret < 0)
134 DPRINTF((TEXT("ExtEscape(GETVFRAMEPHYSICAL) failure.\n")));
135 else
136 DPRINTF((TEXT("frame buffer physical address: 0x%08x\n"),
137 val));
138
139 ret = func(hdc, GETVFRAMELEN, 0, 0, sizeof(u_int32_t),
140 reinterpret_cast <char *>(&val));
141
142 if (ret == 0)
143 DPRINTF((TEXT("ExtEscape(GETVFRAMELEN) not implemented.\n")));
144 else if (ret < 0)
145 DPRINTF((TEXT("ExtEscape(GETVFRAMELEN) failure.\n")));
146 else
147 DPRINTF((TEXT("frame buffer length: 0x%08x\n"), val));
148
149 ReleaseDC(0, hdc);
150
151 }
152
153 BOOL(*Architecture::_load_LockPages(void))(LPVOID, DWORD, PDWORD, int)
154 {
155 return reinterpret_cast <BOOL(*)(LPVOID, DWORD, PDWORD, int)>
156 (_load_func(TEXT("LockPages")));
157 }
158
159 BOOL(*Architecture::_load_UnlockPages(void))(LPVOID, DWORD)
160 {
161 return reinterpret_cast <BOOL(*)(LPVOID, DWORD)>
162 (_load_func(TEXT("UnlockPages")));
163 }
164
165 //
166 // Debug support.
167 //
168 void
169 Architecture::_bitdisp(u_int32_t a, int s, int e, int m, int c)
170 {
171 u_int32_t j, j1;
172 int i, n;
173
174 n = 31; // 32bit only.
175 j1 = 1 << n;
176 e = e ? e : n;
177 for (j = j1, i = n; j > 0; j >>=1, i--) {
178 if (i > e || i < s) {
179 DPRINTF((TEXT("%c"), a & j ? '+' : '-'));
180 } else {
181 DPRINTF((TEXT("%c"), a & j ? '|' : '.'));
182 }
183 }
184 if (m) {
185 DPRINTF((TEXT("[%s]"),(char*)m));
186 }
187 if (c) {
188 for (j = j1, i = n; j > 0; j >>=1, i--) {
189 if (!(i > e || i < s) &&(a & j)) {
190 DPRINTF((TEXT(" %d"), i));
191 }
192 }
193 }
194 DPRINTF((TEXT(" [0x%08x] %d"), a, a));
195 DPRINTF((TEXT("\n")));
196 }
197
198 void
199 Architecture::_dbg_bit_print(u_int32_t reg, u_int32_t mask, const char *name)
200 {
201 static const char onoff[3] = "_x";
202 DPRINTF((TEXT("%S[%c] "), name, onoff[reg & mask ? 1 : 0]));
203 }
204