- add options to the string parameter class that allow it to deal with

raw hex bytes, for the MAC address.
This commit is contained in:
Bryce Denney 2001-06-21 19:27:05 +00:00
parent 8ca273ce73
commit 1bcdee2301
6 changed files with 107 additions and 30 deletions

View File

@ -594,7 +594,7 @@ typedef struct {
bx_param_bool_c *Ovalid;
bx_param_num_c *Oioaddr;
bx_param_num_c *Oirq;
unsigned char macaddr[6];
bx_param_string_c *Omacaddr;
bx_param_string_c *Oethmod;
bx_param_string_c *Oethdev;
} bx_ne2k_options;

View File

@ -1,6 +1,6 @@
/*
* gui/control.cc
* $Id: control.cc,v 1.26 2001-06-21 18:34:50 bdenney Exp $
* $Id: control.cc,v 1.27 2001-06-21 19:27:05 bdenney Exp $
*
* This is code for a text-mode control panel. Note that this file
* does NOT include bochs.h. Instead, it does all of its contact with
@ -217,6 +217,9 @@ ask_yn (char *prompt, Bit32u the_default, Bit32u *out)
}
}
// returns -1 on error (stream closed or something)
// returns 0 if default was taken
// returns 1 if value changed
int
ask_string (char *prompt, char *the_default, char *out)
{
@ -234,7 +237,7 @@ ask_string (char *prompt, char *the_default, char *out)
return 0;
}
strcpy (out, clean);
return 0;
return 1;
}
/******************************************************************/
@ -682,12 +685,28 @@ bx_param_enum_c::text_print (FILE *fp)
void
bx_param_string_c::text_print (FILE *fp)
{
//fprintf (fp, "string parameter, id=%u, name=%s\n", get_id (), get_name ());
//fprintf (fp, "value=%s\n", getptr ());
char *value = getptr ();
int opts = options->get ();
if (opts & BX_RAW_BYTES) {
char buffer[1024];
buffer[0] = 0;
char sep_string[2];
sep_string[0] = separator;
sep_string[1] = 0;
for (int i=0; i<maxsize; i++) {
char eachbyte[16];
sprintf (eachbyte, "%s%02x", (i>0)?sep_string : "", (unsigned int)0xff&val[i]);
strncat (buffer, eachbyte, sizeof(buffer));
}
if (strlen (buffer) > sizeof(buffer)-4) {
assert (0); // raw byte print buffer is probably overflowing. increase the max or make it dynamic
}
value = buffer;
}
if (get_format ()) {
fprintf (fp, get_format (), getptr ());
fprintf (fp, get_format (), value);
} else {
fprintf (fp, "%s: %s", get_name (), getptr ());
fprintf (fp, "%s: %s", get_name (), value);
}
}
@ -775,6 +794,29 @@ bx_param_enum_c::text_ask (FILE *fpin, FILE *fpout)
return 0;
}
int parse_raw_bytes (char *dest, char *src, int destsize, char separator)
{
printf ("parsing src='%s'\n", src);
int i;
unsigned int n;
for (i=0; i<destsize; i++)
dest[i] = 0;
for (i=0; i<destsize; i++) {
while (*src == separator)
src++;
if (*src == 0) break;
// try to read a byte of hex
if (sscanf (src, "%02x", &n) == 1) {
printf ("found a byte %02x\n", n);
dest[i] = n;
src+=2;
} else {
return -1;
}
}
return 0;
}
int
bx_param_string_c::text_ask (FILE *fpin, FILE *fpout)
{
@ -787,12 +829,24 @@ bx_param_string_c::text_ask (FILE *fpin, FILE *fpout)
fprintf (fpout, "\n");
prompt = "Enter a new value, or press return for no change.\n";
}
//FIXME
char buffer[1024];
status = ask_string (prompt, getptr(), buffer);
if (status < 0) return status;
set (buffer);
return 0;
while (1) {
char buffer[1024];
status = ask_string (prompt, getptr(), buffer);
if (status < 0) return status;
int opts = options->get ();
char buffer2[1024];
strcpy (buffer2, buffer);
if (status == 1 && opts & BX_RAW_BYTES) {
// copy raw hex into buffer
status = parse_raw_bytes (buffer, buffer2, maxsize, separator);
if (status < 0) {
fprintf (fpout, "Illegal raw byte format. I expected something like 3A%c03%c12%c...\n", separator, separator, separator);
continue;
}
}
set (buffer);
return 0;
}
}
int

View File

@ -1,6 +1,6 @@
/*
* gui/siminterface.cc
* $Id: siminterface.cc,v 1.26 2001-06-21 14:55:38 bdenney Exp $
* $Id: siminterface.cc,v 1.27 2001-06-21 19:27:05 bdenney Exp $
*
* Defines the actual link between bx_simulator_interface_c methods
* and the simulator. This file includes bochs.h because it needs
@ -433,6 +433,8 @@ bx_param_string_c::bx_param_string_c (bx_id id,
this->maxsize = maxsize;
strncpy (this->val, initial_val, maxsize);
strncpy (this->initial_val, initial_val, maxsize);
this->options = new bx_param_num_c (BXP_NULL,
"stringoptions", NULL, 0, BX_MAX_INT, 0);
set (initial_val);
}
@ -452,7 +454,10 @@ bx_param_string_c::set_handler (param_string_event_handler handler)
Bit32s
bx_param_string_c::get (char *buf, int len)
{
strncpy (buf, val, len);
if (options->get () & BX_RAW_BYTES)
memcpy (buf, val, len);
else
strncpy (buf, val, len);
if (handler) {
// the handler can choose to replace the value in val/len. Also its
// return value is passed back as the return value of get.
@ -468,7 +473,10 @@ bx_param_string_c::set (char *buf)
// the handler can return a different char* to be copied into the value
buf = (*handler)(this, 1, buf, -1);
}
strncpy (val, buf, maxsize);
if (options->get () & BX_RAW_BYTES)
memcpy (val, buf, maxsize);
else
strncpy (val, buf, maxsize);
}
#if 0

View File

@ -1,6 +1,6 @@
/*
* gui/siminterface.h
* $Id: siminterface.h,v 1.18 2001-06-21 18:34:50 bdenney Exp $
* $Id: siminterface.h,v 1.19 2001-06-21 19:27:05 bdenney Exp $
*
* Interface to the simulator, currently only used by control.cc.
* The base class bx_simulator_interface_c, contains only virtual functions
@ -202,7 +202,12 @@ class bx_param_string_c : public bx_param_c {
int maxsize;
char *val, *initial_val;
param_string_event_handler handler;
bx_param_num_c *options;
char separator;
public:
enum {
BX_RAW_BYTES = 1,
} bx_string_opt_bits;
bx_param_string_c (bx_id id,
char *name,
char *description,
@ -213,6 +218,8 @@ public:
Bit32s get (char *buf, int len);
char *getptr () {return val; }
void set (char *buf);
bx_param_num_c *get_options () { return options; }
void set_separator (char sep) {separator = sep; }
#if BX_UI_TEXT
virtual void text_print (FILE *fp);
virtual int text_ask (FILE *fpin, FILE *fpout);

View File

@ -1161,7 +1161,7 @@ bx_ne2k_c::init(bx_devices_c *d)
// Read in values from config file
BX_NE2K_THIS s.base_address = bx_options.ne2k.Oioaddr->get ();
BX_NE2K_THIS s.base_irq = bx_options.ne2k.Oirq->get ();
memcpy(BX_NE2K_THIS s.physaddr, bx_options.ne2k.macaddr, 6);
memcpy(BX_NE2K_THIS s.physaddr, bx_options.ne2k.Omacaddr->getptr (), 6);
BX_NE2K_THIS s.tx_timer_index =
bx_pc_system.register_timer(this, tx_timer_handler, 0,
@ -1213,7 +1213,7 @@ bx_ne2k_c::init(bx_devices_c *d)
// Attach to the simulated ethernet dev
BX_NE2K_THIS ethdev = eth_locator_c::create(bx_options.ne2k.Oethmod->getptr (),
bx_options.ne2k.Oethdev->getptr (),
(const char *) bx_options.ne2k.macaddr,
(const char *) bx_options.ne2k.Omacaddr->getptr (),
rx_handler,
this);
@ -1222,7 +1222,7 @@ bx_ne2k_c::init(bx_devices_c *d)
bx_options.ne2k.Oethmod->getptr ()));
BX_NE2K_THIS ethdev = eth_locator_c::create("null", NULL,
(const char *) bx_options.ne2k.macaddr,
(const char *) bx_options.ne2k.Omacaddr->getptr (),
rx_handler,
this);
if (BX_NE2K_THIS ethdev == NULL)

View File

@ -83,7 +83,7 @@ bx_options_t bx_options = {
NULL, // default private_colormap
NULL, // default i440FXSupport
{NULL, NULL}, // cmos path, cmos image boolean
{ 0, 0, 0, {0,0,0,0,0,0}, NULL, NULL }, // ne2k
{ NULL, NULL, NULL, NULL, NULL, NULL }, // ne2k
NULL, // newHardDriveSupport
{ 0, NULL, NULL, NULL }, // load32bitOSImage hack stuff
// log options: ignore debug, report info and error, crash on panic.
@ -496,6 +496,12 @@ void bx_init_options ()
"to be written",
0, 15,
0);
bx_options.ne2k.Omacaddr = new bx_param_string_c (BXP_NE2K_MACADDR,
"MAC Address",
"to be written",
"", 6);
bx_options.ne2k.Omacaddr->get_options ()->set (bx_options.ne2k.Omacaddr->BX_RAW_BYTES);
bx_options.ne2k.Omacaddr->set_separator (':');
bx_options.ne2k.Oethmod = new bx_param_string_c (BXP_NE2K_ETHMOD,
"Ethernet module",
"to be written",
@ -508,8 +514,7 @@ void bx_init_options ()
bx_options.ne2k.Ovalid,
bx_options.ne2k.Oioaddr,
bx_options.ne2k.Oirq,
#warning cannot set mac address with this interface
// mac address needs work
bx_options.ne2k.Omacaddr,
bx_options.ne2k.Oethmod,
bx_options.ne2k.Oethdev,
NULL
@ -1421,6 +1426,7 @@ parse_line_formatted(char *context, int num_params, char *params[])
#endif
else if (!strcmp(params[0], "ne2k")) {
int tmp[6];
char tmpchar[6];
bx_options.ne2k.Ovalid->set (0);
if ((num_params < 4) || (num_params > 6)) {
BX_PANIC(("%s: ne2k directive malformed.", context));
@ -1448,7 +1454,8 @@ parse_line_formatted(char *context, int num_params, char *params[])
return;
}
for (i=0;i<6;i++)
bx_options.ne2k.macaddr[i] = tmp[i];
tmpchar[i] = (unsigned char)tmp[i];
bx_options.ne2k.Omacaddr->set (tmpchar);
if (num_params > 4) {
if (strncmp(params[4], "ethmod=", 7)) {
BX_PANIC(("%s: ne2k directive malformed.", context));
@ -1575,15 +1582,16 @@ bx_write_ne2k_options (FILE *fp, bx_ne2k_options *opt)
fprintf (fp, "# no ne2k\n");
return 0;
}
char *ptr = opt->Omacaddr->getptr ();
fprintf (fp, "ne2k: ioaddr=0x%x, irq=%d, mac=%02x:%02x:%02x:%02x:%02x:%02x, ethmod=%s, ethdev=%s\n",
opt->Oioaddr->get (),
opt->Oirq->get (),
opt->macaddr[0],
opt->macaddr[1],
opt->macaddr[2],
opt->macaddr[3],
opt->macaddr[4],
opt->macaddr[5],
(unsigned int)ptr[0],
(unsigned int)ptr[1],
(unsigned int)ptr[2],
(unsigned int)ptr[3],
(unsigned int)ptr[4],
(unsigned int)ptr[5],
opt->Oethmod->getptr (),
opt->Oethdev->getptr ());
return 0;