1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
|
/* $NetBSD: hpcboot.cpp,v 1.20 2008/04/28 20:23:20 martin Exp $ */
/*-
* Copyright (c) 2001, 2002, 2004 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by UCHIYAMA Yasushi.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <hpcmenu.h>
#include <hpcboot.h>
#include <menu/window.h>
#include <menu/rootwindow.h>
#include <console.h>
#include <arch.h>
#include <memory.h>
#include <file.h>
#include <load.h>
#include <boot.h>
#include "../binary/build_number.h"
#if _WIN32_WCE <= 200
OSVERSIONINFO WinCEVersion;
#else
OSVERSIONINFOW WinCEVersion;
#endif
int WINAPI
WinMain(HINSTANCE instance, HINSTANCE prev_instance,
LPTSTR cmd_line, int window_show)
{
HpcMenuInterface::Instance(); // Menu System
HpcBootApp *app = 0; // Application body.
int ret = 0;
InitCommonControls();
app = new HpcBootApp(instance);
app->_cons = Console::Instance();
app->_root = new RootWindow(*app);
if (!app->registerClass(reinterpret_cast <WNDPROC>(Window::_wnd_proc)))
goto failed;
if (!app->_root->create(0))
goto failed;
Boot::Instance(); // Boot loader
ret = app->run(); // Main loop.
// NOTREACHED
failed:
Boot::Destroy();
if (app->_root)
delete app->_root;
delete app;
Console::Destroy();
HpcMenuInterface::Destroy();
return ret;
}
//
// boot sequence.
//
void
hpcboot(void *arg)
{
size_t sz = 0;
paddr_t p = 0;
TCHAR *error_message = 0;
HpcMenuInterface &menu = HPC_MENU;
Boot &f = Boot::Instance();
// Open serial port for kernel KGDB.
SerialConsole::OpenCOM1();
menu.progress("0");
if (!f.setup()) {
error_message = TEXT("Architecture not supported.\n");
goto failed_exit;
}
menu.progress("1");
if (!f.create()) {
error_message = TEXT("Architecture ops. not found.\n");
goto failed_exit;
}
// Now we can write console which user specified.
{
DPRINTF_SETUP();
DPRINTF((TEXT("hpcboot build number: %d\n"),
HPCBOOT_BUILD_NUMBER));
DPRINTF((TEXT("%s (cpu=0x%08x machine=0x%08x)\n"),
HPC_MENU.platform_get(HPC_MENU.platform_default()),
HPC_PREFERENCE.platid_hi, HPC_PREFERENCE.platid_lo));
}
menu.progress("2");
if (!f._arch->init()) {
error_message = TEXT("Architecture initialize failed.\n");
goto failed_exit;
}
f._arch->systemInfo();
menu.progress("3");
// kernel / file system image directory.
if (!f._file->setRoot(f.args.fileRoot)) {
error_message = TEXT("Can't set root directory.\n");
goto failed_exit;
}
// determine the size of file system image.
if (f.args.loadmfs)
{
if (!f._file->open(f.args.mfsName)) {
error_message =
TEXT("Can't open file system image.\n");
goto failed_exit;
}
sz = f._file->realsize();
sz = f._mem->roundPage(sz);
f._file->close();
}
menu.progress("4");
if (!f._file->open(f.args.fileName)) {
error_message = TEXT("Can't open kernel image.\n");
goto failed_exit;
}
menu.progress("5");
// put kernel to loader.
if (!f.attachLoader()) {
error_message = TEXT("Can't attach loader.\n");
goto file_close_exit;
}
if (!f._loader->setFile(f._file)) {
error_message = TEXT("Can't initialize loader.\n");
goto file_close_exit;
}
menu.progress("6");
sz += f._mem->roundPage(f._loader->memorySize());
// allocate required memory.
if (!f._arch->allocateMemory(sz)) {
error_message = TEXT("Can't allocate memory.\n");
goto file_close_exit;
}
menu.progress("7");
// load kernel to memory.
if (!f._arch->setupLoader()) {
error_message = TEXT("Can't set up loader.\n");
goto file_close_exit;
}
menu.progress("8");
if (!f._loader->load()) {
error_message = TEXT("Can't load kernel image to memory.\n");
goto file_close_exit;
}
menu.progress("9");
f._file->close();
// load file system image to memory
if (f.args.loadmfs) {
if (!f._file->open(f.args.mfsName)) {
error_message =
TEXT("Can't open file system image.\n");
goto failed_exit;
}
if (!f._loader->loadExtData()) {
error_message =
TEXT("Can't load file system image to memory.\n");
goto file_close_exit;
}
f._file->close();
}
f._loader->loadEnd();
// setup arguments for kernel.
p = f._arch->setupBootInfo(*f._loader);
menu.progress("10");
f._loader->tagDump(3); // dump page chain.(print first 3 links)
// jump to kernel entry.
if (HPC_PREFERENCE.pause_before_boot) {
if (MessageBox(menu._root->_window, TEXT("Push YES to boot."),
TEXT("Last chance..."),
MB_ICONWARNING | MB_YESNO) != IDYES)
{
error_message = TEXT("Canceled by user.\n");
goto failed_exit;
}
// redraw areas damaged by the dialog
UpdateWindow(menu._root->_window);
}
f._arch->jump(p, f._loader->tagStart());
// NOTREACHED
error_message = TEXT("Can't jump to the kernel.\n");
file_close_exit:
f._file->close();
failed_exit:
if (error_message == 0)
error_message = TEXT("Unknown error?\n");
MessageBox(menu._root->_window, error_message,
TEXT("BOOT FAILED"), MB_ICONERROR | MB_OK);
menu.unprogress(); // rewind progress bar
}
//
// HPCBOOT main loop
//
int
HpcBootApp::run(void)
{
MSG msg;
while (GetMessage(&msg, 0, 0, 0)) {
// cancel auto-boot.
if (HPC_PREFERENCE.auto_boot > 0 && _root &&
(msg.message == WM_KEYDOWN ||
msg.message == WM_LBUTTONDOWN)) {
_root->disableTimer();
}
if (!_root->isDialogMessage(msg)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return msg.wParam;
}
BOOL
HpcBootApp::registerClass(WNDPROC proc)
{
TCHAR *wc_name;
WNDCLASS wc;
memset(&wc, 0, sizeof(WNDCLASS));
wc_name = reinterpret_cast <TCHAR *>
(LoadString(_instance, IDS_HPCMENU, 0, 0));
wc.lpfnWndProc = proc;
wc.hInstance = _instance;
wc.hIcon = LoadIcon(_instance, MAKEINTRESOURCE(IDI_ICON));
wc.cbWndExtra = 4; // pointer of `this`
wc.hbrBackground= static_cast <HBRUSH>(GetStockObject(LTGRAY_BRUSH));
wc.lpszClassName= wc_name;
return RegisterClass(&wc);
}
//
// Debug support.
//
void
_bitdisp(uint32_t a, int s, int e, int m, int c)
{
uint32_t j, j1;
int i, n;
DPRINTF_SETUP();
n = 31; // 32bit only.
j1 = 1 << n;
e = e ? e : n;
for (j = j1, i = n; j > 0; j >>=1, i--) {
if (i > e || i < s) {
DPRINTF((TEXT("%c"), a & j ? '+' : '-'));
} else {
DPRINTF((TEXT("%c"), a & j ? '|' : '.'));
}
}
if (m) {
DPRINTF((TEXT("[%s]"),(char*)m));
}
DPRINTF((TEXT(" [0x%08x]"), a));
if (c) {
for (j = j1, i = n; j > 0; j >>=1, i--) {
if (!(i > e || i < s) &&(a & j)) {
DPRINTF((TEXT(" %d"), i));
}
}
}
DPRINTF((TEXT(" %d\n"), a));
}
void
_dbg_bit_print(uint32_t reg, uint32_t mask, const char *name)
{
static const char onoff[3] = "_x";
DPRINTF_SETUP();
DPRINTF((TEXT("%S[%c] "), name, onoff[reg & mask ? 1 : 0]));
}
|