arch.cpp revision 1.8 1 /* -*-C++-*- $NetBSD: arch.cpp,v 1.8 2003/12/18 12:25:03 uwe 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 _mem->getTaggedPageSize() - sizeof(struct BootArgs));
91 _boot_arg->argv = ptokv(p + sizeof(struct BootArgs));
92 menu.setup_bootinfo(_boot_arg->bi);
93 _boot_arg->bi.bi_cnuse = _cons->getBootConsole();
94
95 _boot_arg->bootinfo = ptokv(p + offsetof(struct BootArgs, bi));
96 _boot_arg->kernel_entry = loader.jumpAddr();
97
98 struct bootinfo &bi = _boot_arg->bi;
99 DPRINTF((TEXT("framebuffer: %dx%d type=%d linebytes=%d addr=0x%08x\n"),
100 bi.fb_width, bi.fb_height, bi.fb_type, bi.fb_line_bytes,
101 bi.fb_addr));
102 DPRINTF((TEXT("console = %d\n"), bi.bi_cnuse));
103
104 return p;
105 }
106
107 void *
108 Architecture::_load_func(const TCHAR * name)
109 {
110
111 if (_dll == NULL)
112 _dll = LoadLibrary(TEXT("coredll.dll"));
113
114 if (_dll == NULL) {
115 MessageBox(HpcMenuInterface::Instance()._root->_window,
116 TEXT("Can't load coredll.dll."), TEXT("WARNING"),
117 MB_ICONWARNING | MB_OK);
118
119 return NULL;
120 }
121
122 return reinterpret_cast <void *>(GetProcAddress(_dll, name));
123 }
124
125 void
126 Architecture::systemInfo(void)
127 {
128 u_int32_t val = 0;
129 SYSTEM_INFO si;
130 HDC hdc;
131 BOOL (*getVersionEx)(LPOSVERSIONINFO);
132
133 //
134 // WCE200 ... GetVersionEx
135 // WCE210 or later ... GetVersionExA or GetVersionExW
136 // see winbase.h
137 //
138 getVersionEx = reinterpret_cast <BOOL(*)(LPOSVERSIONINFO)>
139 (_load_func(TEXT("GetVersionEx")));
140
141 if (getVersionEx) {
142 getVersionEx(&WinCEVersion);
143 DPRINTF((TEXT("GetVersionEx\n")));
144 } else {
145 GetVersionEx(&WinCEVersion);
146 DPRINTF((TEXT("GetVersionExW\n")));
147 }
148
149 DPRINTF((TEXT("Windows CE %d.%d\n"), WinCEVersion.dwMajorVersion,
150 WinCEVersion.dwMinorVersion));
151
152 GetSystemInfo(&si);
153 DPRINTF((TEXT("GetSystemInfo:\n")));
154 DPRINTF((TEXT("wProcessorArchitecture 0x%x\n"),
155 si.wProcessorArchitecture));
156 DPRINTF((TEXT("dwPageSize 0x%x\n"),
157 si.dwPageSize));
158 DPRINTF((TEXT("dwAllocationGranularity 0x%08x\n"),
159 si.dwAllocationGranularity));
160 DPRINTF((TEXT("dwProcessorType 0x%x\n"),
161 si.dwProcessorType));
162 DPRINTF((TEXT("wProcessorLevel 0x%x\n"),
163 si.wProcessorLevel));
164 DPRINTF((TEXT("wProcessorRevision 0x%x\n"),
165 si.wProcessorRevision));
166
167 // inquire default setting.
168 FrameBufferInfo fb(0, 0);
169 DPRINTF((TEXT("Display: %dx%d %dbpp\n"), fb.width(), fb.height(),
170 fb.bpp()));
171
172 ReleaseDC(0, hdc);
173 }
174
175 BOOL(*Architecture::_load_LockPages(void))(LPVOID, DWORD, PDWORD, int)
176 {
177
178 return reinterpret_cast <BOOL(*)(LPVOID, DWORD, PDWORD, int)>
179 (_load_func(TEXT("LockPages")));
180 }
181
182 BOOL(*Architecture::_load_UnlockPages(void))(LPVOID, DWORD)
183 {
184
185 return reinterpret_cast <BOOL(*)(LPVOID, DWORD)>
186 (_load_func(TEXT("UnlockPages")));
187 }
188