1*bd926f64Such /* $NetBSD: hpcboot.cpp,v 1.3 2001/04/24 19:27:59 uch Exp $ */ 29173eae7Such 39173eae7Such /*- 49173eae7Such * Copyright (c) 2001 The NetBSD Foundation, Inc. 59173eae7Such * All rights reserved. 69173eae7Such * 79173eae7Such * This code is derived from software contributed to The NetBSD Foundation 89173eae7Such * by UCHIYAMA Yasushi. 99173eae7Such * 109173eae7Such * Redistribution and use in source and binary forms, with or without 119173eae7Such * modification, are permitted provided that the following conditions 129173eae7Such * are met: 139173eae7Such * 1. Redistributions of source code must retain the above copyright 149173eae7Such * notice, this list of conditions and the following disclaimer. 159173eae7Such * 2. Redistributions in binary form must reproduce the above copyright 169173eae7Such * notice, this list of conditions and the following disclaimer in the 179173eae7Such * documentation and/or other materials provided with the distribution. 189173eae7Such * 3. All advertising materials mentioning features or use of this software 199173eae7Such * must display the following acknowledgement: 209173eae7Such * This product includes software developed by the NetBSD 219173eae7Such * Foundation, Inc. and its contributors. 229173eae7Such * 4. Neither the name of The NetBSD Foundation nor the names of its 239173eae7Such * contributors may be used to endorse or promote products derived 249173eae7Such * from this software without specific prior written permission. 259173eae7Such * 269173eae7Such * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 279173eae7Such * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 289173eae7Such * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 299173eae7Such * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 309173eae7Such * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 319173eae7Such * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 329173eae7Such * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 339173eae7Such * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 349173eae7Such * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 359173eae7Such * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 369173eae7Such * POSSIBILITY OF SUCH DAMAGE. 379173eae7Such */ 389173eae7Such 399173eae7Such #include <hpcmenu.h> 409173eae7Such #include <hpcboot.h> 419173eae7Such 429173eae7Such #include <menu/window.h> 439173eae7Such #include <menu/rootwindow.h> 449173eae7Such 459173eae7Such #include <console.h> 469173eae7Such #include <arch.h> 479173eae7Such #include <memory.h> 489173eae7Such #include <file.h> 499173eae7Such #include <load.h> 509173eae7Such 519173eae7Such #include <boot.h> 529173eae7Such 539173eae7Such int WINAPI 549173eae7Such WinMain(HINSTANCE instance, HINSTANCE prev_instance, 559173eae7Such LPTSTR cmd_line, int window_show) 569173eae7Such { 57*bd926f64Such HpcMenuInterface::Instance(); // Menu System 589173eae7Such HpcBootApp *app = 0; // Application body. 599173eae7Such int ret = 0; 609173eae7Such 619173eae7Such InitCommonControls(); 629173eae7Such 639173eae7Such app = new HpcBootApp(instance); 649173eae7Such app->_cons = Console::Instance(); 659173eae7Such app->_root = new RootWindow(*app); 669173eae7Such 679173eae7Such if (!app->registerClass(reinterpret_cast <WNDPROC>(Window::_wnd_proc))) 689173eae7Such goto failed; 699173eae7Such 709173eae7Such if (!app->_root->create(0)) 719173eae7Such goto failed; 729173eae7Such 73*bd926f64Such Boot::Instance(); // Boot loader 749173eae7Such 75*bd926f64Such ret = app->run(); // Main loop. 769173eae7Such // NOTREACHED 779173eae7Such 789173eae7Such failed: 799173eae7Such 809173eae7Such Boot::Destroy(); 819173eae7Such if (app->_root) 829173eae7Such delete app->_root; 839173eae7Such delete app; 849173eae7Such Console::Destroy(); 859173eae7Such HpcMenuInterface::Destroy(); 869173eae7Such 879173eae7Such return ret; 889173eae7Such } 899173eae7Such 90*bd926f64Such // 91*bd926f64Such // boot sequence. 92*bd926f64Such // 939173eae7Such void 94*bd926f64Such hpcboot(void *arg) 959173eae7Such { 969173eae7Such size_t sz = 0; 979173eae7Such paddr_t p = 0; 989173eae7Such TCHAR *error_message = 0; 999173eae7Such 100*bd926f64Such HpcMenuInterface &menu = HPC_MENU; 101*bd926f64Such Boot &f = Boot::Instance(); 102*bd926f64Such 1039173eae7Such menu.progress(); 104*bd926f64Such if (!f.setup()) 1059173eae7Such return; 1069173eae7Such 1079173eae7Such menu.progress(); 1089173eae7Such if (!f.create()) 1099173eae7Such return; 1109173eae7Such 1119173eae7Such menu.progress(); 1129173eae7Such if (!f._arch->init()) { 1139173eae7Such error_message = TEXT("architecture initialize failed.\n"); 1149173eae7Such goto failed; 1159173eae7Such } 1169173eae7Such 1179173eae7Such f._arch->systemInfo(); 1189173eae7Such 1199173eae7Such menu.progress(); 1209173eae7Such // kernel / file system image directory. 1219173eae7Such if (!f._file->setRoot(f.args.fileRoot)) { 1229173eae7Such error_message = TEXT("couldn't set root directory.\n"); 1239173eae7Such goto failed; 1249173eae7Such } 1259173eae7Such 1269173eae7Such // open file system image. 1279173eae7Such if (f.args.loadmfs) 1289173eae7Such { 1299173eae7Such if (!f._file->open(f.args.mfsName)) { 1309173eae7Such error_message = 1319173eae7Such TEXT("couldn't open file system image.\n"); 1329173eae7Such goto failed; 1339173eae7Such } 1349173eae7Such sz = f._file->size(); 1359173eae7Such f._file->close(); 1369173eae7Such } 1379173eae7Such 1389173eae7Such menu.progress(); 1399173eae7Such if (!f._file->open(f.args.fileName)) { 1409173eae7Such error_message = TEXT("couldn't open kernel image.\n"); 1419173eae7Such goto failed; 1429173eae7Such } 1439173eae7Such 1449173eae7Such menu.progress(); 1459173eae7Such // put kernel to loader. 1469173eae7Such if (!f.attachLoader()) 1479173eae7Such goto failed; 1489173eae7Such 1499173eae7Such if (!f._loader->setFile(f._file)) { 1509173eae7Such error_message = TEXT("couldn't initialize loader.\n"); 1519173eae7Such goto failed; 1529173eae7Such } 1539173eae7Such 1549173eae7Such menu.progress(); 1559173eae7Such sz += f._loader->memorySize(); 1569173eae7Such 1579173eae7Such // allocate required memory. 1589173eae7Such if (!f._arch->allocateMemory(sz)) { 1599173eae7Such error_message = TEXT("couldn't allocate memory.\n"); 1609173eae7Such goto failed; 1619173eae7Such } 1629173eae7Such 1639173eae7Such menu.progress(); 1649173eae7Such // load kernel to memory. 1659173eae7Such if (!f._arch->setupLoader()) { 1669173eae7Such error_message = TEXT("couldn't set up loader.\n"); 1679173eae7Such goto failed; 1689173eae7Such } 1699173eae7Such 1709173eae7Such menu.progress(); 1719173eae7Such if (!f._loader->load()) { 1729173eae7Such error_message = 1739173eae7Such TEXT("couldn't load kernel image to memory.\n"); 1749173eae7Such goto failed; 1759173eae7Such } 1769173eae7Such menu.progress(); 17787aeed61Such f._file->close(); 1789173eae7Such 1799173eae7Such // load file system image to memory 1809173eae7Such if (f.args.loadmfs) { 1819173eae7Such f._file->open(f.args.mfsName); 1829173eae7Such f._loader->loadExtData(); 1839173eae7Such f._file->close(); 1849173eae7Such } 1859173eae7Such f._loader->loadEnd(); 1869173eae7Such 1879173eae7Such // setup arguments for kernel. 1889173eae7Such p = f._arch->setupBootInfo(*f._loader); 1899173eae7Such 1909173eae7Such menu.progress(); 1919173eae7Such 1929173eae7Such f._loader->tagDump(3); // dump page chain.(print first 3 links) 1939173eae7Such 1949173eae7Such // jump to kernel entry. 195*bd926f64Such if (HPC_PREFERENCE.pause_before_boot) { 1969173eae7Such if (MessageBox(menu._root->_window, TEXT("Push OK to boot."), 1979173eae7Such TEXT("Last chance..."), MB_YESNO) != IDYES) 1989173eae7Such goto failed; 1999173eae7Such } 2009173eae7Such 2019173eae7Such f._arch->jump(p, f._loader->tagStart()); 2029173eae7Such // NOTREACHED 2039173eae7Such 2049173eae7Such failed: 2059173eae7Such if (error_message == 0) 2069173eae7Such error_message = TEXT("can't jump to kernel.\n"); 20787aeed61Such f._file->close(); 2089173eae7Such MessageBox(menu._root->_window, error_message, 2099173eae7Such TEXT("BOOT FAILED"), 0); 2109173eae7Such } 2119173eae7Such 2129173eae7Such // 2139173eae7Such // HPCBOOT main loop 2149173eae7Such // 2159173eae7Such int 2169173eae7Such HpcBootApp::run(void) 2179173eae7Such { 2189173eae7Such MSG msg; 2199173eae7Such 2209173eae7Such while (GetMessage(&msg, 0, 0, 0)) { 2219173eae7Such // cancel auto-boot. 222*bd926f64Such if (HPC_PREFERENCE.auto_boot > 0 && _root && 2239173eae7Such (msg.message == WM_KEYDOWN || 2249173eae7Such msg.message == WM_LBUTTONDOWN)) { 2259173eae7Such _root->disableTimer(); 2269173eae7Such } 2279173eae7Such if (!_root->isDialogMessage(msg)) { 2289173eae7Such TranslateMessage(&msg); 2299173eae7Such DispatchMessage(&msg); 2309173eae7Such } 2319173eae7Such } 2329173eae7Such return msg.wParam; 2339173eae7Such } 2349173eae7Such 2359173eae7Such BOOL 2369173eae7Such HpcBootApp::registerClass(WNDPROC proc) 2379173eae7Such { 2389173eae7Such TCHAR *wc_name; 2399173eae7Such WNDCLASS wc; 2409173eae7Such 2419173eae7Such memset(&wc, 0, sizeof(WNDCLASS)); 2429173eae7Such wc_name = reinterpret_cast <TCHAR *> 2439173eae7Such (LoadString(_instance, IDS_HPCMENU, 0, 0)); 2449173eae7Such wc.lpfnWndProc = proc; 2459173eae7Such wc.hInstance = _instance; 2469173eae7Such wc.hIcon = LoadIcon(_instance, MAKEINTRESOURCE(IDI_ICON)); 2479173eae7Such wc.cbWndExtra = 4; // pointer of `this` 2489173eae7Such wc.hbrBackground= static_cast <HBRUSH>(GetStockObject(LTGRAY_BRUSH)); 2499173eae7Such wc.lpszClassName= wc_name; 2509173eae7Such 2519173eae7Such return RegisterClass(&wc); 2529173eae7Such } 253