Home | History | Annotate | Line # | Download | only in hpcboot
hpcmenu.cpp revision 1.5
      1  1.5  uch /* -*-C++-*-	$NetBSD: hpcmenu.cpp,v 1.5 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 #include <hpcmenu.h>
     40  1.1  uch #include <hpcboot.h>
     41  1.1  uch #include <res/resource.h>
     42  1.1  uch #include <menu/window.h>
     43  1.1  uch #include <menu/tabwindow.h>
     44  1.1  uch #include <menu/rootwindow.h>
     45  1.1  uch #include <machine/bootinfo.h>
     46  1.1  uch #include <framebuffer.h>
     47  1.1  uch #include <console.h>
     48  1.1  uch 
     49  1.4  uch static BOOL _find_pref_dir(TCHAR *);
     50  1.1  uch //
     51  1.1  uch // Main window
     52  1.1  uch //
     53  1.1  uch class MainTabWindow : public TabWindow
     54  1.1  uch {
     55  1.1  uch private:
     56  1.1  uch 	HWND _edit_md_root;
     57  1.5  uch 	HWND _combobox_serial_speed;
     58  1.1  uch 
     59  1.1  uch 	int _item_idx;
     60  1.1  uch 	void _insert_item(HWND w, TCHAR *name, int id) {
     61  1.1  uch 		int idx = SendDlgItemMessage(w, id, CB_ADDSTRING, 0,
     62  1.1  uch 					     reinterpret_cast <LPARAM>(name));
     63  1.1  uch 		if (idx != CB_ERR)
     64  1.1  uch 			SendDlgItemMessage(w, IDC_MAIN_DIR, CB_SETITEMDATA,
     65  1.1  uch 					   idx, _item_idx++);
     66  1.1  uch 	}
     67  1.1  uch 
     68  1.1  uch public:
     69  1.1  uch 	explicit MainTabWindow(TabWindowBase &base, int id)
     70  1.1  uch 		: TabWindow(base, id, TEXT("WMain")) {
     71  1.1  uch 		_item_idx = 0;
     72  1.1  uch 	}
     73  1.1  uch 	virtual ~MainTabWindow(void) { /* NO-OP */ }
     74  1.1  uch 	virtual void init(HWND w) {
     75  1.1  uch 		HpcMenuInterface &menu = HpcMenuInterface::Instance();
     76  1.1  uch 		struct HpcMenuInterface::HpcMenuPreferences
     77  1.1  uch 			*pref = &menu._pref;
     78  1.1  uch 		_window = w;
     79  1.1  uch 		// insert myself to tab-control
     80  1.1  uch 		TabWindow::init(w);
     81  1.1  uch 
     82  1.1  uch 		// setup child.
     83  1.1  uch 		TCHAR *entry;
     84  1.1  uch 		int i;
     85  1.1  uch 		// kernel directory path
     86  1.1  uch 		for (i = 0; entry = menu.dir(i); i++)
     87  1.1  uch 			_insert_item(w, entry, IDC_MAIN_DIR);
     88  1.1  uch 		SendDlgItemMessage(w, IDC_MAIN_DIR, CB_SETCURSEL,
     89  1.1  uch 				   menu.dir_default(), 0);
     90  1.1  uch 		// platform
     91  1.1  uch 		for (i = 0; entry = menu.platform_get(i); i++)
     92  1.1  uch 			_insert_item(w, entry, IDC_MAIN_PLATFORM);
     93  1.1  uch 		SendDlgItemMessage(w, IDC_MAIN_PLATFORM, CB_SETCURSEL,
     94  1.1  uch 				   menu.platform_default(), 0);
     95  1.1  uch 		// kernel file name.
     96  1.1  uch 		Edit_SetText(GetDlgItem(w, IDC_MAIN_KERNEL),
     97  1.1  uch 			     pref->kernel_user ? pref->kernel_user_file :
     98  1.1  uch 			     TEXT("netbsd.gz"));
     99  1.1  uch 
    100  1.1  uch 		// root file system.
    101  1.1  uch 		int fs = pref->rootfs + IDC_MAIN_ROOT_;
    102  1.1  uch 		_set_check(fs, TRUE);
    103  1.1  uch 
    104  1.1  uch 		_edit_md_root = GetDlgItem(w, IDC_MAIN_ROOT_MD_OPS);
    105  1.1  uch 		Edit_SetText(_edit_md_root, pref->rootfs_file);
    106  1.1  uch 		EnableWindow(_edit_md_root, fs == IDC_MAIN_ROOT_MD
    107  1.1  uch 			     ? TRUE : FALSE);
    108  1.1  uch 
    109  1.1  uch 		// kernel boot options.
    110  1.1  uch 		_set_check(IDC_MAIN_OPTION_A, pref->boot_ask_for_name);
    111  1.1  uch 		_set_check(IDC_MAIN_OPTION_S, pref->boot_single_user);
    112  1.1  uch 		_set_check(IDC_MAIN_OPTION_V, pref->boot_verbose);
    113  1.1  uch 		_set_check(IDC_MAIN_OPTION_H, pref->boot_serial);
    114  1.5  uch 
    115  1.5  uch 		// serial console speed.
    116  1.5  uch 		TCHAR *speed_tab[] = { L"9600", L"19200", L"115200", 0 };
    117  1.5  uch 		int sel = 0;
    118  1.5  uch 		i = 0;
    119  1.5  uch 		for (TCHAR **speed = speed_tab; *speed; speed++, i++) {
    120  1.5  uch 			_insert_item(w, *speed, IDC_MAIN_OPTION_H_SPEED);
    121  1.5  uch 			if (_wtoi(*speed) == pref->serial_speed)
    122  1.5  uch 				sel = i;
    123  1.5  uch 		}
    124  1.5  uch 		_combobox_serial_speed = GetDlgItem(_window,
    125  1.5  uch 						    IDC_MAIN_OPTION_H_SPEED);
    126  1.5  uch 		SendDlgItemMessage(w, IDC_MAIN_OPTION_H_SPEED, CB_SETCURSEL,
    127  1.5  uch 				   sel, 0);
    128  1.5  uch 		EnableWindow(_combobox_serial_speed, pref->boot_serial);
    129  1.1  uch 	}
    130  1.1  uch 
    131  1.1  uch 	void get(void) {
    132  1.1  uch 		HpcMenuInterface &menu = HpcMenuInterface::Instance();
    133  1.1  uch 		struct HpcMenuInterface::HpcMenuPreferences
    134  1.1  uch 			*pref = &menu._pref;
    135  1.1  uch 
    136  1.1  uch 		HWND w = GetDlgItem(_window, IDC_MAIN_DIR);
    137  1.1  uch 		ComboBox_GetText(w, pref->dir_user_path, MAX_PATH);
    138  1.1  uch 		pref->dir_user = TRUE;
    139  1.1  uch 		w = GetDlgItem(_window, IDC_MAIN_KERNEL);
    140  1.1  uch 		Edit_GetText(w, pref->kernel_user_file, MAX_PATH);
    141  1.1  uch 		pref->kernel_user = TRUE;
    142  1.1  uch 
    143  1.1  uch 		int i = ComboBox_GetCurSel(GetDlgItem(_window,
    144  1.1  uch 						      IDC_MAIN_PLATFORM));
    145  1.1  uch 		menu.platform_set(i);
    146  1.1  uch 
    147  1.1  uch 		if (_is_checked(IDC_MAIN_ROOT_WD))
    148  1.1  uch 			pref->rootfs = 0;
    149  1.1  uch 		else if (_is_checked(IDC_MAIN_ROOT_SD))
    150  1.1  uch 			pref->rootfs = 1;
    151  1.1  uch 		else if (_is_checked(IDC_MAIN_ROOT_MD))
    152  1.1  uch 			pref->rootfs = 2;
    153  1.1  uch 		else if (_is_checked(IDC_MAIN_ROOT_NFS))
    154  1.1  uch 			pref->rootfs = 3;
    155  1.1  uch 
    156  1.1  uch 		pref->boot_ask_for_name	= _is_checked(IDC_MAIN_OPTION_A);
    157  1.1  uch 		pref->boot_verbose	= _is_checked(IDC_MAIN_OPTION_V);
    158  1.1  uch 		pref->boot_single_user	= _is_checked(IDC_MAIN_OPTION_S);
    159  1.1  uch 		pref->boot_serial	= _is_checked(IDC_MAIN_OPTION_H);
    160  1.1  uch 		Edit_GetText(_edit_md_root, pref->rootfs_file, MAX_PATH);
    161  1.5  uch 
    162  1.5  uch 		TCHAR tmpbuf[8];
    163  1.5  uch 		ComboBox_GetText(_combobox_serial_speed, tmpbuf, 8);
    164  1.5  uch 		pref->serial_speed = _wtoi(tmpbuf);
    165  1.1  uch 	}
    166  1.1  uch 
    167  1.1  uch 	virtual void command(int id, int msg) {
    168  1.5  uch 		switch (id) {
    169  1.5  uch 		case IDC_MAIN_OPTION_H:
    170  1.5  uch 			EnableWindow(_combobox_serial_speed,
    171  1.5  uch 				     _is_checked(IDC_MAIN_OPTION_H));
    172  1.5  uch 			break;
    173  1.5  uch 		case IDC_MAIN_ROOT_WD:
    174  1.5  uch 			/* FALLTHROUGH */
    175  1.5  uch 		case IDC_MAIN_ROOT_SD:
    176  1.5  uch 			/* FALLTHROUGH */
    177  1.5  uch 		case IDC_MAIN_ROOT_MD:
    178  1.5  uch 			/* FALLTHROUGH */
    179  1.5  uch 		case IDC_MAIN_ROOT_NFS:
    180  1.5  uch 			EnableWindow(_edit_md_root,
    181  1.5  uch 				     _is_checked(IDC_MAIN_ROOT_MD));
    182  1.5  uch 		}
    183  1.1  uch 	}
    184  1.1  uch };
    185  1.1  uch 
    186  1.1  uch //
    187  1.1  uch // Option window
    188  1.1  uch //
    189  1.1  uch class OptionTabWindow : public TabWindow
    190  1.1  uch {
    191  1.1  uch public:
    192  1.1  uch 	HWND _spin_edit;
    193  1.1  uch 	HWND _spin;
    194  1.1  uch #define IS_CHECKED(x)	_is_checked(IDC_OPT_##x)
    195  1.1  uch #define SET_CHECK(x, b)	_set_check(IDC_OPT_##x,(b))
    196  1.1  uch 
    197  1.1  uch public:
    198  1.1  uch 	explicit OptionTabWindow(TabWindowBase &base, int id)
    199  1.1  uch 		: TabWindow(base, id, TEXT("WOption")) {
    200  1.1  uch 		_spin_edit = NULL;
    201  1.1  uch 		_spin = NULL;
    202  1.1  uch 	}
    203  1.1  uch 	virtual ~OptionTabWindow(void) { /* NO-OP */ }
    204  1.1  uch 	virtual void init(HWND w) {
    205  1.1  uch 		HpcMenuInterface &menu = HpcMenuInterface::Instance();
    206  1.1  uch 		struct HpcMenuInterface::HpcMenuPreferences
    207  1.1  uch 			*pref = &menu._pref;
    208  1.1  uch 		_window = w;
    209  1.1  uch 
    210  1.1  uch 		TabWindow::init(_window);
    211  1.1  uch 		_spin_edit = GetDlgItem(_window, IDC_OPT_AUTO_INPUT);
    212  1.1  uch 		_spin = CreateUpDownControl(WS_CHILD | WS_BORDER | WS_VISIBLE |
    213  1.1  uch 					    UDS_SETBUDDYINT | UDS_ALIGNRIGHT,
    214  1.1  uch 					    80, 0, 50, 50, _window,
    215  1.1  uch 					    IDC_OPT_AUTO_UPDOWN,
    216  1.1  uch 					    _app._instance, _spin_edit,
    217  1.1  uch 					    60, 1, 30);
    218  1.1  uch 		BOOL onoff = pref->auto_boot ? TRUE : FALSE;
    219  1.1  uch 		EnableWindow(_spin_edit, onoff);
    220  1.1  uch 		EnableWindow(_spin, onoff);
    221  1.1  uch 
    222  1.1  uch 		SET_CHECK(AUTO, pref->auto_boot);
    223  1.1  uch 		if (pref->auto_boot)
    224  1.1  uch 		{
    225  1.1  uch 			TCHAR tmp[32];
    226  1.1  uch 			wsprintf(tmp, TEXT("%d"), pref->auto_boot);
    227  1.1  uch 			Edit_SetText(_spin_edit, tmp);
    228  1.1  uch 		}
    229  1.1  uch 		SET_CHECK(VIDEO,	pref->reverse_video);
    230  1.1  uch 		SET_CHECK(PAUSE,	pref->pause_before_boot);
    231  1.1  uch 		SET_CHECK(DEBUG,	pref->load_debug_info);
    232  1.1  uch 		SET_CHECK(SAFETY,	pref->safety_message);
    233  1.1  uch 	}
    234  1.1  uch 
    235  1.1  uch 	virtual void command(int id, int msg) {
    236  1.5  uch 		switch (id) {
    237  1.1  uch 		case IDC_OPT_AUTO:
    238  1.1  uch 			if (IS_CHECKED(AUTO)) {
    239  1.1  uch 				EnableWindow(_spin_edit, TRUE);
    240  1.1  uch 				EnableWindow(_spin, TRUE);
    241  1.1  uch 			} else {
    242  1.1  uch 				EnableWindow(_spin_edit, FALSE);
    243  1.1  uch 				EnableWindow(_spin, FALSE);
    244  1.1  uch 			}
    245  1.1  uch 			break;
    246  1.1  uch 		}
    247  1.1  uch 	}
    248  1.1  uch 
    249  1.1  uch 	void get(void) {
    250  1.1  uch 		HpcMenuInterface &menu = HpcMenuInterface::Instance();
    251  1.1  uch 		struct HpcMenuInterface::HpcMenuPreferences
    252  1.1  uch 			*pref = &menu._pref;
    253  1.1  uch 		if (IS_CHECKED(AUTO)) {
    254  1.1  uch 			TCHAR tmp[32];
    255  1.1  uch 			Edit_GetText(_spin_edit, tmp, 32);
    256  1.1  uch 			pref->auto_boot = _wtoi(tmp);
    257  1.1  uch 		} else
    258  1.1  uch 			pref->auto_boot = 0;
    259  1.1  uch 		pref->reverse_video		= IS_CHECKED(VIDEO);
    260  1.1  uch 		pref->pause_before_boot	= IS_CHECKED(PAUSE);
    261  1.1  uch 		pref->load_debug_info	= IS_CHECKED(DEBUG);
    262  1.1  uch 		pref->safety_message	= IS_CHECKED(SAFETY);
    263  1.1  uch 	}
    264  1.1  uch };
    265  1.1  uch 
    266  1.1  uch //
    267  1.1  uch // Console window
    268  1.1  uch //
    269  1.1  uch class ConsoleTabWindow : public TabWindow
    270  1.1  uch {
    271  1.4  uch private:
    272  1.4  uch 	HWND _filename_edit;
    273  1.4  uch 	BOOL _filesave;
    274  1.4  uch 	HANDLE _logfile;
    275  1.4  uch 	BOOL _open_log_file(void);
    276  1.1  uch public:
    277  1.1  uch 	HWND _edit;
    278  1.1  uch 
    279  1.1  uch public:
    280  1.1  uch 	explicit ConsoleTabWindow(TabWindowBase &base, int id)
    281  1.1  uch 		: TabWindow(base, id, TEXT("WConsole")) {
    282  1.1  uch 		_edit = NULL;
    283  1.4  uch 		_logfile = INVALID_HANDLE_VALUE;
    284  1.1  uch 	}
    285  1.4  uch 	virtual ~ConsoleTabWindow(void) {
    286  1.4  uch 		if (_logfile != INVALID_HANDLE_VALUE)
    287  1.4  uch 			CloseHandle(_logfile);
    288  1.1  uch 	}
    289  1.4  uch 	virtual void init(HWND);
    290  1.4  uch 	virtual void command(int, int);
    291  1.1  uch 
    292  1.4  uch 	void print(TCHAR *buf, BOOL = FALSE);
    293  1.1  uch };
    294  1.1  uch 
    295  1.1  uch void
    296  1.4  uch ConsoleTabWindow::print(TCHAR *buf, BOOL force_display)
    297  1.1  uch {
    298  1.1  uch 	int cr;
    299  1.1  uch 	TCHAR *p;
    300  1.1  uch 
    301  1.4  uch 	if (force_display)
    302  1.4  uch 		goto display;
    303  1.4  uch 
    304  1.4  uch 	if (_filesave) {
    305  1.4  uch 		if (_logfile == INVALID_HANDLE_VALUE && !_open_log_file()) {
    306  1.4  uch 			_filesave = FALSE;
    307  1.4  uch 			_set_check(IDC_CONS_FILESAVE, _filesave);
    308  1.4  uch 			EnableWindow(_filename_edit, _filesave);
    309  1.4  uch 			goto display;
    310  1.4  uch 		}
    311  1.4  uch 		DWORD cnt;
    312  1.4  uch 		char c;
    313  1.4  uch 		for (int i = 0; *buf != TEXT('\0'); buf++) {
    314  1.4  uch 			c = *buf & 0x7f;
    315  1.4  uch 			WriteFile(_logfile, &c, 1, &cnt, 0);
    316  1.4  uch 		}
    317  1.4  uch 		FlushFileBuffers(_logfile);
    318  1.4  uch 		return;
    319  1.4  uch 	}
    320  1.4  uch 
    321  1.4  uch  display:
    322  1.1  uch 	// count # of '\n'
    323  1.1  uch 	for (cr = 0, p = buf; p = wcschr(p, TEXT('\n')); cr++, p++)
    324  1.1  uch 		;
    325  1.1  uch 	// total length of new buffer('\n' -> "\r\n" + '\0')
    326  1.1  uch 	int ln = wcslen(buf) + cr + 1;
    327  1.1  uch 
    328  1.1  uch 	// get old buffer.
    329  1.1  uch 	int lo = Edit_GetTextLength(_edit);
    330  1.1  uch 	size_t sz =(lo  + ln) * sizeof(TCHAR);
    331  1.1  uch 
    332  1.1  uch 	p = reinterpret_cast <TCHAR *>(malloc(sz));
    333  1.1  uch 	if (p == NULL)
    334  1.1  uch 		return;
    335  1.1  uch 
    336  1.1  uch 	memset(p, 0, sz);
    337  1.1  uch 	Edit_GetText(_edit, p, lo + 1);
    338  1.1  uch 
    339  1.1  uch 	// put new buffer to end of old buffer.
    340  1.1  uch 	TCHAR *d = p + lo;
    341  1.1  uch 	while (*buf != TEXT('\0')) {
    342  1.1  uch 		TCHAR c = *buf++;
    343  1.1  uch 		if (c == TEXT('\n'))
    344  1.1  uch 			*d++ = TEXT('\r');
    345  1.1  uch 		*d++ = c;
    346  1.1  uch 	}
    347  1.1  uch 	*d = TEXT('\0');
    348  1.1  uch 
    349  1.1  uch 	// display total buffer.
    350  1.1  uch 	Edit_SetText(_edit, p);
    351  1.1  uch //  Edit_Scroll(_edit, Edit_GetLineCount(_edit), 0);
    352  1.1  uch 	UpdateWindow(_edit);
    353  1.1  uch 
    354  1.1  uch 	free(p);
    355  1.1  uch }
    356  1.1  uch 
    357  1.4  uch void
    358  1.4  uch ConsoleTabWindow::init(HWND w)
    359  1.4  uch {
    360  1.4  uch 	// at this time _window is NULL.
    361  1.4  uch 	// use argument of window procedure.
    362  1.4  uch 	TabWindow::init(w);
    363  1.4  uch 	_edit = GetDlgItem(w, IDC_CONS_EDIT);
    364  1.4  uch 	MoveWindow(_edit, 5, 60, _rect.right - _rect.left - 10,
    365  1.4  uch 		   _rect.bottom - _rect.top - 60, TRUE);
    366  1.4  uch 	Edit_FmtLines(_edit, TRUE);
    367  1.4  uch 
    368  1.4  uch 	// log file.
    369  1.4  uch 	_filename_edit = GetDlgItem(w, IDC_CONS_FILENAME);
    370  1.4  uch 	_filesave = FALSE;
    371  1.4  uch 	Edit_SetText(_filename_edit, L"bootlog.txt");
    372  1.4  uch 	EnableWindow(_filename_edit, _filesave);
    373  1.4  uch }
    374  1.4  uch 
    375  1.4  uch void
    376  1.4  uch ConsoleTabWindow::command(int id, int msg)
    377  1.4  uch {
    378  1.4  uch 	HpcMenuInterface &menu = HpcMenuInterface::Instance();
    379  1.4  uch 	struct HpcMenuInterface::cons_hook_args *hook = 0;
    380  1.4  uch 	int bit;
    381  1.4  uch 
    382  1.4  uch 	switch(id) {
    383  1.4  uch 	case IDC_CONS_FILESAVE:
    384  1.4  uch 		_filesave = _is_checked(IDC_CONS_FILESAVE);
    385  1.4  uch 		EnableWindow(_filename_edit, _filesave);
    386  1.4  uch 		break;
    387  1.4  uch 	case IDC_CONS_CHK0:
    388  1.4  uch 		/* FALLTHROUGH */
    389  1.4  uch 	case IDC_CONS_CHK1:
    390  1.4  uch 		/* FALLTHROUGH */
    391  1.4  uch 	case IDC_CONS_CHK2:
    392  1.4  uch 		/* FALLTHROUGH */
    393  1.4  uch 	case IDC_CONS_CHK3:
    394  1.4  uch 		/* FALLTHROUGH */
    395  1.4  uch 	case IDC_CONS_CHK4:
    396  1.4  uch 		/* FALLTHROUGH */
    397  1.4  uch 	case IDC_CONS_CHK5:
    398  1.4  uch 		/* FALLTHROUGH */
    399  1.4  uch 	case IDC_CONS_CHK6:
    400  1.4  uch 		/* FALLTHROUGH */
    401  1.4  uch 	case IDC_CONS_CHK7:
    402  1.4  uch 		bit = 1 << (id - IDC_CONS_CHK_);
    403  1.4  uch 		if (SendDlgItemMessage(_window, id, BM_GETCHECK, 0, 0))
    404  1.4  uch 			menu._cons_parameter |= bit;
    405  1.4  uch 		else
    406  1.4  uch 			menu._cons_parameter &= ~bit;
    407  1.4  uch 		break;
    408  1.4  uch 	case IDC_CONS_BTN0:
    409  1.4  uch 		/* FALLTHROUGH */
    410  1.4  uch 	case IDC_CONS_BTN1:
    411  1.4  uch 		/* FALLTHROUGH */
    412  1.4  uch 	case IDC_CONS_BTN2:
    413  1.4  uch 		/* FALLTHROUGH */
    414  1.4  uch 	case IDC_CONS_BTN3:
    415  1.4  uch 		hook = &menu._cons_hook[id - IDC_CONS_BTN_];
    416  1.4  uch 		if (hook->func)
    417  1.4  uch 			hook->func(hook->arg, menu._cons_parameter);
    418  1.4  uch 
    419  1.4  uch 		break;
    420  1.4  uch 	}
    421  1.4  uch }
    422  1.4  uch 
    423  1.4  uch BOOL
    424  1.4  uch ConsoleTabWindow::_open_log_file()
    425  1.4  uch {
    426  1.4  uch 	TCHAR path[MAX_PATH];
    427  1.4  uch 	TCHAR filename[MAX_PATH];
    428  1.4  uch 	TCHAR filepath[MAX_PATH];
    429  1.4  uch 
    430  1.5  uch 	if (!_find_pref_dir(path)) {
    431  1.4  uch 		print(L"couldn't find temporary directory.\n", TRUE);
    432  1.5  uch 		return FALSE;
    433  1.5  uch 	}
    434  1.5  uch 
    435  1.4  uch 	Edit_GetText(_filename_edit, filename, MAX_PATH);
    436  1.4  uch 	wsprintf(filepath, TEXT("\\%s\\%s"), path, filename);
    437  1.4  uch 	_logfile = CreateFile(filepath, GENERIC_WRITE, 0, 0,
    438  1.4  uch 			      CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL,
    439  1.4  uch 			      0);
    440  1.4  uch 	if (_logfile == INVALID_HANDLE_VALUE)
    441  1.4  uch 		return FALSE;
    442  1.5  uch 
    443  1.4  uch 	wsprintf(path, TEXT("log file is %s\n"), filepath);
    444  1.4  uch 	print(path, TRUE);
    445  1.4  uch 
    446  1.4  uch 	return TRUE;
    447  1.4  uch }
    448  1.4  uch 
    449  1.1  uch TabWindow *
    450  1.1  uch TabWindowBase::boot(int id)
    451  1.1  uch {
    452  1.1  uch 	TabWindow *w = NULL;
    453  1.1  uch 	HpcMenuInterface &menu = HpcMenuInterface::Instance();
    454  1.1  uch 
    455  1.1  uch 	switch(id) {
    456  1.1  uch 	default:
    457  1.1  uch 		break;
    458  1.1  uch 	case IDC_BASE_MAIN:
    459  1.1  uch 		menu._main = new MainTabWindow(*this, IDC_BASE_MAIN);
    460  1.1  uch 		w = menu._main;
    461  1.1  uch 		break;
    462  1.1  uch 	case IDC_BASE_OPTION:
    463  1.1  uch 		menu._option = new OptionTabWindow(*this, IDC_BASE_OPTION);
    464  1.1  uch 		w = menu._option;
    465  1.1  uch 		break;
    466  1.1  uch 	case IDC_BASE_CONSOLE:
    467  1.1  uch 		menu._console = new ConsoleTabWindow(*this, IDC_BASE_CONSOLE);
    468  1.1  uch 		w = menu._console;
    469  1.1  uch 		break;
    470  1.1  uch 	}
    471  1.1  uch 
    472  1.1  uch 	if (w)
    473  1.1  uch 		w->create(0);
    474  1.1  uch 
    475  1.1  uch 	return w;
    476  1.1  uch }
    477  1.1  uch 
    478  1.1  uch //
    479  1.1  uch // External Interface
    480  1.1  uch //
    481  1.1  uch HpcMenuInterface *HpcMenuInterface::_instance = 0;
    482  1.1  uch 
    483  1.1  uch HpcMenuInterface &
    484  1.4  uch HpcMenuInterface::Instance()
    485  1.1  uch {
    486  1.1  uch 	if (!_instance)
    487  1.1  uch 		_instance = new HpcMenuInterface();
    488  1.1  uch 	return *_instance;
    489  1.1  uch }
    490  1.1  uch 
    491  1.1  uch void
    492  1.4  uch HpcMenuInterface::Destroy()
    493  1.1  uch {
    494  1.1  uch 	if (_instance)
    495  1.1  uch 		delete _instance;
    496  1.1  uch }
    497  1.1  uch 
    498  1.1  uch void
    499  1.1  uch HpcMenuInterface::print(TCHAR *buf)
    500  1.1  uch {
    501  1.1  uch 	if (_console)
    502  1.1  uch 		_console->print(buf);
    503  1.1  uch }
    504  1.1  uch 
    505  1.1  uch void
    506  1.4  uch HpcMenuInterface::get_options()
    507  1.1  uch {
    508  1.1  uch 	_main->get();
    509  1.1  uch 	_option->get();
    510  1.1  uch }
    511  1.1  uch 
    512  1.1  uch TCHAR *
    513  1.1  uch HpcMenuInterface::dir(int i)
    514  1.1  uch {
    515  1.1  uch 	int res = IDS_DIR_RES(i);
    516  1.1  uch 	if (!IDS_DIR_RES_VALID(res))
    517  1.1  uch 		return 0;
    518  1.1  uch 
    519  1.1  uch 	if (_pref.dir_user && res == IDS_DIR_USER_DEFINED) {
    520  1.1  uch 		return _pref.dir_user_path;
    521  1.1  uch 	}
    522  1.1  uch 
    523  1.1  uch 	TCHAR *s = reinterpret_cast <TCHAR *>
    524  1.1  uch 		(LoadString(_root->_app._instance, res, 0, 0));
    525  1.1  uch 
    526  1.1  uch 	return s;
    527  1.1  uch }
    528  1.1  uch 
    529  1.1  uch int
    530  1.4  uch HpcMenuInterface::dir_default()
    531  1.1  uch {
    532  1.1  uch 	return _pref.dir_user ? IDS_DIR_SEQ(IDS_DIR_USER_DEFINED) : 0;
    533  1.1  uch }
    534  1.1  uch 
    535  1.1  uch BOOL
    536  1.4  uch HpcMenuInterface::load()
    537  1.1  uch {
    538  1.1  uch 	TCHAR path[MAX_PATH];
    539  1.1  uch 
    540  1.1  uch 	if (!_find_pref_dir(path))
    541  1.1  uch 		return FALSE;
    542  1.1  uch 
    543  1.1  uch 	TCHAR filename[MAX_PATH];
    544  1.1  uch 	wsprintf(filename, TEXT("\\%s\\hpcboot.cnf"), path);
    545  1.1  uch 	HANDLE file = CreateFile(filename, GENERIC_READ, 0, 0, OPEN_EXISTING,
    546  1.1  uch 				 FILE_ATTRIBUTE_NORMAL, 0);
    547  1.1  uch 	if (file == INVALID_HANDLE_VALUE)
    548  1.1  uch 		return FALSE;
    549  1.1  uch 
    550  1.1  uch 	DWORD cnt;
    551  1.1  uch 	// read header.
    552  1.1  uch 	if (!ReadFile(file, &_pref, 12, &cnt, 0))
    553  1.1  uch 		goto bad;
    554  1.1  uch 	if (_pref._magic != HPCBOOT_MAGIC)
    555  1.1  uch 		goto bad;
    556  1.1  uch 	// read all.
    557  1.1  uch 	SetFilePointer(file, 0, 0, FILE_BEGIN);
    558  1.1  uch 	if (!ReadFile(file, &_pref, _pref._size, &cnt, 0))
    559  1.1  uch 		goto bad;
    560  1.1  uch 	CloseHandle(file);
    561  1.1  uch 
    562  1.1  uch 	return TRUE;
    563  1.1  uch  bad:
    564  1.1  uch 	CloseHandle(file);
    565  1.1  uch 	return FALSE;
    566  1.1  uch }
    567  1.1  uch 
    568  1.1  uch BOOL
    569  1.4  uch HpcMenuInterface::save()
    570  1.1  uch {
    571  1.1  uch 	TCHAR path[MAX_PATH];
    572  1.1  uch 
    573  1.1  uch 	if (_find_pref_dir(path)) {
    574  1.1  uch 		TCHAR filename[MAX_PATH];
    575  1.1  uch 		wsprintf(filename, TEXT("\\%s\\hpcboot.cnf"), path);
    576  1.1  uch 		HANDLE file = CreateFile(filename, GENERIC_WRITE, 0, 0,
    577  1.1  uch 					 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL,
    578  1.1  uch 					 0);
    579  1.1  uch 		DWORD cnt;
    580  1.1  uch 		WriteFile(file, &_pref, _pref._size, &cnt, 0);
    581  1.1  uch 		CloseHandle(file);
    582  1.1  uch 		return cnt == _pref._size;
    583  1.1  uch 	}
    584  1.1  uch 
    585  1.1  uch 	return FALSE;
    586  1.1  uch }
    587  1.1  uch 
    588  1.1  uch // arguments for kernel.
    589  1.1  uch int
    590  1.1  uch HpcMenuInterface::setup_kernel_args(vaddr_t v, paddr_t p)
    591  1.1  uch {
    592  1.1  uch 	int argc = 0;
    593  1.1  uch 	kaddr_t *argv = reinterpret_cast <kaddr_t *>(v);
    594  1.1  uch 	char *loc = reinterpret_cast <char *>
    595  1.1  uch 		(v + sizeof(char **) * MAX_KERNEL_ARGS);
    596  1.1  uch 	paddr_t locp = p + sizeof(char **) * MAX_KERNEL_ARGS;
    597  1.1  uch 	size_t len;
    598  1.1  uch 	TCHAR *w;
    599  1.1  uch 
    600  1.1  uch #define SETOPT(c)							\
    601  1.1  uch __BEGIN_MACRO								\
    602  1.1  uch 	argv[argc++] = ptokv(locp);					\
    603  1.1  uch 	*loc++ =(c);							\
    604  1.1  uch 	*loc++ = '\0';							\
    605  1.1  uch 	locp += 2;							\
    606  1.1  uch __END_MACRO
    607  1.1  uch 	// 1st arg is kernel name.
    608  1.1  uch //	DPRINTF_SETUP();  if you want to use debug print, enable this line.
    609  1.1  uch 
    610  1.1  uch 	w = _pref.kernel_user_file;
    611  1.1  uch 	argv[argc++] = ptokv(locp);
    612  1.1  uch 	len = WideCharToMultiByte(CP_ACP, 0, w, wcslen(w), 0, 0, 0, 0);
    613  1.1  uch 	WideCharToMultiByte(CP_ACP, 0, w, len, loc, len, 0, 0);
    614  1.1  uch 	loc[len] = '\0';
    615  1.1  uch 	loc += len + 1;
    616  1.1  uch 	locp += len + 1;
    617  1.1  uch 
    618  1.1  uch 	if (_pref.boot_serial)		// serial console
    619  1.1  uch 		SETOPT('h');
    620  1.1  uch 	if (_pref.boot_verbose)		// boot verbosely
    621  1.1  uch 		SETOPT('v');
    622  1.1  uch 	if (_pref.boot_single_user)	// boot to single user
    623  1.1  uch 		SETOPT('s');
    624  1.1  uch 	if (_pref.boot_ask_for_name)	// ask for file name to boot from
    625  1.1  uch 		SETOPT('a');
    626  1.1  uch 
    627  1.1  uch 	// boot from
    628  1.1  uch 	switch(_pref.rootfs) {
    629  1.1  uch 	case 0:	// wd0
    630  1.1  uch 		break;
    631  1.1  uch 	case 1:	// sd0
    632  1.2  uch 		argv[argc++] = ptokv(locp);
    633  1.2  uch 		strncpy(loc, "b=sd0", 6);
    634  1.2  uch 		loc += 6;
    635  1.2  uch 		locp += 6;
    636  1.1  uch 		break;
    637  1.1  uch 	case 2:	// memory disk
    638  1.1  uch 		w = _pref.rootfs_file;
    639  1.1  uch 		argv[argc++] = ptokv(locp);
    640  1.1  uch 		strncpy(loc, "m=", 2);
    641  1.1  uch 		loc += 2;
    642  1.1  uch 		len = WideCharToMultiByte(CP_ACP, 0, w, wcslen(w), 0, 0, 0, 0);
    643  1.1  uch 		WideCharToMultiByte(CP_ACP, 0, w, len, loc, len, 0, 0);
    644  1.1  uch 		loc[len] = '\0';
    645  1.1  uch 		loc += len + 1;
    646  1.1  uch 		locp += 2 + len + 1;
    647  1.1  uch 		break;
    648  1.1  uch 	case 3:	// nfs
    649  1.1  uch 		argv[argc++] = ptokv(locp);
    650  1.1  uch 		strncpy(loc, "b=nfs", 6);
    651  1.1  uch 		loc += 6;
    652  1.1  uch 		locp += 6;
    653  1.1  uch 		break;
    654  1.1  uch 	}
    655  1.1  uch 
    656  1.1  uch 	return argc;
    657  1.1  uch }
    658  1.1  uch 
    659  1.1  uch // kernel bootinfo.
    660  1.1  uch void
    661  1.1  uch HpcMenuInterface::setup_bootinfo(struct bootinfo &bi)
    662  1.1  uch {
    663  1.1  uch 	FrameBufferInfo fb(_pref.platid_hi, _pref.platid_lo);
    664  1.1  uch 	TIME_ZONE_INFORMATION tz;
    665  1.1  uch 	GetTimeZoneInformation(&tz);
    666  1.1  uch 
    667  1.1  uch 	memset(&bi, 0, sizeof(struct bootinfo));
    668  1.1  uch 	bi.length		= sizeof(struct bootinfo);
    669  1.1  uch 	bi.reserved		= 0;
    670  1.1  uch 	bi.magic		= BOOTINFO_MAGIC;
    671  1.1  uch 	bi.fb_addr		= fb.addr();
    672  1.1  uch 	bi.fb_type		= fb.type();
    673  1.1  uch 	bi.fb_line_bytes	= fb.linebytes();
    674  1.1  uch 	bi.fb_width		= fb.width();
    675  1.1  uch 	bi.fb_height		= fb.height();
    676  1.1  uch 	bi.platid_cpu		= _pref.platid_hi;
    677  1.1  uch 	bi.platid_machine	= _pref.platid_lo;
    678  1.1  uch 	bi.timezone		= tz.Bias;
    679  1.1  uch }
    680  1.1  uch 
    681  1.1  uch // Progress bar
    682  1.1  uch void
    683  1.4  uch HpcMenuInterface::progress()
    684  1.1  uch {
    685  1.1  uch 	SendMessage(_root->_progress_bar->_window, PBM_STEPIT, 0, 0);
    686  1.4  uch }
    687  1.4  uch 
    688  1.4  uch void
    689  1.4  uch HpcMenuInterface::boot()
    690  1.4  uch {
    691  1.4  uch 	struct support_status *tab = _unsupported;
    692  1.4  uch 	u_int32_t cpu = _pref.platid_hi;
    693  1.4  uch 	u_int32_t machine = _pref.platid_lo;
    694  1.4  uch 
    695  1.4  uch 	if (_pref.safety_message)
    696  1.4  uch 		for (; tab->cpu; tab++) {
    697  1.4  uch 			if (tab->cpu == cpu && tab->machine == machine) {
    698  1.4  uch 				MessageBox(_root->_window,
    699  1.4  uch 					   tab->cause ? tab->cause :
    700  1.4  uch 					   L"not supported yet.",
    701  1.4  uch 					   TEXT("BOOT FAILED"), 0);
    702  1.4  uch 				return;
    703  1.4  uch 			}
    704  1.4  uch 		}
    705  1.4  uch 
    706  1.4  uch 	if (_boot_hook.func)
    707  1.4  uch 		_boot_hook.func(_boot_hook.arg, _pref);
    708  1.4  uch }
    709  1.4  uch 
    710  1.4  uch //
    711  1.4  uch // Common utility
    712  1.4  uch //
    713  1.4  uch static BOOL
    714  1.4  uch _find_pref_dir(TCHAR *path)
    715  1.4  uch {
    716  1.4  uch 	WIN32_FIND_DATA fd;
    717  1.4  uch 	HANDLE find;
    718  1.4  uch 
    719  1.4  uch 	lstrcpy(path, TEXT("\\*.*"));
    720  1.4  uch 	find = FindFirstFile(path, &fd);
    721  1.4  uch 
    722  1.4  uch 	if (find != INVALID_HANDLE_VALUE) {
    723  1.4  uch 		do {
    724  1.4  uch 			int attr = fd.dwFileAttributes;
    725  1.4  uch 			if ((attr & FILE_ATTRIBUTE_DIRECTORY) &&
    726  1.4  uch 			    (attr & FILE_ATTRIBUTE_TEMPORARY)) {
    727  1.4  uch 				wcscpy(path, fd.cFileName);
    728  1.4  uch 				FindClose(find);
    729  1.4  uch 				return TRUE;
    730  1.4  uch 			}
    731  1.4  uch 		} while (FindNextFile(find, &fd));
    732  1.4  uch 	}
    733  1.4  uch 	FindClose(find);
    734  1.4  uch 
    735  1.4  uch 	return FALSE;
    736  1.1  uch }
    737