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
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2009-12-04 22:50:29 +03:00
|
|
|
// Copyright (C) 2002-2009 The Bochs Project
|
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-02-16 01:05:43 +03:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2002-10-25 01:07:56 +04:00
|
|
|
// Define BX_PLUGGABLE in files that can be compiled into plugins. For
|
2008-01-27 01:24:03 +03:00
|
|
|
// platforms that require a special tag on exported symbols, BX_PLUGGABLE
|
2002-10-25 01:07:56 +04:00
|
|
|
// is used to know when we are exporting symbols and when we are importing.
|
|
|
|
#define BX_PLUGGABLE
|
|
|
|
|
2004-06-19 19:20:15 +04:00
|
|
|
#include "iodev.h"
|
2008-12-29 23:16:08 +03:00
|
|
|
#include "pic.h"
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2002-10-25 01:07:56 +04:00
|
|
|
#define LOG_THIS thePic->
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2002-10-25 01:07:56 +04:00
|
|
|
bx_pic_c *thePic = NULL;
|
|
|
|
|
2006-02-27 22:04:01 +03:00
|
|
|
int libpic_LTX_plugin_init(plugin_t *plugin, plugintype_t type, int argc, char *argv[])
|
2002-10-25 01:07:56 +04:00
|
|
|
{
|
2006-09-10 21:18:44 +04:00
|
|
|
thePic = new bx_pic_c();
|
2002-10-25 01:07:56 +04:00
|
|
|
bx_devices.pluginPicDevice = thePic;
|
|
|
|
BX_REGISTER_DEVICE_DEVMODEL(plugin, type, thePic, BX_PLUGIN_PIC);
|
|
|
|
return(0); // Success
|
|
|
|
}
|
|
|
|
|
2006-02-27 22:04:01 +03:00
|
|
|
void libpic_LTX_plugin_fini(void)
|
2002-10-25 01:07:56 +04:00
|
|
|
{
|
2006-09-10 21:18:44 +04:00
|
|
|
delete thePic;
|
2002-10-25 01:07:56 +04:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
bx_pic_c::bx_pic_c(void)
|
|
|
|
{
|
2002-10-25 01:07:56 +04:00
|
|
|
put("PIC");
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
bx_pic_c::~bx_pic_c(void)
|
|
|
|
{
|
2006-09-10 21:18:44 +04:00
|
|
|
BX_DEBUG(("Exit"));
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
2006-02-27 22:04:01 +03:00
|
|
|
void bx_pic_c::init(void)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
|
|
|
/* 8259 PIC (Programmable Interrupt Controller) */
|
2003-07-31 23:51:42 +04:00
|
|
|
DEV_register_ioread_handler(this, read_handler, 0x0020, "8259 PIC", 1);
|
|
|
|
DEV_register_ioread_handler(this, read_handler, 0x0021, "8259 PIC", 1);
|
|
|
|
DEV_register_ioread_handler(this, read_handler, 0x00A0, "8259 PIC", 1);
|
|
|
|
DEV_register_ioread_handler(this, read_handler, 0x00A1, "8259 PIC", 1);
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2003-07-31 23:51:42 +04:00
|
|
|
DEV_register_iowrite_handler(this, write_handler, 0x0020, "8259 PIC", 1);
|
|
|
|
DEV_register_iowrite_handler(this, write_handler, 0x0021, "8259 PIC", 1);
|
|
|
|
DEV_register_iowrite_handler(this, write_handler, 0x00A0, "8259 PIC", 1);
|
|
|
|
DEV_register_iowrite_handler(this, write_handler, 0x00A1, "8259 PIC", 1);
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
|
|
|
|
BX_PIC_THIS s.master_pic.single_PIC = 0;
|
|
|
|
BX_PIC_THIS s.master_pic.interrupt_offset = 0x08; /* IRQ0 = INT 0x08 */
|
|
|
|
/* slave PIC connected to IRQ2 of master */
|
|
|
|
BX_PIC_THIS s.master_pic.u.slave_connect_mask = 0x04;
|
|
|
|
BX_PIC_THIS s.master_pic.sfnm = 0; /* normal nested mode */
|
|
|
|
BX_PIC_THIS s.master_pic.buffered_mode = 0; /* unbuffered mode */
|
2004-07-08 22:45:03 +04:00
|
|
|
BX_PIC_THIS s.master_pic.master_slave = 1; /* master PIC */
|
2001-04-10 05:04:59 +04:00
|
|
|
BX_PIC_THIS s.master_pic.auto_eoi = 0; /* manual EOI from CPU */
|
|
|
|
BX_PIC_THIS s.master_pic.imr = 0xFF; /* all IRQ's initially masked */
|
|
|
|
BX_PIC_THIS s.master_pic.isr = 0x00; /* no IRQ's in service */
|
|
|
|
BX_PIC_THIS s.master_pic.irr = 0x00; /* no IRQ's requested */
|
|
|
|
BX_PIC_THIS s.master_pic.read_reg_select = 0; /* IRR */
|
|
|
|
BX_PIC_THIS s.master_pic.irq = 0;
|
|
|
|
BX_PIC_THIS s.master_pic.INT = 0;
|
|
|
|
BX_PIC_THIS s.master_pic.init.in_init = 0;
|
|
|
|
BX_PIC_THIS s.master_pic.init.requires_4 = 0;
|
|
|
|
BX_PIC_THIS s.master_pic.init.byte_expected = 0;
|
|
|
|
BX_PIC_THIS s.master_pic.special_mask = 0;
|
2002-03-25 04:31:59 +03:00
|
|
|
BX_PIC_THIS s.master_pic.lowest_priority = 7;
|
|
|
|
BX_PIC_THIS s.master_pic.polled = 0;
|
|
|
|
BX_PIC_THIS s.master_pic.rotate_on_autoeoi = 0;
|
2004-07-06 23:59:10 +04:00
|
|
|
BX_PIC_THIS s.master_pic.edge_level = 0;
|
2006-01-06 00:57:58 +03:00
|
|
|
BX_PIC_THIS s.master_pic.IRQ_in = 0;
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
BX_PIC_THIS s.slave_pic.single_PIC = 0;
|
|
|
|
BX_PIC_THIS s.slave_pic.interrupt_offset = 0x70; /* IRQ8 = INT 0x70 */
|
|
|
|
BX_PIC_THIS s.slave_pic.u.slave_id = 0x02; /* slave PIC connected to IRQ2 of master */
|
|
|
|
BX_PIC_THIS s.slave_pic.sfnm = 0; /* normal nested mode */
|
|
|
|
BX_PIC_THIS s.slave_pic.buffered_mode = 0; /* unbuffered mode */
|
2004-07-08 22:45:03 +04:00
|
|
|
BX_PIC_THIS s.slave_pic.master_slave = 0; /* slave PIC */
|
2001-04-10 05:04:59 +04:00
|
|
|
BX_PIC_THIS s.slave_pic.auto_eoi = 0; /* manual EOI from CPU */
|
|
|
|
BX_PIC_THIS s.slave_pic.imr = 0xFF; /* all IRQ's initially masked */
|
|
|
|
BX_PIC_THIS s.slave_pic.isr = 0x00; /* no IRQ's in service */
|
|
|
|
BX_PIC_THIS s.slave_pic.irr = 0x00; /* no IRQ's requested */
|
|
|
|
BX_PIC_THIS s.slave_pic.read_reg_select = 0; /* IRR */
|
|
|
|
BX_PIC_THIS s.slave_pic.irq = 0;
|
|
|
|
BX_PIC_THIS s.slave_pic.INT = 0;
|
|
|
|
BX_PIC_THIS s.slave_pic.init.in_init = 0;
|
|
|
|
BX_PIC_THIS s.slave_pic.init.requires_4 = 0;
|
|
|
|
BX_PIC_THIS s.slave_pic.init.byte_expected = 0;
|
|
|
|
BX_PIC_THIS s.slave_pic.special_mask = 0;
|
2002-03-25 04:31:59 +03:00
|
|
|
BX_PIC_THIS s.slave_pic.lowest_priority = 7;
|
|
|
|
BX_PIC_THIS s.slave_pic.polled = 0;
|
|
|
|
BX_PIC_THIS s.slave_pic.rotate_on_autoeoi = 0;
|
2004-07-06 23:59:10 +04:00
|
|
|
BX_PIC_THIS s.slave_pic.edge_level = 0;
|
2006-01-06 00:57:58 +03:00
|
|
|
BX_PIC_THIS s.slave_pic.IRQ_in = 0;
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
2006-02-27 22:04:01 +03:00
|
|
|
void bx_pic_c::reset(unsigned type) {}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2006-05-27 19:54:49 +04:00
|
|
|
void bx_pic_c::register_state(void)
|
|
|
|
{
|
|
|
|
bx_list_c *ctrl;
|
|
|
|
|
2007-09-28 23:52:08 +04:00
|
|
|
bx_list_c *list = new bx_list_c(SIM->get_bochs_root(), "pic", "PIC State", 2);
|
2006-05-27 19:54:49 +04:00
|
|
|
ctrl = new bx_list_c(list, "master", 17);
|
|
|
|
new bx_shadow_num_c(ctrl, "interrupt_offset", &BX_PIC_THIS s.master_pic.interrupt_offset, BASE_HEX);
|
|
|
|
new bx_shadow_num_c(ctrl, "auto_eoi", &BX_PIC_THIS s.master_pic.auto_eoi, BASE_HEX);
|
|
|
|
new bx_shadow_num_c(ctrl, "imr", &BX_PIC_THIS s.master_pic.imr, BASE_HEX);
|
|
|
|
new bx_shadow_num_c(ctrl, "isr", &BX_PIC_THIS s.master_pic.isr, BASE_HEX);
|
|
|
|
new bx_shadow_num_c(ctrl, "irr", &BX_PIC_THIS s.master_pic.irr, BASE_HEX);
|
|
|
|
new bx_shadow_num_c(ctrl, "read_reg_select", &BX_PIC_THIS s.master_pic.read_reg_select);
|
|
|
|
new bx_shadow_num_c(ctrl, "irq", &BX_PIC_THIS s.master_pic.irq, BASE_HEX);
|
|
|
|
new bx_shadow_num_c(ctrl, "lowest_priority", &BX_PIC_THIS s.master_pic.lowest_priority, BASE_HEX);
|
|
|
|
new bx_shadow_bool_c(ctrl, "INT", &BX_PIC_THIS s.master_pic.INT);
|
|
|
|
new bx_shadow_num_c(ctrl, "IRQ_in", &BX_PIC_THIS s.master_pic.IRQ_in, BASE_HEX);
|
|
|
|
new bx_shadow_bool_c(ctrl, "in_init", &BX_PIC_THIS s.master_pic.init.in_init);
|
|
|
|
new bx_shadow_bool_c(ctrl, "requires_4", &BX_PIC_THIS s.master_pic.init.requires_4);
|
|
|
|
new bx_shadow_num_c(ctrl, "byte_expected", &BX_PIC_THIS s.master_pic.init.byte_expected);
|
|
|
|
new bx_shadow_bool_c(ctrl, "special_mask", &BX_PIC_THIS s.master_pic.special_mask);
|
|
|
|
new bx_shadow_bool_c(ctrl, "polled", &BX_PIC_THIS s.master_pic.polled);
|
|
|
|
new bx_shadow_bool_c(ctrl, "rotate_on_autoeoi", &BX_PIC_THIS s.master_pic.rotate_on_autoeoi);
|
|
|
|
new bx_shadow_num_c(ctrl, "edge_level", &BX_PIC_THIS s.master_pic.edge_level, BASE_HEX);
|
|
|
|
ctrl = new bx_list_c(list, "slave", 17);
|
|
|
|
new bx_shadow_num_c(ctrl, "interrupt_offset", &BX_PIC_THIS s.slave_pic.interrupt_offset, BASE_HEX);
|
|
|
|
new bx_shadow_num_c(ctrl, "auto_eoi", &BX_PIC_THIS s.slave_pic.auto_eoi, BASE_HEX);
|
|
|
|
new bx_shadow_num_c(ctrl, "imr", &BX_PIC_THIS s.slave_pic.imr, BASE_HEX);
|
|
|
|
new bx_shadow_num_c(ctrl, "isr", &BX_PIC_THIS s.slave_pic.isr, BASE_HEX);
|
|
|
|
new bx_shadow_num_c(ctrl, "irr", &BX_PIC_THIS s.slave_pic.irr, BASE_HEX);
|
|
|
|
new bx_shadow_num_c(ctrl, "read_reg_select", &BX_PIC_THIS s.slave_pic.read_reg_select);
|
|
|
|
new bx_shadow_num_c(ctrl, "irq", &BX_PIC_THIS s.slave_pic.irq, BASE_HEX);
|
|
|
|
new bx_shadow_num_c(ctrl, "lowest_priority", &BX_PIC_THIS s.slave_pic.lowest_priority, BASE_HEX);
|
|
|
|
new bx_shadow_bool_c(ctrl, "INT", &BX_PIC_THIS s.slave_pic.INT);
|
|
|
|
new bx_shadow_num_c(ctrl, "IRQ_in", &BX_PIC_THIS s.slave_pic.IRQ_in, BASE_HEX);
|
|
|
|
new bx_shadow_bool_c(ctrl, "in_init", &BX_PIC_THIS s.slave_pic.init.in_init);
|
|
|
|
new bx_shadow_bool_c(ctrl, "requires_4", &BX_PIC_THIS s.slave_pic.init.requires_4);
|
|
|
|
new bx_shadow_num_c(ctrl, "byte_expected", &BX_PIC_THIS s.slave_pic.init.byte_expected);
|
|
|
|
new bx_shadow_bool_c(ctrl, "special_mask", &BX_PIC_THIS s.slave_pic.special_mask);
|
|
|
|
new bx_shadow_bool_c(ctrl, "polled", &BX_PIC_THIS s.slave_pic.polled);
|
|
|
|
new bx_shadow_bool_c(ctrl, "rotate_on_autoeoi", &BX_PIC_THIS s.slave_pic.rotate_on_autoeoi);
|
|
|
|
new bx_shadow_num_c(ctrl, "edge_level", &BX_PIC_THIS s.slave_pic.edge_level, BASE_HEX);
|
|
|
|
}
|
|
|
|
|
2006-02-27 22:04:01 +03:00
|
|
|
// static IO port read callback handler
|
|
|
|
// redirects to non-static class handler to avoid virtual functions
|
|
|
|
Bit32u bx_pic_c::read_handler(void *this_ptr, Bit32u address, unsigned io_len)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
|
|
|
#if !BX_USE_PIC_SMF
|
|
|
|
bx_pic_c *class_ptr = (bx_pic_c *) this_ptr;
|
2006-02-27 22:04:01 +03:00
|
|
|
return class_ptr->read(address, io_len);
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
2006-02-27 22:04:01 +03:00
|
|
|
Bit32u bx_pic_c::read(Bit32u address, unsigned io_len)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
|
|
|
#else
|
|
|
|
UNUSED(this_ptr);
|
|
|
|
#endif // !BX_USE_PIC_SMF
|
|
|
|
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_DEBUG(("IO read from %04x", (unsigned) address));
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
8259A PIC
|
|
|
|
*/
|
|
|
|
|
2002-03-25 04:31:59 +03:00
|
|
|
if((address == 0x20 || address == 0x21) && BX_PIC_THIS s.master_pic.polled) {
|
|
|
|
// In polled mode. Treat this as an interrupt acknowledge
|
|
|
|
clear_highest_interrupt(& BX_PIC_THIS s.master_pic);
|
|
|
|
BX_PIC_THIS s.master_pic.polled = 0;
|
|
|
|
service_master_pic();
|
2003-08-04 20:03:09 +04:00
|
|
|
return io_len==1?BX_PIC_THIS s.master_pic.irq:(BX_PIC_THIS s.master_pic.irq)<<8|(BX_PIC_THIS s.master_pic.irq); // Return the current irq requested
|
2002-03-25 04:31:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if((address == 0xa0 || address == 0xa1) && BX_PIC_THIS s.slave_pic.polled) {
|
|
|
|
// In polled mode. Treat this as an interrupt acknowledge
|
|
|
|
clear_highest_interrupt(& BX_PIC_THIS s.slave_pic);
|
|
|
|
BX_PIC_THIS s.slave_pic.polled = 0;
|
|
|
|
service_slave_pic();
|
2003-08-04 20:03:09 +04:00
|
|
|
return io_len==1?BX_PIC_THIS s.slave_pic.irq:(BX_PIC_THIS s.slave_pic.irq)<<8|(BX_PIC_THIS s.slave_pic.irq); // Return the current irq requested
|
2002-03-25 04:31:59 +03:00
|
|
|
}
|
|
|
|
|
2001-04-10 05:04:59 +04:00
|
|
|
switch (address) {
|
|
|
|
case 0x20:
|
|
|
|
if (BX_PIC_THIS s.master_pic.read_reg_select) { /* ISR */
|
2002-03-29 12:13:02 +03:00
|
|
|
BX_DEBUG(("read master ISR = %02x",
|
|
|
|
(unsigned) BX_PIC_THIS s.master_pic.isr));
|
2006-02-27 22:04:01 +03:00
|
|
|
return(BX_PIC_THIS s.master_pic.isr);
|
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
else { /* IRR */
|
2002-03-29 12:13:02 +03:00
|
|
|
BX_DEBUG(("read master IRR = %02x",
|
|
|
|
(unsigned) BX_PIC_THIS s.master_pic.irr));
|
2006-02-27 22:04:01 +03:00
|
|
|
return(BX_PIC_THIS s.master_pic.irr);
|
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
break;
|
|
|
|
case 0x21:
|
2002-03-29 12:13:02 +03:00
|
|
|
BX_DEBUG(("read master IMR = %02x",
|
|
|
|
(unsigned) BX_PIC_THIS s.master_pic.imr));
|
2001-04-10 05:04:59 +04:00
|
|
|
return(BX_PIC_THIS s.master_pic.imr);
|
|
|
|
case 0xA0:
|
|
|
|
if (BX_PIC_THIS s.slave_pic.read_reg_select) { /* ISR */
|
2002-03-29 12:13:02 +03:00
|
|
|
BX_DEBUG(("read slave ISR = %02x",
|
|
|
|
(unsigned) BX_PIC_THIS s.slave_pic.isr));
|
2006-02-27 22:04:01 +03:00
|
|
|
return(BX_PIC_THIS s.slave_pic.isr);
|
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
else { /* IRR */
|
2002-03-29 12:13:02 +03:00
|
|
|
BX_DEBUG(("read slave IRR = %02x",
|
|
|
|
(unsigned) BX_PIC_THIS s.slave_pic.irr));
|
2006-02-27 22:04:01 +03:00
|
|
|
return(BX_PIC_THIS s.slave_pic.irr);
|
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
break;
|
|
|
|
case 0xA1:
|
2002-03-29 12:13:02 +03:00
|
|
|
BX_DEBUG(("read slave IMR = %02x",
|
|
|
|
(unsigned) BX_PIC_THIS s.slave_pic.imr));
|
2001-04-10 05:04:59 +04:00
|
|
|
return(BX_PIC_THIS s.slave_pic.imr);
|
|
|
|
}
|
|
|
|
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_PANIC(("io read to address %04x", (unsigned) address));
|
2001-04-10 05:04:59 +04:00
|
|
|
return(0); /* default if not found above */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-02-27 22:04:01 +03:00
|
|
|
// static IO port write callback handler
|
|
|
|
// redirects to non-static class handler to avoid virtual functions
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2006-02-27 22:04:01 +03:00
|
|
|
void bx_pic_c::write_handler(void *this_ptr, Bit32u address, Bit32u value, unsigned io_len)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
|
|
|
#if !BX_USE_PIC_SMF
|
|
|
|
bx_pic_c *class_ptr = (bx_pic_c *) this_ptr;
|
|
|
|
class_ptr->write(address, value, io_len);
|
|
|
|
}
|
|
|
|
|
2006-02-27 22:04:01 +03:00
|
|
|
void bx_pic_c::write(Bit32u address, Bit32u value, unsigned io_len)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
|
|
|
#else
|
|
|
|
UNUSED(this_ptr);
|
|
|
|
#endif // !BX_USE_PIC_SMF
|
|
|
|
|
2002-03-29 12:13:02 +03:00
|
|
|
BX_DEBUG(("IO write to %04x = %02x", (unsigned) address, (unsigned) value));
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
8259A PIC
|
|
|
|
*/
|
|
|
|
|
|
|
|
switch (address) {
|
|
|
|
case 0x20:
|
|
|
|
if (value & 0x10) { /* initialization command 1 */
|
2002-03-29 12:13:02 +03:00
|
|
|
BX_DEBUG(("master: init command 1 found"));
|
2008-02-16 01:05:43 +03:00
|
|
|
BX_DEBUG((" requires 4 = %u", (unsigned) (value & 0x01)));
|
2002-03-29 12:13:02 +03:00
|
|
|
BX_DEBUG((" cascade mode: [0=cascade,1=single] %u",
|
|
|
|
(unsigned) ((value & 0x02) >> 1)));
|
2001-04-10 05:04:59 +04:00
|
|
|
BX_PIC_THIS s.master_pic.init.in_init = 1;
|
|
|
|
BX_PIC_THIS s.master_pic.init.requires_4 = (value & 0x01);
|
|
|
|
BX_PIC_THIS s.master_pic.init.byte_expected = 2; /* operation command 2 */
|
2002-04-20 20:21:51 +04:00
|
|
|
BX_PIC_THIS s.master_pic.imr = 0x00; /* clear the irq mask register */
|
2001-04-10 05:04:59 +04:00
|
|
|
BX_PIC_THIS s.master_pic.isr = 0x00; /* no IRQ's in service */
|
|
|
|
BX_PIC_THIS s.master_pic.irr = 0x00; /* no IRQ's requested */
|
2002-03-25 04:31:59 +03:00
|
|
|
BX_PIC_THIS s.master_pic.lowest_priority = 7;
|
2001-04-10 05:04:59 +04:00
|
|
|
BX_PIC_THIS s.master_pic.INT = 0; /* reprogramming clears previous INTR request */
|
2002-03-25 04:31:59 +03:00
|
|
|
BX_PIC_THIS s.master_pic.auto_eoi = 0;
|
|
|
|
BX_PIC_THIS s.master_pic.rotate_on_autoeoi = 0;
|
2002-03-29 12:13:02 +03:00
|
|
|
if (value & 0x02)
|
2001-12-31 11:38:08 +03:00
|
|
|
BX_PANIC(("master: ICW1: single mode not supported"));
|
2002-03-29 12:13:02 +03:00
|
|
|
if (value & 0x08) {
|
2001-12-31 11:38:08 +03:00
|
|
|
BX_PANIC(("master: ICW1: level sensitive mode not supported"));
|
2006-02-27 22:04:01 +03:00
|
|
|
}
|
|
|
|
else {
|
2001-12-31 11:38:08 +03:00
|
|
|
BX_DEBUG(("master: ICW1: edge triggered mode selected"));
|
2006-02-27 22:04:01 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
BX_SET_INTR(0);
|
|
|
|
return;
|
2006-02-27 22:04:01 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2008-02-16 01:05:43 +03:00
|
|
|
if ((value & 0x18) == 0x08) { /* OCW3 */
|
2001-04-10 05:04:59 +04:00
|
|
|
Bit8u special_mask, poll, read_op;
|
|
|
|
|
|
|
|
special_mask = (value & 0x60) >> 5;
|
|
|
|
poll = (value & 0x04) >> 2;
|
|
|
|
read_op = (value & 0x03);
|
2002-03-25 04:31:59 +03:00
|
|
|
if (poll) {
|
|
|
|
BX_PIC_THIS s.master_pic.polled = 1;
|
|
|
|
return;
|
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
if (read_op == 0x02) /* read IRR */
|
2006-02-27 22:04:01 +03:00
|
|
|
BX_PIC_THIS s.master_pic.read_reg_select = 0;
|
2001-04-10 05:04:59 +04:00
|
|
|
else if (read_op == 0x03) /* read ISR */
|
2006-02-27 22:04:01 +03:00
|
|
|
BX_PIC_THIS s.master_pic.read_reg_select = 1;
|
2001-04-10 05:04:59 +04:00
|
|
|
if (special_mask == 0x02) { /* cancel special mask */
|
|
|
|
BX_PIC_THIS s.master_pic.special_mask = 0;
|
2006-02-27 22:04:01 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
else if (special_mask == 0x03) { /* set specific mask */
|
|
|
|
BX_PIC_THIS s.master_pic.special_mask = 1;
|
|
|
|
service_master_pic();
|
|
|
|
}
|
2006-02-27 22:04:01 +03:00
|
|
|
return;
|
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
/* OCW2 */
|
|
|
|
switch (value) {
|
2002-03-25 04:31:59 +03:00
|
|
|
case 0x00: // Rotate in auto eoi mode clear
|
|
|
|
case 0x80: // Rotate in auto eoi mode set
|
|
|
|
BX_PIC_THIS s.master_pic.rotate_on_autoeoi = (value != 0);
|
|
|
|
break;
|
2006-02-27 22:04:01 +03:00
|
|
|
case 0x0A: /* select read interrupt request register */
|
|
|
|
BX_PIC_THIS s.master_pic.read_reg_select = 0;
|
|
|
|
break;
|
|
|
|
case 0x0B: /* select read interrupt in-service register */
|
|
|
|
BX_PIC_THIS s.master_pic.read_reg_select = 1;
|
|
|
|
break;
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2002-03-25 04:31:59 +03:00
|
|
|
case 0xA0: // Rotate on non-specific end of interrupt
|
|
|
|
case 0x20: /* end of interrupt command */
|
|
|
|
clear_highest_interrupt(& BX_PIC_THIS s.master_pic);
|
|
|
|
|
|
|
|
if(value == 0xA0) {// Rotate in Auto-EOI mode
|
|
|
|
BX_PIC_THIS s.master_pic.lowest_priority ++;
|
|
|
|
if(BX_PIC_THIS s.master_pic.lowest_priority > 7)
|
|
|
|
BX_PIC_THIS s.master_pic.lowest_priority = 0;
|
|
|
|
}
|
|
|
|
|
2001-04-10 05:04:59 +04:00
|
|
|
service_master_pic();
|
2002-03-25 04:31:59 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x40: // Intel PIC spec-sheet seems to indicate this should be ignored
|
|
|
|
BX_INFO(("IRQ no-op"));
|
|
|
|
break;
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
case 0x60: /* specific EOI 0 */
|
|
|
|
case 0x61: /* specific EOI 1 */
|
|
|
|
case 0x62: /* specific EOI 2 */
|
|
|
|
case 0x63: /* specific EOI 3 */
|
|
|
|
case 0x64: /* specific EOI 4 */
|
|
|
|
case 0x65: /* specific EOI 5 */
|
|
|
|
case 0x66: /* specific EOI 6 */
|
|
|
|
case 0x67: /* specific EOI 7 */
|
|
|
|
BX_PIC_THIS s.master_pic.isr &= ~(1 << (value-0x60));
|
|
|
|
service_master_pic();
|
2002-03-25 04:31:59 +03:00
|
|
|
break;
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
// IRQ lowest priority commands
|
|
|
|
case 0xC0: // 0 7 6 5 4 3 2 1
|
|
|
|
case 0xC1: // 1 0 7 6 5 4 3 2
|
|
|
|
case 0xC2: // 2 1 0 7 6 5 4 3
|
|
|
|
case 0xC3: // 3 2 1 0 7 6 5 4
|
|
|
|
case 0xC4: // 4 3 2 1 0 7 6 5
|
|
|
|
case 0xC5: // 5 4 3 2 1 0 7 6
|
|
|
|
case 0xC6: // 6 5 4 3 2 1 0 7
|
|
|
|
case 0xC7: // 7 6 5 4 3 2 1 0
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_INFO(("IRQ lowest command 0x%x", value));
|
2002-03-25 04:31:59 +03:00
|
|
|
BX_PIC_THIS s.master_pic.lowest_priority = value - 0xC0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0xE0: // specific EOI and rotate 0
|
|
|
|
case 0xE1: // specific EOI and rotate 1
|
|
|
|
case 0xE2: // specific EOI and rotate 2
|
|
|
|
case 0xE3: // specific EOI and rotate 3
|
|
|
|
case 0xE4: // specific EOI and rotate 4
|
|
|
|
case 0xE5: // specific EOI and rotate 5
|
|
|
|
case 0xE6: // specific EOI and rotate 6
|
|
|
|
case 0xE7: // specific EOI and rotate 7
|
|
|
|
BX_PIC_THIS s.master_pic.isr &= ~(1 << (value-0xE0));
|
|
|
|
BX_PIC_THIS s.master_pic.lowest_priority = (value - 0xE0);
|
|
|
|
service_master_pic();
|
2001-04-10 05:04:59 +04:00
|
|
|
break;
|
|
|
|
|
2010-05-18 21:48:48 +04:00
|
|
|
case 0x02: // single mode bit: 1 = single, 0 = cascade
|
|
|
|
// ignore. 386BSD writes this value but works with it ignored.
|
|
|
|
break;
|
|
|
|
|
2001-04-10 05:04:59 +04:00
|
|
|
default:
|
2001-12-31 11:38:08 +03:00
|
|
|
BX_PANIC(("write to port 20h = %02x", value));
|
2006-02-27 22:04:01 +03:00
|
|
|
} /* switch (value) */
|
2001-04-10 05:04:59 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x21:
|
|
|
|
/* initialization mode operation */
|
|
|
|
if (BX_PIC_THIS s.master_pic.init.in_init) {
|
|
|
|
switch (BX_PIC_THIS s.master_pic.init.byte_expected) {
|
|
|
|
case 2:
|
|
|
|
BX_PIC_THIS s.master_pic.interrupt_offset = value & 0xf8;
|
|
|
|
BX_PIC_THIS s.master_pic.init.byte_expected = 3;
|
2002-03-29 12:13:02 +03:00
|
|
|
BX_DEBUG(("master: init command 2 = %02x", (unsigned) value));
|
|
|
|
BX_DEBUG((" offset = INT %02x",
|
|
|
|
BX_PIC_THIS s.master_pic.interrupt_offset));
|
2001-04-10 05:04:59 +04:00
|
|
|
return;
|
|
|
|
break;
|
|
|
|
case 3:
|
2002-03-29 12:13:02 +03:00
|
|
|
BX_DEBUG(("master: init command 3 = %02x", (unsigned) value));
|
2001-04-10 05:04:59 +04:00
|
|
|
if (BX_PIC_THIS s.master_pic.init.requires_4) {
|
|
|
|
BX_PIC_THIS s.master_pic.init.byte_expected = 4;
|
2006-02-27 22:04:01 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
else {
|
|
|
|
BX_PIC_THIS s.master_pic.init.in_init = 0;
|
2006-02-27 22:04:01 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
return;
|
|
|
|
break;
|
|
|
|
case 4:
|
2002-03-25 04:31:59 +03:00
|
|
|
BX_DEBUG(("master: init command 4 = %02x", (unsigned) value));
|
|
|
|
if (value & 0x02) {
|
|
|
|
BX_DEBUG((" auto EOI"));
|
|
|
|
BX_PIC_THIS s.master_pic.auto_eoi = 1;
|
2006-02-27 22:04:01 +03:00
|
|
|
}
|
2002-03-25 04:31:59 +03:00
|
|
|
else {
|
|
|
|
BX_DEBUG(("normal EOI interrupt"));
|
|
|
|
BX_PIC_THIS s.master_pic.auto_eoi = 0;
|
2006-02-27 22:04:01 +03:00
|
|
|
}
|
|
|
|
if (value & 0x01) {
|
|
|
|
BX_DEBUG((" 80x86 mode"));
|
|
|
|
} else
|
|
|
|
BX_PANIC((" not 80x86 mode"));
|
2001-04-10 05:04:59 +04:00
|
|
|
BX_PIC_THIS s.master_pic.init.in_init = 0;
|
|
|
|
return;
|
|
|
|
default:
|
2001-12-31 11:38:08 +03:00
|
|
|
BX_PANIC(("master expecting bad init command"));
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
2006-02-27 22:04:01 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
/* normal operation */
|
2002-03-29 12:13:02 +03:00
|
|
|
BX_DEBUG(("setting master pic IMR to %02x", value));
|
2001-04-10 05:04:59 +04:00
|
|
|
BX_PIC_THIS s.master_pic.imr = value;
|
|
|
|
service_master_pic();
|
|
|
|
return;
|
|
|
|
|
|
|
|
case 0xA0:
|
|
|
|
if (value & 0x10) { /* initialization command 1 */
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_DEBUG(("slave: init command 1 found"));
|
2001-12-31 11:38:08 +03:00
|
|
|
BX_DEBUG((" requires 4 = %u",
|
2008-02-16 01:05:43 +03:00
|
|
|
(unsigned) (value & 0x01)));
|
2001-12-31 11:38:08 +03:00
|
|
|
BX_DEBUG((" cascade mode: [0=cascade,1=single] %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
|
|
|
(unsigned) ((value & 0x02) >> 1)));
|
2001-04-10 05:04:59 +04:00
|
|
|
BX_PIC_THIS s.slave_pic.init.in_init = 1;
|
|
|
|
BX_PIC_THIS s.slave_pic.init.requires_4 = (value & 0x01);
|
|
|
|
BX_PIC_THIS s.slave_pic.init.byte_expected = 2; /* operation command 2 */
|
2002-04-20 20:19:42 +04:00
|
|
|
BX_PIC_THIS s.slave_pic.imr = 0x00; /* clear irq mask */
|
2001-04-10 05:04:59 +04:00
|
|
|
BX_PIC_THIS s.slave_pic.isr = 0x00; /* no IRQ's in service */
|
|
|
|
BX_PIC_THIS s.slave_pic.irr = 0x00; /* no IRQ's requested */
|
2002-03-25 04:31:59 +03:00
|
|
|
BX_PIC_THIS s.slave_pic.lowest_priority = 7;
|
2001-04-10 05:04:59 +04:00
|
|
|
BX_PIC_THIS s.slave_pic.INT = 0; /* reprogramming clears previous INTR request */
|
2007-11-30 11:56:34 +03:00
|
|
|
BX_PIC_THIS s.master_pic.IRQ_in &= ~(1 << 2);
|
2002-03-25 04:31:59 +03:00
|
|
|
BX_PIC_THIS s.slave_pic.auto_eoi = 0;
|
|
|
|
BX_PIC_THIS s.slave_pic.rotate_on_autoeoi = 0;
|
2002-03-29 12:13:02 +03:00
|
|
|
if (value & 0x02)
|
2001-12-31 11:38:08 +03:00
|
|
|
BX_PANIC(("slave: ICW1: single mode not supported"));
|
2002-03-29 12:13:02 +03:00
|
|
|
if (value & 0x08) {
|
2001-12-31 11:38:08 +03:00
|
|
|
BX_PANIC(("slave: ICW1: level sensitive mode not supported"));
|
2006-02-27 22:04:01 +03:00
|
|
|
}
|
|
|
|
else {
|
2001-12-31 11:38:08 +03:00
|
|
|
BX_DEBUG(("slave: ICW1: edge triggered mode selected"));
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
2006-02-27 22:04:01 +03:00
|
|
|
return;
|
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2008-02-16 01:05:43 +03:00
|
|
|
if ((value & 0x18) == 0x08) { /* OCW3 */
|
2001-04-10 05:04:59 +04:00
|
|
|
Bit8u special_mask, poll, read_op;
|
|
|
|
|
|
|
|
special_mask = (value & 0x60) >> 5;
|
|
|
|
poll = (value & 0x04) >> 2;
|
|
|
|
read_op = (value & 0x03);
|
2002-03-25 04:31:59 +03:00
|
|
|
if (poll) {
|
|
|
|
BX_PIC_THIS s.slave_pic.polled = 1;
|
|
|
|
return;
|
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
if (read_op == 0x02) /* read IRR */
|
2006-02-27 22:04:01 +03:00
|
|
|
BX_PIC_THIS s.slave_pic.read_reg_select = 0;
|
2001-04-10 05:04:59 +04:00
|
|
|
else if (read_op == 0x03) /* read ISR */
|
2006-02-27 22:04:01 +03:00
|
|
|
BX_PIC_THIS s.slave_pic.read_reg_select = 1;
|
2001-04-10 05:04:59 +04:00
|
|
|
if (special_mask == 0x02) { /* cancel special mask */
|
|
|
|
BX_PIC_THIS s.slave_pic.special_mask = 0;
|
2006-02-27 22:04:01 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
else if (special_mask == 0x03) { /* set specific mask */
|
|
|
|
BX_PIC_THIS s.slave_pic.special_mask = 1;
|
|
|
|
service_slave_pic();
|
|
|
|
}
|
2006-02-27 22:04:01 +03:00
|
|
|
return;
|
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
switch (value) {
|
2002-03-25 04:31:59 +03:00
|
|
|
case 0x00: // Rotate in auto eoi mode clear
|
|
|
|
case 0x80: // Rotate in auto eoi mode set
|
|
|
|
BX_PIC_THIS s.slave_pic.rotate_on_autoeoi = (value != 0);
|
|
|
|
break;
|
|
|
|
|
2006-02-27 22:04:01 +03:00
|
|
|
case 0x0A: /* select read interrupt request register */
|
|
|
|
BX_PIC_THIS s.slave_pic.read_reg_select = 0;
|
|
|
|
break;
|
|
|
|
case 0x0B: /* select read interrupt in-service register */
|
|
|
|
BX_PIC_THIS s.slave_pic.read_reg_select = 1;
|
|
|
|
break;
|
2002-03-25 04:31:59 +03:00
|
|
|
|
|
|
|
case 0xA0: // Rotate on non-specific end of interrupt
|
|
|
|
case 0x20: /* end of interrupt command */
|
|
|
|
clear_highest_interrupt(& BX_PIC_THIS s.slave_pic);
|
|
|
|
|
|
|
|
if(value == 0xA0) {// Rotate in Auto-EOI mode
|
|
|
|
BX_PIC_THIS s.slave_pic.lowest_priority ++;
|
|
|
|
if(BX_PIC_THIS s.slave_pic.lowest_priority > 7)
|
|
|
|
BX_PIC_THIS s.slave_pic.lowest_priority = 0;
|
|
|
|
}
|
|
|
|
|
2001-04-10 05:04:59 +04:00
|
|
|
service_slave_pic();
|
2002-03-25 04:31:59 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x40: // Intel PIC spec-sheet seems to indicate this should be ignored
|
|
|
|
BX_INFO(("IRQ no-op"));
|
|
|
|
break;
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
case 0x60: /* specific EOI 0 */
|
|
|
|
case 0x61: /* specific EOI 1 */
|
|
|
|
case 0x62: /* specific EOI 2 */
|
|
|
|
case 0x63: /* specific EOI 3 */
|
|
|
|
case 0x64: /* specific EOI 4 */
|
|
|
|
case 0x65: /* specific EOI 5 */
|
|
|
|
case 0x66: /* specific EOI 6 */
|
|
|
|
case 0x67: /* specific EOI 7 */
|
|
|
|
BX_PIC_THIS s.slave_pic.isr &= ~(1 << (value-0x60));
|
|
|
|
service_slave_pic();
|
2002-03-25 04:31:59 +03:00
|
|
|
break;
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2001-11-19 17:41:03 +03:00
|
|
|
// IRQ lowest priority commands
|
|
|
|
case 0xC0: // 0 7 6 5 4 3 2 1
|
|
|
|
case 0xC1: // 1 0 7 6 5 4 3 2
|
|
|
|
case 0xC2: // 2 1 0 7 6 5 4 3
|
|
|
|
case 0xC3: // 3 2 1 0 7 6 5 4
|
|
|
|
case 0xC4: // 4 3 2 1 0 7 6 5
|
|
|
|
case 0xC5: // 5 4 3 2 1 0 7 6
|
|
|
|
case 0xC6: // 6 5 4 3 2 1 0 7
|
|
|
|
case 0xC7: // 7 6 5 4 3 2 1 0
|
|
|
|
BX_INFO(("IRQ lowest command 0x%x", value));
|
2002-03-25 04:31:59 +03:00
|
|
|
BX_PIC_THIS s.slave_pic.lowest_priority = value - 0xC0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0xE0: // specific EOI and rotate 0
|
|
|
|
case 0xE1: // specific EOI and rotate 1
|
|
|
|
case 0xE2: // specific EOI and rotate 2
|
|
|
|
case 0xE3: // specific EOI and rotate 3
|
|
|
|
case 0xE4: // specific EOI and rotate 4
|
|
|
|
case 0xE5: // specific EOI and rotate 5
|
|
|
|
case 0xE6: // specific EOI and rotate 6
|
|
|
|
case 0xE7: // specific EOI and rotate 7
|
|
|
|
BX_PIC_THIS s.slave_pic.isr &= ~(1 << (value-0xE0));
|
|
|
|
BX_PIC_THIS s.slave_pic.lowest_priority = (value - 0xE0);
|
|
|
|
service_slave_pic();
|
2001-11-19 17:41:03 +03:00
|
|
|
break;
|
|
|
|
|
2010-05-18 21:48:48 +04:00
|
|
|
case 0x02: // single mode bit: 1 = single, 0 = cascade
|
|
|
|
// ignore. 386BSD writes this value but works with it ignored.
|
|
|
|
break;
|
|
|
|
|
2001-04-10 05:04:59 +04:00
|
|
|
default:
|
2001-12-31 11:38:08 +03:00
|
|
|
BX_PANIC(("write to port A0h = %02x", value));
|
2006-02-27 22:04:01 +03:00
|
|
|
} /* switch (value) */
|
2001-04-10 05:04:59 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 0xA1:
|
|
|
|
/* initialization mode operation */
|
|
|
|
if (BX_PIC_THIS s.slave_pic.init.in_init) {
|
|
|
|
switch (BX_PIC_THIS s.slave_pic.init.byte_expected) {
|
|
|
|
case 2:
|
|
|
|
BX_PIC_THIS s.slave_pic.interrupt_offset = value & 0xf8;
|
|
|
|
BX_PIC_THIS s.slave_pic.init.byte_expected = 3;
|
2002-03-29 12:13:02 +03:00
|
|
|
BX_DEBUG(("slave: init command 2 = %02x", (unsigned) value));
|
|
|
|
BX_DEBUG((" offset = INT %02x",
|
|
|
|
BX_PIC_THIS s.slave_pic.interrupt_offset));
|
2001-04-10 05:04:59 +04:00
|
|
|
return;
|
|
|
|
case 3:
|
2001-12-31 11:38:08 +03:00
|
|
|
BX_DEBUG(("slave: init command 3 = %02x", (unsigned) value));
|
2001-04-10 05:04:59 +04:00
|
|
|
if (BX_PIC_THIS s.slave_pic.init.requires_4) {
|
|
|
|
BX_PIC_THIS s.slave_pic.init.byte_expected = 4;
|
2006-02-27 22:04:01 +03:00
|
|
|
} else {
|
2001-04-10 05:04:59 +04:00
|
|
|
BX_PIC_THIS s.slave_pic.init.in_init = 0;
|
2006-02-27 22:04:01 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
return;
|
|
|
|
case 4:
|
2002-03-25 04:31:59 +03:00
|
|
|
BX_DEBUG(("slave: init command 4 = %02x", (unsigned) value));
|
|
|
|
if (value & 0x02) {
|
|
|
|
BX_DEBUG((" auto EOI"));
|
|
|
|
BX_PIC_THIS s.slave_pic.auto_eoi = 1;
|
2006-02-27 22:04:01 +03:00
|
|
|
}
|
2002-03-25 04:31:59 +03:00
|
|
|
else {
|
|
|
|
BX_DEBUG(("normal EOI interrupt"));
|
|
|
|
BX_PIC_THIS s.slave_pic.auto_eoi = 0;
|
2006-02-27 22:04:01 +03:00
|
|
|
}
|
|
|
|
if (value & 0x01) {
|
|
|
|
BX_DEBUG((" 80x86 mode"));
|
|
|
|
} else
|
|
|
|
BX_PANIC((" not 80x86 mode"));
|
2001-04-10 05:04:59 +04:00
|
|
|
BX_PIC_THIS s.slave_pic.init.in_init = 0;
|
|
|
|
return;
|
|
|
|
default:
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_PANIC(("slave: expecting bad init command"));
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
2006-02-27 22:04:01 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
/* normal operation */
|
2002-03-29 12:13:02 +03:00
|
|
|
BX_DEBUG(("setting slave pic IMR to %02x", value));
|
2001-04-10 05:04:59 +04:00
|
|
|
BX_PIC_THIS s.slave_pic.imr = value;
|
|
|
|
service_slave_pic();
|
|
|
|
return;
|
2006-02-27 22:04:01 +03:00
|
|
|
} /* switch (address) */
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
2002-01-29 20:20:12 +03:00
|
|
|
// new IRQ signal handling routines
|
2002-01-26 15:03:55 +03:00
|
|
|
|
2006-01-06 00:57:58 +03:00
|
|
|
void bx_pic_c::lower_irq(unsigned irq_no)
|
2002-01-26 15:03:55 +03:00
|
|
|
{
|
2002-01-30 21:33:41 +03:00
|
|
|
#if BX_SUPPORT_APIC
|
|
|
|
// forward this function call to the ioapic too
|
2006-01-08 15:01:25 +03:00
|
|
|
if (DEV_ioapic_present() && (irq_no != 2)) {
|
2009-02-22 13:44:50 +03:00
|
|
|
DEV_ioapic_set_irq_level(irq_no, 0);
|
2005-12-31 17:46:21 +03:00
|
|
|
}
|
2002-01-30 21:33:41 +03:00
|
|
|
#endif
|
|
|
|
|
2006-01-06 00:57:58 +03:00
|
|
|
Bit8u mask = (1 << (irq_no & 7));
|
|
|
|
if ((irq_no <= 7) && (BX_PIC_THIS s.master_pic.IRQ_in & mask)) {
|
2002-01-29 20:20:12 +03:00
|
|
|
BX_DEBUG(("IRQ line %d now low", (unsigned) irq_no));
|
2006-01-06 00:57:58 +03:00
|
|
|
BX_PIC_THIS s.master_pic.IRQ_in &= ~(mask);
|
|
|
|
BX_PIC_THIS s.master_pic.irr &= ~(mask);
|
2002-01-29 20:20:12 +03:00
|
|
|
} else if ((irq_no > 7) && (irq_no <= 15) &&
|
2006-01-06 00:57:58 +03:00
|
|
|
(BX_PIC_THIS s.slave_pic.IRQ_in & mask)) {
|
2002-01-29 20:20:12 +03:00
|
|
|
BX_DEBUG(("IRQ line %d now low", (unsigned) irq_no));
|
2006-01-06 00:57:58 +03:00
|
|
|
BX_PIC_THIS s.slave_pic.IRQ_in &= ~(mask);
|
|
|
|
BX_PIC_THIS s.slave_pic.irr &= ~(mask);
|
2002-01-29 20:20:12 +03:00
|
|
|
}
|
2002-01-26 15:03:55 +03:00
|
|
|
}
|
|
|
|
|
2006-01-06 00:57:58 +03:00
|
|
|
void bx_pic_c::raise_irq(unsigned irq_no)
|
2002-01-26 15:03:55 +03:00
|
|
|
{
|
2002-01-30 21:33:41 +03:00
|
|
|
#if BX_SUPPORT_APIC
|
|
|
|
// forward this function call to the ioapic too
|
2006-01-08 15:01:25 +03:00
|
|
|
if (DEV_ioapic_present() && (irq_no != 2)) {
|
2009-02-22 13:44:50 +03:00
|
|
|
DEV_ioapic_set_irq_level(irq_no, 1);
|
2005-12-31 17:46:21 +03:00
|
|
|
}
|
2002-01-30 21:33:41 +03:00
|
|
|
#endif
|
|
|
|
|
2006-01-06 00:57:58 +03:00
|
|
|
Bit8u mask = (1 << (irq_no & 7));
|
|
|
|
if ((irq_no <= 7) && !(BX_PIC_THIS s.master_pic.IRQ_in & mask)) {
|
2002-01-29 20:20:12 +03:00
|
|
|
BX_DEBUG(("IRQ line %d now high", (unsigned) irq_no));
|
2006-01-06 00:57:58 +03:00
|
|
|
BX_PIC_THIS s.master_pic.IRQ_in |= mask;
|
|
|
|
BX_PIC_THIS s.master_pic.irr |= mask;
|
2002-01-29 20:20:12 +03:00
|
|
|
service_master_pic();
|
|
|
|
} else if ((irq_no > 7) && (irq_no <= 15) &&
|
2006-01-06 00:57:58 +03:00
|
|
|
!(BX_PIC_THIS s.slave_pic.IRQ_in & mask)) {
|
2002-01-29 20:20:12 +03:00
|
|
|
BX_DEBUG(("IRQ line %d now high", (unsigned) irq_no));
|
2006-01-06 00:57:58 +03:00
|
|
|
BX_PIC_THIS s.slave_pic.IRQ_in |= mask;
|
|
|
|
BX_PIC_THIS s.slave_pic.irr |= mask;
|
2002-01-29 20:20:12 +03:00
|
|
|
service_slave_pic();
|
|
|
|
}
|
2002-01-26 15:03:55 +03:00
|
|
|
}
|
|
|
|
|
2006-01-06 00:57:58 +03:00
|
|
|
void bx_pic_c::set_mode(bx_bool ma_sl, Bit8u mode)
|
2004-07-06 23:59:10 +04:00
|
|
|
{
|
|
|
|
if (ma_sl) {
|
|
|
|
BX_PIC_THIS s.master_pic.edge_level = mode;
|
|
|
|
} else {
|
|
|
|
BX_PIC_THIS s.slave_pic.edge_level = mode;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-01-06 00:57:58 +03:00
|
|
|
void bx_pic_c::clear_highest_interrupt(bx_pic_t *pic)
|
2002-03-25 04:31:59 +03:00
|
|
|
{
|
|
|
|
int irq;
|
|
|
|
int lowest_priority;
|
|
|
|
int highest_priority;
|
|
|
|
|
|
|
|
/* clear highest current in service bit */
|
|
|
|
lowest_priority = pic->lowest_priority;
|
|
|
|
highest_priority = lowest_priority + 1;
|
|
|
|
if(highest_priority > 7)
|
|
|
|
highest_priority = 0;
|
|
|
|
|
|
|
|
irq = highest_priority;
|
|
|
|
do {
|
|
|
|
if (pic->isr & (1 << irq)) {
|
|
|
|
pic->isr &= ~(1 << irq);
|
|
|
|
break; /* Return mask of bit cleared. */
|
|
|
|
}
|
|
|
|
|
|
|
|
irq ++;
|
|
|
|
if(irq > 7)
|
|
|
|
irq = 0;
|
|
|
|
} while(irq != highest_priority);
|
|
|
|
}
|
|
|
|
|
2006-02-27 22:04:01 +03:00
|
|
|
void bx_pic_c::service_master_pic(void)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
|
|
|
Bit8u unmasked_requests;
|
|
|
|
int irq;
|
|
|
|
Bit8u isr, max_irq;
|
2002-03-25 04:31:59 +03:00
|
|
|
Bit8u highest_priority = BX_PIC_THIS s.master_pic.lowest_priority + 1;
|
|
|
|
if(highest_priority > 7)
|
|
|
|
highest_priority = 0;
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
if (BX_PIC_THIS s.master_pic.INT) { /* last interrupt still not acknowleged */
|
|
|
|
return;
|
2006-02-27 22:04:01 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
if (BX_PIC_THIS s.master_pic.special_mask) {
|
|
|
|
/* all priorities may be enabled. check all IRR bits except ones
|
|
|
|
* which have corresponding ISR bits set
|
|
|
|
*/
|
2002-03-25 04:31:59 +03:00
|
|
|
max_irq = highest_priority;
|
2006-02-27 22:04:01 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
else { /* normal mode */
|
|
|
|
/* Find the highest priority IRQ that is enabled due to current ISR */
|
|
|
|
isr = BX_PIC_THIS s.master_pic.isr;
|
|
|
|
if (isr) {
|
2002-03-25 04:31:59 +03:00
|
|
|
max_irq = highest_priority;
|
2008-02-16 01:05:43 +03:00
|
|
|
while ((isr & (1 << max_irq)) == 0) {
|
2001-04-10 05:04:59 +04:00
|
|
|
max_irq++;
|
2002-03-25 04:31:59 +03:00
|
|
|
if(max_irq > 7)
|
|
|
|
max_irq = 0;
|
2006-02-27 22:04:01 +03:00
|
|
|
}
|
2008-02-16 01:05:43 +03:00
|
|
|
if (max_irq == highest_priority) return; /* Highest priority interrupt in-service,
|
|
|
|
* no other priorities allowed */
|
2001-05-30 22:56:02 +04:00
|
|
|
if (max_irq > 7) BX_PANIC(("error in service_master_pic()"));
|
2006-02-27 22:04:01 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
else
|
2002-03-25 04:31:59 +03:00
|
|
|
max_irq = highest_priority; /* 0..7 bits in ISR are cleared */
|
2006-02-27 22:04:01 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
/* now, see if there are any higher priority requests */
|
2008-02-16 01:05:43 +03:00
|
|
|
if ((unmasked_requests = (BX_PIC_THIS s.master_pic.irr & ~BX_PIC_THIS s.master_pic.imr))) {
|
2002-03-25 04:31:59 +03:00
|
|
|
irq = highest_priority;
|
|
|
|
do {
|
2001-04-10 05:04:59 +04:00
|
|
|
/* for special mode, since we're looking at all IRQ's, skip if
|
|
|
|
* current IRQ is already in-service
|
|
|
|
*/
|
2008-02-16 01:05:43 +03:00
|
|
|
if (! (BX_PIC_THIS s.master_pic.special_mask && ((BX_PIC_THIS s.master_pic.isr >> irq) & 0x01))) {
|
2002-08-06 18:11:03 +04:00
|
|
|
if (unmasked_requests & (1 << irq)) {
|
|
|
|
BX_DEBUG(("signalling IRQ(%u)", (unsigned) irq));
|
|
|
|
BX_PIC_THIS s.master_pic.INT = 1;
|
|
|
|
BX_PIC_THIS s.master_pic.irq = irq;
|
2006-01-06 00:57:58 +03:00
|
|
|
BX_SET_INTR(1);
|
2002-08-06 18:11:03 +04:00
|
|
|
return;
|
2006-01-06 00:57:58 +03:00
|
|
|
} /* if (unmasked_requests & ... */
|
2008-01-27 01:24:03 +03:00
|
|
|
}
|
2002-03-25 04:31:59 +03:00
|
|
|
|
|
|
|
irq ++;
|
|
|
|
if(irq > 7)
|
|
|
|
irq = 0;
|
2006-02-27 22:04:01 +03:00
|
|
|
} while(irq != max_irq); /* do ... */
|
|
|
|
} /* if (unmasked_requests = ... */
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
2006-02-27 22:04:01 +03:00
|
|
|
void bx_pic_c::service_slave_pic(void)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
|
|
|
Bit8u unmasked_requests;
|
|
|
|
int irq;
|
2002-03-25 04:31:59 +03:00
|
|
|
Bit8u isr, max_irq;
|
|
|
|
Bit8u highest_priority = BX_PIC_THIS s.slave_pic.lowest_priority + 1;
|
|
|
|
if(highest_priority > 7)
|
|
|
|
highest_priority = 0;
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
if (BX_PIC_THIS s.slave_pic.INT) { /* last interrupt still not acknowleged */
|
|
|
|
return;
|
2006-02-27 22:04:01 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2002-01-15 23:42:51 +03:00
|
|
|
if (BX_PIC_THIS s.slave_pic.special_mask) {
|
2001-11-11 03:45:42 +03:00
|
|
|
/* all priorities may be enabled. check all IRR bits except ones
|
|
|
|
* which have corresponding ISR bits set
|
|
|
|
*/
|
2002-03-25 04:31:59 +03:00
|
|
|
max_irq = highest_priority;
|
|
|
|
}
|
|
|
|
else { /* normal mode */
|
|
|
|
/* Find the highest priority IRQ that is enabled due to current ISR */
|
|
|
|
isr = BX_PIC_THIS s.slave_pic.isr;
|
|
|
|
if (isr) {
|
|
|
|
max_irq = highest_priority;
|
2008-02-16 01:05:43 +03:00
|
|
|
while ((isr & (1 << max_irq)) == 0) {
|
2002-03-25 04:31:59 +03:00
|
|
|
max_irq++;
|
|
|
|
if(max_irq > 7)
|
|
|
|
max_irq = 0;
|
2006-02-27 22:04:01 +03:00
|
|
|
}
|
2008-02-16 01:05:43 +03:00
|
|
|
if (max_irq == highest_priority) return; /* Highest priority interrupt in-service,
|
|
|
|
* no other priorities allowed */
|
2002-03-25 04:31:59 +03:00
|
|
|
if (max_irq > 7) BX_PANIC(("error in service_master_pic()"));
|
2006-02-27 22:04:01 +03:00
|
|
|
}
|
2002-03-25 04:31:59 +03:00
|
|
|
else
|
|
|
|
max_irq = highest_priority; /* 0..7 bits in ISR are cleared */
|
2001-11-11 03:45:42 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
/* now, see if there are any higher priority requests */
|
2008-02-16 01:05:43 +03:00
|
|
|
if ((unmasked_requests = (BX_PIC_THIS s.slave_pic.irr & ~BX_PIC_THIS s.slave_pic.imr))) {
|
2002-03-25 04:31:59 +03:00
|
|
|
irq = highest_priority;
|
|
|
|
do {
|
2001-11-11 03:45:42 +03:00
|
|
|
/* for special mode, since we're looking at all IRQ's, skip if
|
|
|
|
* current IRQ is already in-service
|
|
|
|
*/
|
2008-02-16 01:05:43 +03:00
|
|
|
if (! (BX_PIC_THIS s.slave_pic.special_mask && ((BX_PIC_THIS s.slave_pic.isr >> irq) & 0x01))) {
|
2002-08-06 18:11:03 +04:00
|
|
|
if (unmasked_requests & (1 << irq)) {
|
|
|
|
BX_DEBUG(("slave: signalling IRQ(%u)", (unsigned) 8 + irq));
|
|
|
|
|
|
|
|
BX_PIC_THIS s.slave_pic.INT = 1;
|
|
|
|
BX_PIC_THIS s.slave_pic.irq = irq;
|
2002-10-25 01:07:56 +04:00
|
|
|
BX_PIC_THIS raise_irq(2); /* request IRQ 2 on master pic */
|
2002-08-06 18:11:03 +04:00
|
|
|
return;
|
2006-02-27 22:04:01 +03:00
|
|
|
} /* if (unmasked_requests & ... */
|
|
|
|
}
|
2002-03-25 04:31:59 +03:00
|
|
|
|
2006-02-27 22:04:01 +03:00
|
|
|
irq ++;
|
|
|
|
if(irq > 7)
|
|
|
|
irq = 0;
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2006-02-27 22:04:01 +03:00
|
|
|
} while(irq != max_irq); /* do ... */
|
|
|
|
} /* if (unmasked_requests = ... */
|
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2006-02-27 22:04:01 +03:00
|
|
|
/* CPU handshakes with PIC after acknowledging interrupt */
|
|
|
|
Bit8u bx_pic_c::IAC(void)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
|
|
|
Bit8u vector;
|
|
|
|
Bit8u irq;
|
|
|
|
|
|
|
|
BX_SET_INTR(0);
|
|
|
|
BX_PIC_THIS s.master_pic.INT = 0;
|
2006-01-07 21:02:16 +03:00
|
|
|
// Check for spurious interrupt
|
|
|
|
if (BX_PIC_THIS s.master_pic.irr == 0) {
|
|
|
|
return (BX_PIC_THIS s.master_pic.interrupt_offset + 7);
|
|
|
|
}
|
2006-01-06 00:57:58 +03:00
|
|
|
// In level sensitive mode don't clear the irr bit.
|
|
|
|
if (!(BX_PIC_THIS s.master_pic.edge_level & (1 << BX_PIC_THIS s.master_pic.irq)))
|
|
|
|
BX_PIC_THIS s.master_pic.irr &= ~(1 << BX_PIC_THIS s.master_pic.irq);
|
2002-03-25 04:31:59 +03:00
|
|
|
// In autoeoi mode don't set the isr bit.
|
2006-01-06 00:57:58 +03:00
|
|
|
if (!BX_PIC_THIS s.master_pic.auto_eoi)
|
2002-03-25 04:31:59 +03:00
|
|
|
BX_PIC_THIS s.master_pic.isr |= (1 << BX_PIC_THIS s.master_pic.irq);
|
2006-01-06 00:57:58 +03:00
|
|
|
else if (BX_PIC_THIS s.master_pic.rotate_on_autoeoi)
|
2002-03-29 12:13:02 +03:00
|
|
|
BX_PIC_THIS s.master_pic.lowest_priority = BX_PIC_THIS s.master_pic.irq;
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
if (BX_PIC_THIS s.master_pic.irq != 2) {
|
|
|
|
irq = BX_PIC_THIS s.master_pic.irq;
|
|
|
|
vector = irq + BX_PIC_THIS s.master_pic.interrupt_offset;
|
2006-01-06 00:57:58 +03:00
|
|
|
} else { /* IRQ2 = slave pic IRQ8..15 */
|
2001-04-10 05:04:59 +04:00
|
|
|
BX_PIC_THIS s.slave_pic.INT = 0;
|
2006-01-06 00:57:58 +03:00
|
|
|
BX_PIC_THIS s.master_pic.IRQ_in &= ~(1 << 2);
|
2006-01-07 21:02:16 +03:00
|
|
|
// Check for spurious interrupt
|
|
|
|
if (BX_PIC_THIS s.slave_pic.irr == 0) {
|
|
|
|
return (BX_PIC_THIS s.slave_pic.interrupt_offset + 7);
|
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
irq = BX_PIC_THIS s.slave_pic.irq;
|
|
|
|
vector = irq + BX_PIC_THIS s.slave_pic.interrupt_offset;
|
2006-01-06 00:57:58 +03:00
|
|
|
// In level sensitive mode don't clear the irr bit.
|
|
|
|
if (!(BX_PIC_THIS s.slave_pic.edge_level & (1 << BX_PIC_THIS s.slave_pic.irq)))
|
|
|
|
BX_PIC_THIS s.slave_pic.irr &= ~(1 << BX_PIC_THIS s.slave_pic.irq);
|
2002-03-25 04:31:59 +03:00
|
|
|
// In autoeoi mode don't set the isr bit.
|
2006-01-06 00:57:58 +03:00
|
|
|
if (!BX_PIC_THIS s.slave_pic.auto_eoi)
|
2002-03-25 04:31:59 +03:00
|
|
|
BX_PIC_THIS s.slave_pic.isr |= (1 << BX_PIC_THIS s.slave_pic.irq);
|
2006-01-06 00:57:58 +03:00
|
|
|
else if (BX_PIC_THIS s.slave_pic.rotate_on_autoeoi)
|
2002-03-25 04:31:59 +03:00
|
|
|
BX_PIC_THIS s.slave_pic.lowest_priority = BX_PIC_THIS s.slave_pic.irq;
|
2001-04-10 05:04:59 +04:00
|
|
|
service_slave_pic();
|
|
|
|
irq += 8; // for debug printing purposes
|
2006-01-06 00:57:58 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
service_master_pic();
|
|
|
|
|
|
|
|
BX_DBG_IAC_REPORT(vector, irq);
|
|
|
|
return(vector);
|
|
|
|
}
|
|
|
|
|
2009-04-22 00:27:35 +04:00
|
|
|
#if BX_DEBUGGER
|
|
|
|
void bx_pic_c::debug_dump(void)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
2009-04-22 00:27:35 +04:00
|
|
|
dbg_printf("s.master_pic.imr = %02x\n", BX_PIC_THIS s.master_pic.imr);
|
|
|
|
dbg_printf("s.master_pic.isr = %02x\n", BX_PIC_THIS s.master_pic.isr);
|
|
|
|
dbg_printf("s.master_pic.irr = %02x\n", BX_PIC_THIS s.master_pic.irr);
|
|
|
|
dbg_printf("s.master_pic.irq = %02x\n", BX_PIC_THIS s.master_pic.irq);
|
|
|
|
dbg_printf("s.slave_pic.imr = %02x\n", BX_PIC_THIS s.slave_pic.imr);
|
|
|
|
dbg_printf("s.slave_pic.isr = %02x\n", BX_PIC_THIS s.slave_pic.isr);
|
|
|
|
dbg_printf("s.slave_pic.irr = %02x\n", BX_PIC_THIS s.slave_pic.irr);
|
|
|
|
dbg_printf("s.slave_pic.irq = %02x\n", BX_PIC_THIS s.slave_pic.irq);
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
2009-04-22 00:27:35 +04:00
|
|
|
#endif
|