Implemented unregister mechanism for runtime config handlers.

TODO: use it for removable devices with removable media (USB floppy / cdrom).
This commit is contained in:
Volker Ruppert 2015-08-23 07:04:56 +00:00
parent f7726990f2
commit 1df014a8ae
16 changed files with 65 additions and 15 deletions

View File

@ -46,7 +46,10 @@ bx_list_c *root_param = NULL;
// bx_keyboard.s.internal_buffer[4] (or whatever) directly. -Bryce
//
static int rt_conf_id = 0;
typedef struct _rt_conf_entry_t {
int id;
void *device;
rt_conf_handler_t handler;
struct _rt_conf_entry_t *next;
@ -164,7 +167,8 @@ public:
void *userdata);
virtual int configuration_interface(const char* name, ci_command_t command);
virtual int begin_simulation(int argc, char *argv[]);
virtual bx_bool register_runtime_config_handler(void *dev, rt_conf_handler_t handler);
virtual int register_runtime_config_handler(void *dev, rt_conf_handler_t handler);
virtual void unregister_runtime_config_handler(int id);
virtual void update_runtime_options();
virtual void set_sim_thread_func(is_sim_thread_func_t func) {}
virtual bx_bool is_sim_thread();
@ -875,16 +879,17 @@ int bx_real_sim_c::begin_simulation(int argc, char *argv[])
return bx_begin_simulation(argc, argv);
}
bx_bool bx_real_sim_c::register_runtime_config_handler(void *dev, rt_conf_handler_t handler)
int bx_real_sim_c::register_runtime_config_handler(void *dev, rt_conf_handler_t handler)
{
rt_conf_entry_t *rt_conf_entry;
rt_conf_entry = (rt_conf_entry_t *)malloc(sizeof(rt_conf_entry_t));
if (rt_conf_entry == NULL) {
BX_PANIC(("can't allocate rt_conf_entry_t"));
return 0;
return -1;
}
rt_conf_entry->id = rt_conf_id;;
rt_conf_entry->device = dev;
rt_conf_entry->handler = handler;
rt_conf_entry->next = NULL;
@ -899,7 +904,27 @@ bx_bool bx_real_sim_c::register_runtime_config_handler(void *dev, rt_conf_handle
}
temp->next = rt_conf_entry;
}
return 1;
return rt_conf_id++;
}
void bx_real_sim_c::unregister_runtime_config_handler(int id)
{
rt_conf_entry_t *prev = NULL, *next = rt_conf_entries;
while (next != NULL) {
if (next->id == id) {
if (prev != NULL) {
prev->next = next->next;
} else {
rt_conf_entries = next->next;
}
free(next);
break;
} else {
prev = next;
next = next->next;
}
}
}
void bx_real_sim_c::update_runtime_options()

View File

@ -765,7 +765,8 @@ public:
void *userdata) {}
virtual int configuration_interface(const char* name, ci_command_t command) {return -1; }
virtual int begin_simulation(int argc, char *argv[]) {return -1;}
virtual bx_bool register_runtime_config_handler(void *dev, rt_conf_handler_t handler) {return 0;}
virtual int register_runtime_config_handler(void *dev, rt_conf_handler_t handler) {return 0;}
virtual void unregister_runtime_config_handler(int id) {}
virtual void update_runtime_options() {}
typedef bx_bool (*is_sim_thread_func_t)();
is_sim_thread_func_t is_sim_thread_func;

View File

@ -126,12 +126,16 @@ bx_floppy_ctrl_c::bx_floppy_ctrl_c()
put("FLOPPY");
memset(&s, 0, sizeof(s));
s.floppy_timer_index = BX_NULL_TIMER_HANDLE;
s.statusbar_id[0] = -1;
s.statusbar_id[1] = -1;
s.rt_conf_id = -1;
}
bx_floppy_ctrl_c::~bx_floppy_ctrl_c()
{
char pname[10];
SIM->unregister_runtime_config_handler(s.rt_conf_id);
for (int i = 0; i < 2; i++) {
close_media(&BX_FD_THIS s.media[i]);
sprintf(pname, "floppy.%d", i);
@ -302,7 +306,7 @@ void bx_floppy_ctrl_c::init(void)
SIM->get_param_enum("status", floppy)->set_runtime_param(1);
}
// register handler for correct floppy parameter handling after runtime config
SIM->register_runtime_config_handler(this, runtime_config_handler);
BX_FD_THIS s.rt_conf_id = SIM->register_runtime_config_handler(this, runtime_config_handler);
#if BX_DEBUGGER
// register device for the 'info device' command (calls debug_dump())
bx_dbg_register_debug_info("floppy", this);

View File

@ -2,7 +2,7 @@
// $Id$
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2002-2012 The Bochs Project
// Copyright (C) 2002-2015 The Bochs Project
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
@ -127,6 +127,7 @@ private:
Bit8u perp_mode; // perpendicular mode
int statusbar_id[2]; // IDs of the status LEDs
int rt_conf_id; // ID of the runtime config handler
} s; // state information
static Bit32u read_handler(void *this_ptr, Bit32u address, unsigned io_len);

View File

@ -132,8 +132,10 @@ bx_hard_drive_c::bx_hard_drive_c()
channels[channel].drives[device].hdimage = NULL;
channels[channel].drives[device].cdrom.cd = NULL;
channels[channel].drives[device].seek_timer_index = BX_NULL_TIMER_HANDLE;
channels[channel].drives[device].statusbar_id = -1;
}
}
rt_conf_id = -1;
}
bx_hard_drive_c::~bx_hard_drive_c()
@ -141,6 +143,7 @@ bx_hard_drive_c::~bx_hard_drive_c()
char ata_name[20];
bx_list_c *base;
SIM->unregister_runtime_config_handler(rt_conf_id);
for (Bit8u channel=0; channel<BX_MAX_ATA_CHANNEL; channel++) {
for (Bit8u device=0; device<2; device ++) {
if (channels[channel].drives[device].hdimage != NULL) {
@ -271,7 +274,6 @@ void bx_hard_drive_c::init(void)
// If not present
BX_HD_THIS channels[channel].drives[device].device_type = IDE_NONE;
BX_HD_THIS channels[channel].drives[device].statusbar_id = -1;
BX_HD_THIS channels[channel].drives[device].identify_set = 0;
if (SIM->get_param_enum("type", base)->get() == BX_ATA_DEVICE_NONE) continue;
@ -542,7 +544,7 @@ void bx_hard_drive_c::init(void)
BX_HD_THIS pci_enabled = SIM->get_param_bool(BXPN_PCI_ENABLED)->get();
// register handler for correct cdrom parameter handling after runtime config
SIM->register_runtime_config_handler(BX_HD_THIS_PTR, runtime_config_handler);
BX_HD_THIS rt_conf_id = SIM->register_runtime_config_handler(BX_HD_THIS_PTR, runtime_config_handler);
}
void bx_hard_drive_c::reset(unsigned type)

View File

@ -2,7 +2,7 @@
// $Id$
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2001-2014 The Bochs Project
// Copyright (C) 2001-2015 The Bochs Project
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
@ -263,6 +263,7 @@ private:
} channels[BX_MAX_ATA_CHANNEL];
int rt_conf_id;
Bit8u cdrom_count;
bx_bool pci_enabled;
};

View File

@ -221,6 +221,7 @@ bx_es1370_c::bx_es1370_c()
midiout[1] = NULL;
wavemode = 0;
midimode = 0;
s.rt_conf_id = -1;
}
bx_es1370_c::~bx_es1370_c()
@ -228,6 +229,7 @@ bx_es1370_c::~bx_es1370_c()
closemidioutput();
closewaveoutput();
SIM->unregister_runtime_config_handler(s.rt_conf_id);
SIM->get_bochs_root()->remove("es1370");
bx_list_c *misc_rt = (bx_list_c*)SIM->get_param(BXPN_MENU_RUNTIME_MISC);
misc_rt->remove("es1370");
@ -326,7 +328,7 @@ void bx_es1370_c::init(void)
SIM->get_param_num("midimode", base)->set_handler(es1370_param_handler);
SIM->get_param_string("midifile", base)->set_handler(es1370_param_string_handler);
// register handler for correct es1370 parameter handling after runtime config
SIM->register_runtime_config_handler(this, runtime_config_handler);
BX_ES1370_THIS s.rt_conf_id = SIM->register_runtime_config_handler(this, runtime_config_handler);
BX_ES1370_THIS wave_changed = 0;
BX_ES1370_THIS midi_changed = 0;

View File

@ -77,6 +77,7 @@ typedef struct {
Bit8u midicmd_index;
Bit8u midi_buffer[256];
int rt_conf_id;
Bit8u devfunc;
} bx_es1370_t;

View File

@ -219,10 +219,13 @@ bx_sb16_c::bx_sb16_c(void)
midimode = 0;
loglevel = 0;
logfile = NULL;
rt_conf_id = -1;
}
bx_sb16_c::~bx_sb16_c(void)
{
SIM->unregister_runtime_config_handler(rt_conf_id);
closemidioutput();
if (BX_SB16_WAVEOUT1 != NULL) {
@ -433,7 +436,7 @@ void bx_sb16_c::init(void)
SIM->get_param_num("loglevel", base)->set_handler(sb16_param_handler);
SIM->get_param_string("log", base)->set_handler(sb16_param_string_handler);
// register handler for correct sb16 parameter handling after runtime config
SIM->register_runtime_config_handler(this, runtime_config_handler);
BX_SB16_THIS rt_conf_id = SIM->register_runtime_config_handler(this, runtime_config_handler);
BX_SB16_THIS midi_changed = 0;
BX_SB16_THIS wave_changed = 0;
}

View File

@ -159,6 +159,7 @@ private:
int currentdma8;
int currentdma16;
int fmopl_callback_id;
int rt_conf_id;
Bit16u fm_volume;
// the MPU 401 relevant variables

View File

@ -134,12 +134,14 @@ bx_usb_ohci_c::bx_usb_ohci_c()
memset((void*)&hub, 0, sizeof(bx_usb_ohci_t));
device_buffer = NULL;
hub.frame_timer_index = BX_NULL_TIMER_HANDLE;
hub.rt_conf_id = -1;
}
bx_usb_ohci_c::~bx_usb_ohci_c()
{
char pname[16];
SIM->unregister_runtime_config_handler(hub.rt_conf_id);
if (BX_OHCI_THIS device_buffer != NULL)
delete [] BX_OHCI_THIS device_buffer;
@ -207,7 +209,7 @@ void bx_usb_ohci_c::init(void)
}
// register handler for correct device connect handling after runtime config
SIM->register_runtime_config_handler(BX_OHCI_THIS_PTR, runtime_config_handler);
BX_OHCI_THIS hub.rt_conf_id = SIM->register_runtime_config_handler(BX_OHCI_THIS_PTR, runtime_config_handler);
BX_OHCI_THIS hub.device_change = 0;
BX_INFO(("USB OHCI initialized"));

View File

@ -237,6 +237,7 @@ typedef struct {
Bit64u sof_time;
Bit8u device_change;
int rt_conf_id;
} bx_usb_ohci_t;

View File

@ -121,12 +121,14 @@ bx_usb_uhci_c::bx_usb_uhci_c()
memset((void*)&hub, 0, sizeof(bx_usb_uhci_t));
device_buffer = NULL;
hub.timer_index = BX_NULL_TIMER_HANDLE;
hub.rt_conf_id = -1;
}
bx_usb_uhci_c::~bx_usb_uhci_c()
{
char pname[16];
SIM->unregister_runtime_config_handler(hub.rt_conf_id);
if (BX_UHCI_THIS device_buffer != NULL)
delete [] BX_UHCI_THIS device_buffer;
@ -193,7 +195,7 @@ void bx_usb_uhci_c::init(void)
}
// register handler for correct device connect handling after runtime config
SIM->register_runtime_config_handler(BX_UHCI_THIS_PTR, runtime_config_handler);
BX_UHCI_THIS hub.rt_conf_id = SIM->register_runtime_config_handler(BX_UHCI_THIS_PTR, runtime_config_handler);
BX_UHCI_THIS hub.device_change = 0;
BX_INFO(("USB UHCI initialized"));

View File

@ -159,6 +159,7 @@ typedef struct {
Bit8u devfunc;
Bit8u device_change;
int rt_conf_id;
} bx_usb_uhci_t;
#pragma pack (push, 1)

View File

@ -212,6 +212,7 @@ bx_usb_xhci_c::bx_usb_xhci_c()
put("usb_xhci", "XHCI");
memset((void*)&hub, 0, sizeof(bx_usb_xhci_t));
device_buffer = NULL;
hub.rt_conf_id = -1;
//hub.frame_timer_index = BX_NULL_TIMER_HANDLE;
}
@ -219,6 +220,7 @@ bx_usb_xhci_c::~bx_usb_xhci_c()
{
char pname[16];
SIM->unregister_runtime_config_handler(hub.rt_conf_id);
if (BX_XHCI_THIS device_buffer != NULL)
delete [] BX_XHCI_THIS device_buffer;
@ -293,7 +295,7 @@ void bx_usb_xhci_c::init(void)
}
// register handler for correct device connect handling after runtime config
SIM->register_runtime_config_handler(BX_XHCI_THIS_PTR, runtime_config_handler);
BX_XHCI_THIS hub.rt_conf_id = SIM->register_runtime_config_handler(BX_XHCI_THIS_PTR, runtime_config_handler);
BX_XHCI_THIS hub.device_change = 0;
for (i=0; i<USB_XHCI_PORTS; i++)

View File

@ -526,6 +526,7 @@ typedef struct {
Bit8u devfunc;
Bit8u device_change;
int rt_conf_id;
} bx_usb_xhci_t;
// Version 3.0.23.0 of the Renesas uPD720202 driver, even though the card is