/*-
* Copyright (c) 2001, 2004 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by UCHIYAMA Yasushi.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
// arguments for kernel.
int
HpcMenuInterface::setup_kernel_args(vaddr_t v, paddr_t p, size_t sz)
{
int argc = 0;
kaddr_t *argv = reinterpret_cast <kaddr_t *>(v);
char *loc = reinterpret_cast <char *>
(v + sizeof(char **) * MAX_KERNEL_ARGS);
paddr_t locp = p + sizeof(char **) * MAX_KERNEL_ARGS;
size_t len;
TCHAR *w;
char *ptr;
#define SETOPT(c) \
__BEGIN_MACRO \
argv[argc++] = ptokv(locp); \
*loc++ =(c); \
*loc++ = '\0'; \
locp += 2; \
__END_MACRO
// 1st arg is kernel name.
// DPRINTF_SETUP(); //if you want to use debug print, enable this line.
w = _pref.kernel_user_file;
argv[argc++] = ptokv(locp);
len = WideCharToMultiByte(CP_ACP, 0, w, wcslen(w), 0, 0, 0, 0);
WideCharToMultiByte(CP_ACP, 0, w, len, loc, len, 0, 0);
loc[len] = '\0';
loc += len + 1;
locp += len + 1;
if (_pref.boot_serial) // serial console
SETOPT('h');
if (_pref.boot_verbose) // boot verbosely
SETOPT('v');
if (_pref.boot_single_user) // boot to single user
SETOPT('s');
if (_pref.boot_ask_for_name) // ask for file name to boot from
SETOPT('a');
if (_pref.boot_debugger) // break into the kernel debugger
SETOPT('d');
// boot from
switch(_pref.rootfs) {
case 0: // wd0
break;
case 1: // sd0
argv[argc++] = ptokv(locp);
strncpy(loc, "b=sd0", 6);
loc += 6;
locp += 6;
break;
case 2: // memory disk
w = _pref.rootfs_file;
argv[argc++] = ptokv(locp);
strncpy(loc, "m=", 2);
loc += 2;
len = WideCharToMultiByte(CP_ACP, 0, w, wcslen(w), 0, 0, 0, 0);
WideCharToMultiByte(CP_ACP, 0, w, len, loc, len, 0, 0);
loc[len] = '\0';
loc += len + 1;
locp += 2 + len + 1;
break;
case 3: // nfs
argv[argc++] = ptokv(locp);
strncpy(loc, "b=nfs", 6);
loc += 6;
locp += 6;
break;
case 4: // dk0
argv[argc++] = ptokv(locp);
strncpy(loc, "b=dk0", 6);
loc += 6;
locp += 6;
break;
case 5: // ld0
argv[argc++] = ptokv(locp);
strncpy(loc, "b=ld0", 6);
loc += 6;
locp += 6;
break;
}
// Extra kernel options. (Option tab window)
w = _pref.boot_extra;
len = WideCharToMultiByte(CP_ACP, 0, w, wcslen(w), 0, 0, 0, 0);
if ((ptr = (char *)malloc(len)) == NULL) {
MessageBox(_root->_window,
L"Can't allocate memory for extra kernel options.",
TEXT("WARNING"),
MB_ICONWARNING | MB_OK);
UpdateWindow(_root->_window);