arch.cpp revision 1.7.10.4 1 /* -*-C++-*- $NetBSD: arch.cpp,v 1.7.10.4 2004/09/21 13:15:48 skrll 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 HWND owner = HpcMenuInterface::Instance()._root->_window;
116 MessageBox(owner,
117 TEXT("Can't load coredll.dll."), TEXT("WARNING"),
118 MB_ICONWARNING | MB_OK);
119 UpdateWindow(owner);
120
121 return NULL;
122 }
123
124 return reinterpret_cast <void *>(GetProcAddress(_dll, name));
125 }
126
127 void
128 Architecture::systemInfo(void)
129 {
130 u_int32_t val = 0;
131 SYSTEM_INFO si;
132
133 DPRINTF((TEXT("_WIN32_WCE = %d\n"), _WIN32_WCE));
134 //
135 // WCE200 ... GetVersionEx
136 // WCE210 or later ... GetVersionExA or GetVersionExW
137 // see winbase.h
138 //
139 BOOL (*getVersionEx)(LPOSVERSIONINFO);
140 getVersionEx = reinterpret_cast <BOOL(*)(LPOSVERSIONINFO)>
141 (_load_func(TEXT("GetVersionEx")));
142
143 if (getVersionEx) {
144 getVersionEx(&WinCEVersion);
145 DPRINTF((TEXT("GetVersionEx\n")));
146 } else {
147 GetVersionEx(&WinCEVersion);
148 DPRINTF((TEXT("GetVersionExW\n")));
149 }
150
151 DPRINTF((TEXT("Windows CE %d.%d\n"), WinCEVersion.dwMajorVersion,
152 WinCEVersion.dwMinorVersion));
153
154 GetSystemInfo(&si);
155 DPRINTF((TEXT("GetSystemInfo:\n")));
156 #if _WIN32_WCE >= 200
157 DPRINTF((TEXT("wProcessorArchitecture 0x%x\n"),
158 si.wProcessorArchitecture));
159 DPRINTF((TEXT("wProcessorLevel 0x%x\n"),
160 si.wProcessorLevel));
161 DPRINTF((TEXT("wProcessorRevision 0x%x\n"),
162 si.wProcessorRevision));
163 #endif
164 DPRINTF((TEXT("dwPageSize 0x%x\n"),
165 si.dwPageSize));
166 DPRINTF((TEXT("dwAllocationGranularity 0x%08x\n"),
167 si.dwAllocationGranularity));
168 DPRINTF((TEXT("dwProcessorType 0x%x\n"),
169 si.dwProcessorType));
170 // inquire default setting.
171 FrameBufferInfo fb(0, 0);
172 DPRINTF((TEXT("Display: %dx%d %dbpp\n"), fb.width(), fb.height(),
173 fb.bpp()));
174 }
175
176 BOOL(*Architecture::_load_LockPages(void))(LPVOID, DWORD, PDWORD, int)
177 {
178
179 return reinterpret_cast <BOOL(*)(LPVOID, DWORD, PDWORD, int)>
180 (_load_func(TEXT("LockPages")));
181 }
182
183 BOOL(*Architecture::_load_UnlockPages(void))(LPVOID, DWORD)
184 {
185
186 return reinterpret_cast <BOOL(*)(LPVOID, DWORD)>
187 (_load_func(TEXT("UnlockPages")));
188 }
189