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