Home | History | Annotate | Line # | Download | only in hpcboot
hpcboot.cpp revision 1.1.4.1
      1  1.1.4.1  nathanw /*	$NetBSD: hpcboot.cpp,v 1.1.4.1 2001/04/09 01:52:37 nathanw Exp $	*/
      2      1.1      uch 
      3      1.1      uch /*-
      4      1.1      uch  * Copyright (c) 2001 The NetBSD Foundation, Inc.
      5      1.1      uch  * All rights reserved.
      6      1.1      uch  *
      7      1.1      uch  * This code is derived from software contributed to The NetBSD Foundation
      8      1.1      uch  * by UCHIYAMA Yasushi.
      9      1.1      uch  *
     10      1.1      uch  * Redistribution and use in source and binary forms, with or without
     11      1.1      uch  * modification, are permitted provided that the following conditions
     12      1.1      uch  * are met:
     13      1.1      uch  * 1. Redistributions of source code must retain the above copyright
     14      1.1      uch  *    notice, this list of conditions and the following disclaimer.
     15      1.1      uch  * 2. Redistributions in binary form must reproduce the above copyright
     16      1.1      uch  *    notice, this list of conditions and the following disclaimer in the
     17      1.1      uch  *    documentation and/or other materials provided with the distribution.
     18      1.1      uch  * 3. All advertising materials mentioning features or use of this software
     19      1.1      uch  *    must display the following acknowledgement:
     20      1.1      uch  *        This product includes software developed by the NetBSD
     21      1.1      uch  *        Foundation, Inc. and its contributors.
     22      1.1      uch  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23      1.1      uch  *    contributors may be used to endorse or promote products derived
     24      1.1      uch  *    from this software without specific prior written permission.
     25      1.1      uch  *
     26      1.1      uch  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27      1.1      uch  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28      1.1      uch  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29      1.1      uch  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30      1.1      uch  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31      1.1      uch  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32      1.1      uch  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33      1.1      uch  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34      1.1      uch  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35      1.1      uch  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36      1.1      uch  * POSSIBILITY OF SUCH DAMAGE.
     37      1.1      uch  */
     38      1.1      uch 
     39      1.1      uch #include <hpcmenu.h>
     40      1.1      uch #include <hpcboot.h>
     41      1.1      uch 
     42      1.1      uch #include <menu/window.h>
     43      1.1      uch #include <menu/rootwindow.h>
     44      1.1      uch 
     45      1.1      uch #include <console.h>
     46      1.1      uch #include <arch.h>
     47      1.1      uch #include <memory.h>
     48      1.1      uch #include <file.h>
     49      1.1      uch #include <load.h>
     50      1.1      uch 
     51      1.1      uch #include <boot.h>
     52      1.1      uch 
     53      1.1      uch int WINAPI
     54      1.1      uch WinMain(HINSTANCE instance, HINSTANCE prev_instance,
     55      1.1      uch 	LPTSTR cmd_line, int window_show)
     56      1.1      uch {
     57      1.1      uch 	HpcMenuInterface::Instance();
     58      1.1      uch 	HpcBootApp *app = 0;	// Application body.
     59      1.1      uch 	int ret = 0;
     60      1.1      uch 
     61      1.1      uch 	InitCommonControls();
     62      1.1      uch 
     63      1.1      uch 	app = new HpcBootApp(instance);
     64      1.1      uch 	app->_cons = Console::Instance();
     65      1.1      uch 	app->_root = new RootWindow(*app);
     66      1.1      uch 
     67      1.1      uch 	if (!app->registerClass(reinterpret_cast <WNDPROC>(Window::_wnd_proc)))
     68      1.1      uch 		goto failed;
     69      1.1      uch 
     70      1.1      uch 	if (!app->_root->create(0))
     71      1.1      uch 		goto failed;
     72      1.1      uch 
     73      1.1      uch 	Boot::Instance();
     74      1.1      uch 
     75      1.1      uch 	ret = app->run();
     76      1.1      uch 	// NOTREACHED
     77      1.1      uch 
     78      1.1      uch  failed:
     79      1.1      uch 
     80      1.1      uch 	Boot::Destroy();
     81      1.1      uch 	if (app->_root)
     82      1.1      uch 		delete app->_root;
     83      1.1      uch 	delete app;
     84      1.1      uch 	Console::Destroy();
     85      1.1      uch 	HpcMenuInterface::Destroy();
     86      1.1      uch 
     87      1.1      uch 	return ret;
     88      1.1      uch }
     89      1.1      uch 
     90      1.1      uch void
     91      1.1      uch hpcboot(void *arg, struct HpcMenuInterface::HpcMenuPreferences &pref)
     92      1.1      uch {
     93      1.1      uch 	size_t sz = 0;
     94      1.1      uch 	paddr_t p = 0;
     95      1.1      uch 	Boot &f = Boot::Instance();
     96      1.1      uch 	HpcMenuInterface &menu = HpcMenuInterface::Instance();
     97      1.1      uch 	Console *_cons = Console::Instance();
     98      1.1      uch 	TCHAR *error_message = 0;
     99      1.1      uch 
    100      1.1      uch 	menu.progress();
    101      1.1      uch 	if (!f.setup(pref))
    102      1.1      uch 		return;
    103      1.1      uch 
    104      1.1      uch 	menu.progress();
    105      1.1      uch 	if (!f.create())
    106      1.1      uch 		return;
    107      1.1      uch 
    108      1.1      uch 	menu.progress();
    109      1.1      uch 	if (!f._arch->init()) {
    110      1.1      uch 		error_message = TEXT("architecture initialize failed.\n");
    111      1.1      uch 		goto failed;
    112      1.1      uch 	}
    113      1.1      uch 
    114      1.1      uch 	f._arch->systemInfo();
    115      1.1      uch 
    116      1.1      uch 	menu.progress();
    117      1.1      uch 	// kernel / file system image directory.
    118      1.1      uch 	if (!f._file->setRoot(f.args.fileRoot)) {
    119      1.1      uch 		error_message = TEXT("couldn't set root directory.\n");
    120      1.1      uch 		goto failed;
    121      1.1      uch 	}
    122      1.1      uch 
    123      1.1      uch 	// open file system image.
    124      1.1      uch 	if (f.args.loadmfs)
    125      1.1      uch 	{
    126      1.1      uch 		if (!f._file->open(f.args.mfsName)) {
    127      1.1      uch 			error_message =
    128      1.1      uch 				TEXT("couldn't open file system image.\n");
    129      1.1      uch 			goto failed;
    130      1.1      uch 		}
    131      1.1      uch 		sz = f._file->size();
    132      1.1      uch 		f._file->close();
    133      1.1      uch 	}
    134      1.1      uch 
    135      1.1      uch 	menu.progress();
    136      1.1      uch 	if (!f._file->open(f.args.fileName)) {
    137      1.1      uch 		error_message = TEXT("couldn't open kernel image.\n");
    138      1.1      uch 		goto failed;
    139      1.1      uch 	}
    140      1.1      uch 
    141      1.1      uch 	menu.progress();
    142      1.1      uch 	// put kernel to loader.
    143      1.1      uch 	if (!f.attachLoader())
    144      1.1      uch 		goto failed;
    145      1.1      uch 
    146      1.1      uch 	if (!f._loader->setFile(f._file)) {
    147      1.1      uch 		error_message = TEXT("couldn't initialize loader.\n");
    148      1.1      uch 		goto failed;
    149      1.1      uch 	}
    150      1.1      uch 
    151      1.1      uch 	menu.progress();
    152      1.1      uch 	sz += f._loader->memorySize();
    153      1.1      uch 
    154      1.1      uch 	// allocate required memory.
    155      1.1      uch 	if (!f._arch->allocateMemory(sz)) {
    156      1.1      uch 		error_message = TEXT("couldn't allocate memory.\n");
    157      1.1      uch 		goto failed;
    158      1.1      uch 	}
    159      1.1      uch 
    160      1.1      uch 	menu.progress();
    161      1.1      uch 	// load kernel to memory.
    162      1.1      uch 	if (!f._arch->setupLoader()) {
    163      1.1      uch 		error_message = TEXT("couldn't set up loader.\n");
    164      1.1      uch 		goto failed;
    165      1.1      uch 	}
    166      1.1      uch 
    167      1.1      uch 	menu.progress();
    168      1.1      uch 	if (!f._loader->load()) {
    169      1.1      uch 		error_message =
    170      1.1      uch 			TEXT("couldn't load kernel image to memory.\n");
    171      1.1      uch 		goto failed;
    172      1.1      uch 	}
    173      1.1      uch 	menu.progress();
    174  1.1.4.1  nathanw 	f._file->close();
    175      1.1      uch 
    176      1.1      uch 	// load file system image to memory
    177      1.1      uch 	if (f.args.loadmfs) {
    178      1.1      uch 		f._file->open(f.args.mfsName);
    179      1.1      uch 		f._loader->loadExtData();
    180      1.1      uch 		f._file->close();
    181      1.1      uch 	}
    182      1.1      uch 	f._loader->loadEnd();
    183      1.1      uch 
    184      1.1      uch 	// setup arguments for kernel.
    185      1.1      uch 	p = f._arch->setupBootInfo(*f._loader);
    186      1.1      uch 
    187      1.1      uch 	menu.progress();
    188      1.1      uch 
    189      1.1      uch 	f._loader->tagDump(3); // dump page chain.(print first 3 links)
    190      1.1      uch 
    191      1.1      uch 	// jump to kernel entry.
    192      1.1      uch 	if (menu._pref.pause_before_boot) {
    193      1.1      uch 		if (MessageBox(menu._root->_window, TEXT("Push OK to boot."),
    194      1.1      uch 			       TEXT("Last chance..."), MB_YESNO) != IDYES)
    195      1.1      uch 			goto failed;
    196      1.1      uch 	}
    197      1.1      uch 
    198      1.1      uch 	f._arch->jump(p, f._loader->tagStart());
    199      1.1      uch 	// NOTREACHED
    200      1.1      uch 
    201      1.1      uch  failed:
    202      1.1      uch 	if (error_message == 0)
    203      1.1      uch 		error_message = TEXT("can't jump to kernel.\n");
    204  1.1.4.1  nathanw 	f._file->close();
    205      1.1      uch 	MessageBox(menu._root->_window, error_message,
    206      1.1      uch 		   TEXT("BOOT FAILED"), 0);
    207      1.1      uch }
    208      1.1      uch 
    209      1.1      uch //
    210      1.1      uch // HPCBOOT main loop
    211      1.1      uch //
    212      1.1      uch int
    213      1.1      uch HpcBootApp::run(void)
    214      1.1      uch {
    215      1.1      uch 	MSG msg;
    216      1.1      uch 	HpcMenuInterface &menu = HpcMenuInterface::Instance();
    217      1.1      uch 
    218      1.1      uch 	while (GetMessage(&msg, 0, 0, 0)) {
    219      1.1      uch 		// cancel auto-boot.
    220      1.1      uch 		if (menu._pref.auto_boot > 0 && _root &&
    221      1.1      uch 		    (msg.message == WM_KEYDOWN ||
    222      1.1      uch 		     msg.message == WM_LBUTTONDOWN)) {
    223      1.1      uch 			_root->disableTimer();
    224      1.1      uch 		}
    225      1.1      uch 		if (!_root->isDialogMessage(msg)) {
    226      1.1      uch 			TranslateMessage(&msg);
    227      1.1      uch 			DispatchMessage(&msg);
    228      1.1      uch 		}
    229      1.1      uch 	}
    230      1.1      uch 	return msg.wParam;
    231      1.1      uch }
    232      1.1      uch 
    233      1.1      uch BOOL
    234      1.1      uch HpcBootApp::registerClass(WNDPROC proc)
    235      1.1      uch {
    236      1.1      uch 	TCHAR *wc_name;
    237      1.1      uch 	WNDCLASS wc;
    238      1.1      uch 
    239      1.1      uch 	memset(&wc, 0, sizeof(WNDCLASS));
    240      1.1      uch 	wc_name		= reinterpret_cast <TCHAR *>
    241      1.1      uch 		(LoadString(_instance, IDS_HPCMENU, 0, 0));
    242      1.1      uch 	wc.lpfnWndProc	= proc;
    243      1.1      uch 	wc.hInstance	= _instance;
    244      1.1      uch 	wc.hIcon	= LoadIcon(_instance, MAKEINTRESOURCE(IDI_ICON));
    245      1.1      uch 	wc.cbWndExtra	= 4;		// pointer of `this`
    246      1.1      uch 	wc.hbrBackground= static_cast <HBRUSH>(GetStockObject(LTGRAY_BRUSH));
    247      1.1      uch 	wc.lpszClassName= wc_name;
    248      1.1      uch 
    249      1.1      uch 	return RegisterClass(&wc);
    250      1.1      uch }
    251