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