2001-10-03 17:10:38 +04:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
2009-05-05 20:13:13 +04:00
|
|
|
// $Id: devices.cc,v 1.147 2009-05-05 16:13:13 vruppert Exp $
|
2001-10-03 17:10:38 +04:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2002-01-29 20:20:12 +03:00
|
|
|
// Copyright (C) 2002 MandrakeSoft S.A.
|
2001-04-10 05:04:59 +04:00
|
|
|
//
|
|
|
|
// MandrakeSoft S.A.
|
|
|
|
// 43, rue d'Aboukir
|
|
|
|
// 75002 Paris - France
|
|
|
|
// http://www.linux-mandrake.com/
|
|
|
|
// http://www.mandrakesoft.com/
|
|
|
|
//
|
2004-01-15 05:08:37 +03:00
|
|
|
// I/O port handlers API Copyright (C) 2003 by Frank Cornelis
|
2008-01-27 01:24:03 +03:00
|
|
|
//
|
2001-04-10 05:04:59 +04:00
|
|
|
// This library is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU Lesser General Public
|
|
|
|
// License as published by the Free Software Foundation; either
|
|
|
|
// version 2 of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This library is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public
|
|
|
|
// License along with this library; if not, write to the Free Software
|
2009-02-08 12:05:52 +03:00
|
|
|
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
2008-04-17 18:39:33 +04:00
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////////
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
|
2004-06-19 19:20:15 +04:00
|
|
|
#include "iodev.h"
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2008-12-29 23:16:08 +03:00
|
|
|
#include "iodev/virt_timer.h"
|
|
|
|
#include "iodev/slowdown_timer.h"
|
|
|
|
|
|
|
|
#define LOG_THIS bx_devices.
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
/* main memory size (in Kbytes)
|
|
|
|
* subtract 1k for extended BIOS area
|
|
|
|
* report only base memory, not extended mem
|
|
|
|
*/
|
|
|
|
#define BASE_MEMORY_IN_K 640
|
|
|
|
|
|
|
|
|
|
|
|
bx_devices_c bx_devices;
|
|
|
|
|
|
|
|
|
2002-08-27 23:54:46 +04:00
|
|
|
// constructor for bx_devices_c
|
2006-03-07 01:03:16 +03:00
|
|
|
bx_devices_c::bx_devices_c()
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
2001-06-27 23:16:01 +04:00
|
|
|
put("DEV");
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2004-01-15 05:08:37 +03:00
|
|
|
read_port_to_handler = NULL;
|
|
|
|
write_port_to_handler = NULL;
|
2006-09-20 22:24:17 +04:00
|
|
|
io_read_handlers.next = NULL;
|
|
|
|
io_read_handlers.handler_name = NULL;
|
|
|
|
io_write_handlers.next = NULL;
|
|
|
|
io_write_handlers.handler_name = NULL;
|
2006-09-10 21:18:44 +04:00
|
|
|
init_stubs();
|
2006-09-13 22:51:25 +04:00
|
|
|
|
|
|
|
for (unsigned i=0; i < BX_MAX_IRQS; i++) {
|
|
|
|
irq_handler_name[i] = NULL;
|
|
|
|
}
|
2006-09-10 21:18:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
bx_devices_c::~bx_devices_c()
|
|
|
|
{
|
|
|
|
// nothing needed for now
|
|
|
|
timer_handle = BX_NULL_TIMER_HANDLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void bx_devices_c::init_stubs()
|
|
|
|
{
|
2004-08-06 19:49:55 +04:00
|
|
|
#if BX_SUPPORT_PCI
|
2002-11-09 23:51:40 +03:00
|
|
|
pluginPciBridge = &stubPci;
|
2004-07-02 02:18:20 +04:00
|
|
|
pluginPci2IsaBridge = &stubPci2Isa;
|
2005-02-08 21:32:27 +03:00
|
|
|
pluginPciIdeController = &stubPciIde;
|
2006-10-02 14:14:07 +04:00
|
|
|
#if BX_SUPPORT_ACPI
|
2006-10-01 23:51:49 +04:00
|
|
|
pluginACPIController = &stubACPIController;
|
2006-10-02 14:14:07 +04:00
|
|
|
#endif
|
2001-04-10 05:04:59 +04:00
|
|
|
#endif
|
2002-10-25 01:07:56 +04:00
|
|
|
pluginKeyboard = &stubKeyboard;
|
|
|
|
pluginDmaDevice = &stubDma;
|
|
|
|
pluginFloppyDevice = &stubFloppy;
|
|
|
|
pluginCmosDevice = &stubCmos;
|
|
|
|
pluginVgaDevice = &stubVga;
|
|
|
|
pluginPicDevice = &stubPic;
|
|
|
|
pluginHardDrive = &stubHardDrive;
|
2002-11-19 21:56:39 +03:00
|
|
|
pluginNE2kDevice =&stubNE2k;
|
2004-02-03 00:47:26 +03:00
|
|
|
pluginSpeaker = &stubSpeaker;
|
2004-08-06 19:49:55 +04:00
|
|
|
#if BX_SUPPORT_IODEBUG
|
2008-12-30 21:11:13 +03:00
|
|
|
pluginIODebug = &stubIODebug;
|
2001-09-14 19:01:29 +04:00
|
|
|
#endif
|
2009-02-22 13:44:50 +03:00
|
|
|
#if BX_SUPPORT_IOAPIC
|
|
|
|
pluginIOAPIC = &stubIOAPIC;
|
|
|
|
#endif
|
2006-01-17 23:16:59 +03:00
|
|
|
#if 0
|
|
|
|
g2h = NULL;
|
|
|
|
#endif
|
2002-08-27 21:25:18 +04:00
|
|
|
}
|
|
|
|
|
2006-03-14 21:11:22 +03:00
|
|
|
void bx_devices_c::init(BX_MEM_C *newmem)
|
2002-08-27 21:25:18 +04:00
|
|
|
{
|
|
|
|
unsigned i;
|
2006-09-20 22:24:17 +04:00
|
|
|
const char def_name[] = "Default";
|
2009-02-21 14:43:18 +03:00
|
|
|
bx_list_c *plugin_ctrl;
|
|
|
|
bx_param_bool_c *plugin;
|
2009-02-21 19:08:02 +03:00
|
|
|
#if !BX_PLUGINS
|
|
|
|
const char *plugname;
|
|
|
|
#endif
|
2002-08-27 21:25:18 +04:00
|
|
|
|
2009-05-05 20:13:13 +04:00
|
|
|
BX_DEBUG(("Init $Id: devices.cc,v 1.147 2009-05-05 16:13:13 vruppert Exp $"));
|
2002-08-27 21:25:18 +04:00
|
|
|
mem = newmem;
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2009-01-15 20:34:20 +03:00
|
|
|
/* set builtin default handlers, will be overwritten by the real default handler */
|
2006-09-21 00:52:23 +04:00
|
|
|
register_default_io_read_handler(NULL, &default_read_handler, def_name, 7);
|
2004-01-15 05:08:37 +03:00
|
|
|
io_read_handlers.next = &io_read_handlers;
|
|
|
|
io_read_handlers.prev = &io_read_handlers;
|
|
|
|
io_read_handlers.usage_count = 0; // not used with the default handler
|
2006-09-21 00:52:23 +04:00
|
|
|
|
|
|
|
register_default_io_write_handler(NULL, &default_write_handler, def_name, 7);
|
2004-01-15 05:08:37 +03:00
|
|
|
io_write_handlers.next = &io_write_handlers;
|
|
|
|
io_write_handlers.prev = &io_write_handlers;
|
|
|
|
io_write_handlers.usage_count = 0; // not used with the default handler
|
|
|
|
|
|
|
|
if (read_port_to_handler)
|
2006-09-20 22:24:17 +04:00
|
|
|
delete [] read_port_to_handler;
|
2004-01-15 05:08:37 +03:00
|
|
|
if (write_port_to_handler)
|
2006-09-20 22:24:17 +04:00
|
|
|
delete [] write_port_to_handler;
|
2004-01-15 05:08:37 +03:00
|
|
|
read_port_to_handler = new struct io_handler_struct *[PORTS];
|
|
|
|
write_port_to_handler = new struct io_handler_struct *[PORTS];
|
2002-10-25 01:07:56 +04:00
|
|
|
|
|
|
|
/* set handlers to the default one */
|
2004-01-15 05:08:37 +03:00
|
|
|
for (i=0; i < PORTS; i++) {
|
2008-01-27 01:24:03 +03:00
|
|
|
read_port_to_handler[i] = &io_read_handlers;
|
|
|
|
write_port_to_handler[i] = &io_write_handlers;
|
2004-01-15 05:08:37 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
for (i=0; i < BX_MAX_IRQS; i++) {
|
2006-09-13 22:51:25 +04:00
|
|
|
delete [] irq_handler_name[i];
|
2001-04-10 05:04:59 +04:00
|
|
|
irq_handler_name[i] = NULL;
|
2006-05-18 23:57:11 +04:00
|
|
|
}
|
|
|
|
|
2009-03-03 21:29:51 +03:00
|
|
|
// removable devices init
|
|
|
|
bx_keyboard.dev = NULL;
|
|
|
|
bx_keyboard.enq_event = NULL;
|
2009-03-03 23:34:50 +03:00
|
|
|
for (i=0; i < 2; i++) {
|
|
|
|
bx_mouse[i].dev = NULL;
|
|
|
|
bx_mouse[i].enq_event = NULL;
|
|
|
|
bx_mouse[i].enabled_changed = NULL;
|
|
|
|
}
|
2009-01-13 22:01:19 +03:00
|
|
|
// common mouse settings
|
|
|
|
mouse_captured = SIM->get_param_bool(BXPN_MOUSE_ENABLED)->get();
|
|
|
|
mouse_type = SIM->get_param_enum(BXPN_MOUSE_TYPE)->get();
|
|
|
|
|
2006-05-18 23:57:11 +04:00
|
|
|
// register as soon as possible - the devices want to have their timers !
|
|
|
|
bx_virt_timer.init();
|
|
|
|
bx_slowdown_timer.init();
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2002-10-25 16:28:34 +04:00
|
|
|
// BBD: At present, the only difference between "core" and "optional"
|
|
|
|
// plugins is that initialization and reset of optional plugins is handled
|
|
|
|
// by the plugin device list (). Init and reset of core plugins is done
|
|
|
|
// "by hand" in this file. Basically, we're using core plugins when we
|
|
|
|
// want to control the init order.
|
|
|
|
//
|
2002-10-25 01:07:56 +04:00
|
|
|
PLUG_load_plugin(cmos, PLUGTYPE_CORE);
|
|
|
|
PLUG_load_plugin(dma, PLUGTYPE_CORE);
|
|
|
|
PLUG_load_plugin(pic, PLUGTYPE_CORE);
|
2009-01-11 21:46:01 +03:00
|
|
|
PLUG_load_plugin(pit, PLUGTYPE_CORE);
|
2002-10-25 01:07:56 +04:00
|
|
|
PLUG_load_plugin(vga, PLUGTYPE_CORE);
|
|
|
|
PLUG_load_plugin(floppy, PLUGTYPE_CORE);
|
2009-02-21 14:43:18 +03:00
|
|
|
|
|
|
|
// PCI logic (i440FX)
|
|
|
|
if (SIM->get_param_bool(BXPN_I440FX_SUPPORT)->get()) {
|
|
|
|
#if BX_SUPPORT_PCI
|
|
|
|
PLUG_load_plugin(pci, PLUGTYPE_CORE);
|
|
|
|
PLUG_load_plugin(pci2isa, PLUGTYPE_CORE);
|
2009-05-05 20:13:13 +04:00
|
|
|
} else {
|
|
|
|
plugin_ctrl = (bx_list_c*)SIM->get_param(BXPN_PLUGIN_CTRL);
|
|
|
|
SIM->get_param_bool(BX_PLUGIN_PCI_IDE, plugin_ctrl)->set(0);
|
|
|
|
SIM->get_param_bool(BX_PLUGIN_ACPI, plugin_ctrl)->set(0);
|
|
|
|
}
|
2009-02-21 14:43:18 +03:00
|
|
|
#else
|
|
|
|
BX_ERROR(("Bochs is not compiled with PCI support"));
|
|
|
|
}
|
2009-05-05 20:13:13 +04:00
|
|
|
#endif
|
2009-02-21 14:43:18 +03:00
|
|
|
|
|
|
|
// optional plugins not controlled by separate option
|
|
|
|
plugin_ctrl = (bx_list_c*)SIM->get_param(BXPN_PLUGIN_CTRL);
|
|
|
|
for (i = 0; i < (unsigned)plugin_ctrl->get_size(); i++) {
|
|
|
|
plugin = (bx_param_bool_c*)(plugin_ctrl->get(i));
|
|
|
|
if (plugin->get()) {
|
2009-02-21 19:08:02 +03:00
|
|
|
#if BX_PLUGINS
|
2009-02-21 14:43:18 +03:00
|
|
|
PLUG_load_opt_plugin(plugin->get_name());
|
2009-02-21 19:08:02 +03:00
|
|
|
#else
|
|
|
|
// workaround in case of plugins disabled
|
|
|
|
plugname = plugin->get_name();
|
|
|
|
if (!strcmp(plugname, BX_PLUGIN_UNMAPPED)) {
|
|
|
|
PLUG_load_plugin(unmapped, PLUGTYPE_OPTIONAL);
|
|
|
|
}
|
|
|
|
else if (!strcmp(plugname, BX_PLUGIN_BIOSDEV)) {
|
|
|
|
PLUG_load_plugin(biosdev, PLUGTYPE_OPTIONAL);
|
|
|
|
}
|
|
|
|
else if (!strcmp(plugname, BX_PLUGIN_SPEAKER)) {
|
|
|
|
PLUG_load_plugin(speaker, PLUGTYPE_OPTIONAL);
|
|
|
|
}
|
|
|
|
else if (!strcmp(plugname, BX_PLUGIN_EXTFPUIRQ)) {
|
|
|
|
PLUG_load_plugin(extfpuirq, PLUGTYPE_OPTIONAL);
|
|
|
|
}
|
|
|
|
#if BX_SUPPORT_GAMEPORT
|
|
|
|
else if (!strcmp(plugname, BX_PLUGIN_GAMEPORT)) {
|
|
|
|
PLUG_load_plugin(gameport, PLUGTYPE_OPTIONAL);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#if BX_SUPPORT_IODEBUG
|
|
|
|
else if (!strcmp(plugname, BX_PLUGIN_IODEBUG)) {
|
|
|
|
PLUG_load_plugin(iodebug, PLUGTYPE_OPTIONAL);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#if BX_SUPPORT_PCI
|
|
|
|
else if (!strcmp(plugname, BX_PLUGIN_PCI_IDE)) {
|
|
|
|
PLUG_load_plugin(pci_ide, PLUGTYPE_OPTIONAL);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#if BX_SUPPORT_ACPI
|
|
|
|
else if (!strcmp(plugname, BX_PLUGIN_ACPI)) {
|
|
|
|
PLUG_load_plugin(acpi, PLUGTYPE_OPTIONAL);
|
|
|
|
}
|
|
|
|
#endif
|
2009-02-22 13:44:50 +03:00
|
|
|
#if BX_SUPPORT_APIC
|
|
|
|
else if (!strcmp(plugname, BX_PLUGIN_IOAPIC)) {
|
|
|
|
PLUG_load_plugin(ioapic, PLUGTYPE_OPTIONAL);
|
|
|
|
}
|
|
|
|
#endif
|
2009-02-21 19:08:02 +03:00
|
|
|
#endif
|
2009-02-21 14:43:18 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-10-25 01:07:56 +04:00
|
|
|
PLUG_load_plugin(keyboard, PLUGTYPE_OPTIONAL);
|
2004-12-11 11:35:33 +03:00
|
|
|
#if BX_SUPPORT_BUSMOUSE
|
2009-01-13 22:01:19 +03:00
|
|
|
if (mouse_type == BX_MOUSE_TYPE_BUS) {
|
2004-12-11 11:35:33 +03:00
|
|
|
PLUG_load_plugin(busmouse, PLUGTYPE_OPTIONAL);
|
|
|
|
}
|
|
|
|
#endif
|
2009-02-23 21:38:25 +03:00
|
|
|
if (is_harddrv_enabled())
|
|
|
|
PLUG_load_plugin(harddrv, PLUGTYPE_OPTIONAL);
|
2006-03-02 23:13:14 +03:00
|
|
|
if (is_serial_enabled())
|
2002-10-25 01:07:56 +04:00
|
|
|
PLUG_load_plugin(serial, PLUGTYPE_OPTIONAL);
|
2008-01-27 01:24:03 +03:00
|
|
|
if (is_parallel_enabled())
|
2002-10-25 01:07:56 +04:00
|
|
|
PLUG_load_plugin(parallel, PLUGTYPE_OPTIONAL);
|
|
|
|
|
2004-08-06 19:49:55 +04:00
|
|
|
#if BX_SUPPORT_PCI
|
2009-02-21 14:43:18 +03:00
|
|
|
if (SIM->get_param_bool(BXPN_I440FX_SUPPORT)->get()) {
|
2009-04-10 15:10:32 +04:00
|
|
|
#if BX_SUPPORT_PCIVGA && BX_SUPPORT_VBE
|
2005-10-27 12:20:16 +04:00
|
|
|
if ((DEV_is_pci_device("pcivga")) &&
|
2006-02-22 00:35:09 +03:00
|
|
|
(!strcmp(SIM->get_param_string(BXPN_VGA_EXTENSION)->getptr(), "vbe"))) {
|
2005-02-01 22:16:39 +03:00
|
|
|
PLUG_load_plugin(pcivga, PLUGTYPE_OPTIONAL);
|
|
|
|
}
|
2003-01-11 01:43:54 +03:00
|
|
|
#endif
|
2009-01-19 12:48:12 +03:00
|
|
|
#if BX_SUPPORT_USB_UHCI
|
|
|
|
if (is_usb_uhci_enabled()) {
|
|
|
|
PLUG_load_plugin(usb_uhci, PLUGTYPE_OPTIONAL);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#if BX_SUPPORT_USB_OHCI
|
|
|
|
if (is_usb_ohci_enabled()) {
|
|
|
|
PLUG_load_plugin(usb_ohci, PLUGTYPE_OPTIONAL);
|
2006-03-02 23:13:14 +03:00
|
|
|
}
|
2003-01-28 19:58:10 +03:00
|
|
|
#endif
|
2004-08-06 19:49:55 +04:00
|
|
|
#if BX_SUPPORT_PCIDEV
|
2006-02-21 00:29:13 +03:00
|
|
|
if (SIM->get_param_num(BXPN_PCIDEV_VENDOR)->get() != 0xffff) {
|
|
|
|
PLUG_load_plugin(pcidev, PLUGTYPE_OPTIONAL);
|
|
|
|
}
|
2004-01-15 05:08:37 +03:00
|
|
|
#endif
|
2004-10-04 00:06:12 +04:00
|
|
|
#if BX_SUPPORT_PCIPNIC
|
2006-03-02 23:13:14 +03:00
|
|
|
if (SIM->get_param_bool(BXPN_PNIC_ENABLED)->get()) {
|
2004-01-13 22:21:21 +03:00
|
|
|
PLUG_load_plugin(pcipnic, PLUGTYPE_OPTIONAL);
|
2004-02-11 02:47:31 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
#endif
|
2002-11-21 20:10:13 +03:00
|
|
|
}
|
2009-02-21 14:43:18 +03:00
|
|
|
#endif
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2004-07-03 12:20:19 +04:00
|
|
|
// NE2000 NIC
|
2006-03-02 23:13:14 +03:00
|
|
|
if (SIM->get_param_bool(BXPN_NE2K_ENABLED)->get()) {
|
2004-08-06 19:49:55 +04:00
|
|
|
#if BX_SUPPORT_NE2K
|
2004-07-03 12:20:19 +04:00
|
|
|
PLUG_load_plugin(ne2k, PLUGTYPE_OPTIONAL);
|
|
|
|
#else
|
|
|
|
BX_ERROR(("Bochs is not compiled with NE2K support"));
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2001-04-10 05:04:59 +04:00
|
|
|
//--- SOUND ---
|
2006-03-03 23:29:50 +03:00
|
|
|
if (SIM->get_param_bool(BXPN_SB16_ENABLED)->get()) {
|
2002-11-21 20:10:13 +03:00
|
|
|
#if BX_SUPPORT_SB16
|
2002-11-13 21:39:41 +03:00
|
|
|
PLUG_load_plugin(sb16, PLUGTYPE_OPTIONAL);
|
2002-11-21 20:10:13 +03:00
|
|
|
#else
|
|
|
|
BX_ERROR(("Bochs is not compiled with SB16 support"));
|
2001-04-10 05:04:59 +04:00
|
|
|
#endif
|
2002-11-21 20:10:13 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2009-01-15 20:34:20 +03:00
|
|
|
// CMOS RAM & RTC
|
|
|
|
pluginCmosDevice->init();
|
|
|
|
|
|
|
|
/*--- 8237 DMA ---*/
|
|
|
|
pluginDmaDevice->init();
|
|
|
|
|
|
|
|
//--- FLOPPY ---
|
|
|
|
pluginFloppyDevice->init();
|
|
|
|
|
2004-08-06 19:49:55 +04:00
|
|
|
#if BX_SUPPORT_PCI
|
2009-01-15 20:34:20 +03:00
|
|
|
pluginPciBridge->init();
|
|
|
|
pluginPci2IsaBridge->init();
|
2004-06-27 22:23:00 +04:00
|
|
|
#endif
|
|
|
|
|
2001-04-10 05:04:59 +04:00
|
|
|
/*--- VGA adapter ---*/
|
2009-01-15 20:34:20 +03:00
|
|
|
pluginVgaDevice->init();
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
/*--- 8259A PIC ---*/
|
2002-10-25 01:07:56 +04:00
|
|
|
pluginPicDevice->init();
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2009-01-11 21:46:01 +03:00
|
|
|
/*--- 82C54 PIT ---*/
|
|
|
|
pluginPitDevice->init();
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
// Guest to Host interface. Used with special guest drivers
|
|
|
|
// which move data to/from the host environment.
|
|
|
|
g2h = &bx_g2h;
|
2002-10-25 01:07:56 +04:00
|
|
|
g2h->init();
|
2001-04-10 05:04:59 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// system hardware
|
2005-10-01 21:40:07 +04:00
|
|
|
register_io_read_handler(this, &read_handler, 0x0092,
|
|
|
|
"Port 92h System Control", 1);
|
|
|
|
register_io_write_handler(this, &write_handler, 0x0092,
|
|
|
|
"Port 92h System Control", 1);
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
// misc. CMOS
|
2003-04-26 02:06:27 +04:00
|
|
|
Bit32u extended_memory_in_k = mem->get_memory_in_k() > 1024 ? (mem->get_memory_in_k() - 1024) : 0;
|
2005-02-16 20:53:40 +03:00
|
|
|
if (extended_memory_in_k > 0xfc00) extended_memory_in_k = 0xfc00;
|
2003-04-26 02:06:27 +04:00
|
|
|
|
2002-10-25 01:07:56 +04:00
|
|
|
DEV_cmos_set_reg(0x15, (Bit8u) BASE_MEMORY_IN_K);
|
|
|
|
DEV_cmos_set_reg(0x16, (Bit8u) (BASE_MEMORY_IN_K >> 8));
|
2008-02-16 01:05:43 +03:00
|
|
|
DEV_cmos_set_reg(0x17, (Bit8u) (extended_memory_in_k & 0xff));
|
|
|
|
DEV_cmos_set_reg(0x18, (Bit8u) ((extended_memory_in_k >> 8) & 0xff));
|
|
|
|
DEV_cmos_set_reg(0x30, (Bit8u) (extended_memory_in_k & 0xff));
|
|
|
|
DEV_cmos_set_reg(0x31, (Bit8u) ((extended_memory_in_k >> 8) & 0xff));
|
2003-04-26 02:06:27 +04:00
|
|
|
|
|
|
|
Bit32u extended_memory_in_64k = mem->get_memory_in_k() > 16384 ? (mem->get_memory_in_k() - 16384) / 64 : 0;
|
|
|
|
if (extended_memory_in_64k > 0xffff) extended_memory_in_64k = 0xffff;
|
|
|
|
|
2008-02-16 01:05:43 +03:00
|
|
|
DEV_cmos_set_reg(0x34, (Bit8u) (extended_memory_in_64k & 0xff));
|
|
|
|
DEV_cmos_set_reg(0x35, (Bit8u) ((extended_memory_in_64k >> 8) & 0xff));
|
2002-10-16 11:38:37 +04:00
|
|
|
|
2002-10-06 23:04:47 +04:00
|
|
|
if (timer_handle != BX_NULL_TIMER_HANDLE) {
|
2006-03-14 21:11:22 +03:00
|
|
|
timer_handle = bx_pc_system.register_timer(this, timer_handler,
|
2002-10-06 23:04:47 +04:00
|
|
|
(unsigned) BX_IODEV_HANDLER_PERIOD, 1, 1, "devices.cc");
|
|
|
|
}
|
2002-09-09 20:56:56 +04:00
|
|
|
|
|
|
|
// Clear fields for bulk IO acceleration transfers.
|
|
|
|
bulkIOHostAddr = 0;
|
|
|
|
bulkIOQuantumsRequested = 0;
|
|
|
|
bulkIOQuantumsTransferred = 0;
|
2002-10-25 01:07:56 +04:00
|
|
|
|
|
|
|
bx_init_plugins();
|
2003-01-03 14:43:24 +03:00
|
|
|
|
|
|
|
/* now perform checksum of CMOS memory */
|
|
|
|
DEV_cmos_checksum();
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
2006-03-14 21:11:22 +03:00
|
|
|
void bx_devices_c::reset(unsigned type)
|
2002-08-01 16:19:01 +04:00
|
|
|
{
|
2006-03-27 02:15:07 +04:00
|
|
|
mem->disable_smram();
|
2004-08-06 19:49:55 +04:00
|
|
|
#if BX_SUPPORT_PCI
|
2006-04-15 21:03:59 +04:00
|
|
|
if (SIM->get_param_bool(BXPN_I440FX_SUPPORT)->get()) {
|
2002-11-09 23:51:40 +03:00
|
|
|
pluginPciBridge->reset(type);
|
|
|
|
pluginPci2IsaBridge->reset(type);
|
|
|
|
}
|
2002-08-27 23:54:46 +04:00
|
|
|
#endif
|
2002-10-25 01:07:56 +04:00
|
|
|
pluginCmosDevice->reset(type);
|
|
|
|
pluginDmaDevice->reset(type);
|
|
|
|
pluginFloppyDevice->reset(type);
|
|
|
|
pluginVgaDevice->reset(type);
|
|
|
|
pluginPicDevice->reset(type);
|
2009-01-11 21:46:01 +03:00
|
|
|
pluginPitDevice->reset(type);
|
2004-07-03 12:20:19 +04:00
|
|
|
// now reset optional plugins
|
2002-10-25 01:07:56 +04:00
|
|
|
bx_reset_plugins(type);
|
2002-08-01 16:19:01 +04:00
|
|
|
}
|
|
|
|
|
2006-04-15 21:03:59 +04:00
|
|
|
void bx_devices_c::register_state()
|
|
|
|
{
|
2006-05-27 19:54:49 +04:00
|
|
|
bx_virt_timer.register_state();
|
2006-04-15 21:03:59 +04:00
|
|
|
#if BX_SUPPORT_PCI
|
|
|
|
if (SIM->get_param_bool(BXPN_I440FX_SUPPORT)->get()) {
|
|
|
|
pluginPciBridge->register_state();
|
|
|
|
pluginPci2IsaBridge->register_state();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
pluginCmosDevice->register_state();
|
|
|
|
pluginDmaDevice->register_state();
|
|
|
|
pluginFloppyDevice->register_state();
|
|
|
|
pluginVgaDevice->register_state();
|
|
|
|
pluginPicDevice->register_state();
|
2009-01-11 21:46:01 +03:00
|
|
|
pluginPitDevice->register_state();
|
2006-04-15 21:03:59 +04:00
|
|
|
// now register state of optional plugins
|
|
|
|
bx_plugins_register_state();
|
|
|
|
}
|
|
|
|
|
|
|
|
void bx_devices_c::after_restore_state()
|
|
|
|
{
|
2006-05-27 19:54:49 +04:00
|
|
|
bx_slowdown_timer.after_restore_state();
|
|
|
|
#if BX_SUPPORT_PCI
|
|
|
|
if (SIM->get_param_bool(BXPN_I440FX_SUPPORT)->get()) {
|
|
|
|
pluginPciBridge->after_restore_state();
|
|
|
|
pluginPci2IsaBridge->after_restore_state();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
pluginCmosDevice->after_restore_state();
|
|
|
|
pluginVgaDevice->after_restore_state();
|
2006-04-15 21:03:59 +04:00
|
|
|
bx_plugins_after_restore_state();
|
|
|
|
}
|
|
|
|
|
2006-09-07 22:50:51 +04:00
|
|
|
void bx_devices_c::exit()
|
|
|
|
{
|
2006-09-20 22:24:17 +04:00
|
|
|
// delete i/o handlers before unloading plugins
|
|
|
|
struct io_handler_struct *io_read_handler = io_read_handlers.next;
|
|
|
|
struct io_handler_struct *curr = NULL;
|
|
|
|
while (io_read_handler != &io_read_handlers) {
|
|
|
|
io_read_handler->prev->next = io_read_handler->next;
|
|
|
|
io_read_handler->next->prev = io_read_handler->prev;
|
|
|
|
curr = io_read_handler;
|
|
|
|
io_read_handler = io_read_handler->next;
|
|
|
|
delete [] curr->handler_name;
|
|
|
|
delete curr;
|
|
|
|
}
|
|
|
|
struct io_handler_struct *io_write_handler = io_write_handlers.next;
|
|
|
|
while (io_write_handler != &io_write_handlers) {
|
|
|
|
io_write_handler->prev->next = io_write_handler->next;
|
|
|
|
io_write_handler->next->prev = io_write_handler->prev;
|
|
|
|
curr = io_write_handler;
|
|
|
|
io_write_handler = io_write_handler->next;
|
|
|
|
delete [] curr->handler_name;
|
|
|
|
delete curr;
|
|
|
|
}
|
|
|
|
|
2006-09-18 22:10:49 +04:00
|
|
|
bx_virt_timer.setup();
|
2006-09-16 23:30:56 +04:00
|
|
|
bx_slowdown_timer.exit();
|
|
|
|
|
2009-01-11 21:46:01 +03:00
|
|
|
PLUG_unload_plugin(pit);
|
2006-09-10 13:13:47 +04:00
|
|
|
PLUG_unload_plugin(cmos);
|
|
|
|
PLUG_unload_plugin(dma);
|
|
|
|
PLUG_unload_plugin(pic);
|
|
|
|
PLUG_unload_plugin(vga);
|
|
|
|
PLUG_unload_plugin(floppy);
|
|
|
|
#if BX_SUPPORT_PCI
|
|
|
|
PLUG_unload_plugin(pci);
|
|
|
|
PLUG_unload_plugin(pci2isa);
|
|
|
|
#endif
|
|
|
|
bx_unload_plugins();
|
2006-09-10 21:18:44 +04:00
|
|
|
init_stubs();
|
2006-09-07 22:50:51 +04:00
|
|
|
}
|
|
|
|
|
2006-03-07 01:03:16 +03:00
|
|
|
Bit32u bx_devices_c::read_handler(void *this_ptr, Bit32u address, unsigned io_len)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
|
|
|
#if !BX_USE_DEV_SMF
|
|
|
|
bx_devices_c *class_ptr = (bx_devices_c *) this_ptr;
|
2006-03-07 01:03:16 +03:00
|
|
|
return class_ptr->port92_read(address, io_len);
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
2006-03-07 01:03:16 +03:00
|
|
|
Bit32u bx_devices_c::port92_read(Bit32u address, unsigned io_len)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
|
|
|
#else
|
|
|
|
UNUSED(this_ptr);
|
|
|
|
#endif // !BX_USE_DEV_SMF
|
|
|
|
|
2001-06-27 23:16:01 +04:00
|
|
|
BX_DEBUG(("port92h read partially supported!!!"));
|
|
|
|
BX_DEBUG((" returning %02x", (unsigned) (BX_GET_ENABLE_A20() << 1)));
|
2001-04-10 05:04:59 +04:00
|
|
|
return(BX_GET_ENABLE_A20() << 1);
|
|
|
|
}
|
|
|
|
|
2006-03-07 01:03:16 +03:00
|
|
|
void bx_devices_c::write_handler(void *this_ptr, Bit32u address, Bit32u value, unsigned io_len)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
|
|
|
#if !BX_USE_DEV_SMF
|
|
|
|
bx_devices_c *class_ptr = (bx_devices_c *) this_ptr;
|
|
|
|
class_ptr->port92_write(address, value, io_len);
|
|
|
|
}
|
|
|
|
|
2006-03-07 01:03:16 +03:00
|
|
|
void bx_devices_c::port92_write(Bit32u address, Bit32u value, unsigned io_len)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
|
|
|
#else
|
|
|
|
UNUSED(this_ptr);
|
|
|
|
#endif // !BX_USE_DEV_SMF
|
|
|
|
|
2004-04-09 01:23:41 +04:00
|
|
|
BX_DEBUG(("port92h write of %02x partially supported!!!", (unsigned) value));
|
2001-06-27 23:16:01 +04:00
|
|
|
BX_DEBUG(("A20: set_enable_a20() called"));
|
2008-02-16 01:05:43 +03:00
|
|
|
BX_SET_ENABLE_A20((value & 0x02) >> 1);
|
2001-08-31 20:06:32 +04:00
|
|
|
BX_DEBUG(("A20: now %u", (unsigned) BX_GET_ENABLE_A20()));
|
2004-04-09 01:23:41 +04:00
|
|
|
if (value & 0x01) { /* high speed reset */
|
|
|
|
BX_INFO(("iowrite to port0x92 : reset resquested"));
|
2004-06-21 14:39:24 +04:00
|
|
|
bx_pc_system.Reset(BX_RESET_SOFTWARE);
|
2004-04-09 01:23:41 +04:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
2009-01-15 20:34:20 +03:00
|
|
|
// This defines the builtin default read handler,
|
2002-10-25 01:07:56 +04:00
|
|
|
// so Bochs does not segfault if unmapped is not loaded
|
2006-03-07 01:03:16 +03:00
|
|
|
Bit32u bx_devices_c::default_read_handler(void *this_ptr, Bit32u address, unsigned io_len)
|
2002-10-25 01:07:56 +04:00
|
|
|
{
|
|
|
|
UNUSED(this_ptr);
|
|
|
|
return 0xffffffff;
|
|
|
|
}
|
|
|
|
|
2009-01-15 20:34:20 +03:00
|
|
|
// This defines the builtin default write handler,
|
2002-10-25 01:07:56 +04:00
|
|
|
// so Bochs does not segfault if unmapped is not loaded
|
2006-03-07 01:03:16 +03:00
|
|
|
void bx_devices_c::default_write_handler(void *this_ptr, Bit32u address, Bit32u value, unsigned io_len)
|
2002-10-25 01:07:56 +04:00
|
|
|
{
|
|
|
|
UNUSED(this_ptr);
|
|
|
|
}
|
|
|
|
|
2006-03-07 01:03:16 +03:00
|
|
|
void bx_devices_c::timer_handler(void *this_ptr)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
|
|
|
bx_devices_c *class_ptr = (bx_devices_c *) this_ptr;
|
|
|
|
class_ptr->timer();
|
|
|
|
}
|
|
|
|
|
2006-03-07 01:03:16 +03:00
|
|
|
void bx_devices_c::timer()
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
2002-10-25 01:07:56 +04:00
|
|
|
// separate calls to bx_gui->handle_events from the keyboard code.
|
|
|
|
{
|
|
|
|
static int multiple=0;
|
2007-04-09 01:57:06 +04:00
|
|
|
if (++multiple==10)
|
2002-10-25 01:07:56 +04:00
|
|
|
{
|
|
|
|
multiple=0;
|
2006-03-14 21:11:22 +03:00
|
|
|
SIM->periodic();
|
|
|
|
if (! bx_pc_system.kill_bochs_request)
|
2002-10-25 01:07:56 +04:00
|
|
|
bx_gui->handle_events();
|
|
|
|
}
|
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
2006-03-07 01:03:16 +03:00
|
|
|
bx_bool bx_devices_c::register_irq(unsigned irq, const char *name)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
|
|
|
if (irq >= BX_MAX_IRQS) {
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_PANIC(("IO device %s registered with IRQ=%d above %u",
|
merge in BRANCH-io-cleanup.
To see the commit logs for this use either cvsweb or
cvs update -r BRANCH-io-cleanup and then 'cvs log' the various files.
In general this provides a generic interface for logging.
logfunctions:: is a class that is inherited by some classes, and also
. allocated as a standalone global called 'genlog'. All logging uses
. one of the ::info(), ::error(), ::ldebug(), ::panic() methods of this
. class through 'BX_INFO(), BX_ERROR(), BX_DEBUG(), BX_PANIC()' macros
. respectively.
.
. An example usage:
. BX_INFO(("Hello, World!\n"));
iofunctions:: is a class that is allocated once by default, and assigned
as the iofunction of each logfunctions instance. It is this class that
maintains the file descriptor and other output related code, at this
point using vfprintf(). At some future point, someone may choose to
write a gui 'console' for bochs to which messages would be redirected
simply by assigning a different iofunction class to the various logfunctions
objects.
More cleanup is coming, but this works for now. If you want to see alot
of debugging output, in main.cc, change onoff[LOGLEV_DEBUG]=0 to =1.
Comments, bugs, flames, to me: todd@fries.net
2001-05-15 18:49:57 +04:00
|
|
|
name, irq, (unsigned) BX_MAX_IRQS-1));
|
2006-09-13 22:51:25 +04:00
|
|
|
return 0;
|
2006-03-07 01:03:16 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
if (irq_handler_name[irq]) {
|
2008-12-29 21:02:01 +03:00
|
|
|
BX_PANIC(("IRQ %u conflict, %s with %s", irq, irq_handler_name[irq], name));
|
2006-09-13 22:51:25 +04:00
|
|
|
return 0;
|
2006-03-07 01:03:16 +03:00
|
|
|
}
|
2006-09-13 22:51:25 +04:00
|
|
|
irq_handler_name[irq] = new char[strlen(name)+1];
|
|
|
|
strcpy(irq_handler_name[irq], name);
|
|
|
|
return 1;
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
2006-03-07 01:03:16 +03:00
|
|
|
bx_bool bx_devices_c::unregister_irq(unsigned irq, const char *name)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
|
|
|
if (irq >= BX_MAX_IRQS) {
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_PANIC(("IO device %s tried to unregister IRQ %d above %u",
|
merge in BRANCH-io-cleanup.
To see the commit logs for this use either cvsweb or
cvs update -r BRANCH-io-cleanup and then 'cvs log' the various files.
In general this provides a generic interface for logging.
logfunctions:: is a class that is inherited by some classes, and also
. allocated as a standalone global called 'genlog'. All logging uses
. one of the ::info(), ::error(), ::ldebug(), ::panic() methods of this
. class through 'BX_INFO(), BX_ERROR(), BX_DEBUG(), BX_PANIC()' macros
. respectively.
.
. An example usage:
. BX_INFO(("Hello, World!\n"));
iofunctions:: is a class that is allocated once by default, and assigned
as the iofunction of each logfunctions instance. It is this class that
maintains the file descriptor and other output related code, at this
point using vfprintf(). At some future point, someone may choose to
write a gui 'console' for bochs to which messages would be redirected
simply by assigning a different iofunction class to the various logfunctions
objects.
More cleanup is coming, but this works for now. If you want to see alot
of debugging output, in main.cc, change onoff[LOGLEV_DEBUG]=0 to =1.
Comments, bugs, flames, to me: todd@fries.net
2001-05-15 18:49:57 +04:00
|
|
|
name, irq, (unsigned) BX_MAX_IRQS-1));
|
2006-09-13 22:51:25 +04:00
|
|
|
return 0;
|
2006-03-07 01:03:16 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
if (!irq_handler_name[irq]) {
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_INFO(("IO device %s tried to unregister IRQ %d, not registered",
|
merge in BRANCH-io-cleanup.
To see the commit logs for this use either cvsweb or
cvs update -r BRANCH-io-cleanup and then 'cvs log' the various files.
In general this provides a generic interface for logging.
logfunctions:: is a class that is inherited by some classes, and also
. allocated as a standalone global called 'genlog'. All logging uses
. one of the ::info(), ::error(), ::ldebug(), ::panic() methods of this
. class through 'BX_INFO(), BX_ERROR(), BX_DEBUG(), BX_PANIC()' macros
. respectively.
.
. An example usage:
. BX_INFO(("Hello, World!\n"));
iofunctions:: is a class that is allocated once by default, and assigned
as the iofunction of each logfunctions instance. It is this class that
maintains the file descriptor and other output related code, at this
point using vfprintf(). At some future point, someone may choose to
write a gui 'console' for bochs to which messages would be redirected
simply by assigning a different iofunction class to the various logfunctions
objects.
More cleanup is coming, but this works for now. If you want to see alot
of debugging output, in main.cc, change onoff[LOGLEV_DEBUG]=0 to =1.
Comments, bugs, flames, to me: todd@fries.net
2001-05-15 18:49:57 +04:00
|
|
|
name, irq));
|
2006-09-13 22:51:25 +04:00
|
|
|
return 0;
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (strcmp(irq_handler_name[irq], name)) {
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_INFO(("IRQ %u not registered to %s but to %s", irq,
|
merge in BRANCH-io-cleanup.
To see the commit logs for this use either cvsweb or
cvs update -r BRANCH-io-cleanup and then 'cvs log' the various files.
In general this provides a generic interface for logging.
logfunctions:: is a class that is inherited by some classes, and also
. allocated as a standalone global called 'genlog'. All logging uses
. one of the ::info(), ::error(), ::ldebug(), ::panic() methods of this
. class through 'BX_INFO(), BX_ERROR(), BX_DEBUG(), BX_PANIC()' macros
. respectively.
.
. An example usage:
. BX_INFO(("Hello, World!\n"));
iofunctions:: is a class that is allocated once by default, and assigned
as the iofunction of each logfunctions instance. It is this class that
maintains the file descriptor and other output related code, at this
point using vfprintf(). At some future point, someone may choose to
write a gui 'console' for bochs to which messages would be redirected
simply by assigning a different iofunction class to the various logfunctions
objects.
More cleanup is coming, but this works for now. If you want to see alot
of debugging output, in main.cc, change onoff[LOGLEV_DEBUG]=0 to =1.
Comments, bugs, flames, to me: todd@fries.net
2001-05-15 18:49:57 +04:00
|
|
|
name, irq_handler_name[irq]));
|
2006-09-13 22:51:25 +04:00
|
|
|
return 0;
|
2006-03-07 01:03:16 +03:00
|
|
|
}
|
2006-09-13 22:51:25 +04:00
|
|
|
delete [] irq_handler_name[irq];
|
2001-04-10 05:04:59 +04:00
|
|
|
irq_handler_name[irq] = NULL;
|
2006-09-13 22:51:25 +04:00
|
|
|
return 1;
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
2006-03-07 01:03:16 +03:00
|
|
|
bx_bool bx_devices_c::register_io_read_handler(void *this_ptr, bx_read_handler_t f,
|
2006-09-20 22:24:17 +04:00
|
|
|
Bit32u addr, const char *name, Bit8u mask)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
2008-12-29 21:02:01 +03:00
|
|
|
addr &= 0xffff;
|
2005-10-01 21:40:07 +04:00
|
|
|
|
2004-01-15 05:08:37 +03:00
|
|
|
if (!f)
|
2006-09-13 22:51:25 +04:00
|
|
|
return 0;
|
2004-01-15 05:08:37 +03:00
|
|
|
|
|
|
|
/* first check if the port already has a handlers != the default handler */
|
|
|
|
if (read_port_to_handler[addr] &&
|
2005-10-01 21:40:07 +04:00
|
|
|
read_port_to_handler[addr] != &io_read_handlers) { // the default
|
|
|
|
BX_ERROR(("IO device address conflict(read) at IO address %Xh",
|
|
|
|
(unsigned) addr));
|
|
|
|
BX_ERROR((" conflicting devices: %s & %s",
|
|
|
|
read_port_to_handler[addr]->handler_name, name));
|
2006-09-13 22:51:25 +04:00
|
|
|
return 0;
|
2004-01-15 05:08:37 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
/* first find existing handle for function or create new one */
|
2004-01-15 05:08:37 +03:00
|
|
|
struct io_handler_struct *curr = &io_read_handlers;
|
|
|
|
struct io_handler_struct *io_read_handler = NULL;
|
|
|
|
do {
|
2008-01-27 01:24:03 +03:00
|
|
|
if (curr->funct == f &&
|
|
|
|
curr->mask == mask &&
|
2005-10-01 21:40:07 +04:00
|
|
|
curr->this_ptr == this_ptr &&
|
2009-05-01 13:12:07 +04:00
|
|
|
!strcmp(curr->handler_name, name)) { // really want the same name too
|
2005-10-01 21:40:07 +04:00
|
|
|
io_read_handler = curr;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
curr = curr->next;
|
2004-01-15 05:08:37 +03:00
|
|
|
} while (curr->next != &io_read_handlers);
|
2005-10-01 21:40:07 +04:00
|
|
|
|
2004-01-15 05:08:37 +03:00
|
|
|
if (!io_read_handler) {
|
2005-10-01 21:40:07 +04:00
|
|
|
io_read_handler = new struct io_handler_struct;
|
|
|
|
io_read_handler->funct = (void *)f;
|
|
|
|
io_read_handler->this_ptr = this_ptr;
|
2006-09-20 22:24:17 +04:00
|
|
|
io_read_handler->handler_name = new char[strlen(name)+1];
|
|
|
|
strcpy(io_read_handler->handler_name, name);
|
2005-10-01 21:40:07 +04:00
|
|
|
io_read_handler->mask = mask;
|
|
|
|
io_read_handler->usage_count = 0;
|
|
|
|
// add the handler to the double linked list of handlers
|
|
|
|
io_read_handlers.prev->next = io_read_handler;
|
|
|
|
io_read_handler->next = &io_read_handlers;
|
|
|
|
io_read_handler->prev = io_read_handlers.prev;
|
|
|
|
io_read_handlers.prev = io_read_handler;
|
2004-01-15 05:08:37 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2004-01-15 05:08:37 +03:00
|
|
|
io_read_handler->usage_count++;
|
|
|
|
read_port_to_handler[addr] = io_read_handler;
|
2006-09-13 22:51:25 +04:00
|
|
|
return 1; // address mapped successfully
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
2006-03-07 01:03:16 +03:00
|
|
|
bx_bool bx_devices_c::register_io_write_handler(void *this_ptr, bx_write_handler_t f,
|
2006-09-20 22:24:17 +04:00
|
|
|
Bit32u addr, const char *name, Bit8u mask)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
2008-12-29 21:02:01 +03:00
|
|
|
addr &= 0xffff;
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2004-01-15 05:08:37 +03:00
|
|
|
if (!f)
|
2006-09-13 22:51:25 +04:00
|
|
|
return 0;
|
2005-10-01 21:40:07 +04:00
|
|
|
|
2004-01-15 05:08:37 +03:00
|
|
|
/* first check if the port already has a handlers != the default handler */
|
|
|
|
if (write_port_to_handler[addr] &&
|
2005-10-01 21:40:07 +04:00
|
|
|
write_port_to_handler[addr] != &io_write_handlers) { // the default
|
|
|
|
BX_ERROR(("IO device address conflict(write) at IO address %Xh",
|
|
|
|
(unsigned) addr));
|
|
|
|
BX_ERROR((" conflicting devices: %s & %s",
|
|
|
|
write_port_to_handler[addr]->handler_name, name));
|
2006-09-13 22:51:25 +04:00
|
|
|
return 0;
|
2004-01-15 05:08:37 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2004-01-15 05:08:37 +03:00
|
|
|
/* first find existing handle for function or create new one */
|
|
|
|
struct io_handler_struct *curr = &io_write_handlers;
|
|
|
|
struct io_handler_struct *io_write_handler = NULL;
|
|
|
|
do {
|
2008-01-27 01:24:03 +03:00
|
|
|
if (curr->funct == f &&
|
|
|
|
curr->mask == mask &&
|
2005-10-01 21:40:07 +04:00
|
|
|
curr->this_ptr == this_ptr &&
|
2009-05-01 13:12:07 +04:00
|
|
|
!strcmp(curr->handler_name, name)) { // really want the same name too
|
2005-10-01 21:40:07 +04:00
|
|
|
io_write_handler = curr;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
curr = curr->next;
|
2004-01-15 05:08:37 +03:00
|
|
|
} while (curr->next != &io_write_handlers);
|
2005-10-01 21:40:07 +04:00
|
|
|
|
2004-01-15 05:08:37 +03:00
|
|
|
if (!io_write_handler) {
|
2005-10-01 21:40:07 +04:00
|
|
|
io_write_handler = new struct io_handler_struct;
|
|
|
|
io_write_handler->funct = (void *)f;
|
|
|
|
io_write_handler->this_ptr = this_ptr;
|
2006-09-20 22:24:17 +04:00
|
|
|
io_write_handler->handler_name = new char[strlen(name)+1];
|
|
|
|
strcpy(io_write_handler->handler_name, name);
|
2005-10-01 21:40:07 +04:00
|
|
|
io_write_handler->mask = mask;
|
|
|
|
io_write_handler->usage_count = 0;
|
|
|
|
// add the handler to the double linked list of handlers
|
|
|
|
io_write_handlers.prev->next = io_write_handler;
|
|
|
|
io_write_handler->next = &io_write_handlers;
|
|
|
|
io_write_handler->prev = io_write_handlers.prev;
|
|
|
|
io_write_handlers.prev = io_write_handler;
|
2004-01-15 05:08:37 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2004-01-15 05:08:37 +03:00
|
|
|
io_write_handler->usage_count++;
|
|
|
|
write_port_to_handler[addr] = io_write_handler;
|
2006-09-13 22:51:25 +04:00
|
|
|
return 1; // address mapped successfully
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
2006-03-07 01:03:16 +03:00
|
|
|
bx_bool bx_devices_c::register_io_read_handler_range(void *this_ptr, bx_read_handler_t f,
|
2005-10-01 21:40:07 +04:00
|
|
|
Bit32u begin_addr, Bit32u end_addr,
|
|
|
|
const char *name, Bit8u mask)
|
2004-01-15 05:08:37 +03:00
|
|
|
{
|
2004-02-03 00:47:26 +03:00
|
|
|
Bit32u addr;
|
2008-12-29 21:02:01 +03:00
|
|
|
begin_addr &= 0xffff;
|
|
|
|
end_addr &= 0xffff;
|
2004-01-15 05:08:37 +03:00
|
|
|
|
|
|
|
if (end_addr < begin_addr) {
|
2005-10-01 21:40:07 +04:00
|
|
|
BX_ERROR(("!!! end_addr < begin_addr !!!"));
|
2006-09-13 22:51:25 +04:00
|
|
|
return 0;
|
2004-01-15 05:08:37 +03:00
|
|
|
}
|
2008-01-27 01:24:03 +03:00
|
|
|
|
2004-01-15 05:08:37 +03:00
|
|
|
if (!f) {
|
2005-10-01 21:40:07 +04:00
|
|
|
BX_ERROR(("!!! f == NULL !!!"));
|
2006-09-13 22:51:25 +04:00
|
|
|
return 0;
|
2004-01-15 05:08:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* first check if the port already has a handlers != the default handler */
|
|
|
|
for (addr = begin_addr; addr <= end_addr; addr++)
|
2005-10-01 21:40:07 +04:00
|
|
|
if (read_port_to_handler[addr] &&
|
|
|
|
read_port_to_handler[addr] != &io_read_handlers) { // the default
|
|
|
|
BX_ERROR(("IO device address conflict(read) at IO address %Xh",
|
|
|
|
(unsigned) addr));
|
|
|
|
BX_ERROR((" conflicting devices: %s & %s",
|
|
|
|
read_port_to_handler[addr]->handler_name, name));
|
2006-09-13 22:51:25 +04:00
|
|
|
return 0;
|
2005-10-01 21:40:07 +04:00
|
|
|
}
|
2004-01-15 05:08:37 +03:00
|
|
|
|
|
|
|
/* first find existing handle for function or create new one */
|
|
|
|
struct io_handler_struct *curr = &io_read_handlers;
|
|
|
|
struct io_handler_struct *io_read_handler = NULL;
|
|
|
|
do {
|
2008-01-27 01:24:03 +03:00
|
|
|
if (curr->funct == f &&
|
|
|
|
curr->mask == mask &&
|
2005-10-01 21:40:07 +04:00
|
|
|
curr->this_ptr == this_ptr &&
|
2009-05-01 13:12:07 +04:00
|
|
|
!strcmp(curr->handler_name, name)) {
|
2005-10-01 21:40:07 +04:00
|
|
|
io_read_handler = curr;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
curr = curr->next;
|
2004-01-15 05:08:37 +03:00
|
|
|
} while (curr->next != &io_read_handlers);
|
2005-10-01 21:40:07 +04:00
|
|
|
|
2004-01-15 05:08:37 +03:00
|
|
|
if (!io_read_handler) {
|
2005-10-01 21:40:07 +04:00
|
|
|
io_read_handler = new struct io_handler_struct;
|
|
|
|
io_read_handler->funct = (void *)f;
|
|
|
|
io_read_handler->this_ptr = this_ptr;
|
2006-09-20 22:24:17 +04:00
|
|
|
io_read_handler->handler_name = new char[strlen(name)+1];
|
|
|
|
strcpy(io_read_handler->handler_name, name);
|
2005-10-01 21:40:07 +04:00
|
|
|
io_read_handler->mask = mask;
|
|
|
|
io_read_handler->usage_count = 0;
|
|
|
|
// add the handler to the double linked list of handlers
|
|
|
|
io_read_handlers.prev->next = io_read_handler;
|
|
|
|
io_read_handler->next = &io_read_handlers;
|
|
|
|
io_read_handler->prev = io_read_handlers.prev;
|
|
|
|
io_read_handlers.prev = io_read_handler;
|
2004-01-15 05:08:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
io_read_handler->usage_count += end_addr - begin_addr + 1;
|
|
|
|
for (addr = begin_addr; addr <= end_addr; addr++)
|
|
|
|
read_port_to_handler[addr] = io_read_handler;
|
2006-09-13 22:51:25 +04:00
|
|
|
return 1; // address mapped successfully
|
2004-01-15 05:08:37 +03:00
|
|
|
}
|
|
|
|
|
2006-03-07 01:03:16 +03:00
|
|
|
bx_bool bx_devices_c::register_io_write_handler_range(void *this_ptr, bx_write_handler_t f,
|
2005-10-01 21:40:07 +04:00
|
|
|
Bit32u begin_addr, Bit32u end_addr,
|
|
|
|
const char *name, Bit8u mask)
|
2002-10-25 01:07:56 +04:00
|
|
|
{
|
2004-02-03 00:47:26 +03:00
|
|
|
Bit32u addr;
|
2008-12-29 21:02:01 +03:00
|
|
|
begin_addr &= 0xffff;
|
|
|
|
end_addr &= 0xffff;
|
2002-10-25 01:07:56 +04:00
|
|
|
|
2004-01-15 05:08:37 +03:00
|
|
|
if (end_addr < begin_addr) {
|
2005-10-01 21:40:07 +04:00
|
|
|
BX_ERROR(("!!! end_addr < begin_addr !!!"));
|
2006-09-13 22:51:25 +04:00
|
|
|
return 0;
|
2004-01-15 05:08:37 +03:00
|
|
|
}
|
2008-01-27 01:24:03 +03:00
|
|
|
|
2004-01-15 05:08:37 +03:00
|
|
|
if (!f) {
|
2005-10-01 21:40:07 +04:00
|
|
|
BX_ERROR(("!!! f == NULL !!!"));
|
2006-09-13 22:51:25 +04:00
|
|
|
return 0;
|
2004-01-15 05:08:37 +03:00
|
|
|
}
|
2002-10-25 01:07:56 +04:00
|
|
|
|
2004-01-15 05:08:37 +03:00
|
|
|
/* first check if the port already has a handlers != the default handler */
|
|
|
|
for (addr = begin_addr; addr <= end_addr; addr++)
|
2005-10-01 21:40:07 +04:00
|
|
|
if (write_port_to_handler[addr] &&
|
|
|
|
write_port_to_handler[addr] != &io_write_handlers) { // the default
|
|
|
|
BX_ERROR(("IO device address conflict(read) at IO address %Xh",
|
|
|
|
(unsigned) addr));
|
|
|
|
BX_ERROR((" conflicting devices: %s & %s",
|
|
|
|
write_port_to_handler[addr]->handler_name, name));
|
2006-09-13 22:51:25 +04:00
|
|
|
return 0;
|
2005-10-01 21:40:07 +04:00
|
|
|
}
|
2004-01-15 05:08:37 +03:00
|
|
|
|
|
|
|
/* first find existing handle for function or create new one */
|
|
|
|
struct io_handler_struct *curr = &io_write_handlers;
|
|
|
|
struct io_handler_struct *io_write_handler = NULL;
|
|
|
|
do {
|
2008-01-27 01:24:03 +03:00
|
|
|
if (curr->funct == f &&
|
|
|
|
curr->mask == mask &&
|
2005-10-01 21:40:07 +04:00
|
|
|
curr->this_ptr == this_ptr &&
|
2009-05-01 13:12:07 +04:00
|
|
|
!strcmp(curr->handler_name, name)) {
|
2005-10-01 21:40:07 +04:00
|
|
|
io_write_handler = curr;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
curr = curr->next;
|
2004-01-15 05:08:37 +03:00
|
|
|
} while (curr->next != &io_write_handlers);
|
2005-10-01 21:40:07 +04:00
|
|
|
|
2004-01-15 05:08:37 +03:00
|
|
|
if (!io_write_handler) {
|
2005-10-01 21:40:07 +04:00
|
|
|
io_write_handler = new struct io_handler_struct;
|
|
|
|
io_write_handler->funct = (void *)f;
|
|
|
|
io_write_handler->this_ptr = this_ptr;
|
2006-09-20 22:24:17 +04:00
|
|
|
io_write_handler->handler_name = new char[strlen(name)+1];
|
|
|
|
strcpy(io_write_handler->handler_name, name);
|
2005-10-01 21:40:07 +04:00
|
|
|
io_write_handler->mask = mask;
|
|
|
|
io_write_handler->usage_count = 0;
|
|
|
|
// add the handler to the double linked list of handlers
|
|
|
|
io_write_handlers.prev->next = io_write_handler;
|
|
|
|
io_write_handler->next = &io_write_handlers;
|
|
|
|
io_write_handler->prev = io_write_handlers.prev;
|
|
|
|
io_write_handlers.prev = io_write_handler;
|
2004-01-15 05:08:37 +03:00
|
|
|
}
|
2002-10-25 01:07:56 +04:00
|
|
|
|
2004-01-15 05:08:37 +03:00
|
|
|
io_write_handler->usage_count += end_addr - begin_addr + 1;
|
|
|
|
for (addr = begin_addr; addr <= end_addr; addr++)
|
|
|
|
write_port_to_handler[addr] = io_write_handler;
|
2006-09-13 22:51:25 +04:00
|
|
|
return 1; // address mapped successfully
|
2004-01-15 05:08:37 +03:00
|
|
|
}
|
2002-10-25 01:07:56 +04:00
|
|
|
|
2004-01-15 05:08:37 +03:00
|
|
|
|
|
|
|
// Registration of default handlers (mainly be the unmapped device)
|
2006-03-07 01:03:16 +03:00
|
|
|
bx_bool bx_devices_c::register_default_io_read_handler(void *this_ptr, bx_read_handler_t f,
|
2005-10-01 21:40:07 +04:00
|
|
|
const char *name, Bit8u mask)
|
2004-01-15 05:08:37 +03:00
|
|
|
{
|
2005-10-01 21:40:07 +04:00
|
|
|
io_read_handlers.funct = (void *)f;
|
|
|
|
io_read_handlers.this_ptr = this_ptr;
|
2006-09-20 22:24:17 +04:00
|
|
|
if (io_read_handlers.handler_name) {
|
|
|
|
delete [] io_read_handlers.handler_name;
|
|
|
|
}
|
|
|
|
io_read_handlers.handler_name = new char[strlen(name)+1];
|
|
|
|
strcpy(io_read_handlers.handler_name, name);
|
2005-10-01 21:40:07 +04:00
|
|
|
io_read_handlers.mask = mask;
|
2008-12-29 21:02:01 +03:00
|
|
|
|
2008-01-27 01:24:03 +03:00
|
|
|
return 1;
|
2002-10-25 01:07:56 +04:00
|
|
|
}
|
|
|
|
|
2006-03-07 01:03:16 +03:00
|
|
|
bx_bool bx_devices_c::register_default_io_write_handler(void *this_ptr, bx_write_handler_t f,
|
2005-10-01 21:40:07 +04:00
|
|
|
const char *name, Bit8u mask)
|
2002-10-25 01:07:56 +04:00
|
|
|
{
|
2005-10-01 21:40:07 +04:00
|
|
|
io_write_handlers.funct = (void *)f;
|
|
|
|
io_write_handlers.this_ptr = this_ptr;
|
2006-09-20 22:24:17 +04:00
|
|
|
if (io_write_handlers.handler_name) {
|
|
|
|
delete [] io_write_handlers.handler_name;
|
|
|
|
}
|
|
|
|
io_write_handlers.handler_name = new char[strlen(name)+1];
|
|
|
|
strcpy(io_write_handlers.handler_name, name);
|
2005-10-01 21:40:07 +04:00
|
|
|
io_write_handlers.mask = mask;
|
2008-12-29 21:02:01 +03:00
|
|
|
|
2008-01-27 01:24:03 +03:00
|
|
|
return 1;
|
2004-01-15 05:08:37 +03:00
|
|
|
}
|
2002-10-25 01:07:56 +04:00
|
|
|
|
2006-03-07 01:03:16 +03:00
|
|
|
bx_bool bx_devices_c::unregister_io_read_handler(void *this_ptr, bx_read_handler_t f,
|
2005-10-01 21:40:07 +04:00
|
|
|
Bit32u addr, Bit8u mask)
|
2004-01-15 05:08:37 +03:00
|
|
|
{
|
2008-12-29 21:02:01 +03:00
|
|
|
addr &= 0xffff;
|
2005-10-01 21:40:07 +04:00
|
|
|
|
|
|
|
struct io_handler_struct *io_read_handler = read_port_to_handler[addr];
|
|
|
|
|
|
|
|
//BX_INFO(("Unregistering I/O read handler at %#x", addr));
|
|
|
|
|
|
|
|
if (!io_read_handler) {
|
|
|
|
BX_ERROR((">>> NO IO_READ_HANDLER <<<"));
|
2006-09-13 22:51:25 +04:00
|
|
|
return 0;
|
2005-10-01 21:40:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (io_read_handler == &io_read_handlers) {
|
|
|
|
BX_ERROR((">>> CANNOT UNREGISTER THE DEFAULT IO_READ_HANDLER <<<"));
|
2006-09-13 22:51:25 +04:00
|
|
|
return 0; // cannot unregister the default handler
|
2005-10-01 21:40:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (io_read_handler->funct != f) {
|
|
|
|
BX_ERROR((">>> NOT THE SAME IO_READ_HANDLER FUNC <<<"));
|
2006-09-13 22:51:25 +04:00
|
|
|
return 0;
|
2005-10-01 21:40:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (io_read_handler->this_ptr != this_ptr) {
|
|
|
|
BX_ERROR((">>> NOT THE SAME IO_READ_HANDLER THIS_PTR <<<"));
|
2006-09-13 22:51:25 +04:00
|
|
|
return 0;
|
2005-10-01 21:40:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (io_read_handler->mask != mask) {
|
|
|
|
BX_ERROR((">>> NOT THE SAME IO_READ_HANDLER MASK <<<"));
|
2006-09-13 22:51:25 +04:00
|
|
|
return 0;
|
2005-10-01 21:40:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
read_port_to_handler[addr] = &io_read_handlers; // reset to default
|
|
|
|
io_read_handler->usage_count--;
|
|
|
|
|
|
|
|
if (!io_read_handler->usage_count) { // kill this handler entry
|
|
|
|
io_read_handler->prev->next = io_read_handler->next;
|
|
|
|
io_read_handler->next->prev = io_read_handler->prev;
|
2006-09-20 22:24:17 +04:00
|
|
|
delete [] io_read_handler->handler_name;
|
2005-10-01 21:40:07 +04:00
|
|
|
delete io_read_handler;
|
|
|
|
}
|
2006-09-13 22:51:25 +04:00
|
|
|
return 1;
|
2004-01-15 05:08:37 +03:00
|
|
|
}
|
|
|
|
|
2006-03-07 01:03:16 +03:00
|
|
|
bx_bool bx_devices_c::unregister_io_write_handler(void *this_ptr, bx_write_handler_t f,
|
2005-10-01 21:40:07 +04:00
|
|
|
Bit32u addr, Bit8u mask)
|
2004-01-15 05:08:37 +03:00
|
|
|
{
|
2008-12-29 21:02:01 +03:00
|
|
|
addr &= 0xffff;
|
2005-10-01 21:40:07 +04:00
|
|
|
|
|
|
|
struct io_handler_struct *io_write_handler = write_port_to_handler[addr];
|
|
|
|
|
|
|
|
if (!io_write_handler)
|
2006-09-13 22:51:25 +04:00
|
|
|
return 0;
|
2005-10-01 21:40:07 +04:00
|
|
|
|
|
|
|
if (io_write_handler == &io_write_handlers)
|
2006-09-13 22:51:25 +04:00
|
|
|
return 0; // cannot unregister the default handler
|
2005-10-01 21:40:07 +04:00
|
|
|
|
|
|
|
if (io_write_handler->funct != f)
|
2006-09-13 22:51:25 +04:00
|
|
|
return 0;
|
2005-10-01 21:40:07 +04:00
|
|
|
|
|
|
|
if (io_write_handler->this_ptr != this_ptr)
|
2006-09-13 22:51:25 +04:00
|
|
|
return 0;
|
2005-10-01 21:40:07 +04:00
|
|
|
|
|
|
|
if (io_write_handler->mask != mask)
|
2006-09-13 22:51:25 +04:00
|
|
|
return 0;
|
2005-10-01 21:40:07 +04:00
|
|
|
|
|
|
|
write_port_to_handler[addr] = &io_write_handlers; // reset to default
|
|
|
|
io_write_handler->usage_count--;
|
|
|
|
|
|
|
|
if (!io_write_handler->usage_count) { // kill this handler entry
|
|
|
|
io_write_handler->prev->next = io_write_handler->next;
|
|
|
|
io_write_handler->next->prev = io_write_handler->prev;
|
2006-09-20 22:24:17 +04:00
|
|
|
delete [] io_write_handler->handler_name;
|
2005-10-01 21:40:07 +04:00
|
|
|
delete io_write_handler;
|
|
|
|
}
|
2006-09-13 22:51:25 +04:00
|
|
|
return 1;
|
2004-01-15 05:08:37 +03:00
|
|
|
}
|
2002-10-25 01:07:56 +04:00
|
|
|
|
2006-03-07 01:03:16 +03:00
|
|
|
bx_bool bx_devices_c::unregister_io_read_handler_range(void *this_ptr, bx_read_handler_t f,
|
2005-10-01 21:40:07 +04:00
|
|
|
Bit32u begin, Bit32u end, Bit8u mask)
|
2004-01-15 05:08:37 +03:00
|
|
|
{
|
2008-12-29 21:02:01 +03:00
|
|
|
begin &= 0xffff;
|
|
|
|
end &= 0xffff;
|
2005-10-01 21:40:07 +04:00
|
|
|
Bit32u addr;
|
2006-09-13 22:51:25 +04:00
|
|
|
bx_bool ret = 1;
|
2005-10-01 21:40:07 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* the easy way this time
|
|
|
|
*/
|
|
|
|
for (addr = begin; addr <= end; addr++)
|
|
|
|
if (!unregister_io_read_handler(this_ptr, f, addr, mask))
|
2006-09-13 22:51:25 +04:00
|
|
|
ret = 0;
|
2005-10-01 21:40:07 +04:00
|
|
|
|
|
|
|
return ret;
|
2002-10-25 01:07:56 +04:00
|
|
|
}
|
|
|
|
|
2006-03-07 01:03:16 +03:00
|
|
|
bx_bool bx_devices_c::unregister_io_write_handler_range(void *this_ptr, bx_write_handler_t f,
|
2005-10-01 21:40:07 +04:00
|
|
|
Bit32u begin, Bit32u end, Bit8u mask)
|
2004-01-15 05:08:37 +03:00
|
|
|
{
|
2008-12-29 21:02:01 +03:00
|
|
|
begin &= 0xffff;
|
|
|
|
end &= 0xffff;
|
2005-10-01 21:40:07 +04:00
|
|
|
Bit32u addr;
|
2006-09-13 22:51:25 +04:00
|
|
|
bx_bool ret = 1;
|
2005-10-01 21:40:07 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* the easy way this time
|
|
|
|
*/
|
|
|
|
for (addr = begin; addr <= end; addr++)
|
|
|
|
if (!unregister_io_write_handler(this_ptr, f, addr, mask))
|
2006-09-13 22:51:25 +04:00
|
|
|
ret = 0;
|
2005-10-01 21:40:07 +04:00
|
|
|
|
|
|
|
return ret;
|
2004-01-15 05:08:37 +03:00
|
|
|
}
|
|
|
|
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Read a byte of data from the IO memory address space
|
|
|
|
*/
|
|
|
|
|
2003-03-03 02:59:12 +03:00
|
|
|
Bit32u BX_CPP_AttrRegparmN(2)
|
2001-04-10 05:04:59 +04:00
|
|
|
bx_devices_c::inp(Bit16u addr, unsigned io_len)
|
|
|
|
{
|
2004-01-15 05:08:37 +03:00
|
|
|
struct io_handler_struct *io_read_handler;
|
2001-04-10 05:04:59 +04:00
|
|
|
Bit32u ret;
|
|
|
|
|
|
|
|
BX_INSTR_INP(addr, io_len);
|
2008-01-27 01:24:03 +03:00
|
|
|
|
2004-01-15 05:08:37 +03:00
|
|
|
io_read_handler = read_port_to_handler[addr];
|
|
|
|
if (io_read_handler->mask & io_len) {
|
|
|
|
ret = ((bx_read_handler_t)io_read_handler->funct)(io_read_handler->this_ptr, (Bit32u)addr, io_len);
|
2003-07-31 16:04:48 +04:00
|
|
|
} else {
|
|
|
|
switch (io_len) {
|
|
|
|
case 1: ret = 0xff; break;
|
|
|
|
case 2: ret = 0xffff; break;
|
|
|
|
default: ret = 0xffffffff; break;
|
|
|
|
}
|
2005-10-01 21:40:07 +04:00
|
|
|
if (addr != 0x0cf8) { // don't flood the logfile when probing PCI
|
|
|
|
BX_ERROR(("read from port 0x%04x with len %d returns 0x%x", addr, io_len, ret));
|
|
|
|
}
|
2003-07-31 16:04:48 +04:00
|
|
|
}
|
2008-12-29 21:02:01 +03:00
|
|
|
|
2001-06-28 23:48:04 +04:00
|
|
|
BX_INSTR_INP2(addr, io_len, ret);
|
2001-04-10 05:04:59 +04:00
|
|
|
BX_DBG_IO_REPORT(addr, io_len, BX_READ, ret);
|
2008-12-29 21:02:01 +03:00
|
|
|
|
2001-04-10 05:04:59 +04:00
|
|
|
return(ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Write a byte of data to the IO memory address space.
|
|
|
|
*/
|
|
|
|
|
2003-03-03 02:59:12 +03:00
|
|
|
void BX_CPP_AttrRegparmN(3)
|
2001-04-10 05:04:59 +04:00
|
|
|
bx_devices_c::outp(Bit16u addr, Bit32u value, unsigned io_len)
|
|
|
|
{
|
2004-01-15 05:08:37 +03:00
|
|
|
struct io_handler_struct *io_write_handler;
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2008-12-29 21:02:01 +03:00
|
|
|
BX_INSTR_OUTP(addr, io_len, value);
|
2001-04-10 05:04:59 +04:00
|
|
|
BX_DBG_IO_REPORT(addr, io_len, BX_WRITE, value);
|
2008-01-27 01:24:03 +03:00
|
|
|
|
2004-01-15 05:08:37 +03:00
|
|
|
io_write_handler = write_port_to_handler[addr];
|
|
|
|
if (io_write_handler->mask & io_len) {
|
|
|
|
((bx_write_handler_t)io_write_handler->funct)(io_write_handler->this_ptr, (Bit32u)addr, value, io_len);
|
2005-10-01 21:40:07 +04:00
|
|
|
} else if (addr != 0x0cf8) { // don't flood the logfile when probing PCI
|
2003-07-31 16:04:48 +04:00
|
|
|
BX_ERROR(("write to port 0x%04x with len %d ignored", addr, io_len));
|
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
2002-10-25 01:07:56 +04:00
|
|
|
|
2009-02-23 21:38:25 +03:00
|
|
|
bx_bool bx_devices_c::is_harddrv_enabled(void)
|
|
|
|
{
|
|
|
|
char pname[24];
|
|
|
|
|
|
|
|
for (int i=0; i<BX_MAX_ATA_CHANNEL; i++) {
|
|
|
|
sprintf(pname, "ata.%d.resources.enabled", i);
|
|
|
|
if (SIM->get_param_bool(pname)->get())
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-04-17 18:39:33 +04:00
|
|
|
bx_bool bx_devices_c::is_serial_enabled(void)
|
2002-10-25 01:07:56 +04:00
|
|
|
{
|
2006-03-01 20:14:36 +03:00
|
|
|
char pname[24];
|
|
|
|
|
2002-10-25 01:07:56 +04:00
|
|
|
for (int i=0; i<BX_N_SERIAL_PORTS; i++) {
|
2006-03-01 20:14:36 +03:00
|
|
|
sprintf(pname, "ports.serial.%d.enabled", i+1);
|
|
|
|
if (SIM->get_param_bool(pname)->get())
|
2008-09-18 21:18:36 +04:00
|
|
|
return 1;
|
2002-10-25 01:07:56 +04:00
|
|
|
}
|
2008-09-18 21:18:36 +04:00
|
|
|
return 0;
|
2002-10-25 01:07:56 +04:00
|
|
|
}
|
|
|
|
|
2009-01-19 12:48:12 +03:00
|
|
|
bx_bool bx_devices_c::is_parallel_enabled(void)
|
2003-01-28 19:58:10 +03:00
|
|
|
{
|
2009-01-19 12:48:12 +03:00
|
|
|
char pname[26];
|
2006-03-01 20:14:36 +03:00
|
|
|
|
2009-01-19 12:48:12 +03:00
|
|
|
for (int i=0; i<BX_N_PARALLEL_PORTS; i++) {
|
|
|
|
sprintf(pname, "ports.parallel.%d.enabled", i+1);
|
2006-03-01 20:14:36 +03:00
|
|
|
if (SIM->get_param_bool(pname)->get())
|
2009-01-19 12:48:12 +03:00
|
|
|
return 1;
|
2003-01-28 19:58:10 +03:00
|
|
|
}
|
2008-09-18 21:18:36 +04:00
|
|
|
return 0;
|
2003-01-28 19:58:10 +03:00
|
|
|
}
|
|
|
|
|
2009-01-19 12:48:12 +03:00
|
|
|
bx_bool bx_devices_c::is_usb_ohci_enabled(void)
|
2002-10-25 01:07:56 +04:00
|
|
|
{
|
2009-01-19 16:13:32 +03:00
|
|
|
if (SIM->get_param_bool(BXPN_OHCI_ENABLED)->get()) {
|
|
|
|
return 1;
|
|
|
|
}
|
2009-01-19 12:48:12 +03:00
|
|
|
return 0;
|
|
|
|
}
|
2006-03-01 20:14:36 +03:00
|
|
|
|
2009-01-19 12:48:12 +03:00
|
|
|
bx_bool bx_devices_c::is_usb_uhci_enabled(void)
|
|
|
|
{
|
2009-01-19 16:13:32 +03:00
|
|
|
if (SIM->get_param_bool(BXPN_UHCI_ENABLED)->get()) {
|
2009-01-19 12:48:12 +03:00
|
|
|
return 1;
|
2002-10-25 01:07:56 +04:00
|
|
|
}
|
2008-09-18 21:18:36 +04:00
|
|
|
return 0;
|
2002-10-25 01:07:56 +04:00
|
|
|
}
|
2007-02-03 20:56:35 +03:00
|
|
|
|
2009-03-03 21:29:51 +03:00
|
|
|
// removable keyboard/mouse registration
|
|
|
|
void bx_devices_c::register_removable_keyboard(void *dev, bx_keyb_enq_t keyb_enq)
|
|
|
|
{
|
|
|
|
if (bx_keyboard.dev == NULL) {
|
|
|
|
bx_keyboard.dev = dev;
|
|
|
|
bx_keyboard.enq_event = keyb_enq;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void bx_devices_c::unregister_removable_keyboard(void *dev)
|
|
|
|
{
|
2009-03-03 23:34:50 +03:00
|
|
|
if (dev == bx_keyboard.dev) {
|
2009-03-03 21:29:51 +03:00
|
|
|
bx_keyboard.dev = NULL;
|
|
|
|
bx_keyboard.enq_event = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-03 23:34:50 +03:00
|
|
|
void bx_devices_c::register_default_mouse(void *dev, bx_mouse_enq_t mouse_enq,
|
|
|
|
bx_mouse_enabled_changed_t mouse_enabled_changed)
|
|
|
|
{
|
|
|
|
if (bx_mouse[0].dev == NULL) {
|
|
|
|
bx_mouse[0].dev = dev;
|
|
|
|
bx_mouse[0].enq_event = mouse_enq;
|
|
|
|
bx_mouse[0].enabled_changed = mouse_enabled_changed;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-03 00:21:16 +03:00
|
|
|
void bx_devices_c::register_removable_mouse(void *dev, bx_mouse_enq_t mouse_enq,
|
|
|
|
bx_mouse_enabled_changed_t mouse_enabled_changed)
|
|
|
|
{
|
2009-03-03 23:34:50 +03:00
|
|
|
if (bx_mouse[1].dev == NULL) {
|
|
|
|
bx_mouse[1].dev = dev;
|
|
|
|
bx_mouse[1].enq_event = mouse_enq;
|
|
|
|
bx_mouse[1].enabled_changed = mouse_enabled_changed;
|
2009-03-03 00:21:16 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void bx_devices_c::unregister_removable_mouse(void *dev)
|
|
|
|
{
|
2009-03-03 23:34:50 +03:00
|
|
|
if (dev == bx_mouse[1].dev) {
|
|
|
|
bx_mouse[1].dev = NULL;
|
|
|
|
bx_mouse[1].enq_event = NULL;
|
|
|
|
bx_mouse[1].enabled_changed = NULL;
|
2009-03-03 00:21:16 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-03 21:29:51 +03:00
|
|
|
bx_bool bx_devices_c::optional_key_enq(Bit8u *scan_code)
|
|
|
|
{
|
|
|
|
if (bx_keyboard.dev != NULL) {
|
|
|
|
return bx_keyboard.enq_event(bx_keyboard.dev, scan_code);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// common mouse device handlers
|
2009-01-13 22:01:19 +03:00
|
|
|
void bx_devices_c::mouse_enabled_changed(bx_bool enabled)
|
|
|
|
{
|
|
|
|
mouse_captured = enabled;
|
2009-03-03 23:34:50 +03:00
|
|
|
|
|
|
|
if ((bx_mouse[1].dev != NULL) && (bx_mouse[1].enabled_changed != NULL)) {
|
|
|
|
bx_mouse[1].enabled_changed(bx_mouse[1].dev, enabled);
|
2009-01-19 12:48:12 +03:00
|
|
|
return;
|
|
|
|
}
|
2009-01-13 22:01:19 +03:00
|
|
|
|
2009-03-03 23:34:50 +03:00
|
|
|
if ((bx_mouse[0].dev != NULL) && (bx_mouse[0].enabled_changed != NULL)) {
|
|
|
|
bx_mouse[0].enabled_changed(bx_mouse[0].dev, enabled);
|
|
|
|
}
|
2009-01-13 22:01:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void bx_devices_c::mouse_motion(int delta_x, int delta_y, int delta_z, unsigned button_state)
|
|
|
|
{
|
|
|
|
// If mouse events are disabled on the GUI headerbar, don't
|
|
|
|
// generate any mouse data
|
|
|
|
if (!mouse_captured)
|
|
|
|
return;
|
|
|
|
|
2009-03-03 00:21:16 +03:00
|
|
|
// if a removable mouse is connected, redirect mouse data to the device
|
2009-03-03 23:34:50 +03:00
|
|
|
if (bx_mouse[1].dev != NULL) {
|
|
|
|
bx_mouse[1].enq_event(bx_mouse[1].dev, delta_x, delta_y, delta_z, button_state);
|
2009-01-19 12:48:12 +03:00
|
|
|
return;
|
|
|
|
}
|
2009-01-13 22:01:19 +03:00
|
|
|
|
2009-03-03 23:34:50 +03:00
|
|
|
// if a mouse is connected, direct mouse data to the device
|
|
|
|
if (bx_mouse[0].dev != NULL) {
|
|
|
|
bx_mouse[0].enq_event(bx_mouse[0].dev, delta_x, delta_y, delta_z, button_state);
|
2009-01-13 22:01:19 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-02-03 20:56:35 +03:00
|
|
|
void bx_pci_device_stub_c::register_pci_state(bx_list_c *list, Bit8u *pci_conf)
|
|
|
|
{
|
|
|
|
char name[6];
|
|
|
|
|
|
|
|
bx_list_c *pci = new bx_list_c(list, "pci_conf", 256);
|
2008-04-17 18:39:33 +04:00
|
|
|
for (unsigned i=0; i<256; i++) {
|
2007-02-03 20:56:35 +03:00
|
|
|
sprintf(name, "0x%02x", i);
|
|
|
|
new bx_shadow_num_c(pci, name, &pci_conf[i], BASE_HEX);
|
|
|
|
}
|
|
|
|
}
|