save the network configuration lines using the parameter tree

- fixed bochsrc line after a "raw byte" string parameter
- changed parameter name "macaddr" to "mac" (same as bochsrc option parameter)
- skip disabled parameters when building the bochsrc line
- added "multiline" switch to select the output format (one or multiple lines)
- renamed siminterface method and use it in the network devices code
This commit is contained in:
Volker Ruppert 2013-01-19 12:25:53 +00:00
parent daf92361fe
commit a5e5ac69b0
8 changed files with 65 additions and 102 deletions

View File

@ -2,7 +2,7 @@
// $Id$
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2001-2011 The Bochs Project
// Copyright (C) 2001-2013 The Bochs Project
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
@ -125,8 +125,7 @@ void bx_init_usb_options(const char *usb_name, const char *pname, int maxports);
int bx_parse_nic_params(const char *context, const char *param, bx_list_c *base);
int bx_parse_usb_port_params(const char *context, bx_bool devopt,
const char *param, int maxports, bx_list_c *base);
int bx_write_param_list(FILE *fp, bx_list_c *base);
int bx_write_pci_nic_options(FILE *fp, bx_list_c *base);
int bx_write_param_list(FILE *fp, bx_list_c *base, bx_bool multiline);
int bx_write_usb_options(FILE *fp, int maxports, bx_list_c *base);
Bit32u crc32(const Bit8u *buf, int len);
// for param-tree testing only

View File

@ -2,7 +2,7 @@
// $Id$
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2002-2012 The Bochs Project
// Copyright (C) 2002-2013 The Bochs Project
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
@ -174,7 +174,7 @@ void bx_init_std_nic_options(const char *name, bx_list_c *menu)
sprintf(descr, "MAC address of the %s device. Don't use an address of a machine on your net.", name);
macaddr = new bx_param_string_c(menu,
"macaddr",
"mac",
"MAC Address",
descr,
"", 6);
@ -2096,7 +2096,7 @@ int bx_parse_nic_params(const char *context, const char *param, bx_list_c *base)
}
for (n=0;n<6;n++)
tmpchar[n] = (unsigned char)tmp[n];
SIM->get_param_string("macaddr", base)->set(tmpchar);
SIM->get_param_string("mac", base)->set(tmpchar);
valid |= 0x04;
} else if (!strncmp(param, "ethmod=", 7)) {
if (!SIM->get_param_enum("ethmod", base)->set_by_name(&param[7]))
@ -3194,56 +3194,62 @@ static int parse_line_formatted(const char *context, int num_params, char *param
}
int bx_write_param_list(FILE *fp, bx_list_c *base)
int bx_write_param_list(FILE *fp, bx_list_c *base, bx_bool multiline)
{
char bxrcline[BX_PATHNAME_LEN], tmpstr[BX_PATHNAME_LEN], tmpbyte[4];
if (base == NULL) return -1;
int p = 0;
sprintf(bxrcline, "%s: ", base->get_name());
for (int i = 0; i < base->get_size(); i++) {
bx_param_c *param = base->get(i);
sprintf(tmpstr, "%s=", param->get_name());
strcat(bxrcline, tmpstr);
switch (param->get_type()) {
case BXT_PARAM_NUM:
if (((bx_param_num_c*)param)->get_base() == BASE_DEC) {
sprintf(tmpstr, FMT_LL "d", ((bx_param_num_c*)param)->get64());
} else {
sprintf(tmpstr, "0x" FMT_LL "x", ((bx_param_num_c*)param)->get64());
}
break;
case BXT_PARAM_BOOL:
sprintf(tmpstr, "%d", ((bx_param_bool_c*)param)->get());
break;
case BXT_PARAM_ENUM:
sprintf(tmpstr, "%s", ((bx_param_enum_c*)param)->get_selected());
break;
case BXT_PARAM_STRING:
if (((bx_param_string_c*)param)->get_options() & bx_param_string_c::RAW_BYTES) {
tmpstr[0] = 0;
for (i = 0; i < ((bx_param_string_c*)param)->get_maxsize(); i++) {
if (i > 0) {
tmpbyte[0] = ((bx_param_string_c*)param)->get_separator();
tmpbyte[1] = 0;
if (param->get_enabled()) {
if (p > 0) {
strcat(bxrcline, ", ");
}
sprintf(tmpstr, "%s=", param->get_name());
strcat(bxrcline, tmpstr);
switch (param->get_type()) {
case BXT_PARAM_NUM:
if (((bx_param_num_c*)param)->get_base() == BASE_DEC) {
sprintf(tmpstr, FMT_LL "d", ((bx_param_num_c*)param)->get64());
} else {
sprintf(tmpstr, "0x" FMT_LL "x", ((bx_param_num_c*)param)->get64());
}
break;
case BXT_PARAM_BOOL:
sprintf(tmpstr, "%d", ((bx_param_bool_c*)param)->get());
break;
case BXT_PARAM_ENUM:
sprintf(tmpstr, "%s", ((bx_param_enum_c*)param)->get_selected());
break;
case BXT_PARAM_STRING:
if (((bx_param_string_c*)param)->get_options() & bx_param_string_c::RAW_BYTES) {
tmpstr[0] = 0;
for (int j = 0; j < ((bx_param_string_c*)param)->get_maxsize(); j++) {
if (j > 0) {
tmpbyte[0] = ((bx_param_string_c*)param)->get_separator();
tmpbyte[1] = 0;
strcat(tmpstr, tmpbyte);
}
sprintf(tmpbyte, "%02x", (Bit8u)((bx_param_string_c*)param)->getptr()[j]);
strcat(tmpstr, tmpbyte);
}
sprintf(tmpbyte, "%02x", (Bit8u)((bx_param_string_c*)param)->getptr()[i]);
strcat(tmpstr, tmpbyte);
} else {
sprintf(tmpstr, "\"%s\"", ((bx_param_string_c*)param)->getptr());
}
} else {
sprintf(tmpstr, "\"%s\"", ((bx_param_string_c*)param)->getptr());
}
break;
default:
BX_ERROR(("bx_write_param_list(): unsupported parameter type"));
break;
default:
BX_ERROR(("bx_write_param_list(): unsupported parameter type"));
}
strcat(bxrcline, tmpstr);
p++;
}
strcat(bxrcline, tmpstr);
if ((i + 1) < base->get_size()) {
if (strlen(bxrcline) > 80) {
if (multiline && (strlen(bxrcline) > 80)) {
fprintf(fp, "%s\n", bxrcline);
sprintf(bxrcline, "%s: ", base->get_name());
} else {
strcat(bxrcline, ", ");
p = 0;
}
} else {
fprintf(fp, "%s\n", bxrcline);
@ -3365,27 +3371,6 @@ int bx_write_usb_options(FILE *fp, int maxports, bx_list_c *base)
return 0;
}
int bx_write_pci_nic_options(FILE *fp, bx_list_c *base)
{
fprintf (fp, "%s: enabled=%d", base->get_name(), SIM->get_param_bool("enabled", base)->get());
if (SIM->get_param_bool("enabled", base)->get()) {
char *ptr = SIM->get_param_string("macaddr", base)->getptr();
fprintf (fp, ", mac=%02x:%02x:%02x:%02x:%02x:%02x, ethmod=%s, ethdev=%s, script=%s, bootrom=%s",
(unsigned int)(0xff & ptr[0]),
(unsigned int)(0xff & ptr[1]),
(unsigned int)(0xff & ptr[2]),
(unsigned int)(0xff & ptr[3]),
(unsigned int)(0xff & ptr[4]),
(unsigned int)(0xff & ptr[5]),
SIM->get_param_enum("ethmod", base)->get_selected(),
SIM->get_param_string("ethdev", base)->getptr(),
SIM->get_param_string("script", base)->getptr(),
SIM->get_param_string("bootrom", base)->getptr());
}
fprintf (fp, "\n");
return 0;
}
int bx_write_loader_options(FILE *fp)
{
if (SIM->get_param_enum(BXPN_LOAD32BITOS_WHICH)->get() == Load32bitOSNone) {
@ -3643,7 +3628,7 @@ int bx_write_configuration(const char *rc, int overwrite)
#if BX_CPU_LEVEL >= 4
if (! SIM->get_param_enum(BXPN_CPU_MODEL)->get()) {
// dump only when using BX_GENERIC CPUDB profile
bx_write_param_list(fp, (bx_list_c*) SIM->get_param("cpuid"));
bx_write_param_list(fp, (bx_list_c*) SIM->get_param("cpuid"), 1);
}
#endif

View File

@ -2,7 +2,7 @@
// $Id$
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2002-2011 The Bochs Project
// Copyright (C) 2002-2013 The Bochs Project
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
@ -203,7 +203,7 @@ public:
virtual int parse_nic_params(const char *context, const char *param, bx_list_c *base);
virtual int parse_usb_port_params(const char *context, bx_bool devopt,
const char *param, int maxports, bx_list_c *base);
virtual int write_pci_nic_options(FILE *fp, bx_list_c *base);
virtual int write_param_list(FILE *fp, bx_list_c *base, bx_bool multiline);
virtual int write_usb_options(FILE *fp, int maxports, bx_list_c *base);
private:
@ -1469,9 +1469,9 @@ int bx_real_sim_c::parse_usb_port_params(const char *context, bx_bool devopt,
return bx_parse_usb_port_params(context, devopt, param, maxports, base);
}
int bx_real_sim_c::write_pci_nic_options(FILE *fp, bx_list_c *base)
int bx_real_sim_c::write_param_list(FILE *fp, bx_list_c *base, bx_bool multiline)
{
return bx_write_pci_nic_options(fp, base);
return bx_write_param_list(fp, base, multiline);
}
int bx_real_sim_c::write_usb_options(FILE *fp, int maxports, bx_list_c *base)

View File

@ -2,7 +2,7 @@
// $Id$
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2001-2012 The Bochs Project
// Copyright (C) 2001-2013 The Bochs Project
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
@ -763,7 +763,7 @@ public:
virtual int parse_nic_params(const char *context, const char *param, bx_list_c *base) {return 0;}
virtual int parse_usb_port_params(const char *context, bx_bool devopt,
const char *param, int maxports, bx_list_c *base) {return 0;}
virtual int write_pci_nic_options(FILE *fp, bx_list_c *base) {return 0;}
virtual int write_param_list(FILE *fp, bx_list_c *base, bx_bool multiline) {return 0;}
virtual int write_usb_options(FILE *fp, int maxports, bx_list_c *base) {return 0;}
};

View File

@ -12,7 +12,7 @@
// Copyright (c) 2007 Dan Aloni
// Copyright (c) 2004 Antony T Curtis
//
// Copyright (C) 2011 The Bochs Project
// Copyright (C) 2011-2013 The Bochs Project
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
@ -335,8 +335,7 @@ Bit32s e1000_options_parser(const char *context, int num_params, char *params[])
Bit32s e1000_options_save(FILE *fp)
{
SIM->write_pci_nic_options(fp, (bx_list_c*) SIM->get_param(BXPN_E1000));
return 0;
return SIM->write_param_list(fp, (bx_list_c*) SIM->get_param(BXPN_E1000), 0);
}
// device plugin entry points
@ -454,7 +453,7 @@ void bx_e1000_c::init(void)
((bx_param_bool_c*)((bx_list_c*)SIM->get_param(BXPN_PLUGIN_CTRL))->get_by_name("e1000"))->set(0);
return;
}
memcpy(macaddr, SIM->get_param_string("macaddr", base)->getptr(), 6);
memcpy(macaddr, SIM->get_param_string("mac", base)->getptr(), 6);
memcpy(BX_E1000_THIS s.eeprom_data, e1000_eeprom_template,
sizeof(e1000_eeprom_template));

View File

@ -2,7 +2,7 @@
// $Id$
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2001-2012 The Bochs Project
// Copyright (C) 2001-2013 The Bochs Project
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
@ -129,26 +129,7 @@ Bit32s ne2k_options_parser(const char *context, int num_params, char *params[])
Bit32s ne2k_options_save(FILE *fp)
{
bx_list_c *base = (bx_list_c*) SIM->get_param(BXPN_NE2K);
fprintf(fp, "ne2k: enabled=%d", SIM->get_param_bool("enabled", base)->get());
if (SIM->get_param_bool("enabled", base)->get()) {
char *ptr = SIM->get_param_string("macaddr", base)->getptr();
fprintf(fp, ", ioaddr=0x%x, irq=%d, mac=%02x:%02x:%02x:%02x:%02x:%02x, ethmod=%s, ethdev=%s, script=%s, bootrom=%s",
SIM->get_param_num("ioaddr", base)->get(),
SIM->get_param_num("irq", base)->get(),
(unsigned int)(0xff & ptr[0]),
(unsigned int)(0xff & ptr[1]),
(unsigned int)(0xff & ptr[2]),
(unsigned int)(0xff & ptr[3]),
(unsigned int)(0xff & ptr[4]),
(unsigned int)(0xff & ptr[5]),
SIM->get_param_enum("ethmod", base)->get_selected(),
SIM->get_param_string("ethdev", base)->getptr(),
SIM->get_param_string("script", base)->getptr(),
SIM->get_param_string("bootrom", base)->getptr());
}
fprintf(fp, "\n");
return 0;
return SIM->write_param_list(fp, (bx_list_c*) SIM->get_param(BXPN_NE2K), 0);
}
// device plugin entry points
@ -208,7 +189,7 @@ void bx_ne2k_c::init(void)
((bx_param_bool_c*)((bx_list_c*)SIM->get_param(BXPN_PLUGIN_CTRL))->get_by_name("ne2k"))->set(0);
return;
}
memcpy(macaddr, SIM->get_param_string("macaddr", base)->getptr(), 6);
memcpy(macaddr, SIM->get_param_string("mac", base)->getptr(), 6);
strcpy(devname, "NE2000 NIC");
BX_NE2K_THIS s.pci_enabled = SIM->is_pci_device(BX_PLUGIN_NE2K);

View File

@ -2,7 +2,7 @@
// $Id$
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2001-2011 The Bochs Project
// Copyright (C) 2001-2013 The Bochs Project
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
@ -63,7 +63,7 @@ void* bx_netmod_ctl_c::init_module(bx_list_c *base, void *rxh, void *rxstat, bx_
const char *modname = SIM->get_param_enum("ethmod", base)->get_selected();
ethmod = eth_locator_c::create(modname,
SIM->get_param_string("ethdev", base)->getptr(),
(const char *) SIM->get_param_string("macaddr", base)->getptr(),
(const char *) SIM->get_param_string("mac", base)->getptr(),
(eth_rx_handler_t)rxh, (eth_rx_status_t)rxstat, netdev,
SIM->get_param_string("script", base)->getptr());
@ -73,7 +73,7 @@ void* bx_netmod_ctl_c::init_module(bx_list_c *base, void *rxh, void *rxstat, bx_
BX_INFO(("could not find eth module %s - using null instead", modname));
ethmod = eth_locator_c::create("null", NULL,
(const char *) SIM->get_param_string("macaddr", base)->getptr(),
(const char *) SIM->get_param_string("mac", base)->getptr(),
(eth_rx_handler_t)rxh, (eth_rx_status_t)rxstat, netdev, "");
if (ethmod == NULL)
BX_PANIC(("could not locate null module"));

View File

@ -89,8 +89,7 @@ Bit32s pnic_options_parser(const char *context, int num_params, char *params[])
Bit32s pnic_options_save(FILE *fp)
{
SIM->write_pci_nic_options(fp, (bx_list_c*) SIM->get_param(BXPN_PNIC));
return 0;
return SIM->write_param_list(fp, (bx_list_c*) SIM->get_param(BXPN_PNIC), 0);
}
// device plugin entry points
@ -147,7 +146,7 @@ void bx_pcipnic_c::init(void)
return;
}
memcpy(BX_PNIC_THIS s.macaddr, SIM->get_param_string("macaddr", base)->getptr(), 6);
memcpy(BX_PNIC_THIS s.macaddr, SIM->get_param_string("mac", base)->getptr(), 6);
BX_PNIC_THIS s.devfunc = 0x00;
DEV_register_pci_handlers(this, &BX_PNIC_THIS s.devfunc, BX_PLUGIN_PCIPNIC,