- several changes for restart support in wx (not yet complete)

* don't initialize cpu specific parameters for the wx debugger if they already
    exist
  * separate siminterface method init_save_restore() added
  * old wx specific handling in quit_sim() removed
  * new bx_list_c method clear() deletes all parameters from the list
  * moved devices cleanup code from the pc_system to a new devices method exit()
  * pc_system init code now sets ticksTotal to 0
This commit is contained in:
Volker Ruppert 2006-09-07 18:50:51 +00:00
parent 3dfc9b4d5a
commit 5dd0d64b11
7 changed files with 107 additions and 89 deletions

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////
// $Id: init.cc,v 1.122 2006-08-31 18:21:16 sshwarts Exp $
// $Id: init.cc,v 1.123 2006-09-07 18:50:51 vruppert Exp $
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2001 MandrakeSoft S.A.
@ -258,15 +258,17 @@ void BX_CPU_C::initialize(BX_MEM_C *addrspace)
// they can be visible in the config interface.
// (Experimental, obviously not a complete list)
bx_param_num_c *param;
char cpu_name[10], cpu_title[10];
char cpu_name[10], cpu_title[10], cpu_pname[16];
const char *fmt16 = "%04X";
const char *fmt32 = "%08X";
Bit32u oldbase = bx_param_num_c::set_default_base(16);
const char *oldfmt = bx_param_num_c::set_default_format(fmt32);
sprintf(cpu_name, "%d", BX_CPU_ID);
sprintf(cpu_title, "CPU %d", BX_CPU_ID);
bx_list_c *list = new bx_list_c(SIM->get_param(BXPN_WX_CPU_STATE),
cpu_name, cpu_title, 60);
sprintf(cpu_pname, "%s.%d", BXPN_WX_CPU_STATE, BX_CPU_ID);
if (SIM->get_param(cpu_pname) == NULL) {
bx_list_c *list = new bx_list_c(SIM->get_param(BXPN_WX_CPU_STATE),
cpu_name, cpu_title, 60);
#define DEFPARAM_NORMAL(name,field) \
new bx_shadow_num_c(list, #name, &(field))
@ -294,8 +296,8 @@ void BX_CPU_C::initialize(BX_MEM_C *addrspace)
DEFPARAM_NORMAL(CR4, cr4.registerValue);
#endif
// segment registers require a handler function because they have
// special get/set requirements.
// segment registers require a handler function because they have
// special get/set requirements.
#define DEFPARAM_SEG_REG(x) \
param = new bx_param_num_c(list, \
#x, #x, "", 0, 0xffff, 0); \
@ -309,25 +311,25 @@ void BX_CPU_C::initialize(BX_MEM_C *addrspace)
#name"_limit", \
& BX_CPU_THIS_PTR field.limit);
DEFPARAM_SEG_REG(CS);
DEFPARAM_SEG_REG(DS);
DEFPARAM_SEG_REG(SS);
DEFPARAM_SEG_REG(ES);
DEFPARAM_SEG_REG(FS);
DEFPARAM_SEG_REG(GS);
DEFPARAM_SEG_REG(LDTR);
DEFPARAM_SEG_REG(TR);
DEFPARAM_GLOBAL_SEG_REG(GDTR, gdtr);
DEFPARAM_GLOBAL_SEG_REG(IDTR, idtr);
DEFPARAM_SEG_REG(CS);
DEFPARAM_SEG_REG(DS);
DEFPARAM_SEG_REG(SS);
DEFPARAM_SEG_REG(ES);
DEFPARAM_SEG_REG(FS);
DEFPARAM_SEG_REG(GS);
DEFPARAM_SEG_REG(LDTR);
DEFPARAM_SEG_REG(TR);
DEFPARAM_GLOBAL_SEG_REG(GDTR, gdtr);
DEFPARAM_GLOBAL_SEG_REG(IDTR, idtr);
#undef DEFPARAM_NORMAL
#undef DEFPARAM_SEG_REG
#undef DEFPARAM_GLOBAL_SEG_REG
param = new bx_shadow_num_c(list, "EFLAGS",
&BX_CPU_THIS_PTR eflags.val32);
param = new bx_shadow_num_c(list, "EFLAGS",
&BX_CPU_THIS_PTR eflags.val32);
// flags implemented in lazy_flags.cc must be done with a handler
// that calls their get function, to force them to be computed.
// flags implemented in lazy_flags.cc must be done with a handler
// that calls their get function, to force them to be computed.
#define DEFPARAM_EFLAG(name) \
param = new bx_param_bool_c(list, \
#name, #name, "", get_##name()); \
@ -338,39 +340,40 @@ void BX_CPU_C::initialize(BX_MEM_C *addrspace)
param->set_handler(cpu_param_handler);
#if BX_CPU_LEVEL >= 4
DEFPARAM_EFLAG(ID);
DEFPARAM_EFLAG(VIP);
DEFPARAM_EFLAG(VIF);
DEFPARAM_EFLAG(AC);
DEFPARAM_EFLAG(ID);
DEFPARAM_EFLAG(VIP);
DEFPARAM_EFLAG(VIF);
DEFPARAM_EFLAG(AC);
#endif
#if BX_CPU_LEVEL >= 3
DEFPARAM_EFLAG(VM);
DEFPARAM_EFLAG(RF);
DEFPARAM_EFLAG(VM);
DEFPARAM_EFLAG(RF);
#endif
#if BX_CPU_LEVEL >= 2
DEFPARAM_EFLAG(NT);
// IOPL is a special case because it is 2 bits wide.
param = new bx_shadow_num_c(
list,
"IOPL",
&eflags.val32, 10,
12, 13);
param->set_range(0, 3);
param->set_format("%d");
DEFPARAM_EFLAG(NT);
// IOPL is a special case because it is 2 bits wide.
param = new bx_shadow_num_c(
list,
"IOPL",
&eflags.val32, 10,
12, 13);
param->set_range(0, 3);
param->set_format("%d");
#endif
DEFPARAM_LAZY_EFLAG(OF);
DEFPARAM_EFLAG(DF);
DEFPARAM_EFLAG(IF);
DEFPARAM_EFLAG(TF);
DEFPARAM_LAZY_EFLAG(SF);
DEFPARAM_LAZY_EFLAG(ZF);
DEFPARAM_LAZY_EFLAG(AF);
DEFPARAM_LAZY_EFLAG(PF);
DEFPARAM_LAZY_EFLAG(CF);
DEFPARAM_LAZY_EFLAG(OF);
DEFPARAM_EFLAG(DF);
DEFPARAM_EFLAG(IF);
DEFPARAM_EFLAG(TF);
DEFPARAM_LAZY_EFLAG(SF);
DEFPARAM_LAZY_EFLAG(ZF);
DEFPARAM_LAZY_EFLAG(AF);
DEFPARAM_LAZY_EFLAG(PF);
DEFPARAM_LAZY_EFLAG(CF);
// restore defaults
bx_param_num_c::set_default_base(oldbase);
bx_param_num_c::set_default_format(oldfmt);
// restore defaults
bx_param_num_c::set_default_base(oldbase);
bx_param_num_c::set_default_format(oldfmt);
}
}
#endif
}

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////
// $Id: siminterface.cc,v 1.165 2006-09-04 18:36:47 vruppert Exp $
// $Id: siminterface.cc,v 1.166 2006-09-07 18:50:51 vruppert Exp $
/////////////////////////////////////////////////////////////////////////
//
// See siminterface.h for description of the siminterface concept.
@ -144,6 +144,7 @@ public:
virtual Bit32s save_user_options(FILE *fp);
#if BX_SUPPORT_SAVE_RESTORE
// save/restore support
virtual void init_save_restore();
virtual bx_bool save_state(const char *checkpoint_path);
virtual bx_bool restore_config();
virtual bx_bool restore_logopts();
@ -274,16 +275,6 @@ void bx_init_siminterface()
"bochs",
"list of top level bochs parameters",
30);
#if BX_SUPPORT_SAVE_RESTORE
bx_list_c *list = new bx_list_c(root_param,
"save_restore",
"subtree for save/restore",
30);
new bx_list_c(list,
"cpu",
"CPU State",
BX_MAX_SMP_THREADS_SUPPORTED);
#endif
}
}
@ -362,14 +353,8 @@ void bx_real_sim_c::quit_sim(int code) {
if (quit_context != NULL) {
longjmp(*quit_context, 1);
BX_PANIC(("in bx_real_sim_c::quit_sim, longjmp should never return"));
}
if (SIM->is_wx_selected()) {
// in wxWidgets, the whole simulator is running in a separate thread.
// our only job is to end the thread as soon as possible, NOT to shut
// down the whole application with an exit.
bx_stop_simulation();
} else {
// just a single thread. Use exit() to stop the application.
// use exit() to stop the application.
if (!code)
BX_PANIC(("Quit simulation command"));
::exit(exit_code);
@ -611,13 +596,6 @@ void bx_real_sim_c::periodic()
refresh_ci();
refresh_counter = 0;
}
#if 0
// watch for memory leaks. Allocate a small block of memory, print the
// pointer that is returned, then free.
BxEvent *memcheck = new BxEvent ();
BX_INFO(("memory allocation at %p", memcheck));
delete memcheck;
#endif
}
// create a disk image file called filename, size=512 bytes * sectors.
@ -872,6 +850,24 @@ Bit32s bx_real_sim_c::save_user_options(FILE *fp)
}
#if BX_SUPPORT_SAVE_RESTORE
void bx_real_sim_c::init_save_restore()
{
bx_list_c *list;
if ((list = get_sr_root()) != NULL) {
list->clear();
} else {
list = new bx_list_c(root_param,
"save_restore",
"subtree for save/restore",
30);
}
new bx_list_c(list,
"cpu",
"CPU State",
BX_MAX_SMP_THREADS_SUPPORTED);
}
bx_bool bx_real_sim_c::save_state(const char *checkpoint_path)
{
char sr_file[BX_PATHNAME_LEN];
@ -2057,3 +2053,14 @@ void bx_list_c::reset()
get(i)->reset();
}
}
void bx_list_c::clear()
{
int i, imax = get_size();
bx_param_c *param;
for (i=0; i<imax; i++) {
param = get(i);
delete param;
}
this->size = 0;
}

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////
// $Id: siminterface.h,v 1.200 2006-08-29 20:10:26 vruppert Exp $
// $Id: siminterface.h,v 1.201 2006-09-07 18:50:51 vruppert Exp $
/////////////////////////////////////////////////////////////////////////
//
// Intro to siminterface by Bryce Denney:
@ -964,6 +964,7 @@ public:
void set_parent(bx_param_c *newparent);
bx_param_c *get_parent() { return parent; }
virtual void reset();
virtual void clear();
#if BX_USE_TEXTCONFIG
virtual void text_print(FILE *);
virtual int text_ask(FILE *fpin, FILE *fpout);
@ -1231,6 +1232,7 @@ public:
virtual Bit32s save_user_options(FILE *fp) {return -1;}
#if BX_SUPPORT_SAVE_RESTORE
// save/restore support
virtual void init_save_restore() {}
virtual bx_bool save_state(const char *checkpoint_path) {return 0;}
virtual bx_bool restore_config() {return 0;}
virtual bx_bool restore_logopts() {return 0;}

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////
// $Id: devices.cc,v 1.101 2006-05-27 15:54:48 sshwarts Exp $
// $Id: devices.cc,v 1.102 2006-09-07 18:50:51 vruppert Exp $
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2002 MandrakeSoft S.A.
@ -105,7 +105,7 @@ void bx_devices_c::init(BX_MEM_C *newmem)
{
unsigned i;
BX_DEBUG(("Init $Id: devices.cc,v 1.101 2006-05-27 15:54:48 sshwarts Exp $"));
BX_DEBUG(("Init $Id: devices.cc,v 1.102 2006-09-07 18:50:51 vruppert Exp $"));
mem = newmem;
/* set no-default handlers, will be overwritten by the real default handler */
@ -379,6 +379,16 @@ void bx_devices_c::after_restore_state()
}
#endif
void bx_devices_c::exit()
{
if (DEV_cmos_present())
DEV_cmos_save_image();
if (DEV_hd_present())
DEV_hd_close_harddrive();
BX_INFO(("Last time is %u", (unsigned) DEV_cmos_get_timeval()));
}
Bit32u bx_devices_c::read_handler(void *this_ptr, Bit32u address, unsigned io_len)
{
#if !BX_USE_DEV_SMF

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////
// $Id: iodev.h,v 1.75 2006-05-27 15:54:48 sshwarts Exp $
// $Id: iodev.h,v 1.76 2006-09-07 18:50:51 vruppert Exp $
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2002 MandrakeSoft S.A.
@ -389,6 +389,8 @@ public:
// The types of reset conditions are defined in bochs.h:
// power-on, hardware, or software.
void reset(unsigned type);
// Cleanup the devices when the simulation quits.
void exit(void);
#if BX_SUPPORT_SAVE_RESTORE
void register_state(void);
void after_restore_state(void);

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////
// $Id: main.cc,v 1.339 2006-07-21 18:26:53 vruppert Exp $
// $Id: main.cc,v 1.340 2006-09-07 18:50:51 vruppert Exp $
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2002 MandrakeSoft S.A.
@ -813,6 +813,7 @@ bx_bool load_and_init_display_lib()
int bx_begin_simulation (int argc, char *argv[])
{
#if BX_SUPPORT_SAVE_RESTORE
SIM->init_save_restore();
if (SIM->get_param_bool(BXPN_RESTORE_FLAG)->get()) {
if (!SIM->restore_config()) {
BX_PANIC(("cannot restore configuration"));
@ -846,12 +847,11 @@ int bx_begin_simulation (int argc, char *argv[])
bx_gui->update_drive_status_buttons();
// iniialize statusbar and set all items inactive
#if BX_SUPPORT_SAVE_RESTORE
if (!SIM->get_param_bool(BXPN_RESTORE_FLAG)->get()) {
if (!SIM->get_param_bool(BXPN_RESTORE_FLAG)->get())
#endif
{
bx_gui->statusbar_setitem(-1, 0);
#if BX_SUPPORT_SAVE_RESTORE
}
#endif
// The set handler for mouse_enabled does not actually update the gui
// until init_done is set. This forces the set handler to be called,

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////
// $Id: pc_system.cc,v 1.62 2006-05-29 22:33:38 sshwarts Exp $
// $Id: pc_system.cc,v 1.63 2006-09-07 18:50:51 vruppert Exp $
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2002 MandrakeSoft S.A.
@ -82,8 +82,8 @@ bx_pc_system_c::bx_pc_system_c()
void bx_pc_system_c::initialize(Bit32u ips)
{
ticksTotal = 0;
HRQ = 0;
kill_bochs_request = 0;
// parameter 'ips' is the processor speed in Instructions-Per-Second
@ -214,13 +214,7 @@ Bit8u bx_pc_system_c::IAC(void)
void bx_pc_system_c::exit(void)
{
if (DEV_cmos_present())
DEV_cmos_save_image();
if (DEV_hd_present())
DEV_hd_close_harddrive();
BX_INFO(("Last time is %u", (unsigned) DEV_cmos_get_timeval()));
bx_devices.exit();
if (bx_gui) bx_gui->exit();
}