From f0a3679e34200cf08f88bd36179874fbdecdeb20 Mon Sep 17 00:00:00 2001 From: Volker Ruppert Date: Sun, 11 Nov 2012 12:21:09 +0000 Subject: [PATCH] moved function is_pci_device() to the siminterface class --- bochs/gui/siminterface.cc | 23 ++++++++++++++++++++++- bochs/gui/siminterface.h | 2 ++ bochs/iodev/devices.cc | 18 ------------------ bochs/iodev/display/svga_cirrus.cc | 2 +- bochs/iodev/display/vga.cc | 2 +- bochs/iodev/iodev.h | 1 - bochs/iodev/network/ne2k.cc | 16 ++++------------ bochs/plugin.h | 1 - 8 files changed, 30 insertions(+), 35 deletions(-) diff --git a/bochs/gui/siminterface.cc b/bochs/gui/siminterface.cc index aa2b27ae0..304115bc2 100644 --- a/bochs/gui/siminterface.cc +++ b/bochs/gui/siminterface.cc @@ -151,6 +151,7 @@ public: bx_param_c *get_first_hd() { return get_first_atadevice(BX_ATA_DEVICE_DISK); } + virtual bx_bool is_pci_device(const char *name); #if BX_DEBUGGER virtual void debug_break(); virtual void debug_interpret_cmd (char *cmd); @@ -746,13 +747,33 @@ bx_param_c *bx_real_sim_c::get_first_atadevice(Bit32u search_type) Bit32u type = SIM->get_param_enum(pname)->get(); if (present && (type == search_type)) { sprintf(pname, "ata.%d.%s", channel, (slave==0)?"master":"slave"); - return SIM->get_param(pname); + return SIM->get_param(pname); } } } return NULL; } +bx_bool bx_real_sim_c::is_pci_device(const char *name) +{ +#if BX_SUPPORT_PCI + unsigned i; + char devname[80]; + char *device; + + if (SIM->get_param_bool(BXPN_PCI_ENABLED)->get()) { + for (i = 0; i < BX_N_PCI_SLOTS; i++) { + sprintf(devname, "pci.slot.%d", i+1); + device = SIM->get_param_string(devname)->getptr(); + if ((strlen(device) > 0) && (!strcmp(name, device))) { + return 1; + } + } + } +#endif + return 0; +} + #if BX_DEBUGGER // this can be safely called from either thread. diff --git a/bochs/gui/siminterface.h b/bochs/gui/siminterface.h index 3c1bdd3e9..492358b19 100644 --- a/bochs/gui/siminterface.h +++ b/bochs/gui/siminterface.h @@ -711,6 +711,8 @@ public: virtual bx_param_c *get_first_cdrom() {return NULL;} // return first cdrom in ATA interface virtual bx_param_c *get_first_hd() {return NULL;} + // return 1 if device is connected to a PCI slot + virtual bx_bool is_pci_device(const char *name) {return 0;} #if BX_DEBUGGER // for debugger: same behavior as pressing control-C virtual void debug_break() {} diff --git a/bochs/iodev/devices.cc b/bochs/iodev/devices.cc index b04725714..10028c9f3 100644 --- a/bochs/iodev/devices.cc +++ b/bochs/iodev/devices.cc @@ -1195,24 +1195,6 @@ void bx_pci_device_stub_c::load_pci_rom(const char *path) BX_INFO(("loaded PCI ROM '%s' (size=%u / PCI=%uk)", path, (unsigned) stat_buf.st_size, pci_rom_size >> 10)); } -bx_bool bx_devices_c::is_pci_device(const char *name) -{ -#if BX_SUPPORT_PCI - unsigned i; - char devname[80]; - char *device; - - for (i = 0; i < BX_N_PCI_SLOTS; i++) { - sprintf(devname, "pci.slot.%d", i+1); - device = SIM->get_param_string(devname)->getptr(); - if ((strlen(device) > 0) && (!strcmp(name, device))) { - return 1; - } - } -#endif - return 0; -} - #if BX_SUPPORT_PCI bx_bool bx_devices_c::register_pci_handlers(bx_pci_device_stub_c *dev, Bit8u *devfunc, const char *name, diff --git a/bochs/iodev/display/svga_cirrus.cc b/bochs/iodev/display/svga_cirrus.cc index 0b0804819..a72bc33d2 100644 --- a/bochs/iodev/display/svga_cirrus.cc +++ b/bochs/iodev/display/svga_cirrus.cc @@ -258,7 +258,7 @@ void bx_svga_cirrus_c::init_vga_extension(void) // initialize SVGA stuffs. BX_CIRRUS_THIS bx_vgacore_c::init_iohandlers(svga_read_handler, svga_write_handler); BX_CIRRUS_THIS bx_vgacore_c::init_systemtimer(svga_timer_handler, svga_param_handler); - BX_CIRRUS_THIS pci_enabled = DEV_is_pci_device("cirrus"); + BX_CIRRUS_THIS pci_enabled = SIM->is_pci_device("cirrus"); BX_CIRRUS_THIS svga_init_members(); #if BX_SUPPORT_PCI if (BX_CIRRUS_THIS pci_enabled) diff --git a/bochs/iodev/display/vga.cc b/bochs/iodev/display/vga.cc index a30f13778..533fb54a8 100644 --- a/bochs/iodev/display/vga.cc +++ b/bochs/iodev/display/vga.cc @@ -93,7 +93,7 @@ void bx_vga_c::init_vga_extension(void) BX_VGA_THIS init_iohandlers(read_handler, write_handler); BX_VGA_THIS init_systemtimer(timer_handler, vga_param_handler); - BX_VGA_THIS pci_enabled = DEV_is_pci_device("pcivga"); + BX_VGA_THIS pci_enabled = SIM->is_pci_device("pcivga"); // The following is for the VBE display extension BX_VGA_THIS vbe_present = 0; diff --git a/bochs/iodev/iodev.h b/bochs/iodev/iodev.h index c465838ed..eb748569a 100644 --- a/bochs/iodev/iodev.h +++ b/bochs/iodev/iodev.h @@ -422,7 +422,6 @@ public: void mouse_enabled_changed(bx_bool enabled); void mouse_motion(int delta_x, int delta_y, int delta_z, unsigned button_state, bx_bool absxy); - bx_bool is_pci_device(const char *name); #if BX_SUPPORT_PCI Bit32u pci_get_confAddr(void) {return pci.confAddr;} bx_bool register_pci_handlers(bx_pci_device_stub_c *device, Bit8u *devfunc, diff --git a/bochs/iodev/network/ne2k.cc b/bochs/iodev/network/ne2k.cc index 4874b81cd..0bf249b6a 100644 --- a/bochs/iodev/network/ne2k.cc +++ b/bochs/iodev/network/ne2k.cc @@ -89,14 +89,8 @@ Bit32s ne2k_options_parser(const char *context, int num_params, char *params[]) if (!SIM->get_param_bool("enabled", base)->get()) { SIM->get_param_enum("ethmod", base)->set_by_name("null"); } - if (SIM->get_param_bool(BXPN_PCI_ENABLED)->get()) { - for (int slot = 1; slot < 6; slot++) { - sprintf(tmpdev, "pci.slot.%d", slot); - if (!strcmp(SIM->get_param_string(tmpdev)->getptr(), "ne2k")) { - valid |= 0x03; - break; - } - } + if (SIM->is_pci_device(BX_PLUGIN_NE2K)) { + valid |= 0x03; } for (int i = 1; i < num_params; i++) { if (!strncmp(params[i], "ioaddr=", 7)) { @@ -216,13 +210,11 @@ void bx_ne2k_c::init(void) return; } memcpy(macaddr, SIM->get_param_string("macaddr", base)->getptr(), 6); - BX_NE2K_THIS s.pci_enabled = 0; strcpy(devname, "NE2000 NIC"); + BX_NE2K_THIS s.pci_enabled = SIM->is_pci_device(BX_PLUGIN_NE2K); #if BX_SUPPORT_PCI - if ((SIM->get_param_bool(BXPN_PCI_ENABLED)->get()) && - (DEV_is_pci_device(BX_PLUGIN_NE2K))) { - BX_NE2K_THIS s.pci_enabled = 1; + if (BX_NE2K_THIS s.pci_enabled) { strcpy(devname, "NE2000 PCI NIC"); BX_NE2K_THIS s.devfunc = 0x00; DEV_register_pci_handlers(this, &BX_NE2K_THIS s.devfunc, diff --git a/bochs/plugin.h b/bochs/plugin.h index b6088322c..8174fa0f8 100644 --- a/bochs/plugin.h +++ b/bochs/plugin.h @@ -223,7 +223,6 @@ extern "C" { ///////// PCI macros #define DEV_register_pci_handlers(a,b,c,d) \ (bx_devices.register_pci_handlers(a,b,c,d)) -#define DEV_is_pci_device(name) bx_devices.is_pci_device(name) #define DEV_pci_get_confAddr() bx_devices.pci_get_confAddr() #define DEV_pci_set_irq(a,b,c) bx_devices.pluginPci2IsaBridge->pci_set_irq(a,b,c) #define DEV_pci_set_base_mem(a,b,c,d,e,f) \