Bochs/bochs/patches/patch.param-tree
2005-08-10 19:29:22 +00:00

843 lines
27 KiB
Plaintext

----------------------------------------------------------------------
Patch name: patch.param-tree
Author: Bryce Denney
Date: Mon Mar 17 00:21:53 EST 2003
Status: Not complete
Detailed description:
I'm trying to organize the parameters into a tree structure instead of
a huge flat list. I want to get rid of the bx_id enumerated type and
parameter id numbers entirely. Instead of locating a parameter by its
id number (e.g. BXP_COM2_ENABLED) which is set at compile time, it can be
located by a string name such as "serial.1.enabled". This string would find
the parameter by traversing a tree of parameters that looks something like
serial
0
enabled (was BXP_COM1_ENABLED)
path (was BXP_COM1_PATH)
1
enabled (was BXP_COM2_ENABLED)
path (was BXP_COM2_PATH)
2
enabled (was BXP_COM3_ENABLED)
path (was BXP_COM3_PATH)
3
enabled (was BXP_COM4_ENABLED)
path (was BXP_COM4_PATH)
This is not ready to be checked in! I wanted to commit the patch in case
anybody wanted to see the direction I was heading. I added some testing
code in main.cc, and I've converted just one parameter into tree form:
memory.ram.megs
The old way to look up this value was with the id number
SIM->get_param(BXP_MEM_SIZE);
The new way to look it up is with the string
SIM->get_param("memory.ram.megs");
The patch now applies to current CVS again. There are no functional changes
present yet.
(Volker Ruppert, July 31, 2005)
Converted romimage, vgaromimage and optromimage parameter to the param-tree
structure.
(Volker Ruppert, Aug 10, 2005)
Patch was created with:
diff -u
Apply patch to what version:
cvs checked out on 10 Aug 2005
Instructions:
To patch, go to main bochs directory.
Type "patch -p0 < THIS_PATCH_FILE".
----------------------------------------------------------------------
diff -urNX /home/volker/exclude-bochs /home/volker/bochs/bochs.h ./bochs.h
--- /home/volker/bochs/bochs.h 2005-07-31 17:35:01.000000000 +0200
+++ ./bochs.h 2005-07-31 17:45:13.000000000 +0200
@@ -111,6 +111,7 @@
int bx_read_configuration (char *rcfile);
int bx_write_configuration (char *rcfile, int overwrite);
void bx_reset_options (void);
+void print_tree (bx_param_c *node, int level = 0);
//
// some macros to interface the CPU and memory to external environment
diff -urNX /home/volker/exclude-bochs /home/volker/bochs/config.cc ./config.cc
--- /home/volker/bochs/config.cc 2005-08-07 17:50:07.000000000 +0200
+++ ./config.cc 2005-08-07 19:39:41.822785232 +0200
@@ -372,6 +372,8 @@
memset (&bx_options, 0, sizeof(bx_options));
+ bx_param_c *root_param = SIM->get_param(".");
+
// quick start option, set by command line arg
new bx_param_enum_c (BXP_BOCHS_START,
"Bochs start types",
@@ -809,9 +811,16 @@
menu = new bx_list_c (BXP_BOOT, "Boot options", "", boot_init_list);
#endif
+ // memory subtree
+ bx_list_c *memory = new bx_list_c (root_param, "memory", "");
+ bx_list_c *ram = new bx_list_c (memory, "ram", "");
+ bx_list_c *rom = new bx_list_c (memory, "rom", "");
+ bx_list_c *vgarom = new bx_list_c (memory, "vgarom", "");
+ bx_list_c *optrom = new bx_list_c (memory, "optrom", "");
+
// memory options (ram & rom)
- bx_options.memory.Osize = new bx_param_num_c (BXP_MEM_SIZE,
- "memory.ram.megs",
+ bx_options.memory.Osize = new bx_param_num_c (ram,
+ "megs",
"Amount of RAM in megabytes",
1, 2048,
BX_DEFAULT_MEM_MEGS);
@@ -822,15 +831,15 @@
bx_options.memory.Osize->set_options (bx_param_num_c::USE_SPIN_CONTROL);
#endif
- bx_options.rom.Opath = new bx_param_filename_c (BXP_ROM_PATH,
- "memory.rom.path",
+ bx_options.rom.Opath = new bx_param_filename_c (rom,
+ "path",
"Pathname of ROM image to load",
"", BX_PATHNAME_LEN);
bx_options.rom.Opath->set_format ("Name of ROM BIOS image: %s");
sprintf(name, "%s/BIOS-bochs-latest", BX_SHARE_PATH);
bx_options.rom.Opath->set (name);
- bx_options.rom.Oaddress = new bx_param_num_c (BXP_ROM_ADDRESS,
- "memory.rom.addr",
+ bx_options.rom.Oaddress = new bx_param_num_c (rom,
+ "addr",
"The address at which the ROM image should be loaded",
0, BX_MAX_BIT32U,
0xf0000);
@@ -843,8 +852,8 @@
bx_options.rom.Oaddress->set_format ("ROM BIOS address: 0x%05x");
#endif
- bx_options.vgarom.Opath = new bx_param_filename_c (BXP_VGA_ROM_PATH,
- "memory.vgarom.path",
+ bx_options.vgarom.Opath = new bx_param_filename_c (vgarom,
+ "path",
"Pathname of VGA ROM image to load",
"", BX_PATHNAME_LEN);
bx_options.vgarom.Opath->set_format ("Name of VGA BIOS image: %s");
@@ -855,19 +864,19 @@
bx_options.vgarom.Opath->set (name);
for (i=0; i<4; i++) {
- sprintf (name, "memory.optrom.%d.path", i+1);
+ sprintf (name, "%d", i+1);
+ bx_list_c *optnum = new bx_list_c (optrom, strdup(name), "");
sprintf (descr, "Pathname of optional ROM image #%d to load", i+1);
- bx_options.optrom[i].Opath = new bx_param_filename_c ((bx_id)(BXP_OPTROM1_PATH+i),
- strdup(name),
+ bx_options.optrom[i].Opath = new bx_param_filename_c (optnum,
+ "path",
strdup(descr),
"", BX_PATHNAME_LEN);
sprintf (label, "Name of optional ROM image #%d", i+1);
strcat(label, " : %s");
bx_options.optrom[i].Opath->set_format (strdup(label));
- sprintf (name, "memory.optrom.%d.address", i+1);
sprintf (descr, "The address at which the optional ROM image #%d should be loaded", i+1);
- bx_options.optrom[i].Oaddress = new bx_param_num_c ((bx_id)(BXP_OPTROM1_ADDRESS+i),
- strdup(name),
+ bx_options.optrom[i].Oaddress = new bx_param_num_c (optnum,
+ "addr",
strdup(descr),
0, BX_MAX_BIT32U,
0);
@@ -1700,6 +1709,9 @@
};
menu = new bx_list_c (BXP_MENU_RUNTIME, "Misc runtime options", "", runtime_init_list);
menu->get_options ()->set (menu->SHOW_PARENT | menu->SHOW_GROUP_NAME);
+
+ printf ("parameter tree:\n");
+ print_tree (root_param, 0);
}
void bx_reset_options ()
@@ -1745,7 +1757,7 @@
bx_options.OfloppySigCheck->reset();
// memory (ram & rom)
- bx_options.memory.Osize->reset();
+ SIM->get_param("memory.ram.megs")->reset ();
bx_options.rom.Opath->reset();
bx_options.rom.Oaddress->reset();
bx_options.vgarom.Opath->reset();
@@ -2609,7 +2621,7 @@
if (num_params != 2) {
PARSE_ERR(("%s: megs directive: wrong # args.", context));
}
- bx_options.memory.Osize->set (atol(params[1]));
+ SIM->get_param_num("memory.ram.megs")->set (atol(params[1]));
} else if (!strcmp(params[0], "romimage")) {
if (num_params != 3) {
PARSE_ERR(("%s: romimage directive: wrong # args.", context));
diff -urNX /home/volker/exclude-bochs /home/volker/bochs/gui/siminterface.cc ./gui/siminterface.cc
--- /home/volker/bochs/gui/siminterface.cc 2005-01-05 20:50:54.000000000 +0100
+++ ./gui/siminterface.cc 2005-08-07 18:50:56.320529176 +0200
@@ -11,6 +11,7 @@
bx_simulator_interface_c *SIM = NULL;
logfunctions *siminterface_log = NULL;
+bx_list_c *root_param = NULL;
#define LOG_THIS siminterface_log->
// bx_simulator_interface just defines the interface that the Bochs simulator
@@ -52,10 +53,19 @@
virtual int register_param (bx_id id, bx_param_c *it);
virtual void reset_all_param ();
virtual bx_param_c *get_param (bx_id id);
+ virtual bx_param_c *get_param (const char *pname, bx_param_c *base=NULL);
+ // deprecated
virtual bx_param_num_c *get_param_num (bx_id id);
+ // deprecated
virtual bx_param_string_c *get_param_string (bx_id id);
+ // deprecated
virtual bx_param_bool_c *get_param_bool (bx_id id);
+ // deprecated
virtual bx_param_enum_c *get_param_enum (bx_id id);
+ virtual bx_param_num_c *get_param_num (const char *pname);
+ virtual bx_param_string_c *get_param_string (const char *pname);
+ virtual bx_param_bool_c *get_param_bool (const char *pname);
+ virtual bx_param_enum_c *get_param_enum (const char *pname);
virtual int get_n_log_modules ();
virtual char *get_prefix (int mod);
virtual int get_log_action (int mod, int level);
@@ -146,6 +156,56 @@
return retval;
}
+// recursive function to find parameters from the path
+static
+bx_param_c *find_param (const char *full_pname, const char *rest_of_pname, bx_param_c *base)
+{
+ const char *from = rest_of_pname;
+ char component[BX_PATHNAME_LEN];
+ char *to = component;
+ // copy the first piece of pname into component, stopping at first separator
+ // or at the end of the string
+ while (*from != 0 && *from != '.') {
+ *to = *from;
+ to++;
+ from++;
+ }
+ *to = 0;
+ if (!component[0]) {
+ BX_PANIC (("find_param: found empty component in parameter name %s", full_pname));
+ // or does that mean that we're done?
+ }
+ if (base->get_type() != BXT_LIST) {
+ BX_PANIC (("find_param: base was not a list!"));
+ }
+ BX_INFO (("searching for component '%s' in list '%s'", component, base->get_name()));
+
+ // find the component in the list.
+ bx_list_c *list = (bx_list_c *)base;
+ bx_param_c *child = list->get_by_name (component);
+ // if child not found, there is nothing else that can be done. return NULL.
+ if (child == NULL) return NULL;
+ if (from[0] == 0) {
+ // that was the end of the path, we're done
+ return child;
+ }
+ // continue parsing the path
+ BX_ASSERT(from[0] == '.');
+ from++; // skip over the separator
+ return find_param (full_pname, from, child);
+}
+
+bx_param_c *
+bx_real_sim_c::get_param (const char *pname, bx_param_c *base)
+{
+ if (base == NULL)
+ base = root_param;
+ // to access top level object, look for parameter "."
+ if (pname[0] == '.' && pname[1] == 0)
+ return base;
+ return find_param (pname, pname, base);
+}
+
bx_param_num_c *
bx_real_sim_c::get_param_num (bx_id id) {
bx_param_c *generic = get_param(id);
@@ -160,6 +220,20 @@
return NULL;
}
+bx_param_num_c *
+bx_real_sim_c::get_param_num (const char *pname) {
+ bx_param_c *generic = get_param(pname);
+ if (generic==NULL) {
+ BX_PANIC (("get_param_num(%s) could not find a parameter", pname));
+ return NULL;
+ }
+ int type = generic->get_type ();
+ if (type == BXT_PARAM_NUM || type == BXT_PARAM_BOOL || type == BXT_PARAM_ENUM)
+ return (bx_param_num_c *)generic;
+ BX_PANIC (("get_param_num(%s) could not find an integer parameter with that name", pname));
+ return NULL;
+}
+
bx_param_string_c *
bx_real_sim_c::get_param_string (bx_id id) {
bx_param_c *generic = get_param(id);
@@ -173,6 +247,19 @@
return NULL;
}
+bx_param_string_c *
+bx_real_sim_c::get_param_string (const char *pname) {
+ bx_param_c *generic = get_param(pname);
+ if (generic==NULL) {
+ BX_PANIC (("get_param_string(%s) could not find a parameter", pname));
+ return NULL;
+ }
+ if (generic->get_type () == BXT_PARAM_STRING)
+ return (bx_param_string_c *)generic;
+ BX_PANIC (("get_param_string(%s) could not find an integer parameter with that name", pname));
+ return NULL;
+}
+
bx_param_bool_c *
bx_real_sim_c::get_param_bool (bx_id id) {
bx_param_c *generic = get_param(id);
@@ -186,6 +273,19 @@
return NULL;
}
+bx_param_bool_c *
+bx_real_sim_c::get_param_bool (const char *pname) {
+ bx_param_c *generic = get_param(pname);
+ if (generic==NULL) {
+ BX_PANIC (("get_param_bool(%s) could not find a parameter", pname));
+ return NULL;
+ }
+ if (generic->get_type () == BXT_PARAM_BOOL)
+ return (bx_param_bool_c *)generic;
+ BX_PANIC (("get_param_bool(%s) could not find a bool parameter with that name", pname));
+ return NULL;
+}
+
bx_param_enum_c *
bx_real_sim_c::get_param_enum (bx_id id) {
bx_param_c *generic = get_param(id);
@@ -199,6 +299,19 @@
return NULL;
}
+bx_param_enum_c *
+bx_real_sim_c::get_param_enum (const char *pname) {
+ bx_param_c *generic = get_param(pname);
+ if (generic==NULL) {
+ BX_PANIC (("get_param_enum(%s) could not find a parameter", pname));
+ return NULL;
+ }
+ if (generic->get_type () == BXT_PARAM_ENUM)
+ return (bx_param_enum_c *)generic;
+ BX_PANIC (("get_param_enum(%s) could not find a enum parameter with that name", pname));
+ return NULL;
+}
+
void bx_init_siminterface ()
{
siminterface_log = new logfunctions ();
@@ -206,6 +319,12 @@
siminterface_log->settype(CTRLLOG);
if (SIM == NULL)
SIM = new bx_real_sim_c();
+ if (root_param == NULL) {
+ root_param = new bx_list_c (NULL,
+ "bochs",
+ "list of top level bochs parameters",
+ 30);
+ }
}
bx_simulator_interface_c::bx_simulator_interface_c ()
@@ -806,6 +925,7 @@
this->group_name = NULL;
this->runtime_param = 0;
this->enabled = 1;
+ this->parent = NULL;
SIM->register_param (id, this);
}
@@ -815,6 +935,22 @@
return old;
}
+void bx_list_c::set_parent (bx_param_c *newparent) {
+ if (parent) {
+ // if this object already had a parent, the correct thing
+ // to do would be to remove this object from the parent's
+ // list of children. Deleting children is currently
+ // not supported.
+ BX_PANIC (("bx_list_c::set_parent: changing from one parent to another is not supported"));
+ }
+ if (newparent) {
+ BX_ASSERT(newparent->get_type() == BXT_LIST);
+ this->parent = (bx_list_c *)newparent;
+ this->parent->add (this);
+ }
+}
+
+
bx_param_num_c::bx_param_num_c (bx_id id,
char *name,
char *description,
@@ -835,6 +971,28 @@
set (initial_val);
}
+bx_param_num_c::bx_param_num_c (bx_param_c *parent,
+ char *name,
+ char *description,
+ Bit64s min, Bit64s max, Bit64s initial_val)
+ : bx_param_c (BXP_NULL, name, description)
+{
+ set_type (BXT_PARAM_NUM);
+ this->min = min;
+ this->max = max;
+ this->initial_val = initial_val;
+ this->val.number = initial_val;
+ this->handler = NULL;
+ this->base = default_base;
+ // dependent_list must be initialized before the set(),
+ // because set calls update_dependents().
+ dependent_list = NULL;
+ set (initial_val);
+ BX_ASSERT(parent->get_type() == BXT_LIST);
+ this->parent = (bx_list_c *) parent;
+ if (this->parent) this->parent->add (this);
+}
+
Bit32u bx_param_num_c::default_base = 10;
Bit32u bx_param_num_c::set_default_base (Bit32u val) {
@@ -892,7 +1050,7 @@
val.number = newval;
}
if ((val.number < min || val.number > max) && (Bit64u)max != BX_MAX_BIT64U)
- BX_PANIC (("numerical parameter %s was set to " FMT_LL "d, which is out of range " FMT_LL "d to " FMT_LL "d", get_name (), val.number, min, max));
+ BX_PANIC (("numerical parameter '%s' was set to " FMT_LL "d, which is out of range " FMT_LL "d to " FMT_LL "d", get_name (), val.number, min, max));
if (dependent_list != NULL) update_dependents ();
}
@@ -1105,6 +1263,12 @@
}
}
+void
+bx_shadow_num_c::reset ()
+{
+ BX_PANIC (("reset not supported on bx_shadow_num_c yet"));
+}
+
bx_param_bool_c::bx_param_bool_c (bx_id id,
char *name,
char *description,
@@ -1213,6 +1377,31 @@
set (initial_val);
}
+bx_param_string_c::bx_param_string_c (bx_param_c *parent,
+ char *name,
+ char *description,
+ char *initial_val,
+ int maxsize)
+ : bx_param_c (BXP_NULL, name, description)
+{
+ set_type (BXT_PARAM_STRING);
+ if (maxsize < 0)
+ maxsize = strlen(initial_val) + 1;
+ this->val = new char[maxsize];
+ this->initial_val = new char[maxsize];
+ this->handler = NULL;
+ this->enable_handler = NULL;
+ 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_BIT64S, 0);
+ set (initial_val);
+ BX_ASSERT(parent->get_type() == BXT_LIST);
+ this->parent = (bx_list_c *) parent;
+ if (this->parent) this->parent->add (this);
+}
+
bx_param_filename_c::bx_param_filename_c (bx_id id,
char *name,
char *description,
@@ -1223,6 +1412,16 @@
get_options()->set (IS_FILENAME);
}
+bx_param_filename_c::bx_param_filename_c (bx_param_c *parent,
+ char *name,
+ char *description,
+ char *initial_val,
+ int maxsize)
+ : bx_param_string_c (parent, name, description, initial_val, maxsize)
+{
+ get_options()->set (IS_FILENAME);
+}
+
bx_param_string_c::~bx_param_string_c ()
{
if ( this->val != NULL )
@@ -1316,6 +1515,7 @@
this->size = 0;
this->maxsize = maxsize;
this->list = new bx_param_c* [maxsize];
+ this->parent = NULL;
init ();
}
@@ -1326,6 +1526,24 @@
this->size = 0;
this->maxsize = maxsize;
this->list = new bx_param_c* [maxsize];
+ this->parent = NULL;
+ init ();
+}
+
+bx_list_c::bx_list_c (bx_param_c *parent, char *name, char *description,
+ int maxsize)
+ : bx_param_c (BXP_NULL, name, description)
+{
+ set_type (BXT_LIST);
+ this->size = 0;
+ this->maxsize = maxsize;
+ this->list = new bx_param_c* [maxsize];
+ this->parent = NULL;
+ if (parent) {
+ BX_ASSERT(parent->get_type() == BXT_LIST);
+ this->parent = (bx_list_c *)parent;
+ this->parent->add (this);
+ }
init ();
}
@@ -1341,6 +1559,7 @@
for (int i=0; i<this->size; i++)
this->list[i] = init_list[i];
init ();
+ this->parent = NULL;
}
bx_list_c::~bx_list_c()
@@ -1381,17 +1600,15 @@
this->choice = new bx_param_num_c (BXP_NULL,
"list_choice", "", 0, BX_MAX_BIT64S,
1);
- this->parent = NULL;
}
bx_list_c *
bx_list_c::clone ()
{
- bx_list_c *newlist = new bx_list_c (BXP_NULL, name, description, maxsize);
+ bx_list_c *newlist = new bx_list_c (get_parent(), name, description, maxsize);
for (int i=0; i<get_size (); i++)
newlist->add (get(i));
newlist->set_options (get_options ());
- newlist->set_parent (get_parent ());
return newlist;
}
@@ -1411,3 +1628,16 @@
return list[index];
}
+bx_param_c *
+bx_list_c::get_by_name (const char *name)
+{
+ int i, imax = get_size ();
+ for (i=0; i<imax; i++) {
+ bx_param_c *p = get(i);
+ if (0 == strcmp (name, p->get_name ())) {
+ return p;
+ }
+ }
+ return NULL;
+}
+
diff -urNX /home/volker/exclude-bochs /home/volker/bochs/gui/siminterface.h ./gui/siminterface.h
--- /home/volker/bochs/gui/siminterface.h 2005-07-31 16:49:45.000000000 +0200
+++ ./gui/siminterface.h 2005-08-07 18:51:30.985259336 +0200
@@ -885,6 +885,7 @@
class BOCHSAPI bx_param_c : public bx_object_c {
BOCHSAPI_CYGONLY static const char *default_text_format;
protected:
+ bx_list_c *parent;
char *name;
char *description;
char *label; // label string for text menus and gui dialogs
@@ -895,6 +896,7 @@
int enabled;
public:
bx_param_c (bx_id id, char *name, char *description);
+ bx_param_c *get_parent () { return (bx_param_c *) parent; }
void set_format (const char *format) {text_format = format;}
const char *get_format () {return text_format;}
void set_ask_format (char *format) {ask_format = format; }
@@ -909,7 +911,7 @@
char *get_description () { return description; }
int get_enabled () { return enabled; }
virtual void set_enabled (int enabled) { this->enabled = enabled; }
- void reset () {}
+ virtual void reset () {}
int getint () {return -1;}
static const char* set_default_format (const char *f);
static const char *get_default_format () { return default_text_format; }
@@ -955,7 +957,11 @@
char *name,
char *description,
Bit64s min, Bit64s max, Bit64s initial_val);
- void reset ();
+ bx_param_num_c (bx_param_c *parent,
+ char *name,
+ char *description,
+ Bit64s min, Bit64s max, Bit64s initial_val);
+ virtual void reset ();
void set_handler (param_event_handler handler);
void set_enable_handler (param_enable_handler handler);
virtual bx_list_c *get_dependent_list () { return dependent_list; }
@@ -1040,6 +1046,7 @@
Bit8u lowbit = 0);
virtual Bit64s get64 ();
virtual void set (Bit64s val);
+ virtual void reset ();
};
class BOCHSAPI bx_param_bool_c : public bx_param_num_c {
@@ -1113,8 +1120,13 @@
char *description,
char *initial_val,
int maxsize=-1);
+ bx_param_string_c (bx_param_c *parent,
+ char *name,
+ char *description,
+ char *initial_val,
+ int maxsize=-1);
virtual ~bx_param_string_c ();
- void reset ();
+ virtual void reset ();
void set_handler (param_string_event_handler handler);
void set_enable_handler (param_enable_handler handler);
virtual void set_enabled (int enabled);
@@ -1142,10 +1154,17 @@
char *description,
char *initial_val,
int maxsize=-1);
+ bx_param_filename_c (bx_param_c *parent,
+ char *name,
+ char *description,
+ char *initial_val,
+ int maxsize=-1);
};
+#define BX_DEFAULT_LIST_SIZE 6
+
class BOCHSAPI bx_list_c : public bx_param_c {
-private:
+protected:
// just a list of bx_param_c objects. size tells current number of
// objects in the list, and maxsize tells how many list items are
// allocated in the constructor.
@@ -1162,8 +1181,7 @@
// title of the menu or series
bx_param_string_c *title;
// if the menu shows a "return to previous menu" type of choice,
- // this controls where that choice will go.
- bx_param_c *parent;
+ // "parent" controls where that choice will go.
void init ();
public:
enum {
@@ -1188,19 +1206,21 @@
// item (used in the runtime menu).
SHOW_GROUP_NAME = (1<<4)
} bx_listopt_bits;
- bx_list_c (bx_id id, int maxsize);
+ bx_list_c (bx_id id, int maxsize = BX_DEFAULT_LIST_SIZE);
bx_list_c (bx_id id, char *name, char *description, bx_param_c **init_list);
- bx_list_c (bx_id id, char *name, char *description, int maxsize);
+ bx_list_c (bx_id id, char *name, char *description, int maxsize = BX_DEFAULT_LIST_SIZE);
+ bx_list_c (bx_param_c *parent, char *name, char *description, int maxsize = BX_DEFAULT_LIST_SIZE);
virtual ~bx_list_c();
bx_list_c *clone ();
void add (bx_param_c *param);
bx_param_c *get (int index);
+ bx_param_c *get_by_name (const char *name);
int get_size () { return size; }
bx_param_num_c *get_options () { return options; }
void set_options (bx_param_num_c *newopt) { options = newopt; }
bx_param_num_c *get_choice () { return choice; }
bx_param_string_c *get_title () { return title; }
- void set_parent (bx_param_c *newparent) { parent = newparent; }
+ void set_parent (bx_param_c *newparent);
bx_param_c *get_parent () { return parent; }
#if BX_USE_TEXTCONFIG
virtual void text_print (FILE *);
@@ -1404,10 +1424,19 @@
virtual int register_param (bx_id id, bx_param_c *it) {return -1;}
virtual void reset_all_param () {}
virtual bx_param_c *get_param (bx_id id) {return NULL;}
+ virtual bx_param_c *get_param (const char *pname, bx_param_c *base=NULL) {return NULL;}
+ // deprecated
virtual bx_param_num_c *get_param_num (bx_id id) {return NULL;}
+ // deprecated
virtual bx_param_string_c *get_param_string (bx_id id) {return NULL;}
+ // deprecated
virtual bx_param_bool_c *get_param_bool (bx_id id) {return NULL;}
+ // deprecated
virtual bx_param_enum_c *get_param_enum (bx_id id) {return NULL;}
+ virtual bx_param_num_c *get_param_num (const char *pname) {return NULL;}
+ virtual bx_param_string_c *get_param_string (const char *pname) {return NULL;}
+ virtual bx_param_bool_c *get_param_bool (const char *pname) {return NULL;}
+ virtual bx_param_enum_c *get_param_enum (const char *pname) {return NULL;}
virtual int get_n_log_modules () {return -1;}
virtual char *get_prefix (int mod) {return 0;}
virtual int get_log_action (int mod, int level) {return -1;}
diff -urNX /home/volker/exclude-bochs /home/volker/bochs/main.cc ./main.cc
--- /home/volker/bochs/main.cc 2005-08-07 11:03:15.000000000 +0200
+++ ./main.cc 2005-08-07 19:56:48.715673784 +0200
@@ -176,6 +176,105 @@
}
#endif
+void bx_test_params () {
+ printf ("Begin\n");
+
+ // create numeric parameter a
+ bx_param_num_c *ap = new bx_param_num_c (BXP_NULL,
+ "parameter a",
+ "description of a",
+ 0, // minimum value
+ 10, // maximum value
+ 1); // default value
+ printf ("%s is %d\n", ap->get_name(), ap->get ());
+ ap->set(10);
+ printf ("%s is %d\n", ap->get_name(), ap->get ());
+ //ap->set(11); // causes assert because 11 is out of range
+ printf ("Resetting a to initial value.\n");
+ ap->reset ();
+ printf ("%s is %d\n", ap->get_name(), ap->get ());
+ Bit32u b = 77;
+ bx_param_num_c *bp = new bx_shadow_num_c (BXP_NULL,
+ "shadow parameter b",
+ "description of b",
+ &b);
+ printf ("%s is %d\n", bp->get_name(), bp->get ());
+ b = 32;
+ printf ("%s is %d\n", bp->get_name(), bp->get ());
+ bp->set (45);
+ printf ("%s is %d\n", bp->get_name(), bp->get ());
+ //printf ("Resetting b to initial value.\n");
+ //bp->reset (); // not supported on shadow params
+ printf ("%s is %d\n", bp->get_name(), bp->get ());
+ printf ("End\n");
+}
+
+void print_tree (bx_param_c *node, int level)
+{
+ int i;
+ for (i=0; i<level; i++)
+ printf (" ");
+ if (node == NULL) {
+ printf ("NULL pointer\n");
+ return;
+ }
+ switch (node->get_type()) {
+ case BXT_PARAM_NUM:
+ if (((bx_param_num_c*)node)->get_base() == 10) {
+ printf ("%s = %d (number)\n", node->get_name(), ((bx_param_num_c*)node)->get());
+ } else {
+ printf ("%s = 0x%x (hex number)\n", node->get_name(), ((bx_param_num_c*)node)->get());
+ }
+ break;
+ case BXT_PARAM_BOOL:
+ printf ("%s = %s (boolean)\n", node->get_name(), ((bx_param_bool_c*)node)->get()?"true":"false");
+ break;
+ case BXT_PARAM:
+ case BXT_PARAM_ENUM:
+ case BXT_PARAM_STRING:
+ printf ("%s = '%s' (string)\n", node->get_name(), ((bx_param_string_c*)node)->getptr());
+ break;
+ case BXT_LIST:
+ {
+ printf ("%s = \n", node->get_name ());
+ bx_list_c *list = (bx_list_c*)node;
+ for (i=0; i < list->get_size (); i++) {
+ print_tree (list->get(i), level+1);
+ }
+ break;
+ }
+ }
+}
+
+void test_lookup (const char *pname)
+{
+ printf ("looking up parameter '%s'\n", pname);
+ bx_param_c *param = SIM->get_param (pname);
+ print_tree (param);
+}
+
+void bx_test_param_tree () {
+ printf ("bx_test_param_tree\n");
+ bx_list_c *top = new bx_list_c (BXP_NULL,
+ "bochs", "top level object",
+ 20);
+ bx_list_c *memory = new bx_list_c (top, "memory", "", 5);
+ bx_list_c *ram = new bx_list_c (memory, "ram", "", 5);
+ new bx_param_num_c (ram, "size", "Size of RAM in megabytes",
+ 1, BX_MAX_BIT32U, BX_DEFAULT_MEM_MEGS);
+ bx_list_c *rom = new bx_list_c (memory, "rom", "", 5);
+ new bx_param_num_c (rom, "address", "ROM Address",
+ 0, 0xffff, 0xf000);
+ print_tree (top);
+ printf ("Finding memory size: \n");
+ test_lookup (".");
+ test_lookup ("memory.ram.size");
+ test_lookup ("memory.ram");
+ //test_lookup ("memory.ram."); // illegal
+ //test_lookup ("memory.ram..size"); // illegal
+ printf ("bx_test_param_tree done\n");
+}
+
int bxmain () {
#ifdef HAVE_LOCALE_H
// Initialize locale (for isprint() and other functions)
@@ -183,6 +282,12 @@
#endif
bx_user_quit = 0;
bx_init_siminterface (); // create the SIM object
+ //bx_test_params ();
+ //bx_test_param_tree ();
+ //exit(0);
+
+
+
static jmp_buf context;
if (setjmp (context) == 0) {
SIM->set_quit_context (&context);
@@ -849,7 +954,8 @@
BX_ERROR(("No romimage to load. Is your bochsrc file loaded/valid ?"));
}
- Bit32u memSize = bx_options.memory.Osize->get ()*1024*1024;
+ bx_param_num_c *bxp_memsize = SIM->get_param_num("memory.ram.megs");
+ Bit32u memSize = bxp_memsize->get() * 1024*1024;
#if BX_SUPPORT_ICACHE
pageWriteStampTable.alloc(memSize);