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