2001-10-03 17:10:38 +04:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
2011-02-25 01:05:47 +03:00
|
|
|
// $Id$
|
2001-10-03 17:10:38 +04:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2018-02-04 12:41:50 +03:00
|
|
|
// Copyright (C) 2001-2018 The Bochs Project
|
2001-04-10 05:04:59 +04:00
|
|
|
//
|
2004-01-15 05:08:37 +03:00
|
|
|
// I/O port handlers API Copyright (C) 2003 by Frank Cornelis
|
|
|
|
//
|
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
|
|
|
#ifndef IODEV_H
|
|
|
|
#define IODEV_H
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2004-06-19 19:20:15 +04:00
|
|
|
#include "bochs.h"
|
2011-08-18 02:41:03 +04:00
|
|
|
#include "plugin.h"
|
2010-02-26 17:18:19 +03:00
|
|
|
#include "param_names.h"
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
/* number of IRQ lines supported. In an ISA PC there are two
|
|
|
|
PIC chips cascaded together. each has 8 IRQ lines, so there
|
|
|
|
should be 16 IRQ's total */
|
|
|
|
#define BX_MAX_IRQS 16
|
2009-01-16 14:53:38 +03:00
|
|
|
|
|
|
|
/* size of internal buffer for mouse devices */
|
|
|
|
#define BX_MOUSE_BUFF_SIZE 48
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2012-07-14 18:20:36 +04:00
|
|
|
/* maximum size of the ISA DMA buffer */
|
|
|
|
#define BX_DMA_BUFFER_SIZE 512
|
|
|
|
|
2012-11-08 23:12:26 +04:00
|
|
|
#define BX_MAX_PCI_DEVICES 20
|
|
|
|
|
2001-04-10 05:04:59 +04:00
|
|
|
typedef Bit32u (*bx_read_handler_t)(void *, Bit32u, unsigned);
|
|
|
|
typedef void (*bx_write_handler_t)(void *, Bit32u, Bit32u, unsigned);
|
|
|
|
|
2017-04-01 00:32:58 +03:00
|
|
|
typedef bx_bool (*bx_kbd_gen_scancode_t)(void *, Bit32u);
|
2012-06-21 21:33:37 +04:00
|
|
|
typedef void (*bx_mouse_enq_t)(void *, int, int, int, unsigned, bx_bool);
|
2009-03-03 00:21:16 +03:00
|
|
|
typedef void (*bx_mouse_enabled_changed_t)(void *, bx_bool);
|
|
|
|
|
2001-04-10 05:04:59 +04:00
|
|
|
#if BX_USE_DEV_SMF
|
|
|
|
# define BX_DEV_SMF static
|
|
|
|
# define BX_DEV_THIS bx_devices.
|
|
|
|
#else
|
|
|
|
# define BX_DEV_SMF
|
|
|
|
# define BX_DEV_THIS this->
|
|
|
|
#endif
|
|
|
|
|
2002-10-25 01:07:56 +04:00
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
// bx_devmodel_c declaration
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
|
2008-01-27 01:24:03 +03:00
|
|
|
// This class defines virtual methods that are common to all devices.
|
|
|
|
// Child classes do not need to implement all of them, because in this
|
|
|
|
// definition they are defined as empty, as opposed to being pure
|
2002-10-25 01:07:56 +04:00
|
|
|
// virtual (= 0).
|
|
|
|
class BOCHSAPI bx_devmodel_c : public logfunctions {
|
|
|
|
public:
|
2006-03-08 00:11:20 +03:00
|
|
|
virtual ~bx_devmodel_c() {}
|
2002-10-25 01:07:56 +04:00
|
|
|
virtual void init(void) {}
|
|
|
|
virtual void reset(unsigned type) {}
|
2006-04-15 21:03:59 +04:00
|
|
|
virtual void register_state(void) {}
|
|
|
|
virtual void after_restore_state(void) {}
|
2009-04-22 00:27:35 +04:00
|
|
|
#if BX_DEBUGGER
|
2012-04-23 21:06:19 +04:00
|
|
|
virtual void debug_dump(int argc, char **argv) {}
|
2009-04-22 00:27:35 +04:00
|
|
|
#endif
|
2002-10-25 01:07:56 +04:00
|
|
|
};
|
|
|
|
|
2015-02-17 21:28:25 +03:00
|
|
|
// forward declarations
|
2007-02-03 20:56:35 +03:00
|
|
|
class bx_list_c;
|
2011-01-13 01:34:42 +03:00
|
|
|
class device_image_t;
|
2013-11-05 22:06:39 +04:00
|
|
|
class cdrom_base_c;
|
2015-02-17 21:28:25 +03:00
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
2017-03-26 11:09:28 +03:00
|
|
|
// bx_pci_device_c declaration
|
2015-02-17 21:28:25 +03:00
|
|
|
//////////////////////////////////////////////////////////////////////
|
2007-02-03 20:56:35 +03:00
|
|
|
|
2017-03-26 11:09:28 +03:00
|
|
|
#if BX_SUPPORT_PCI
|
2018-02-04 12:41:50 +03:00
|
|
|
|
|
|
|
#define BX_PCI_BAR_TYPE_NONE 0
|
|
|
|
#define BX_PCI_BAR_TYPE_MEM 1
|
|
|
|
#define BX_PCI_BAR_TYPE_IO 2
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
Bit8u type;
|
|
|
|
Bit32u size;
|
|
|
|
Bit32u addr;
|
|
|
|
union {
|
|
|
|
struct {
|
|
|
|
memory_handler_t rh;
|
|
|
|
memory_handler_t wh;
|
|
|
|
const Bit8u *dummy;
|
|
|
|
} mem;
|
|
|
|
struct {
|
|
|
|
bx_read_handler_t rh;
|
|
|
|
bx_write_handler_t wh;
|
|
|
|
const Bit8u *mask;
|
|
|
|
} io;
|
|
|
|
};
|
|
|
|
} bx_pci_bar_t;
|
|
|
|
|
2017-03-26 11:09:28 +03:00
|
|
|
class BOCHSAPI bx_pci_device_c : public bx_devmodel_c {
|
2006-03-08 00:11:20 +03:00
|
|
|
public:
|
2018-02-04 12:41:50 +03:00
|
|
|
bx_pci_device_c(): pci_rom(NULL), pci_rom_size(0) {
|
|
|
|
for (int i = 0; i < 6; i++) pci_bar[i].type = BX_PCI_BAR_TYPE_NONE;
|
|
|
|
}
|
2017-03-26 11:09:28 +03:00
|
|
|
virtual ~bx_pci_device_c() {
|
2011-06-27 23:46:13 +04:00
|
|
|
if (pci_rom != NULL) delete [] pci_rom;
|
|
|
|
}
|
2008-01-27 01:24:03 +03:00
|
|
|
|
2017-03-24 22:57:25 +03:00
|
|
|
virtual Bit32u pci_read_handler(Bit8u address, unsigned io_len);
|
2018-02-04 12:41:50 +03:00
|
|
|
void pci_write_handler_common(Bit8u address, Bit32u value, unsigned io_len);
|
2006-03-08 00:11:20 +03:00
|
|
|
virtual void pci_write_handler(Bit8u address, Bit32u value, unsigned io_len) {}
|
2018-02-04 12:41:50 +03:00
|
|
|
virtual void pci_bar_change_notify(void) {}
|
2007-02-03 20:56:35 +03:00
|
|
|
|
2018-02-04 21:17:28 +03:00
|
|
|
void init_pci_conf(Bit16u vid, Bit16u did, Bit8u rev, Bit32u classc,
|
|
|
|
Bit8u headt, Bit8u intpin);
|
2018-02-04 12:41:50 +03:00
|
|
|
void init_bar_io(Bit8u num, Bit16u size, bx_read_handler_t rh,
|
|
|
|
bx_write_handler_t wh, const Bit8u *mask);
|
|
|
|
void init_bar_mem(Bit8u num, Bit32u size, memory_handler_t rh, memory_handler_t wh);
|
2011-06-23 19:56:02 +04:00
|
|
|
void register_pci_state(bx_list_c *list);
|
2017-10-08 18:54:21 +03:00
|
|
|
void after_restore_pci_state(memory_handler_t mem_read_handler);
|
2011-06-26 21:42:07 +04:00
|
|
|
void load_pci_rom(const char *path);
|
|
|
|
|
2018-02-04 12:41:50 +03:00
|
|
|
void set_name(const char *name) {pci_name = name;}
|
2018-02-18 10:41:42 +03:00
|
|
|
const char* get_name(void) {return pci_name;}
|
2018-02-04 12:41:50 +03:00
|
|
|
|
2011-06-23 19:56:02 +04:00
|
|
|
protected:
|
2018-02-04 12:41:50 +03:00
|
|
|
const char *pci_name;
|
2011-06-23 19:56:02 +04:00
|
|
|
Bit8u pci_conf[256];
|
2018-02-04 12:41:50 +03:00
|
|
|
bx_pci_bar_t pci_bar[6];
|
2011-06-27 23:46:13 +04:00
|
|
|
Bit8u *pci_rom;
|
2011-06-26 21:42:07 +04:00
|
|
|
Bit32u pci_rom_address;
|
|
|
|
Bit32u pci_rom_size;
|
2018-02-04 12:41:50 +03:00
|
|
|
memory_handler_t pci_rom_read_handler;
|
2006-03-08 00:11:20 +03:00
|
|
|
};
|
2017-03-26 11:09:28 +03:00
|
|
|
#endif
|
2006-03-08 00:11:20 +03:00
|
|
|
|
2002-10-25 01:07:56 +04:00
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
// declare stubs for devices
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
|
2006-03-08 00:11:20 +03:00
|
|
|
//////////////////////////////////////////////////////////////////////
|
2002-10-25 01:07:56 +04:00
|
|
|
#define STUBFUNC(dev,method) \
|
2008-02-16 01:05:43 +03:00
|
|
|
pluginlog->panic("%s called in %s stub. you must not have loaded the %s plugin", #dev, #method, #dev)
|
2006-03-08 00:11:20 +03:00
|
|
|
//////////////////////////////////////////////////////////////////////
|
2002-10-25 01:07:56 +04:00
|
|
|
|
|
|
|
class BOCHSAPI bx_keyb_stub_c : public bx_devmodel_c {
|
2006-03-08 00:11:20 +03:00
|
|
|
public:
|
2002-10-25 01:07:56 +04:00
|
|
|
// stubs for bx_keyb_c methods
|
2003-07-13 23:51:21 +04:00
|
|
|
virtual void gen_scancode(Bit32u key) {
|
2002-10-25 01:07:56 +04:00
|
|
|
STUBFUNC(keyboard, gen_scancode);
|
|
|
|
}
|
|
|
|
virtual void paste_bytes(Bit8u *data, Bit32s length) {
|
|
|
|
STUBFUNC(keyboard, paste_bytes);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class BOCHSAPI bx_hard_drive_stub_c : public bx_devmodel_c {
|
2006-03-08 00:11:20 +03:00
|
|
|
public:
|
2015-07-15 13:20:22 +03:00
|
|
|
virtual Bit32u get_first_cd_handle(void) {
|
|
|
|
return BX_MAX_ATA_CHANNEL*2;
|
2002-10-25 01:07:56 +04:00
|
|
|
}
|
2016-06-01 23:29:44 +03:00
|
|
|
|
|
|
|
virtual bx_bool get_cd_media_status(Bit32u handle) { return 0; }
|
|
|
|
virtual bx_bool set_cd_media_status(Bit32u handle, bx_bool status) {
|
2002-10-25 01:07:56 +04:00
|
|
|
STUBFUNC(HD, set_cd_media_status); return 0;
|
|
|
|
}
|
2016-06-01 23:29:44 +03:00
|
|
|
|
|
|
|
virtual Bit32u virt_read_handler(Bit32u address, unsigned io_len) { return 0; }
|
|
|
|
virtual void virt_write_handler(Bit32u address, Bit32u value, unsigned io_len) {}
|
|
|
|
|
2005-10-30 17:14:03 +03:00
|
|
|
virtual bx_bool bmdma_read_sector(Bit8u channel, Bit8u *buffer, Bit32u *sector_size) {
|
2005-02-08 21:32:27 +03:00
|
|
|
STUBFUNC(HD, bmdma_read_sector); return 0;
|
|
|
|
}
|
|
|
|
virtual bx_bool bmdma_write_sector(Bit8u channel, Bit8u *buffer) {
|
|
|
|
STUBFUNC(HD, bmdma_write_sector); return 0;
|
|
|
|
}
|
|
|
|
virtual void bmdma_complete(Bit8u channel) {
|
|
|
|
STUBFUNC(HD, bmdma_complete);
|
|
|
|
}
|
2002-10-25 01:07:56 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
class BOCHSAPI bx_floppy_stub_c : public bx_devmodel_c {
|
2006-03-08 00:11:20 +03:00
|
|
|
public:
|
2002-10-25 01:07:56 +04:00
|
|
|
virtual unsigned set_media_status(unsigned drive, unsigned status) {
|
|
|
|
STUBFUNC(floppy, set_media_status); return 0;
|
|
|
|
}
|
|
|
|
};
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2002-10-25 01:07:56 +04:00
|
|
|
class BOCHSAPI bx_cmos_stub_c : public bx_devmodel_c {
|
2006-03-08 00:11:20 +03:00
|
|
|
public:
|
2018-02-24 21:04:36 +03:00
|
|
|
virtual Bit32u get_reg(Bit8u reg) {
|
2002-10-25 01:07:56 +04:00
|
|
|
STUBFUNC(cmos, get_reg); return 0;
|
|
|
|
}
|
2018-02-24 21:04:36 +03:00
|
|
|
virtual void set_reg(Bit8u reg, Bit32u val) {
|
2002-10-25 01:07:56 +04:00
|
|
|
STUBFUNC(cmos, set_reg);
|
|
|
|
}
|
|
|
|
virtual void checksum_cmos(void) {
|
|
|
|
STUBFUNC(cmos, checksum);
|
|
|
|
}
|
2017-04-15 23:31:07 +03:00
|
|
|
virtual void enable_irq(bx_bool enabled) {
|
|
|
|
STUBFUNC(cmos, enable_irq);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class BOCHSAPI bx_pit_stub_c : public bx_devmodel_c {
|
|
|
|
public:
|
|
|
|
virtual void enable_irq(bx_bool enabled) {
|
|
|
|
STUBFUNC(pit, enable_irq);
|
|
|
|
}
|
2002-10-25 01:07:56 +04:00
|
|
|
};
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2002-10-25 01:07:56 +04:00
|
|
|
class BOCHSAPI bx_dma_stub_c : public bx_devmodel_c {
|
2006-03-08 00:11:20 +03:00
|
|
|
public:
|
2002-10-25 01:07:56 +04:00
|
|
|
virtual unsigned registerDMA8Channel(
|
|
|
|
unsigned channel,
|
2012-07-13 01:20:46 +04:00
|
|
|
Bit16u (* dmaRead)(Bit8u *data_byte, Bit16u maxlen),
|
|
|
|
Bit16u (* dmaWrite)(Bit8u *data_byte, Bit16u maxlen),
|
2006-03-08 00:11:20 +03:00
|
|
|
const char *name)
|
|
|
|
{
|
2002-10-25 01:07:56 +04:00
|
|
|
STUBFUNC(dma, registerDMA8Channel); return 0;
|
|
|
|
}
|
|
|
|
virtual unsigned registerDMA16Channel(
|
|
|
|
unsigned channel,
|
2012-07-13 01:20:46 +04:00
|
|
|
Bit16u (* dmaRead)(Bit16u *data_word, Bit16u maxlen),
|
|
|
|
Bit16u (* dmaWrite)(Bit16u *data_word, Bit16u maxlen),
|
2006-03-08 00:11:20 +03:00
|
|
|
const char *name)
|
|
|
|
{
|
2002-10-25 01:07:56 +04:00
|
|
|
STUBFUNC(dma, registerDMA16Channel); return 0;
|
|
|
|
}
|
|
|
|
virtual unsigned unregisterDMAChannel(unsigned channel) {
|
|
|
|
STUBFUNC(dma, unregisterDMAChannel); return 0;
|
|
|
|
}
|
|
|
|
virtual unsigned get_TC(void) {
|
|
|
|
STUBFUNC(dma, get_TC); return 0;
|
|
|
|
}
|
2002-10-25 15:44:41 +04:00
|
|
|
virtual void set_DRQ(unsigned channel, bx_bool val) {
|
2002-10-25 01:07:56 +04:00
|
|
|
STUBFUNC(dma, set_DRQ);
|
|
|
|
}
|
|
|
|
virtual void raise_HLDA(void) {
|
|
|
|
STUBFUNC(dma, raise_HLDA);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class BOCHSAPI bx_pic_stub_c : public bx_devmodel_c {
|
2006-03-08 00:11:20 +03:00
|
|
|
public:
|
2002-10-25 01:07:56 +04:00
|
|
|
virtual void raise_irq(unsigned irq_no) {
|
2008-01-27 01:24:03 +03:00
|
|
|
STUBFUNC(pic, raise_irq);
|
2002-10-25 01:07:56 +04:00
|
|
|
}
|
|
|
|
virtual void lower_irq(unsigned irq_no) {
|
2008-01-27 01:24:03 +03:00
|
|
|
STUBFUNC(pic, lower_irq);
|
2002-10-25 01:07:56 +04:00
|
|
|
}
|
2004-07-06 23:59:10 +04:00
|
|
|
virtual void set_mode(bx_bool ma_sl, Bit8u mode) {
|
2008-01-27 01:24:03 +03:00
|
|
|
STUBFUNC(pic, set_mode);
|
2004-07-06 23:59:10 +04:00
|
|
|
}
|
2002-10-25 01:07:56 +04:00
|
|
|
virtual Bit8u IAC(void) {
|
|
|
|
STUBFUNC(pic, IAC); return 0;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-03-26 11:09:28 +03:00
|
|
|
class BOCHSAPI bx_vga_stub_c
|
|
|
|
#if BX_SUPPORT_PCI
|
|
|
|
: public bx_pci_device_c
|
|
|
|
#else
|
|
|
|
: public bx_devmodel_c
|
|
|
|
#endif
|
|
|
|
{
|
2006-03-08 00:11:20 +03:00
|
|
|
public:
|
2017-10-10 21:06:16 +03:00
|
|
|
virtual void vga_redraw_area(unsigned x0, unsigned y0, unsigned width,
|
|
|
|
unsigned height) {
|
|
|
|
STUBFUNC(vga, vga_redraw_area);
|
2002-10-25 01:07:56 +04:00
|
|
|
}
|
2010-08-15 23:57:50 +04:00
|
|
|
virtual Bit8u mem_read(bx_phy_address addr) {
|
2002-10-25 01:07:56 +04:00
|
|
|
STUBFUNC(vga, mem_read); return 0;
|
|
|
|
}
|
2010-08-15 23:57:50 +04:00
|
|
|
virtual void mem_write(bx_phy_address addr, Bit8u value) {
|
2002-10-25 01:07:56 +04:00
|
|
|
STUBFUNC(vga, mem_write);
|
|
|
|
}
|
2008-01-27 01:24:03 +03:00
|
|
|
virtual void get_text_snapshot(Bit8u **text_snapshot,
|
2002-10-25 01:07:56 +04:00
|
|
|
unsigned *txHeight, unsigned *txWidth) {
|
2008-01-27 01:24:03 +03:00
|
|
|
STUBFUNC(vga, get_text_snapshot);
|
2002-10-25 01:07:56 +04:00
|
|
|
}
|
2012-10-25 19:53:04 +04:00
|
|
|
virtual void set_override(bx_bool enabled, void *dev) {
|
2012-01-27 22:50:07 +04:00
|
|
|
STUBFUNC(vga, set_override);
|
|
|
|
}
|
2012-10-28 12:23:39 +04:00
|
|
|
virtual void refresh_display(void *this_ptr, bx_bool redraw) {
|
|
|
|
STUBFUNC(vga, refresh_display);
|
2002-10-25 01:07:56 +04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-03-26 11:09:28 +03:00
|
|
|
class BOCHSAPI bx_speaker_stub_c : public bx_devmodel_c {
|
|
|
|
public:
|
|
|
|
virtual void beep_on(float frequency) {
|
|
|
|
bx_gui->beep_on(frequency);
|
|
|
|
}
|
|
|
|
virtual void beep_off() {
|
|
|
|
bx_gui->beep_off();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
#if BX_SUPPORT_PCI
|
|
|
|
class BOCHSAPI bx_pci2isa_stub_c : public bx_pci_device_c {
|
2006-03-08 00:11:20 +03:00
|
|
|
public:
|
2004-07-04 21:10:05 +04:00
|
|
|
virtual void pci_set_irq (Bit8u devfunc, unsigned line, bx_bool level) {
|
2004-07-02 02:18:20 +04:00
|
|
|
STUBFUNC(pci2isa, pci_set_irq);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-03-26 11:09:28 +03:00
|
|
|
class BOCHSAPI bx_pci_ide_stub_c : public bx_pci_device_c {
|
2006-03-08 00:11:20 +03:00
|
|
|
public:
|
2005-09-05 22:32:23 +04:00
|
|
|
virtual bx_bool bmdma_present(void) {
|
2005-02-08 21:32:27 +03:00
|
|
|
return 0;
|
|
|
|
}
|
2014-01-19 22:13:12 +04:00
|
|
|
virtual void bmdma_start_transfer(Bit8u channel) {}
|
2005-09-05 22:32:23 +04:00
|
|
|
virtual void bmdma_set_irq(Bit8u channel) {}
|
2005-02-08 21:32:27 +03:00
|
|
|
};
|
|
|
|
|
2017-03-26 11:09:28 +03:00
|
|
|
class BOCHSAPI bx_acpi_ctrl_stub_c : public bx_pci_device_c {
|
2006-10-01 23:51:49 +04:00
|
|
|
public:
|
2007-08-04 12:57:42 +04:00
|
|
|
virtual void generate_smi(Bit8u value) {}
|
2006-10-01 23:51:49 +04:00
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2008-12-30 21:11:13 +03:00
|
|
|
#if BX_SUPPORT_IODEBUG
|
|
|
|
class BOCHSAPI bx_iodebug_stub_c : public bx_devmodel_c {
|
|
|
|
public:
|
2012-04-19 22:03:13 +04:00
|
|
|
virtual void mem_write(BX_CPU_C *cpu, bx_phy_address addr, unsigned len, void *data) {}
|
|
|
|
virtual void mem_read(BX_CPU_C *cpu, bx_phy_address addr, unsigned len, void *data) {}
|
2008-12-30 21:11:13 +03:00
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2009-02-22 13:44:50 +03:00
|
|
|
#if BX_SUPPORT_APIC
|
|
|
|
class BOCHSAPI bx_ioapic_stub_c : public bx_devmodel_c {
|
|
|
|
public:
|
2012-11-25 23:06:03 +04:00
|
|
|
virtual void set_enabled(bx_bool enabled, Bit16u base_offset) {}
|
2009-02-22 13:44:50 +03:00
|
|
|
virtual void receive_eoi(Bit8u vector) {}
|
|
|
|
virtual void set_irq_level(Bit8u int_in, bx_bool level) {}
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2011-03-31 20:54:06 +04:00
|
|
|
#if BX_SUPPORT_GAMEPORT
|
|
|
|
class BOCHSAPI bx_game_stub_c : public bx_devmodel_c {
|
|
|
|
public:
|
|
|
|
virtual void set_enabled(bx_bool val) {
|
|
|
|
STUBFUNC(gameport, set_enabled);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2011-01-13 01:34:42 +03:00
|
|
|
class BOCHSAPI bx_hdimage_ctl_stub_c : public bx_devmodel_c {
|
|
|
|
public:
|
|
|
|
virtual device_image_t* init_image(Bit8u image_mode, Bit64u disk_size, const char *journal) {
|
|
|
|
STUBFUNC(hdimage_ctl, init_image); return NULL;
|
|
|
|
}
|
2013-11-05 22:06:39 +04:00
|
|
|
virtual cdrom_base_c* init_cdrom(const char *dev) {
|
2011-07-17 21:23:12 +04:00
|
|
|
STUBFUNC(hdimage_ctl, init_cdrom); return NULL;
|
|
|
|
}
|
2011-01-13 01:34:42 +03:00
|
|
|
};
|
|
|
|
|
2002-10-25 01:07:56 +04:00
|
|
|
class BOCHSAPI bx_devices_c : public logfunctions {
|
2001-04-10 05:04:59 +04:00
|
|
|
public:
|
2008-12-29 23:16:08 +03:00
|
|
|
bx_devices_c();
|
|
|
|
~bx_devices_c();
|
|
|
|
|
2006-09-10 21:18:44 +04:00
|
|
|
// Initialize the device stubs (in constructur and exit())
|
|
|
|
void init_stubs(void);
|
2002-08-27 23:54:46 +04:00
|
|
|
// Register I/O addresses and IRQ lines. Initialize any internal
|
|
|
|
// structures. init() is called only once, even if the simulator
|
|
|
|
// reboots or is restarted.
|
2001-05-23 11:48:11 +04:00
|
|
|
void init(BX_MEM_C *);
|
2002-08-27 23:54:46 +04:00
|
|
|
// Enter reset state in response to a reset condition.
|
|
|
|
// The types of reset conditions are defined in bochs.h:
|
|
|
|
// power-on, hardware, or software.
|
|
|
|
void reset(unsigned type);
|
2006-09-07 22:50:51 +04:00
|
|
|
// Cleanup the devices when the simulation quits.
|
|
|
|
void exit(void);
|
2006-04-15 21:03:59 +04:00
|
|
|
void register_state(void);
|
|
|
|
void after_restore_state(void);
|
2001-05-23 11:48:11 +04:00
|
|
|
BX_MEM_C *mem; // address space associated with these devices
|
2006-09-20 22:24:17 +04:00
|
|
|
bx_bool register_io_read_handler(void *this_ptr, bx_read_handler_t f,
|
|
|
|
Bit32u addr, const char *name, Bit8u mask);
|
|
|
|
bx_bool unregister_io_read_handler(void *this_ptr, bx_read_handler_t f,
|
|
|
|
Bit32u addr, Bit8u mask);
|
|
|
|
bx_bool register_io_write_handler(void *this_ptr, bx_write_handler_t f,
|
|
|
|
Bit32u addr, const char *name, Bit8u mask);
|
|
|
|
bx_bool unregister_io_write_handler(void *this_ptr, bx_write_handler_t f,
|
2008-02-16 01:05:43 +03:00
|
|
|
Bit32u addr, Bit8u mask);
|
2006-09-20 22:24:17 +04:00
|
|
|
bx_bool register_io_read_handler_range(void *this_ptr, bx_read_handler_t f,
|
|
|
|
Bit32u begin_addr, Bit32u end_addr,
|
|
|
|
const char *name, Bit8u mask);
|
|
|
|
bx_bool register_io_write_handler_range(void *this_ptr, bx_write_handler_t f,
|
|
|
|
Bit32u begin_addr, Bit32u end_addr,
|
2008-02-16 01:05:43 +03:00
|
|
|
const char *name, Bit8u mask);
|
2006-09-20 22:24:17 +04:00
|
|
|
bx_bool unregister_io_read_handler_range(void *this_ptr, bx_read_handler_t f,
|
|
|
|
Bit32u begin, Bit32u end, Bit8u mask);
|
|
|
|
bx_bool unregister_io_write_handler_range(void *this_ptr, bx_write_handler_t f,
|
|
|
|
Bit32u begin, Bit32u end, Bit8u mask);
|
|
|
|
bx_bool register_default_io_read_handler(void *this_ptr, bx_read_handler_t f, const char *name, Bit8u mask);
|
|
|
|
bx_bool register_default_io_write_handler(void *this_ptr, bx_write_handler_t f, const char *name, Bit8u mask);
|
2002-10-25 15:44:41 +04:00
|
|
|
bx_bool register_irq(unsigned irq, const char *name);
|
|
|
|
bx_bool unregister_irq(unsigned irq, const char *name);
|
2003-03-03 02:59:12 +03:00
|
|
|
Bit32u inp(Bit16u addr, unsigned io_len) BX_CPP_AttrRegparmN(2);
|
|
|
|
void outp(Bit16u addr, Bit32u value, unsigned io_len) BX_CPP_AttrRegparmN(3);
|
2009-03-03 21:29:51 +03:00
|
|
|
|
2017-04-01 00:32:58 +03:00
|
|
|
void register_removable_keyboard(void *dev, bx_kbd_gen_scancode_t kbd_gen_scancode);
|
2009-03-03 21:29:51 +03:00
|
|
|
void unregister_removable_keyboard(void *dev);
|
2009-03-03 23:34:50 +03:00
|
|
|
void register_default_mouse(void *dev, bx_mouse_enq_t mouse_enq, bx_mouse_enabled_changed_t mouse_enabled_changed);
|
2009-03-03 00:21:16 +03:00
|
|
|
void register_removable_mouse(void *dev, bx_mouse_enq_t mouse_enq, bx_mouse_enabled_changed_t mouse_enabled_changed);
|
|
|
|
void unregister_removable_mouse(void *dev);
|
2017-04-01 00:32:58 +03:00
|
|
|
void gen_scancode(Bit32u key);
|
2017-04-22 18:32:07 +03:00
|
|
|
void release_keys(void);
|
2009-01-13 22:01:19 +03:00
|
|
|
void mouse_enabled_changed(bx_bool enabled);
|
2012-06-21 21:33:37 +04:00
|
|
|
void mouse_motion(int delta_x, int delta_y, int delta_z, unsigned button_state, bx_bool absxy);
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2012-11-08 23:12:26 +04:00
|
|
|
#if BX_SUPPORT_PCI
|
2012-11-09 17:30:52 +04:00
|
|
|
Bit32u pci_get_confAddr(void) {return pci.confAddr;}
|
2017-03-26 11:09:28 +03:00
|
|
|
bx_bool register_pci_handlers(bx_pci_device_c *device, Bit8u *devfunc,
|
2012-11-09 17:30:52 +04:00
|
|
|
const char *name, const char *descr);
|
|
|
|
bx_bool pci_set_base_mem(void *this_ptr, memory_handler_t f1, memory_handler_t f2,
|
|
|
|
Bit32u *addr, Bit8u *pci_conf, unsigned size);
|
|
|
|
bx_bool pci_set_base_io(void *this_ptr, bx_read_handler_t f1, bx_write_handler_t f2,
|
|
|
|
Bit32u *addr, Bit8u *pci_conf, unsigned size,
|
|
|
|
const Bit8u *iomask, const char *name);
|
2012-11-08 23:12:26 +04:00
|
|
|
#endif
|
|
|
|
|
2001-04-10 05:04:59 +04:00
|
|
|
static void timer_handler(void *);
|
|
|
|
void timer(void);
|
|
|
|
|
2017-03-26 11:09:28 +03:00
|
|
|
bx_cmos_stub_c *pluginCmosDevice;
|
2004-02-02 02:42:04 +03:00
|
|
|
bx_dma_stub_c *pluginDmaDevice;
|
|
|
|
bx_floppy_stub_c *pluginFloppyDevice;
|
2002-10-25 01:07:56 +04:00
|
|
|
bx_hard_drive_stub_c *pluginHardDrive;
|
2011-01-13 01:34:42 +03:00
|
|
|
bx_hdimage_ctl_stub_c *pluginHDImageCtl;
|
2017-03-26 11:09:28 +03:00
|
|
|
bx_keyb_stub_c *pluginKeyboard;
|
|
|
|
bx_pic_stub_c *pluginPicDevice;
|
2017-04-15 23:31:07 +03:00
|
|
|
bx_pit_stub_c *pluginPitDevice;
|
2004-02-02 02:42:04 +03:00
|
|
|
bx_speaker_stub_c *pluginSpeaker;
|
2017-03-26 11:09:28 +03:00
|
|
|
bx_vga_stub_c *pluginVgaDevice;
|
2004-08-06 19:49:55 +04:00
|
|
|
#if BX_SUPPORT_IODEBUG
|
2008-12-30 21:11:13 +03:00
|
|
|
bx_iodebug_stub_c *pluginIODebug;
|
2001-09-14 19:01:29 +04:00
|
|
|
#endif
|
2009-02-22 13:44:50 +03:00
|
|
|
#if BX_SUPPORT_APIC
|
2009-02-23 21:38:25 +03:00
|
|
|
bx_ioapic_stub_c *pluginIOAPIC;
|
2009-02-22 13:44:50 +03:00
|
|
|
#endif
|
2011-03-31 20:54:06 +04:00
|
|
|
#if BX_SUPPORT_GAMEPORT
|
|
|
|
bx_game_stub_c *pluginGameport;
|
|
|
|
#endif
|
2017-03-26 11:09:28 +03:00
|
|
|
#if BX_SUPPORT_PCI
|
|
|
|
bx_pci2isa_stub_c *pluginPci2IsaBridge;
|
|
|
|
bx_pci_ide_stub_c *pluginPciIdeController;
|
|
|
|
bx_acpi_ctrl_stub_c *pluginACPIController;
|
|
|
|
#endif
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2002-10-25 01:07:56 +04:00
|
|
|
// stub classes that the pointers (above) can point to until a plugin is
|
|
|
|
// loaded
|
|
|
|
bx_cmos_stub_c stubCmos;
|
2017-03-26 11:09:28 +03:00
|
|
|
bx_dma_stub_c stubDma;
|
|
|
|
bx_floppy_stub_c stubFloppy;
|
2002-10-25 01:07:56 +04:00
|
|
|
bx_hard_drive_stub_c stubHardDrive;
|
2011-01-13 01:34:42 +03:00
|
|
|
bx_hdimage_ctl_stub_c stubHDImage;
|
2017-03-26 11:09:28 +03:00
|
|
|
bx_keyb_stub_c stubKeyboard;
|
2002-10-25 01:07:56 +04:00
|
|
|
bx_pic_stub_c stubPic;
|
2017-04-15 23:31:07 +03:00
|
|
|
bx_pit_stub_c stubPit;
|
2004-02-03 00:47:26 +03:00
|
|
|
bx_speaker_stub_c stubSpeaker;
|
2017-03-26 11:09:28 +03:00
|
|
|
bx_vga_stub_c stubVga;
|
2008-12-30 21:11:13 +03:00
|
|
|
#if BX_SUPPORT_IODEBUG
|
|
|
|
bx_iodebug_stub_c stubIODebug;
|
|
|
|
#endif
|
2009-02-22 13:44:50 +03:00
|
|
|
#if BX_SUPPORT_APIC
|
|
|
|
bx_ioapic_stub_c stubIOAPIC;
|
|
|
|
#endif
|
2011-03-31 20:54:06 +04:00
|
|
|
#if BX_SUPPORT_GAMEPORT
|
|
|
|
bx_game_stub_c stubGameport;
|
|
|
|
#endif
|
2017-03-26 11:09:28 +03:00
|
|
|
#if BX_SUPPORT_PCI
|
|
|
|
bx_pci2isa_stub_c stubPci2Isa;
|
|
|
|
bx_pci_ide_stub_c stubPciIde;
|
|
|
|
bx_acpi_ctrl_stub_c stubACPIController;
|
|
|
|
#endif
|
2002-10-25 01:07:56 +04:00
|
|
|
|
2002-09-09 20:56:56 +04:00
|
|
|
// Some info to pass to devices which can handled bulk IO. This allows
|
|
|
|
// the interface to remain the same for IO devices which can't handle
|
|
|
|
// bulk IO. We should probably implement special INPBulk() and OUTBulk()
|
|
|
|
// functions which stick these values in the bx_devices_c class, and
|
|
|
|
// then call the normal functions rather than having gross globals
|
|
|
|
// variables.
|
2005-04-02 15:30:08 +04:00
|
|
|
Bit8u* bulkIOHostAddr;
|
2002-09-09 20:56:56 +04:00
|
|
|
unsigned bulkIOQuantumsRequested;
|
|
|
|
unsigned bulkIOQuantumsTransferred;
|
|
|
|
|
2001-04-10 05:04:59 +04:00
|
|
|
private:
|
2002-10-25 01:07:56 +04:00
|
|
|
|
2004-01-15 05:08:37 +03:00
|
|
|
struct io_handler_struct {
|
2012-11-08 23:12:26 +04:00
|
|
|
struct io_handler_struct *next;
|
|
|
|
struct io_handler_struct *prev;
|
|
|
|
void *funct; // C++ type checking is great, but annoying
|
|
|
|
void *this_ptr;
|
|
|
|
char *handler_name; // name of device
|
|
|
|
int usage_count;
|
|
|
|
Bit8u mask; // io_len mask
|
2004-01-15 05:08:37 +03:00
|
|
|
};
|
|
|
|
struct io_handler_struct io_read_handlers;
|
|
|
|
struct io_handler_struct io_write_handlers;
|
|
|
|
#define PORTS 0x10000
|
|
|
|
struct io_handler_struct **read_port_to_handler;
|
|
|
|
struct io_handler_struct **write_port_to_handler;
|
2008-01-27 01:24:03 +03:00
|
|
|
|
2001-04-10 05:04:59 +04:00
|
|
|
// more for informative purposes, the names of the devices which
|
|
|
|
// are use each of the IRQ 0..15 lines are stored here
|
2006-09-13 22:51:25 +04:00
|
|
|
char *irq_handler_name[BX_MAX_IRQS];
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
static Bit32u read_handler(void *this_ptr, Bit32u address, unsigned io_len);
|
|
|
|
static void write_handler(void *this_ptr, Bit32u address, Bit32u value, unsigned io_len);
|
2012-11-08 23:12:26 +04:00
|
|
|
BX_DEV_SMF Bit32u read(Bit32u address, unsigned io_len);
|
|
|
|
BX_DEV_SMF void write(Bit32u address, Bit32u value, unsigned io_len);
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2002-10-25 01:07:56 +04:00
|
|
|
static Bit32u default_read_handler(void *this_ptr, Bit32u address, unsigned io_len);
|
|
|
|
static void default_write_handler(void *this_ptr, Bit32u address, Bit32u value, unsigned io_len);
|
|
|
|
|
2009-01-13 22:01:19 +03:00
|
|
|
bx_bool mouse_captured; // host mouse capture enabled
|
|
|
|
Bit8u mouse_type;
|
2009-03-03 21:29:51 +03:00
|
|
|
struct {
|
|
|
|
void *dev;
|
|
|
|
bx_mouse_enq_t enq_event;
|
|
|
|
bx_mouse_enabled_changed_t enabled_changed;
|
2009-03-03 23:34:50 +03:00
|
|
|
} bx_mouse[2];
|
2009-03-03 21:29:51 +03:00
|
|
|
struct {
|
|
|
|
void *dev;
|
2017-04-01 00:32:58 +03:00
|
|
|
bx_kbd_gen_scancode_t gen_scancode;
|
2017-04-22 18:32:07 +03:00
|
|
|
bx_bool bxkey_state[BX_KEY_NBKEYS];
|
2009-03-03 21:29:51 +03:00
|
|
|
} bx_keyboard;
|
2009-01-13 22:01:19 +03:00
|
|
|
|
2012-11-08 23:12:26 +04:00
|
|
|
struct {
|
|
|
|
bx_bool enabled;
|
|
|
|
#if BX_SUPPORT_PCI
|
|
|
|
Bit8u handler_id[0x100]; // 256 devices/functions
|
|
|
|
struct {
|
2017-03-26 11:09:28 +03:00
|
|
|
bx_pci_device_c *handler;
|
2012-11-08 23:12:26 +04:00
|
|
|
} pci_handler[BX_MAX_PCI_DEVICES];
|
|
|
|
unsigned num_pci_handlers;
|
|
|
|
|
|
|
|
bx_bool slot_used[BX_N_PCI_SLOTS];
|
|
|
|
|
|
|
|
Bit32u confAddr;
|
|
|
|
#endif
|
|
|
|
} pci;
|
|
|
|
|
2001-04-10 05:04:59 +04:00
|
|
|
int timer_handle;
|
2009-01-19 12:48:12 +03:00
|
|
|
|
2012-08-20 11:35:30 +04:00
|
|
|
bx_bool network_enabled;
|
|
|
|
bx_bool sound_enabled;
|
|
|
|
bx_bool usb_enabled;
|
|
|
|
|
2009-02-23 21:38:25 +03:00
|
|
|
bx_bool is_harddrv_enabled();
|
2012-01-13 21:04:47 +04:00
|
|
|
bx_bool is_network_enabled();
|
|
|
|
bx_bool is_sound_enabled();
|
|
|
|
bx_bool is_usb_enabled();
|
2006-03-06 22:23:13 +03:00
|
|
|
};
|
|
|
|
|
2008-04-17 18:39:33 +04:00
|
|
|
// memory stub has an assumption that there are no memory accesses splitting 4K page
|
|
|
|
BX_CPP_INLINE void DEV_MEM_READ_PHYSICAL(bx_phy_address phy_addr, unsigned len, Bit8u *ptr)
|
2008-06-12 00:59:50 +04:00
|
|
|
{
|
|
|
|
unsigned remainingInPage = 0x1000 - (phy_addr & 0xfff);
|
2008-06-12 01:10:02 +04:00
|
|
|
if (len <= remainingInPage) {
|
2008-06-12 00:59:50 +04:00
|
|
|
BX_MEM(0)->readPhysicalPage(NULL, phy_addr, len, ptr);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
BX_MEM(0)->readPhysicalPage(NULL, phy_addr, remainingInPage, ptr);
|
|
|
|
ptr += remainingInPage;
|
|
|
|
phy_addr += remainingInPage;
|
|
|
|
len -= remainingInPage;
|
|
|
|
BX_MEM(0)->readPhysicalPage(NULL, phy_addr, len, ptr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-02 23:41:54 +04:00
|
|
|
BX_CPP_INLINE void DEV_MEM_READ_PHYSICAL_DMA(bx_phy_address phy_addr, unsigned len, Bit8u *ptr)
|
2008-04-17 18:39:33 +04:00
|
|
|
{
|
|
|
|
while(len > 0) {
|
|
|
|
unsigned remainingInPage = 0x1000 - (phy_addr & 0xfff);
|
|
|
|
if (len < remainingInPage) remainingInPage = len;
|
2011-12-02 23:41:54 +04:00
|
|
|
BX_MEM(0)->dmaReadPhysicalPage(phy_addr, remainingInPage, ptr);
|
2008-04-17 18:39:33 +04:00
|
|
|
ptr += remainingInPage;
|
|
|
|
phy_addr += remainingInPage;
|
|
|
|
len -= remainingInPage;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// memory stub has an assumption that there are no memory accesses splitting 4K page
|
|
|
|
BX_CPP_INLINE void DEV_MEM_WRITE_PHYSICAL(bx_phy_address phy_addr, unsigned len, Bit8u *ptr)
|
2008-06-12 00:59:50 +04:00
|
|
|
{
|
|
|
|
unsigned remainingInPage = 0x1000 - (phy_addr & 0xfff);
|
2008-06-12 01:10:02 +04:00
|
|
|
if (len <= remainingInPage) {
|
2008-06-12 00:59:50 +04:00
|
|
|
BX_MEM(0)->writePhysicalPage(NULL, phy_addr, len, ptr);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
BX_MEM(0)->writePhysicalPage(NULL, phy_addr, remainingInPage, ptr);
|
|
|
|
ptr += remainingInPage;
|
|
|
|
phy_addr += remainingInPage;
|
|
|
|
len -= remainingInPage;
|
|
|
|
BX_MEM(0)->writePhysicalPage(NULL, phy_addr, len, ptr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-02 23:41:54 +04:00
|
|
|
BX_CPP_INLINE void DEV_MEM_WRITE_PHYSICAL_DMA(bx_phy_address phy_addr, unsigned len, Bit8u *ptr)
|
2008-04-17 18:39:33 +04:00
|
|
|
{
|
|
|
|
while(len > 0) {
|
|
|
|
unsigned remainingInPage = 0x1000 - (phy_addr & 0xfff);
|
|
|
|
if (len < remainingInPage) remainingInPage = len;
|
2011-12-02 23:41:54 +04:00
|
|
|
BX_MEM(0)->dmaWritePhysicalPage(phy_addr, remainingInPage, ptr);
|
2008-04-17 18:39:33 +04:00
|
|
|
ptr += remainingInPage;
|
|
|
|
phy_addr += remainingInPage;
|
|
|
|
len -= remainingInPage;
|
|
|
|
}
|
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2008-02-16 01:05:43 +03:00
|
|
|
BOCHSAPI extern bx_devices_c bx_devices;
|
2004-06-19 19:20:15 +04:00
|
|
|
|
|
|
|
#endif /* IODEV_H */
|