- now megs, ips, mouse_enabled, vga_update_interval, and rom_path

are using Bryce's experimental parameter structures.
This commit is contained in:
Bryce Denney 2001-06-16 19:29:59 +00:00
parent c5b355e4bd
commit 8f5bb7419d
5 changed files with 218 additions and 63 deletions

View File

@ -325,6 +325,7 @@ class iofunctions {
#define CPU15LOG 40
#define CTRLLOG 41
#define UNMAPLOG 42
#define SERRLOG 43
public:
@ -606,7 +607,8 @@ typedef struct {
} bx_vgarom_options;
typedef struct {
size_t megs;
//size_t megs;
bx_param_num_c *size;
} bx_mem_options;
typedef struct {

View File

@ -1,6 +1,6 @@
/*
* gui/control.cc
* $Id: control.cc,v 1.18 2001-06-15 23:52:34 bdenney Exp $
* $Id: control.cc,v 1.19 2001-06-16 19:29:59 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
@ -400,6 +400,7 @@ void build_runtime_options_prompt (char *format, char *buf, int size)
{
bx_floppy_options floppyop;
bx_cdrom_options cdromop;
bx_param_num_c *ips = SIM->get_param_num (BXP_IPS);
char buffer[3][128];
for (int i=0; i<2; i++) {
SIM->get_floppy_options (i, &floppyop);
@ -413,9 +414,9 @@ void build_runtime_options_prompt (char *format, char *buf, int size)
cdromop.dev, cdromop.present?"":"not ",
cdromop.inserted?"inserted":"ejected");
snprintf (buf, size, format, buffer[0], buffer[1], buffer[2],
SIM->ips->get (),
SIM->vga_update_interval->get (),
SIM->mouse_enabled->get () ? "enabled" : "disabled");
ips->get (),
SIM->get_param_num (BXP_VGA_UPDATE_INTERVAL)->get (),
SIM->get_param_num (BXP_MOUSE_ENABLED)->get () ? "enabled" : "disabled");
}
// return value of bx_control_panel:
@ -477,12 +478,13 @@ int bx_control_panel (int menu)
case BX_CPANEL_START_OPTS_MEM:
{
char prompt[CPANEL_PATH_LEN], vgapath[CPANEL_PATH_LEN], rompath[CPANEL_PATH_LEN];
if (SIM->get_rom_path (rompath, CPANEL_PATH_LEN) < 0)
bx_param_num_c *memsize = SIM->get_param_num (BXP_MEM_SIZE);
if (SIM->rom_path->get (rompath, CPANEL_PATH_LEN) < 0)
strcpy (rompath, "none");
if (SIM->get_vga_path (vgapath, CPANEL_PATH_LEN) < 0)
strcpy (vgapath, "none");
sprintf (prompt, startup_mem_options_prompt,
SIM->memsize->get (),
memsize->get (),
vgapath, rompath,
SIM->get_rom_address ());
if (ask_int (prompt, 0, 4, 0, &choice) < 0) return -1;
@ -499,11 +501,12 @@ int bx_control_panel (int menu)
case BX_CPANEL_START_OPTS_INTERFACE:
{
char prompt[1024];
int interval = SIM->vga_update_interval->get ();
int interval = SIM->get_param_num (BXP_VGA_UPDATE_INTERVAL)->get ();
bx_param_num_c *ips = SIM->get_param_num (BXP_IPS);
sprintf (prompt, startup_interface_options,
interval,
SIM->mouse_enabled->get () ? "enabled" : "disabled",
SIM->ips->get (),
SIM->get_param_num (BXP_MOUSE_ENABLED)->get () ? "enabled" : "disabled",
ips->get (),
SIM->get_private_colormap () ? "enabled" : "disabled");
if (ask_int (prompt, 0, 4, 0, &choice) < 0) return -1;
switch (choice) {
@ -635,10 +638,10 @@ void bx_edit_rom_path (int vga)
return;
SIM->set_vga_path (newpath);
} else {
if (SIM->get_rom_path (oldpath, CPANEL_PATH_LEN) < 0) return;
if (SIM->rom_path->get (oldpath, CPANEL_PATH_LEN) < 0) return;
if (ask_string ("Enter pathname of the ROM image: [%s] ", oldpath, newpath) < 0)
return;
SIM->set_rom_path (newpath);
SIM->rom_path->set (newpath);
}
}
@ -670,32 +673,35 @@ void bx_boot_from ()
void bx_edit_mem ()
{
int newval, oldval = SIM->memsize->get ();
bx_param_num_c *memsize = SIM->get_param_num (BXP_MEM_SIZE);
int newval, oldval = memsize->get ();
if (ask_int ("How much memory (megabytes) in the simulated machine? [%d] ", 1, 1<<30, oldval, &newval) < 0)
return;
SIM->memsize->set (newval);
memsize->set (newval);
}
void bx_ips_change ()
{
char prompt[1024];
int oldips = SIM->ips->get ();
bx_param_num_c *ips = SIM->get_param_num (BXP_IPS);
int oldips = ips->get ();
sprintf (prompt, "Type a new value for ips: [%d] ", oldips);
int newips;
if (ask_int (prompt, 1, 1<<30, oldips, &newips) < 0)
return;
SIM->ips->set (newips);
ips->set (newips);
}
void bx_vga_update_interval ()
{
char prompt[1024];
int old = SIM->vga_update_interval->get ();
bx_param_num_c *pinterval = SIM->get_param_num (BXP_VGA_UPDATE_INTERVAL);
int old = pinterval->get ();
sprintf (prompt, "Type a new value for VGA update interval: [%d] ", old);
int newinterval;
if (ask_int (prompt, 1, 1<<30, old, &newinterval) < 0)
return;
SIM->vga_update_interval->set (newinterval);
pinterval->set (newinterval);
}
static void bx_print_log_action_table ()
@ -761,10 +767,11 @@ void bx_log_options (int individual)
void bx_mouse_enable ()
{
int newval, oldval = SIM->mouse_enabled->get ();
bx_param_num_c *mouse_en = SIM->get_param_num (BXP_MOUSE_ENABLED);
int newval, oldval = mouse_en->get ();
if (ask_yn ("Enable the mouse? [%s] ", oldval, &newval) < 0) return;
if (newval == oldval) return;
SIM->mouse_enabled->set (newval);
mouse_en->set (newval);
}
int bx_read_rc (char *rc)

View File

@ -1,6 +1,6 @@
/*
* gui/siminterface.cc
* $Id: siminterface.cc,v 1.13 2001-06-15 23:52:34 bdenney Exp $
* $Id: siminterface.cc,v 1.14 2001-06-16 19:29:59 bdenney Exp $
*
* Defines the actual link between bx_simulator_interface_c methods
* and the simulator. This file includes bochs.h because it needs
@ -25,6 +25,8 @@ class bx_real_sim_c : public bx_simulator_interface_c {
#define NOTIFY_TYPE_STRING
public:
bx_real_sim_c ();
virtual bx_param_c *get_param (bx_id id);
virtual bx_param_num_c *get_param_num (bx_id id);
virtual int get_n_log_modules ();
virtual char *get_prefix (int mod);
virtual int get_log_action (int mod, int level);
@ -49,8 +51,6 @@ public:
virtual char *get_floppy_type_name (int type);
virtual int get_boot_hard_disk ();
virtual int set_boot_hard_disk (int val);
virtual int get_rom_path (char *buf, int len);
virtual int set_rom_path (char *path);
virtual int get_vga_path (char *buf, int len);
virtual int set_vga_path (char *path);
virtual int get_rom_address ();
@ -64,8 +64,34 @@ public:
virtual int log_msg_2 (char *prefix, int *level, char *msg, int len);
};
bx_param_c *
bx_real_sim_c::get_param (bx_id id)
{
switch (id)
{
case BXP_IPS: return SIM->ips;
case BXP_VGA_UPDATE_INTERVAL: return SIM->vga_update_interval;
case BXP_MOUSE_ENABLED: return SIM->mouse_enabled;
case BXP_MEM_SIZE: return bx_options.memory.size;
case BXP_ROM_PATH: return SIM->rom_path;
default:
BX_PANIC (("get_param can't find id %u", id));
}
}
bx_param_num_c *
bx_real_sim_c::get_param_num (bx_id id) {
bx_param_c *generic = get_param(id);
if (generic==NULL) {
BX_PANIC (("get_param_num(%u) could not find a parameter", id));
}
if (generic->get_type () == BXT_PARAM_NUM)
return (bx_param_num_c *)generic;
BX_PANIC (("get_param_num %u could not find an integer parameter with that id", id));
}
Bit32s
multipurpose_handler (bx_param_c *param, int set, Bit32s val)
int_param_handler (bx_param_c *param, int set, Bit32s val)
{
/* this function handles change events on several parameters */
switch (param->get_id ()) {
@ -92,20 +118,30 @@ multipurpose_handler (bx_param_c *param, int set, Bit32s val)
} else {
return bx_gui.gui_get_mouse_enable ();
}
case BXP_MEM_SIZE:
/* for simple stuff like mem size, you only need this handler because
the memory expects to find the value in bx_options.memory.megs.
If instead it looked for the value here in SIM->memsize, then
no handler is necessary. */
if (set)
return (bx_options.memory.megs = val);
else
return bx_options.memory.megs;
default:
BX_PANIC (("multipurpose_handler called with unknown parameter"));
BX_PANIC (("int_param_handler called with unknown parameter"));
return -1;
}
}
Bit32s string_param_handler(bx_param_string_c *param, int set, char *val, int maxlen)
{
switch (param->get_id ()) {
case BXP_ROM_PATH:
if (set) {
bx_options.rom.path = strdup (val);
} else {
if (bx_options.rom.path == NULL) val[0] = 0;
else strncpy (val, bx_options.rom.path, maxlen);
}
return 0;
default:
BX_PANIC (("string_param_handler called with unknown parameter"));
return -1;
}
}
void init_siminterface ()
{
siminterface_log = new logfunctions ();
@ -114,13 +150,13 @@ void init_siminterface ()
if (SIM == NULL)
SIM = new bx_real_sim_c();
SIM->ips = new bx_param_num_c (BXP_IPS, "ips", "Emulated instructions per second, used to calibrate bochs emulated\ntime with wall clock time.", 1, 1<<31, 500000);
SIM->ips->set_handler (multipurpose_handler);
SIM->ips->set_handler (int_param_handler);
SIM->vga_update_interval = new bx_param_num_c (BXP_VGA_UPDATE_INTERVAL, "vga_update_interval", "Number of microseconds between VGA updates", 1, 1<<31, 30000);
SIM->vga_update_interval->set_handler (multipurpose_handler);
SIM->vga_update_interval->set_handler (int_param_handler);
SIM->mouse_enabled = new bx_param_num_c (BXP_MOUSE_ENABLED, "mouse_enabled", "Controls whether the mouse sends events to bochs", 0, 1, 0);
SIM->mouse_enabled->set_handler (multipurpose_handler);
SIM->memsize = new bx_param_num_c (BXP_MEM_SIZE, "megs", "Amount of RAM in megabytes", 1, 1<<31, 4);
SIM->memsize->set_handler (multipurpose_handler);
SIM->mouse_enabled->set_handler (int_param_handler);
SIM->rom_path = new bx_param_string_c (BXP_ROM_PATH, "romimage", "Pathname of ROM image to load", BX_PATHNAME_LEN, "");
SIM->rom_path->set_handler (string_param_handler);
}
bx_simulator_interface_c::bx_simulator_interface_c ()
@ -322,6 +358,7 @@ bx_real_sim_c::set_boot_hard_disk (int val)
return 0;
}
#if 0
int
bx_real_sim_c::get_rom_path (char *buf, int len)
{
@ -338,6 +375,7 @@ bx_real_sim_c::set_rom_path (char *path)
bx_options.rom.path = strdup (path);
return 0;
}
#endif
int
bx_real_sim_c::get_vga_path (char *buf, int len)
@ -479,21 +517,59 @@ bx_param_num_c::reset ()
Bit32s
bx_param_num_c::get ()
{
int retval = val;
if (handler) {
retval = (*handler)(this, 0, val);
}
return retval;
if (handler)
val = (*handler)(this, 0, val);
return val;
}
Bit32s
void
bx_param_num_c::set (Bit32s newval)
{
if (handler)
val = (*handler)(this, 1, newval);
else
val = newval;
return newval;
}
bx_param_string_c::bx_param_string_c (bx_id id,
char *name,
char *description,
int maxsize,
char *initial_val)
: bx_param_c (id, name, description)
{
if (maxsize < 1)
maxsize = strlen(initial_val) + 1;
this->val = new char[maxsize];
this->initial_val = new char[maxsize];
this->maxsize = maxsize;
strncpy (this->val, initial_val, maxsize);
strncpy (this->initial_val, initial_val, maxsize);
}
void
bx_param_string_c::reset () {
strncpy (this->val, this->initial_val, maxsize);
}
Bit32s
bx_param_string_c::get (char *buf, int len)
{
if (handler)
(*handler)(this, 0, buf, len);
else
strncpy (buf, val, len);
return 0;
}
void
bx_param_string_c::set (char *buf)
{
if (handler)
(*handler)(this, 1, buf, -1);
else
strncpy (val, buf, maxsize);
}
bx_node_c::bx_node_c (bx_id id)

View File

@ -1,6 +1,6 @@
/*
* gui/siminterface.h
* $Id: siminterface.h,v 1.9 2001-06-15 23:52:34 bdenney Exp $
* $Id: siminterface.h,v 1.10 2001-06-16 19:29:59 bdenney Exp $
*
* Interface to the simulator, currently only used by control.cc.
* The base class bx_simulator_interface_c, contains only virtual functions
@ -61,7 +61,9 @@ typedef enum {
BXP_IPS = 101,
BXP_VGA_UPDATE_INTERVAL,
BXP_MOUSE_ENABLED,
BXP_MEM_SIZE
BXP_MEM_SIZE,
BXP_ROM_PATH,
BXP_VGA_ROM_PATH
} bx_id;
typedef enum {
@ -71,6 +73,29 @@ typedef enum {
BXT_PARAM_NUM
} bx_objtype;
////////////////////////////////////////////////////////////////////
// Abstract type.
struct bx_any {
Bit32u type;
union s {
int integer;
int boolean;
struct string {
char *val;
int alloc_len;
};
struct list {
Bit32u size;
bx_any *array;
};
};
};
////////////////////////////////////////////////////////////////////
class bx_object_c {
private:
bx_id id;
@ -94,23 +119,62 @@ public:
char *get_name () { return name; }
char *get_description () { return description; }
void reset () {}
int getint () {return -1;}
};
// make it only handle ints for now
typedef Bit32s (*param_event_handler)(class bx_param_c *, int set, Bit32s val);
typedef Bit32s (*param_any_event_handler)(class bx_param_any_c *, int set, bx_any val);
class bx_param_any_c : public bx_param_c {
bx_any min, max, val, initial_val;
param_any_event_handler handler;
public:
bx_param_any_c (bx_id id,
char *name,
char *description,
bx_any min, bx_any max, bx_any initial_val);
bx_param_any_c (bx_id id,
char *name,
char *description,
bx_any initial_val);
void reset ();
void set_handler (param_any_event_handler handler) { this->handler = handler; }
bx_any get ();
void set (bx_any val);
};
typedef Bit32s (*param_num_event_handler)(class bx_param_c *, int set, Bit32s val);
class bx_param_num_c : public bx_param_c {
Bit32s min, max, val, initial_val;
param_event_handler handler;
param_num_event_handler handler;
public:
bx_param_num_c (bx_id id,
char *name,
char *description,
Bit32s min, Bit32s max, Bit32s initial_val);
void reset ();
void set_handler (param_event_handler handler) { this->handler = handler; }
void set_handler (param_num_event_handler handler) { this->handler = handler; }
Bit32s get ();
Bit32s set (Bit32s val);
void set (Bit32s val);
};
typedef Bit32s (*param_string_event_handler)(class bx_param_string_c *, int set, char *val, int maxlen);
class bx_param_string_c : public bx_param_c {
int maxsize;
char *val, *initial_val;
param_string_event_handler handler;
public:
bx_param_string_c (bx_id id,
char *name,
char *description,
int maxsize,
char *initial_val);
void reset ();
void set_handler (param_string_event_handler handler) { this->handler = handler; }
Bit32s get (char *buf, int len);
char *getptr () {return val; }
void set (char *buf);
};
class bx_node_c : public bx_object_c {
@ -124,6 +188,7 @@ public:
bx_object_c *getcar () { return car; }
bx_object_c *getcdr () { return cdr; }
};
////////////////////////////////////////////////////////////////////
class bx_simulator_interface_c {
int init_done;
@ -132,10 +197,12 @@ public:
int get_init_done () { return init_done; }
int set_init_done (int n) { init_done = n; return 0;}
virtual bx_param_c *get_param (bx_id id) {return NULL;}
virtual bx_param_num_c *get_param_num (bx_id id) {return NULL;}
bx_param_num_c *ips;
bx_param_num_c *vga_update_interval;
bx_param_num_c *mouse_enabled;
bx_param_num_c *memsize;
bx_param_num_c *vga_update_interval;
bx_param_string_c *rom_path;
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;}
@ -160,8 +227,6 @@ public:
virtual char *get_floppy_type_name (int type) {return NULL;}
virtual int get_boot_hard_disk () {return -1;}
virtual int set_boot_hard_disk (int val) {return -1;}
virtual int get_rom_path (char *buf, int len) {return -1;}
virtual int set_rom_path (char *path) {return -1;}
virtual int get_vga_path (char *buf, int len) {return -1;}
virtual int set_vga_path (char *path) {return -1;}
virtual int get_rom_address () {return -1;}

View File

@ -69,7 +69,7 @@ bx_options_t bx_options = {
{ 0, "", 0 }, // cdromd
{ NULL, 0 }, // rom
{ NULL }, // vgarom
{ BX_DEFAULT_MEM_MEGS }, // memory
{ NULL /*BX_DEFAULT_MEM_MEGS*/ }, // memory
{ 0, NULL, NULL, NULL, 0, 0, 0, 0 }, // SB16
"a", // boot drive
300000, // vga update interval
@ -452,6 +452,11 @@ void bx_print_header ()
fprintf (stderr, "%s\n", divider);
}
void bx_init_options ()
{
bx_options.memory.size = new bx_param_num_c (BXP_MEM_SIZE, "megs", "Amount of RAM in megabytes", 1, 1<<31, 4);
}
int
main(int argc, char *argv[])
{
@ -466,6 +471,7 @@ main(int argc, char *argv[])
bx_print_header ();
bx_init_bx_dbg ();
bx_init_options ();
int read_rc_already = 0;
#if BX_USE_CONTROL_PANEL
@ -576,7 +582,6 @@ int bx_parse_cmdline (int argc, char *argv[])
int
bx_init_hardware()
{
// This function used to
// all configuration has been read, now initialize everything.
for (int level=0; level<N_LOGLEV; level++)
@ -595,7 +600,7 @@ bx_init_hardware()
#endif
#if BX_SMP_PROCESSORS==1
BX_MEM(0)->init_memory(bx_options.memory.megs * 1024*1024);
BX_MEM(0)->init_memory(bx_options.memory.size->get () * 1024*1024);
BX_MEM(0)->load_ROM(bx_options.rom.path, bx_options.rom.address);
BX_MEM(0)->load_ROM(bx_options.vgarom.path, 0xc0000);
BX_CPU(0)->init (BX_MEM(0));
@ -603,7 +608,7 @@ bx_init_hardware()
#else
// SMP initialization
bx_mem_array[0] = new BX_MEM_C ();
bx_mem_array[0]->init_memory(bx_options.memory.megs * 1024*1024);
bx_mem_array[0]->init_memory(bx_options.memory.size->get () * 1024*1024);
bx_mem_array[0]->load_ROM(bx_options.rom.path, bx_options.rom.address);
bx_mem_array[0]->load_ROM(bx_options.vgarom.path, 0xc0000);
for (int i=0; i<BX_SMP_PROCESSORS; i++) {
@ -1074,7 +1079,7 @@ parse_line_formatted(char *context, int num_params, char *params[])
if (num_params != 2) {
BX_PANIC(("%s: megs directive: wrong # args.", context));
}
bx_options.memory.megs = atol(params[1]);
bx_options.memory.size->set (atol(params[1]));
}
else if (!strcmp(params[0], "floppy_command_delay")) {
if (num_params != 2) {
@ -1478,7 +1483,7 @@ bx_write_configuration (char *rc, int overwrite)
fprintf (fp, "vgaromimage: %s\n", bx_options.vgarom.path);
else
fprintf (fp, "# no vgaromimage\n");
fprintf (fp, "megs: %d\n", bx_options.memory.megs);
fprintf (fp, "megs: %d\n", bx_options.memory.size->get ());
bx_write_sb16_options (fp, &bx_options.sb16);
fprintf (fp, "boot: %s\n", bx_options.bootdrive);
fprintf (fp, "vga_update_interval: %lu\n", bx_options.vga_update_interval);