Partial sync with save-restore

This commit is contained in:
Stanislav Shwartsman 2006-05-27 14:02:34 +00:00
parent 65e0fea773
commit 7c1767d17a
8 changed files with 106 additions and 68 deletions

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////
// $Id: cpu.h,v 1.294 2006-05-24 16:46:56 sshwarts Exp $
// $Id: cpu.h,v 1.295 2006-05-27 14:02:34 sshwarts Exp $
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2001 MandrakeSoft S.A.
@ -2812,6 +2812,7 @@ public: // for now...
BX_SMF void parse_selector(Bit16u raw_selector, bx_selector_t *selector) BX_CPP_AttrRegparmN(2);
BX_SMF void parse_descriptor(Bit32u dword1, Bit32u dword2, bx_descriptor_t *temp) BX_CPP_AttrRegparmN(3);
BX_SMF Bit8u ar_byte(const bx_descriptor_t *d) BX_CPP_AttrRegparmN(1);
BX_SMF void set_ar_byte(bx_descriptor_t *d, Bit8u ar_byte) BX_CPP_AttrRegparmN(2);
BX_SMF Bit32u get_descriptor_l(const bx_descriptor_t *) BX_CPP_AttrRegparmN(1);
BX_SMF Bit32u get_descriptor_h(const bx_descriptor_t *) BX_CPP_AttrRegparmN(1);
BX_SMF Bit16u get_segment_ar_data(const bx_descriptor_t *d) BX_CPP_AttrRegparmN(1);

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////
// $Id: segment_ctrl_pro.cc,v 1.61 2006-05-21 20:41:48 sshwarts Exp $
// $Id: segment_ctrl_pro.cc,v 1.62 2006-05-27 14:02:34 sshwarts Exp $
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2001 MandrakeSoft S.A.
@ -338,6 +338,22 @@ BX_CPU_C::ar_byte(const bx_descriptor_t *d)
}
}
void BX_CPP_AttrRegparmN(2)
BX_CPU_C::set_ar_byte(bx_descriptor_t *d, Bit8u ar_byte)
{
d->p = (ar_byte >> 7) & 0x01;
d->dpl = (ar_byte >> 5) & 0x03;
d->segment = (ar_byte >> 4) & 0x01;
d->type = (ar_byte & 0x0f);
if (d->segment) {
d->u.segment.executable = (ar_byte >> 3) & 0x01;
d->u.segment.c_ed = (ar_byte >> 2) & 0x01;
d->u.segment.r_w = (ar_byte >> 1) & 0x01;
d->u.segment.a = (ar_byte >> 0) & 0x01;
}
}
Bit32u BX_CPP_AttrRegparmN(1)
BX_CPU_C::get_descriptor_l(const bx_descriptor_t *d)
{

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////
// $Id: siminterface.cc,v 1.147 2006-05-22 21:29:54 sshwarts Exp $
// $Id: siminterface.cc,v 1.148 2006-05-27 14:02:34 sshwarts Exp $
/////////////////////////////////////////////////////////////////////////
//
// See siminterface.h for description of the siminterface concept.
@ -1111,7 +1111,11 @@ void bx_real_sim_c::save_sr_param(FILE *fp, bx_param_c *node, const char *sr_pat
fprintf(fp, "%d\n", ((bx_param_num_c*)node)->get());
}
} else {
fprintf(fp, node->get_format(), ((bx_param_num_c*)node)->get());
if (node->get_format()) {
fprintf(fp, node->get_format(), ((bx_param_num_c*)node)->get());
} else {
fprintf(fp, "0x%x", ((bx_param_num_c*)node)->get());
}
fprintf(fp, "\n");
}
break;
@ -1236,6 +1240,10 @@ bx_param_num_c::bx_param_num_c(bx_param_c *parent,
this->initial_val = initial_val;
this->val.number = initial_val;
this->handler = NULL;
#if BX_SUPPORT_SAVE_RESTORE
this->save_handler = NULL;
this->restore_handler = NULL;
#endif
this->enable_handler = NULL;
this->base = default_base;
this->is_shadow = is_shadow;
@ -1272,6 +1280,15 @@ void bx_param_num_c::set_handler(param_event_handler handler)
//set (get ());
}
#if BX_SUPPORT_SAVE_RESTORE
void bx_param_num_c::set_sr_handlers(void *devptr, param_sr_handler save, param_sr_handler restore)
{
this->sr_devptr = devptr;
this->save_handler = save;
this->restore_handler = restore;
}
#endif
void bx_param_num_c::set_enable_handler(param_enable_handler handler)
{
this->enable_handler = handler;
@ -1284,6 +1301,11 @@ void bx_param_num_c::set_dependent_list(bx_list_c *l) {
Bit64s bx_param_num_c::get64()
{
#if BX_SUPPORT_SAVE_RESTORE
if (save_handler) {
return (*save_handler)(sr_devptr, this, val.number);
}
#endif
if (handler) {
// the handler can decide what value to return and/or do some side effect
return (*handler)(this, 0, val.number);
@ -1303,6 +1325,12 @@ void bx_param_num_c::set(Bit64s newval)
// just set the value. This code does not check max/min.
val.number = newval;
}
#if BX_SUPPORT_SAVE_RESTORE
if (restore_handler) {
val.number = newval;
(*restore_handler)(sr_devptr, this, newval);
}
#endif
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));
if (dependent_list != NULL) update_dependents();
@ -1343,12 +1371,11 @@ void bx_param_num_c::set_enabled(int en)
// Signed 64 bit
bx_shadow_num_c::bx_shadow_num_c(bx_param_c *parent,
char *name,
char *description,
Bit64s *ptr_to_real_val,
int base,
Bit8u highbit,
Bit8u lowbit)
: bx_param_num_c(parent, name, description, NULL, BX_MIN_BIT64S, BX_MAX_BIT64S, *ptr_to_real_val, 1)
: bx_param_num_c(parent, name, NULL, NULL, BX_MIN_BIT64S, BX_MAX_BIT64S, *ptr_to_real_val, 1)
{
this->varsize = 64;
this->lowbit = lowbit;
@ -1363,12 +1390,11 @@ bx_shadow_num_c::bx_shadow_num_c(bx_param_c *parent,
// Unsigned 64 bit
bx_shadow_num_c::bx_shadow_num_c(bx_param_c *parent,
char *name,
char *label,
Bit64u *ptr_to_real_val,
int base,
Bit8u highbit,
Bit8u lowbit)
: bx_param_num_c(parent, name, label, NULL, BX_MIN_BIT64U, BX_MAX_BIT64U, *ptr_to_real_val, 1)
: bx_param_num_c(parent, name, NULL, NULL, BX_MIN_BIT64U, BX_MAX_BIT64U, *ptr_to_real_val, 1)
{
this->varsize = 64;
this->lowbit = lowbit;
@ -1383,12 +1409,11 @@ bx_shadow_num_c::bx_shadow_num_c(bx_param_c *parent,
// Signed 32 bit
bx_shadow_num_c::bx_shadow_num_c(bx_param_c *parent,
char *name,
char *label,
Bit32s *ptr_to_real_val,
int base,
Bit8u highbit,
Bit8u lowbit)
: bx_param_num_c(parent, name, label, NULL, BX_MIN_BIT32S, BX_MAX_BIT32S, *ptr_to_real_val, 1)
: bx_param_num_c(parent, name, NULL, NULL, BX_MIN_BIT32S, BX_MAX_BIT32S, *ptr_to_real_val, 1)
{
this->varsize = 16;
this->lowbit = lowbit;
@ -1403,12 +1428,11 @@ bx_shadow_num_c::bx_shadow_num_c(bx_param_c *parent,
// Unsigned 32 bit
bx_shadow_num_c::bx_shadow_num_c(bx_param_c *parent,
char *name,
char *label,
Bit32u *ptr_to_real_val,
int base,
Bit8u highbit,
Bit8u lowbit)
: bx_param_num_c(parent, name, label, NULL, BX_MIN_BIT32U, BX_MAX_BIT32U, *ptr_to_real_val, 1)
: bx_param_num_c(parent, name, NULL, NULL, BX_MIN_BIT32U, BX_MAX_BIT32U, *ptr_to_real_val, 1)
{
this->varsize = 32;
this->lowbit = lowbit;
@ -1423,12 +1447,11 @@ bx_shadow_num_c::bx_shadow_num_c(bx_param_c *parent,
// Signed 16 bit
bx_shadow_num_c::bx_shadow_num_c(bx_param_c *parent,
char *name,
char *label,
Bit16s *ptr_to_real_val,
int base,
Bit8u highbit,
Bit8u lowbit)
: bx_param_num_c(parent, name, label, NULL, BX_MIN_BIT16S, BX_MAX_BIT16S, *ptr_to_real_val, 1)
: bx_param_num_c(parent, name, NULL, NULL, BX_MIN_BIT16S, BX_MAX_BIT16S, *ptr_to_real_val, 1)
{
this->varsize = 16;
this->lowbit = lowbit;
@ -1443,12 +1466,11 @@ bx_shadow_num_c::bx_shadow_num_c(bx_param_c *parent,
// Unsigned 16 bit
bx_shadow_num_c::bx_shadow_num_c(bx_param_c *parent,
char *name,
char *label,
Bit16u *ptr_to_real_val,
int base,
Bit8u highbit,
Bit8u lowbit)
: bx_param_num_c(parent, name, label, NULL, BX_MIN_BIT16U, BX_MAX_BIT16U, *ptr_to_real_val, 1)
: bx_param_num_c(parent, name, NULL, NULL, BX_MIN_BIT16U, BX_MAX_BIT16U, *ptr_to_real_val, 1)
{
this->varsize = 16;
this->lowbit = lowbit;
@ -1463,12 +1485,11 @@ bx_shadow_num_c::bx_shadow_num_c(bx_param_c *parent,
// Signed 8 bit
bx_shadow_num_c::bx_shadow_num_c(bx_param_c *parent,
char *name,
char *label,
Bit8s *ptr_to_real_val,
int base,
Bit8u highbit,
Bit8u lowbit)
: bx_param_num_c(parent, name, label, NULL, BX_MIN_BIT8S, BX_MAX_BIT8S, *ptr_to_real_val, 1)
: bx_param_num_c(parent, name, NULL, NULL, BX_MIN_BIT8S, BX_MAX_BIT8S, *ptr_to_real_val, 1)
{
this->varsize = 16;
this->lowbit = lowbit;
@ -1484,12 +1505,11 @@ bx_shadow_num_c::bx_shadow_num_c(bx_param_c *parent,
// Unsigned 8 bit
bx_shadow_num_c::bx_shadow_num_c(bx_param_c *parent,
char *name,
char *label,
Bit8u *ptr_to_real_val,
int base,
Bit8u highbit,
Bit8u lowbit)
: bx_param_num_c(parent, name, label, NULL, BX_MIN_BIT8U, BX_MAX_BIT8U, *ptr_to_real_val, 1)
: bx_param_num_c(parent, name, NULL, NULL, BX_MIN_BIT8U, BX_MAX_BIT8U, *ptr_to_real_val, 1)
{
this->varsize = 8;
this->lowbit = lowbit;
@ -1723,7 +1743,7 @@ void bx_param_string_c::set_enabled(int en)
// The enable handler may wish to allow/disallow the action
if (enable_handler) {
en = (*enable_handler)(this, en);
}
}
bx_param_c::set_enabled(en);
}
@ -1877,9 +1897,11 @@ void bx_list_c::init(const char *list_title)
this->title->set((char *)list_title);
}
this->options = new bx_param_num_c(NULL,
"list_option", "", "", 0, BX_MAX_BIT64S, 0);
"list_option", "", "", 0, BX_MAX_BIT64S,
0);
this->choice = new bx_param_num_c(NULL,
"list_choice", "", "", 0, BX_MAX_BIT64S, 1);
"list_choice", "", "", 0, BX_MAX_BIT64S,
1);
}
void bx_list_c::set_parent(bx_param_c *newparent) {

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////
// $Id: siminterface.h,v 1.191 2006-05-22 21:29:54 sshwarts Exp $
// $Id: siminterface.h,v 1.192 2006-05-27 14:02:34 sshwarts Exp $
/////////////////////////////////////////////////////////////////////////
//
// Intro to siminterface by Bryce Denney:
@ -633,6 +633,9 @@ public:
};
typedef Bit64s (*param_event_handler)(class bx_param_c *, int set, Bit64s val);
#if BX_SUPPORT_SAVE_RESTORE
typedef Bit64s (*param_sr_handler)(void *devptr, class bx_param_c *, Bit64s val);
#endif
typedef int (*param_enable_handler)(class bx_param_c *, int en);
class BOCHSAPI bx_param_num_c : public bx_param_c {
@ -654,6 +657,11 @@ protected:
bx_bool *pbool; // used by bx_shadow_bool_c
} val;
param_event_handler handler;
#if BX_SUPPORT_SAVE_RESTORE
void *sr_devptr;
param_sr_handler save_handler;
param_sr_handler restore_handler;
#endif
param_enable_handler enable_handler;
int base;
Bit32u options;
@ -672,6 +680,9 @@ public:
bx_bool is_shadow = 0);
virtual void reset();
void set_handler(param_event_handler handler);
#if BX_SUPPORT_SAVE_RESTORE
void set_sr_handlers(void *devptr, param_sr_handler save, param_sr_handler restore);
#endif
void set_enable_handler(param_enable_handler handler);
virtual bx_list_c *get_dependent_list() { return dependent_list; }
void set_dependent_list(bx_list_c *l);
@ -707,56 +718,48 @@ class BOCHSAPI bx_shadow_num_c : public bx_param_num_c {
public:
bx_shadow_num_c(bx_param_c *parent,
char *name,
char *label,
Bit64s *ptr_to_real_val,
int base = BASE_DEC,
Bit8u highbit = 63,
Bit8u lowbit = 0);
bx_shadow_num_c(bx_param_c *parent,
char *name,
char *label,
Bit64u *ptr_to_real_val,
int base = BASE_DEC,
Bit8u highbit = 63,
Bit8u lowbit = 0);
bx_shadow_num_c(bx_param_c *parent,
char *name,
char *label,
Bit32s *ptr_to_real_val,
int base = BASE_DEC,
Bit8u highbit = 31,
Bit8u lowbit = 0);
bx_shadow_num_c(bx_param_c *parent,
char *name,
char *label,
Bit32u *ptr_to_real_val,
int base = BASE_DEC,
Bit8u highbit = 31,
Bit8u lowbit = 0);
bx_shadow_num_c(bx_param_c *parent,
char *name,
char *label,
Bit16s *ptr_to_real_val,
int base = BASE_DEC,
Bit8u highbit = 15,
Bit8u lowbit = 0);
bx_shadow_num_c(bx_param_c *parent,
char *name,
char *label,
Bit16u *ptr_to_real_val,
int base = BASE_DEC,
Bit8u highbit = 15,
Bit8u lowbit = 0);
bx_shadow_num_c(bx_param_c *parent,
char *name,
char *label,
Bit8s *ptr_to_real_val,
int base = BASE_DEC,
Bit8u highbit = 7,
Bit8u lowbit = 0);
bx_shadow_num_c(bx_param_c *parent,
char *name,
char *label,
Bit8u *ptr_to_real_val,
int base = BASE_DEC,
Bit8u highbit = 7,

View File

@ -1,5 +1,5 @@
////////////////////////////////////////////////////////////////////////
// $Id: virt_timer.cc,v 1.27 2006-03-07 21:11:20 sshwarts Exp $
// $Id: virt_timer.cc,v 1.28 2006-05-27 14:02:34 sshwarts Exp $
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2002 MandrakeSoft S.A.
@ -165,15 +165,14 @@ void bx_virt_timer_c::periodic(Bit64u time_passed)
current_timers_time += time_passed;
//If no events are occurring, just pass the time and we're done.
if( time_passed < timers_next_event_time ) {
return;
}
if(time_passed < timers_next_event_time) return;
//Starting timer handler calls.
in_timer_handler = 1;
//Otherwise, cause any events to occur that should.
unsigned i;
for(i=0;i<numTimers;i++) {
if( timer[i].inUse && timer[i].active ) {
if(timer[i].inUse && timer[i].active) {
//Assert that we haven't skipped any timers.
BX_ASSERT(current_timers_time <= timer[i].timeToFire);
if(timer[i].timeToFire == current_timers_time) {
@ -197,7 +196,7 @@ void bx_virt_timer_c::periodic(Bit64u time_passed)
// but then convert it back to a cycle count afterwards.
timers_next_event_time = current_timers_time + BX_MAX_VIRTUAL_TIME;
for(i=0;i<numTimers;i++) {
if( timer[i].inUse && timer[i].active && ((timer[i].timeToFire)<timers_next_event_time) ) {
if(timer[i].inUse && timer[i].active && ((timer[i].timeToFire)<timers_next_event_time)) {
timers_next_event_time = timer[i].timeToFire;
}
}
@ -249,7 +248,7 @@ Bit64u bx_virt_timer_c::time_usec_sequential(void)
//Register a timer handler to go off after a given interval.
//Register a timer handler to go off with a periodic interval.
int bx_virt_timer_c::register_timer( void *this_ptr, bx_timer_handler_t handler,
int bx_virt_timer_c::register_timer(void *this_ptr, bx_timer_handler_t handler,
Bit32u useconds,
bx_bool continuous, bx_bool active,
const char *id)
@ -292,13 +291,12 @@ int bx_virt_timer_c::register_timer( void *this_ptr, bx_timer_handler_t handler,
}
//unregister a previously registered timer.
unsigned bx_virt_timer_c::unregisterTimer(int timerID)
bx_bool bx_virt_timer_c::unregisterTimer(unsigned timerID)
{
if(!use_virtual_timers) {
return bx_pc_system.unregisterTimer(timerID);
}
BX_ASSERT(timerID >= 0);
BX_ASSERT(timerID < BX_MAX_VIRTUAL_TIMERS);
if (timer[timerID].active) {
@ -308,6 +306,7 @@ unsigned bx_virt_timer_c::unregisterTimer(int timerID)
//No need to prevent doing this to unused timers.
timer[timerID].inUse = 0;
if (timerID == (numTimers-1)) numTimers--;
return(1);
}
@ -329,7 +328,6 @@ void bx_virt_timer_c::activate_timer(unsigned timer_index, Bit32u useconds,
return;
}
BX_ASSERT(timer_index >= 0);
BX_ASSERT(timer_index < BX_MAX_VIRTUAL_TIMERS);
BX_ASSERT(timer[timer_index].inUse);
@ -348,14 +346,13 @@ void bx_virt_timer_c::activate_timer(unsigned timer_index, Bit32u useconds,
}
//deactivate (but don't unregister) a currently registered timer.
void bx_virt_timer_c::deactivate_timer( unsigned timer_index )
void bx_virt_timer_c::deactivate_timer(unsigned timer_index)
{
if(!use_virtual_timers) {
bx_pc_system.deactivate_timer(timer_index);
return;
}
BX_ASSERT(timer_index >= 0);
BX_ASSERT(timer_index < BX_MAX_VIRTUAL_TIMERS);
//No need to prevent doing this to unused/inactive timers.
@ -411,8 +408,7 @@ void bx_virt_timer_c::init(void)
total_real_usec=0;
last_realtime_delta=0;
//System time variables:
last_usec = 0
;
last_usec = 0;
usec_per_second = USEC_PER_SECOND;
stored_delta=0;
last_system_usec=0;

View File

@ -1,5 +1,5 @@
////////////////////////////////////////////////////////////////////////
// $Id: virt_timer.h,v 1.9 2006-03-07 21:11:20 sshwarts Exp $
// $Id: virt_timer.h,v 1.10 2006-05-27 14:02:34 sshwarts Exp $
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2002 MandrakeSoft S.A.
@ -127,7 +127,7 @@ public:
bx_bool continuous, bx_bool active, const char *id);
//unregister a previously registered timer.
unsigned unregisterTimer(int timerID);
bx_bool unregisterTimer(unsigned timerID);
void start_timers(void);

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////
// $Id: pc_system.cc,v 1.57 2006-05-18 18:08:30 sshwarts Exp $
// $Id: pc_system.cc,v 1.58 2006-05-27 14:02:34 sshwarts Exp $
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2002 MandrakeSoft S.A.
@ -513,32 +513,32 @@ void bx_pc_system_c::deactivate_timer(unsigned i)
timer[i].active = 0;
}
unsigned bx_pc_system_c::unregisterTimer(int timerIndex)
bx_bool bx_pc_system_c::unregisterTimer(unsigned timerIndex)
{
unsigned i = (unsigned) timerIndex;
#if BX_TIMER_DEBUG
if (i >= numTimers)
BX_PANIC(("unregisterTimer: timer %u OOB", i));
if (i == 0)
if (timerIndex >= numTimers)
BX_PANIC(("unregisterTimer: timer %u OOB", timerIndex));
if (timerIndex == 0)
BX_PANIC(("unregisterTimer: timer 0 is the nullTimer!"));
if (timer[i].inUse == 0)
BX_PANIC(("unregisterTimer: timer %u is not in-use!", i));
if (timer[timerIndex].inUse == 0)
BX_PANIC(("unregisterTimer: timer %u is not in-use!", timerIndex));
#endif
if (timer[i].active) {
BX_PANIC(("unregisterTimer: timer '%s' is still active!", timer[i].id));
if (timer[timerIndex].active) {
BX_PANIC(("unregisterTimer: timer '%s' is still active!", timer[timerIndex].id));
return(0); // Fail.
}
// Reset timer fields for good measure.
timer[i].inUse = 0; // No longer registered.
timer[i].period = BX_MAX_BIT64S; // Max value (invalid)
timer[i].timeToFire = BX_MAX_BIT64S; // Max value (invalid)
timer[i].continuous = 0;
timer[i].funct = NULL;
timer[i].this_ptr = NULL;
memset(timer[i].id, 0, BxMaxTimerIDLen);
timer[timerIndex].inUse = 0; // No longer registered.
timer[timerIndex].period = BX_MAX_BIT64S; // Max value (invalid)
timer[timerIndex].timeToFire = BX_MAX_BIT64S; // Max value (invalid)
timer[timerIndex].continuous = 0;
timer[timerIndex].funct = NULL;
timer[timerIndex].this_ptr = NULL;
memset(timer[timerIndex].id, 0, BxMaxTimerIDLen);
if (timerIndex == (numTimers-1)) numTimers--;
return(1); // OK
}

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////
// $Id: pc_system.h,v 1.37 2006-04-29 17:21:45 sshwarts Exp $
// $Id: pc_system.h,v 1.38 2006-05-27 14:02:34 sshwarts Exp $
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2004 MandrakeSoft S.A.
@ -94,7 +94,7 @@ public:
void initialize(Bit32u ips);
int register_timer(void *this_ptr, bx_timer_handler_t, Bit32u useconds,
bx_bool continuous, bx_bool active, const char *id);
unsigned unregisterTimer(int timerID);
bx_bool unregisterTimer(unsigned timerID);
void start_timers(void);
void activate_timer(unsigned timer_index, Bit32u useconds, bx_bool continuous);
void deactivate_timer(unsigned timer_index);