Home | History | Annotate | Line # | Download | only in hpcboot
      1  1.14  martin /* -*-C++-*-	$NetBSD: hpcmenu.h,v 1.14 2008/04/28 20:23:20 martin Exp $	*/
      2   1.1     uch 
      3   1.1     uch /*-
      4  1.10     uch  * Copyright (c) 2001, 2004 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  *
     19   1.1     uch  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20   1.1     uch  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21   1.1     uch  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22   1.1     uch  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23   1.1     uch  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24   1.1     uch  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25   1.1     uch  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26   1.1     uch  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27   1.1     uch  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28   1.1     uch  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29   1.1     uch  * POSSIBILITY OF SUCH DAMAGE.
     30   1.1     uch  */
     31   1.1     uch 
     32   1.1     uch #ifndef _HPCBOOT_MENU_H_
     33  1.11     uch #define	_HPCBOOT_MENU_H_
     34   1.1     uch 
     35   1.1     uch #include <hpcdefs.h>
     36   1.1     uch 
     37   1.1     uch // forward declaration.
     38   1.1     uch class Console;
     39  1.11     uch class HpcBootApp;
     40   1.1     uch class RootWindow;
     41   1.1     uch class BootButton;
     42   1.1     uch class CancelButton;
     43   1.1     uch class ProgressBar;
     44   1.1     uch class TabWindowBase;
     45   1.1     uch class MainTabWindow;
     46   1.1     uch class OptionTabWindow;
     47   1.1     uch class ConsoleTabWindow;
     48   1.1     uch struct bootinfo;
     49   1.1     uch 
     50   1.1     uch // Application
     51   1.1     uch class HpcBootApp {
     52   1.1     uch public:
     53   1.1     uch 	HINSTANCE	_instance;
     54   1.1     uch 	HWND		_cmdbar;
     55   1.1     uch 	RootWindow	*_root;
     56   1.5     uch 	Console		*_cons;
     57   1.1     uch 	int		_cx_char, _cy_char; // 5, 14
     58   1.1     uch 
     59   1.1     uch private:
     60   1.1     uch 	void _get_font_size(void) {
     61   1.1     uch 		HDC hdc = GetDC(0);
     62   1.1     uch 		TEXTMETRIC tm;
     63   1.1     uch 		SelectObject(hdc, GetStockObject(SYSTEM_FONT));
     64   1.1     uch 		GetTextMetrics(hdc, &tm);
     65   1.1     uch 		_cx_char = tm.tmAveCharWidth;
     66   1.1     uch 		_cy_char = tm.tmHeight + tm.tmExternalLeading;
     67   1.1     uch 		ReleaseDC(0, hdc);
     68   1.1     uch 	}
     69   1.1     uch 
     70   1.1     uch public:
     71   1.1     uch 	explicit HpcBootApp(HINSTANCE instance) : _instance(instance) {
     72   1.1     uch 		_root	= 0;
     73   1.1     uch 		_cmdbar	= 0;
     74   1.1     uch 		_get_font_size();
     75   1.1     uch 	}
     76   1.1     uch 	virtual ~HpcBootApp(void) { /* NO-OP */ }
     77   1.1     uch 
     78   1.1     uch 	BOOL registerClass(WNDPROC proc);
     79   1.1     uch 	int run(void);
     80   1.1     uch };
     81   1.1     uch 
     82   1.1     uch // internal representation of user input.
     83   1.1     uch class HpcMenuInterface
     84   1.1     uch {
     85   1.1     uch public:
     86   1.1     uch 	struct HpcMenuPreferences {
     87  1.11     uch #define	HPCBOOT_MAGIC		0x177d5753
     88   1.1     uch 		int		_magic;
     89   1.1     uch 		int		_version;
     90   1.1     uch 		size_t	_size;	// size of HpcMenuPreferences structure.
     91   1.1     uch 		int		dir;
     92   1.1     uch 		BOOL	dir_user;
     93   1.1     uch 		TCHAR	dir_user_path[MAX_PATH];
     94   1.1     uch 		BOOL	kernel_user;
     95   1.1     uch 		TCHAR	kernel_user_file[MAX_PATH];
     96   1.1     uch 		unsigned	platid_hi;
     97   1.1     uch 		unsigned	platid_lo;
     98   1.1     uch 		int		rootfs;
     99   1.1     uch 		TCHAR	rootfs_file[MAX_PATH];
    100   1.1     uch 		// kernel options.
    101   1.1     uch 		BOOL	boot_serial;
    102   1.1     uch 		BOOL	boot_verbose;
    103   1.1     uch 		BOOL	boot_single_user;
    104   1.1     uch 		BOOL	boot_ask_for_name;
    105   1.7   enami 		BOOL	boot_debugger;
    106   1.1     uch 		// boot loader options.
    107   1.1     uch 		int		auto_boot;
    108   1.1     uch 		BOOL	reverse_video;
    109   1.1     uch 		BOOL	pause_before_boot;
    110   1.1     uch 		BOOL	load_debug_info;
    111   1.1     uch 		BOOL	safety_message;
    112   1.4     uch 		// serial console speed
    113   1.4     uch 		int	serial_speed;
    114  1.11     uch #define	MAX_BOOT_STR 256
    115   1.8     uch 		TCHAR	boot_extra[MAX_BOOT_STR];
    116   1.1     uch 	};
    117   1.3     uch 	struct support_status {
    118  1.13     uwe 		uint32_t cpu, machine;
    119   1.3     uch 		const TCHAR *cause;
    120   1.3     uch 	};
    121   1.3     uch 	static struct support_status _unsupported[];
    122   1.1     uch 
    123   1.1     uch 	RootWindow		*_root;
    124   1.1     uch 	MainTabWindow		*_main;
    125   1.5     uch 	OptionTabWindow		*_option;
    126   1.1     uch 	ConsoleTabWindow	*_console;
    127   1.1     uch 	struct HpcMenuPreferences _pref;
    128   1.1     uch 
    129   1.1     uch 	struct boot_hook_args {
    130   1.5     uch 		void(*func)(void *);
    131   1.1     uch 		void *arg;
    132   1.1     uch 	} _boot_hook;
    133   1.1     uch 
    134   1.1     uch 	struct cons_hook_args {
    135   1.1     uch 		void(*func)(void *, unsigned char);
    136   1.1     uch 		void *arg;
    137   1.1     uch 	} _cons_hook [4];
    138   1.2     uch 	int _cons_parameter; // Console tab window check buttons.
    139   1.1     uch 
    140   1.1     uch private:
    141   1.1     uch 	static HpcMenuInterface *_instance;
    142   1.1     uch 
    143   1.5     uch 	void _set_default_pref(void);
    144   1.1     uch 	enum _platform_op {
    145   1.1     uch 		_PLATFORM_OP_GET,
    146   1.1     uch 		_PLATFORM_OP_SET,
    147   1.1     uch 		_PLATFORM_OP_DEFAULT
    148   1.1     uch 	};
    149   1.1     uch 	void *_platform(int, enum _platform_op);
    150   1.1     uch 
    151   1.1     uch protected:
    152   1.5     uch 	HpcMenuInterface(void);
    153   1.1     uch 	virtual ~HpcMenuInterface(void) { /* NO-OP */ }
    154   1.1     uch 
    155   1.1     uch public:
    156   1.1     uch 	static HpcMenuInterface &Instance(void);
    157   1.1     uch 	static void Destroy(void);
    158   1.1     uch 
    159   1.1     uch 	// preferences.
    160   1.1     uch 	BOOL load(void);
    161   1.1     uch 	BOOL save(void);
    162  1.11     uch 
    163   1.1     uch 	// Boot button
    164   1.1     uch 	// when user click `boot button' inquires all options.
    165   1.1     uch 	void get_options(void);
    166   1.1     uch 	enum { MAX_KERNEL_ARGS = 16 };
    167   1.8     uch 	int setup_kernel_args(vaddr_t, paddr_t, size_t);
    168   1.1     uch 	void setup_bootinfo(struct bootinfo &bi);
    169   1.1     uch 	void register_boot_hook(struct boot_hook_args &arg) {
    170   1.1     uch 		_boot_hook = arg;
    171   1.1     uch 	}
    172   1.1     uch 	// call architecture dependent boot function.
    173   1.3     uch 	void boot(void);
    174   1.9     uwe 
    175   1.1     uch 	// Progress bar.
    176  1.10     uch 	void progress(const char * = NULL);
    177   1.9     uwe 	void unprogress(void);
    178   1.1     uch 
    179   1.1     uch 	// Console window interface.
    180   1.1     uch 	void print(TCHAR *);
    181   1.1     uch 	void register_cons_hook(struct cons_hook_args &arg, int id) {
    182   1.1     uch 		if (id >= 0 && id < 4)
    183   1.1     uch 			_cons_hook[id] = arg;
    184   1.1     uch 	}
    185   1.1     uch 
    186   1.1     uch 	// Main window options
    187   1.1     uch 	TCHAR *dir(int);
    188   1.1     uch 	int dir_default(void);
    189  1.11     uch 
    190   1.1     uch 	// platform
    191   1.1     uch 	TCHAR *platform_get(int n) {
    192   1.1     uch 		return reinterpret_cast <TCHAR *>
    193   1.6     uch 		    (_platform(n, _PLATFORM_OP_GET));
    194   1.1     uch 	}
    195   1.1     uch 	int platform_default(void) {
    196   1.1     uch 		return reinterpret_cast <int>
    197   1.6     uch 		    (_platform(0, _PLATFORM_OP_DEFAULT));
    198   1.1     uch 	}
    199   1.1     uch 	void platform_set(int n) { _platform(n, _PLATFORM_OP_SET); }
    200   1.1     uch };
    201   1.5     uch 
    202   1.5     uch /* Global access macro */
    203  1.11     uch #define	HPC_MENU	(HpcMenuInterface::Instance())
    204  1.11     uch #define	HPC_PREFERENCE	(HPC_MENU._pref)
    205   1.1     uch 
    206   1.1     uch #endif // _HPCBOOT_MENU_H_
    207