No empty .Rs/.Re
[netbsd-mini2440.git] / sys / arch / hpc / stand / hpcboot / hpcboot.cpp
blobf5e7f59fb37d79a8bd6c84460f03b161ccd04ab1
1 /* $NetBSD: hpcboot.cpp,v 1.19 2006/03/05 04:05:39 uwe Exp $ */
3 /*-
4 * Copyright (c) 2001, 2002, 2004 The NetBSD Foundation, Inc.
5 * All rights reserved.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by UCHIYAMA Yasushi.
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.
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.
32 #include <hpcmenu.h>
33 #include <hpcboot.h>
35 #include <menu/window.h>
36 #include <menu/rootwindow.h>
38 #include <console.h>
39 #include <arch.h>
40 #include <memory.h>
41 #include <file.h>
42 #include <load.h>
44 #include <boot.h>
46 #include "../binary/build_number.h"
48 #if _WIN32_WCE <= 200
49 OSVERSIONINFO WinCEVersion;
50 #else
51 OSVERSIONINFOW WinCEVersion;
52 #endif
54 int WINAPI
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.
60 int ret = 0;
62 InitCommonControls();
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)))
69 goto failed;
71 if (!app->_root->create(0))
72 goto failed;
74 Boot::Instance(); // Boot loader
76 ret = app->run(); // Main loop.
77 // NOTREACHED
79 failed:
81 Boot::Destroy();
82 if (app->_root)
83 delete app->_root;
84 delete app;
85 Console::Destroy();
86 HpcMenuInterface::Destroy();
88 return ret;
92 // boot sequence.
94 void
95 hpcboot(void *arg)
97 size_t sz = 0;
98 paddr_t p = 0;
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();
107 menu.progress("0");
108 if (!f.setup()) {
109 error_message = TEXT("Architecture not supported.\n");
110 goto failed_exit;
113 menu.progress("1");
114 if (!f.create()) {
115 error_message = TEXT("Architecture ops. not found.\n");
116 goto failed_exit;
119 // Now we can write console which user specified.
121 DPRINTF_SETUP();
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));
129 menu.progress("2");
130 if (!f._arch->init()) {
131 error_message = TEXT("Architecture initialize failed.\n");
132 goto failed_exit;
135 f._arch->systemInfo();
137 menu.progress("3");
138 // kernel / file system image directory.
139 if (!f._file->setRoot(f.args.fileRoot)) {
140 error_message = TEXT("Can't set root directory.\n");
141 goto failed_exit;
144 // determine the size of file system image.
145 if (f.args.loadmfs)
147 if (!f._file->open(f.args.mfsName)) {
148 error_message =
149 TEXT("Can't open file system image.\n");
150 goto failed_exit;
152 sz = f._file->realsize();
153 sz = f._mem->roundPage(sz);
154 f._file->close();
157 menu.progress("4");
158 if (!f._file->open(f.args.fileName)) {
159 error_message = TEXT("Can't open kernel image.\n");
160 goto failed_exit;
163 menu.progress("5");
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;
175 menu.progress("6");
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;
184 menu.progress("7");
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;
191 menu.progress("8");
192 if (!f._loader->load()) {
193 error_message = TEXT("Can't load kernel image to memory.\n");
194 goto file_close_exit;
196 menu.progress("9");
197 f._file->close();
199 // load file system image to memory
200 if (f.args.loadmfs) {
201 if (!f._file->open(f.args.mfsName)) {
202 error_message =
203 TEXT("Can't open file system image.\n");
204 goto failed_exit;
206 if (!f._loader->loadExtData()) {
207 error_message =
208 TEXT("Can't load file system image to memory.\n");
209 goto file_close_exit;
211 f._file->close();
213 f._loader->loadEnd();
215 // setup arguments for kernel.
216 p = f._arch->setupBootInfo(*f._loader);
218 menu.progress("10");
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");
229 goto failed_exit;
231 // redraw areas damaged by the dialog
232 UpdateWindow(menu._root->_window);
235 f._arch->jump(p, f._loader->tagStart());
236 // NOTREACHED
237 error_message = TEXT("Can't jump to the kernel.\n");
239 file_close_exit:
240 f._file->close();
242 failed_exit:
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
252 // HPCBOOT main loop
255 HpcBootApp::run(void)
257 MSG msg;
259 while (GetMessage(&msg, 0, 0, 0)) {
260 // cancel auto-boot.
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);
271 return msg.wParam;
274 BOOL
275 HpcBootApp::registerClass(WNDPROC proc)
277 TCHAR *wc_name;
278 WNDCLASS wc;
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);
295 // Debug support.
297 void
298 _bitdisp(uint32_t a, int s, int e, int m, int c)
300 uint32_t j, j1;
301 int i, n;
303 DPRINTF_SETUP();
305 n = 31; // 32bit only.
306 j1 = 1 << n;
307 e = e ? e : n;
308 for (j = j1, i = n; j > 0; j >>=1, i--) {
309 if (i > e || i < s) {
310 DPRINTF((TEXT("%c"), a & j ? '+' : '-'));
311 } else {
312 DPRINTF((TEXT("%c"), a & j ? '|' : '.'));
315 if (m) {
316 DPRINTF((TEXT("[%s]"),(char*)m));
319 DPRINTF((TEXT(" [0x%08x]"), a));
321 if (c) {
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));
332 void
333 _dbg_bit_print(uint32_t reg, uint32_t mask, const char *name)
335 static const char onoff[3] = "_x";
337 DPRINTF_SETUP();
339 DPRINTF((TEXT("%S[%c] "), name, onoff[reg & mask ? 1 : 0]));