1 /* $NetBSD: hpcboot.cpp,v 1.19 2006/03/05 04:05:39 uwe Exp $ */
4 * Copyright (c) 2001, 2002, 2004 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
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.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
35 #include <menu/window.h>
36 #include <menu/rootwindow.h>
46 #include "../binary/build_number.h"
49 OSVERSIONINFO WinCEVersion
;
51 OSVERSIONINFOW WinCEVersion
;
55 WinMain(HINSTANCE instance
, HINSTANCE prev_instance
,
56 LPTSTR cmd_line
, int window_show
)
58 HpcMenuInterface::Instance(); // Menu System
59 HpcBootApp
*app
= 0; // Application body.
64 app
= new HpcBootApp(instance
);
65 app
->_cons
= Console::Instance();
66 app
->_root
= new RootWindow(*app
);
68 if (!app
->registerClass(reinterpret_cast <WNDPROC
>(Window::_wnd_proc
)))
71 if (!app
->_root
->create(0))
74 Boot::Instance(); // Boot loader
76 ret
= app
->run(); // Main loop.
86 HpcMenuInterface::Destroy();
99 TCHAR
*error_message
= 0;
101 HpcMenuInterface
&menu
= HPC_MENU
;
102 Boot
&f
= Boot::Instance();
104 // Open serial port for kernel KGDB.
105 SerialConsole::OpenCOM1();
109 error_message
= TEXT("Architecture not supported.\n");
115 error_message
= TEXT("Architecture ops. not found.\n");
119 // Now we can write console which user specified.
122 DPRINTF((TEXT("hpcboot build number: %d\n"),
123 HPCBOOT_BUILD_NUMBER
));
124 DPRINTF((TEXT("%s (cpu=0x%08x machine=0x%08x)\n"),
125 HPC_MENU
.platform_get(HPC_MENU
.platform_default()),
126 HPC_PREFERENCE
.platid_hi
, HPC_PREFERENCE
.platid_lo
));
130 if (!f
._arch
->init()) {
131 error_message
= TEXT("Architecture initialize failed.\n");
135 f
._arch
->systemInfo();
138 // kernel / file system image directory.
139 if (!f
._file
->setRoot(f
.args
.fileRoot
)) {
140 error_message
= TEXT("Can't set root directory.\n");
144 // determine the size of file system image.
147 if (!f
._file
->open(f
.args
.mfsName
)) {
149 TEXT("Can't open file system image.\n");
152 sz
= f
._file
->realsize();
153 sz
= f
._mem
->roundPage(sz
);
158 if (!f
._file
->open(f
.args
.fileName
)) {
159 error_message
= TEXT("Can't open kernel image.\n");
164 // put kernel to loader.
165 if (!f
.attachLoader()) {
166 error_message
= TEXT("Can't attach loader.\n");
167 goto file_close_exit
;
170 if (!f
._loader
->setFile(f
._file
)) {
171 error_message
= TEXT("Can't initialize loader.\n");
172 goto file_close_exit
;
176 sz
+= f
._mem
->roundPage(f
._loader
->memorySize());
178 // allocate required memory.
179 if (!f
._arch
->allocateMemory(sz
)) {
180 error_message
= TEXT("Can't allocate memory.\n");
181 goto file_close_exit
;
185 // load kernel to memory.
186 if (!f
._arch
->setupLoader()) {
187 error_message
= TEXT("Can't set up loader.\n");
188 goto file_close_exit
;
192 if (!f
._loader
->load()) {
193 error_message
= TEXT("Can't load kernel image to memory.\n");
194 goto file_close_exit
;
199 // load file system image to memory
200 if (f
.args
.loadmfs
) {
201 if (!f
._file
->open(f
.args
.mfsName
)) {
203 TEXT("Can't open file system image.\n");
206 if (!f
._loader
->loadExtData()) {
208 TEXT("Can't load file system image to memory.\n");
209 goto file_close_exit
;
213 f
._loader
->loadEnd();
215 // setup arguments for kernel.
216 p
= f
._arch
->setupBootInfo(*f
._loader
);
220 f
._loader
->tagDump(3); // dump page chain.(print first 3 links)
222 // jump to kernel entry.
223 if (HPC_PREFERENCE
.pause_before_boot
) {
224 if (MessageBox(menu
._root
->_window
, TEXT("Push YES to boot."),
225 TEXT("Last chance..."),
226 MB_ICONWARNING
| MB_YESNO
) != IDYES
)
228 error_message
= TEXT("Canceled by user.\n");
231 // redraw areas damaged by the dialog
232 UpdateWindow(menu
._root
->_window
);
235 f
._arch
->jump(p
, f
._loader
->tagStart());
237 error_message
= TEXT("Can't jump to the kernel.\n");
243 if (error_message
== 0)
244 error_message
= TEXT("Unknown error?\n");
245 MessageBox(menu
._root
->_window
, error_message
,
246 TEXT("BOOT FAILED"), MB_ICONERROR
| MB_OK
);
248 menu
.unprogress(); // rewind progress bar
255 HpcBootApp::run(void)
259 while (GetMessage(&msg
, 0, 0, 0)) {
261 if (HPC_PREFERENCE
.auto_boot
> 0 && _root
&&
262 (msg
.message
== WM_KEYDOWN
||
263 msg
.message
== WM_LBUTTONDOWN
)) {
264 _root
->disableTimer();
266 if (!_root
->isDialogMessage(msg
)) {
267 TranslateMessage(&msg
);
268 DispatchMessage(&msg
);
275 HpcBootApp::registerClass(WNDPROC proc
)
280 memset(&wc
, 0, sizeof(WNDCLASS
));
281 wc_name
= reinterpret_cast <TCHAR
*>
282 (LoadString(_instance
, IDS_HPCMENU
, 0, 0));
283 wc
.lpfnWndProc
= proc
;
284 wc
.hInstance
= _instance
;
285 wc
.hIcon
= LoadIcon(_instance
, MAKEINTRESOURCE(IDI_ICON
));
286 wc
.cbWndExtra
= 4; // pointer of `this`
287 wc
.hbrBackground
= static_cast <HBRUSH
>(GetStockObject(LTGRAY_BRUSH
));
288 wc
.lpszClassName
= wc_name
;
290 return RegisterClass(&wc
);
298 _bitdisp(uint32_t a
, int s
, int e
, int m
, int c
)
305 n
= 31; // 32bit only.
308 for (j
= j1
, i
= n
; j
> 0; j
>>=1, i
--) {
309 if (i
> e
|| i
< s
) {
310 DPRINTF((TEXT("%c"), a
& j
? '+' : '-'));
312 DPRINTF((TEXT("%c"), a
& j
? '|' : '.'));
316 DPRINTF((TEXT("[%s]"),(char*)m
));
319 DPRINTF((TEXT(" [0x%08x]"), a
));
322 for (j
= j1
, i
= n
; j
> 0; j
>>=1, i
--) {
323 if (!(i
> e
|| i
< s
) &&(a
& j
)) {
324 DPRINTF((TEXT(" %d"), i
));
329 DPRINTF((TEXT(" %d\n"), a
));
333 _dbg_bit_print(uint32_t reg
, uint32_t mask
, const char *name
)
335 static const char onoff
[3] = "_x";
339 DPRINTF((TEXT("%S[%c] "), name
, onoff
[reg
& mask
? 1 : 0]));