hpcmenu.h revision 1.4 1 1.4 uch /* -*-C++-*- $NetBSD: hpcmenu.h,v 1.4 2001/03/25 17:13:16 uch 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 #ifndef _HPCBOOT_MENU_H_
40 1.1 uch #define _HPCBOOT_MENU_H_
41 1.1 uch
42 1.1 uch #include <hpcdefs.h>
43 1.1 uch
44 1.1 uch // forward declaration.
45 1.1 uch class Console;
46 1.1 uch class HpcBootApp;
47 1.1 uch class RootWindow;
48 1.1 uch class BootButton;
49 1.1 uch class CancelButton;
50 1.1 uch class ProgressBar;
51 1.1 uch class TabWindowBase;
52 1.1 uch class MainTabWindow;
53 1.1 uch class OptionTabWindow;
54 1.1 uch class ConsoleTabWindow;
55 1.1 uch struct bootinfo;
56 1.1 uch
57 1.1 uch // Application
58 1.1 uch class HpcBootApp {
59 1.1 uch public:
60 1.1 uch HINSTANCE _instance;
61 1.1 uch HWND _cmdbar;
62 1.1 uch RootWindow *_root;
63 1.1 uch Console *_cons;
64 1.1 uch int _cx_char, _cy_char; // 5, 14
65 1.1 uch
66 1.1 uch private:
67 1.1 uch void _get_font_size(void) {
68 1.1 uch HDC hdc = GetDC(0);
69 1.1 uch TEXTMETRIC tm;
70 1.1 uch SelectObject(hdc, GetStockObject(SYSTEM_FONT));
71 1.1 uch GetTextMetrics(hdc, &tm);
72 1.1 uch _cx_char = tm.tmAveCharWidth;
73 1.1 uch _cy_char = tm.tmHeight + tm.tmExternalLeading;
74 1.1 uch ReleaseDC(0, hdc);
75 1.1 uch }
76 1.1 uch
77 1.1 uch public:
78 1.1 uch explicit HpcBootApp(HINSTANCE instance) : _instance(instance) {
79 1.1 uch _root = 0;
80 1.1 uch _cmdbar = 0;
81 1.1 uch _get_font_size();
82 1.1 uch }
83 1.1 uch virtual ~HpcBootApp(void) { /* NO-OP */ }
84 1.1 uch
85 1.1 uch BOOL registerClass(WNDPROC proc);
86 1.1 uch int run(void);
87 1.1 uch };
88 1.1 uch
89 1.1 uch // internal representation of user input.
90 1.1 uch class HpcMenuInterface
91 1.1 uch {
92 1.1 uch public:
93 1.1 uch struct HpcMenuPreferences {
94 1.1 uch #define HPCBOOT_MAGIC 0x177d5753
95 1.1 uch int _magic;
96 1.1 uch int _version;
97 1.1 uch size_t _size; // size of HpcMenuPreferences structure.
98 1.1 uch int dir;
99 1.1 uch BOOL dir_user;
100 1.1 uch TCHAR dir_user_path[MAX_PATH];
101 1.1 uch BOOL kernel_user;
102 1.1 uch TCHAR kernel_user_file[MAX_PATH];
103 1.1 uch unsigned platid_hi;
104 1.1 uch unsigned platid_lo;
105 1.1 uch int rootfs;
106 1.1 uch TCHAR rootfs_file[MAX_PATH];
107 1.1 uch // kernel options.
108 1.1 uch BOOL boot_serial;
109 1.1 uch BOOL boot_verbose;
110 1.1 uch BOOL boot_single_user;
111 1.1 uch BOOL boot_ask_for_name;
112 1.1 uch // boot loader options.
113 1.1 uch int auto_boot;
114 1.1 uch BOOL reverse_video;
115 1.1 uch BOOL pause_before_boot;
116 1.1 uch BOOL load_debug_info;
117 1.1 uch BOOL safety_message;
118 1.4 uch // serial console speed
119 1.4 uch int serial_speed;
120 1.1 uch };
121 1.3 uch struct support_status {
122 1.3 uch u_int32_t cpu, machine;
123 1.3 uch const TCHAR *cause;
124 1.3 uch };
125 1.3 uch static struct support_status _unsupported[];
126 1.1 uch
127 1.1 uch RootWindow *_root;
128 1.1 uch MainTabWindow *_main;
129 1.1 uch OptionTabWindow *_option;
130 1.1 uch ConsoleTabWindow *_console;
131 1.1 uch struct HpcMenuPreferences _pref;
132 1.1 uch
133 1.1 uch struct boot_hook_args {
134 1.1 uch void(*func)(void *, struct HpcMenuPreferences &);
135 1.1 uch void *arg;
136 1.1 uch } _boot_hook;
137 1.1 uch
138 1.1 uch struct cons_hook_args {
139 1.1 uch void(*func)(void *, unsigned char);
140 1.1 uch void *arg;
141 1.1 uch } _cons_hook [4];
142 1.2 uch int _cons_parameter; // Console tab window check buttons.
143 1.1 uch
144 1.1 uch private:
145 1.1 uch static HpcMenuInterface *_instance;
146 1.1 uch
147 1.1 uch void _set_default_pref(void) {
148 1.1 uch // set default.
149 1.1 uch _pref._magic = HPCBOOT_MAGIC;
150 1.1 uch _pref.dir = 0;
151 1.1 uch _pref.dir_user = FALSE;
152 1.1 uch _pref.kernel_user = FALSE;
153 1.1 uch _pref.platid_hi = 0;
154 1.1 uch _pref.platid_lo = 0;
155 1.1 uch _pref.rootfs = 0;
156 1.4 uch wsprintf(_pref.rootfs_file, TEXT("miniroot.fs"));
157 1.1 uch _pref.boot_serial = FALSE;
158 1.1 uch _pref.boot_verbose = FALSE;
159 1.1 uch _pref.boot_single_user = FALSE;
160 1.1 uch _pref.boot_ask_for_name = FALSE;
161 1.1 uch _pref.auto_boot = 0;
162 1.1 uch _pref.reverse_video = FALSE;
163 1.1 uch _pref.pause_before_boot = TRUE;
164 1.1 uch _pref.safety_message = TRUE;
165 1.4 uch #ifdef MIPS
166 1.4 uch _pref.serial_speed = 9600; // historical reason.
167 1.4 uch #else
168 1.4 uch _pref.serial_speed = 19200;
169 1.4 uch #endif
170 1.1 uch }
171 1.1 uch enum _platform_op {
172 1.1 uch _PLATFORM_OP_GET,
173 1.1 uch _PLATFORM_OP_SET,
174 1.1 uch _PLATFORM_OP_DEFAULT
175 1.1 uch };
176 1.1 uch void *_platform(int, enum _platform_op);
177 1.1 uch
178 1.1 uch protected:
179 1.1 uch HpcMenuInterface(void) {
180 1.1 uch if (!load())
181 1.1 uch _set_default_pref();
182 1.1 uch _pref._version = HPCBOOT_VERSION;
183 1.1 uch _pref._size = sizeof(HpcMenuPreferences);
184 1.1 uch
185 1.2 uch _cons_parameter = 0;
186 1.1 uch memset(_cons_hook, 0, sizeof(struct cons_hook_args) * 4);
187 1.1 uch memset(&_boot_hook, 0, sizeof(struct boot_hook_args));
188 1.1 uch }
189 1.1 uch virtual ~HpcMenuInterface(void) { /* NO-OP */ }
190 1.1 uch
191 1.1 uch public:
192 1.1 uch static HpcMenuInterface &Instance(void);
193 1.1 uch static void Destroy(void);
194 1.1 uch
195 1.1 uch // preferences.
196 1.1 uch BOOL load(void);
197 1.1 uch BOOL save(void);
198 1.1 uch
199 1.1 uch // Boot button
200 1.1 uch // when user click `boot button' inquires all options.
201 1.1 uch void get_options(void);
202 1.1 uch enum { MAX_KERNEL_ARGS = 16 };
203 1.1 uch int setup_kernel_args(vaddr_t, paddr_t);
204 1.1 uch void setup_bootinfo(struct bootinfo &bi);
205 1.1 uch void register_boot_hook(struct boot_hook_args &arg) {
206 1.1 uch _boot_hook = arg;
207 1.1 uch }
208 1.1 uch // call architecture dependent boot function.
209 1.3 uch void boot(void);
210 1.1 uch // Progress bar.
211 1.1 uch void progress(void);
212 1.1 uch
213 1.1 uch // Console window interface.
214 1.1 uch void print(TCHAR *);
215 1.1 uch void register_cons_hook(struct cons_hook_args &arg, int id) {
216 1.1 uch if (id >= 0 && id < 4)
217 1.1 uch _cons_hook[id] = arg;
218 1.1 uch }
219 1.1 uch
220 1.1 uch // Main window options
221 1.1 uch TCHAR *dir(int);
222 1.1 uch int dir_default(void);
223 1.1 uch
224 1.1 uch // platform
225 1.1 uch TCHAR *platform_get(int n) {
226 1.1 uch return reinterpret_cast <TCHAR *>
227 1.1 uch (_platform(n, _PLATFORM_OP_GET));
228 1.1 uch }
229 1.1 uch int platform_default(void) {
230 1.1 uch return reinterpret_cast <int>
231 1.1 uch (_platform(0, _PLATFORM_OP_DEFAULT));
232 1.1 uch }
233 1.1 uch void platform_set(int n) { _platform(n, _PLATFORM_OP_SET); }
234 1.1 uch };
235 1.1 uch
236 1.1 uch #endif // _HPCBOOT_MENU_H_
237