2017-05-30 03:38:38 +02:00
|
|
|
/*
|
|
|
|
|
* 86Box A hypervisor and IBM PC system emulator that specializes in
|
|
|
|
|
* running old operating systems and software designed for IBM
|
|
|
|
|
* PC systems and compatibles from 1981 through fairly recent
|
|
|
|
|
* system designs based on the PCI bus.
|
|
|
|
|
*
|
|
|
|
|
* Emulation of Intel System I/O PCI chip.
|
|
|
|
|
*
|
2017-06-02 01:38:25 +02:00
|
|
|
* Version: @(#)sio.c 1.0.1 2017/06/02
|
2017-05-30 03:38:38 +02:00
|
|
|
*
|
2017-06-02 01:38:25 +02:00
|
|
|
* Author: Sarah Walker, <http://pcem-emulator.co.uk/>
|
|
|
|
|
* Miran Grca, <mgrca8@gmail.com>
|
|
|
|
|
* Copyright 2008-2017 Sarah Walker.
|
|
|
|
|
* Copyright 2016-2017 Miran Grca.
|
2017-05-30 03:38:38 +02:00
|
|
|
*/
|
|
|
|
|
|
2016-06-26 00:34:39 +02:00
|
|
|
#include <string.h>
|
2017-06-02 01:38:25 +02:00
|
|
|
|
2016-06-26 00:34:39 +02:00
|
|
|
#include "ibm.h"
|
2017-01-31 20:39:36 +01:00
|
|
|
#include "cdrom.h"
|
2017-05-05 01:49:42 +02:00
|
|
|
#include "disc.h"
|
|
|
|
|
#include "dma.h"
|
|
|
|
|
#include "fdc.h"
|
2017-06-02 01:38:25 +02:00
|
|
|
#include "keyboard_at.h"
|
2016-06-26 00:34:39 +02:00
|
|
|
#include "ide.h"
|
|
|
|
|
#include "io.h"
|
|
|
|
|
#include "mem.h"
|
|
|
|
|
#include "pci.h"
|
|
|
|
|
|
|
|
|
|
#include "sio.h"
|
|
|
|
|
|
|
|
|
|
static uint8_t card_sio[256];
|
|
|
|
|
|
|
|
|
|
void sio_write(int func, int addr, uint8_t val, void *priv)
|
|
|
|
|
{
|
|
|
|
|
if (func > 0)
|
2017-06-02 01:38:25 +02:00
|
|
|
return;
|
2016-06-26 00:34:39 +02:00
|
|
|
|
2017-06-02 01:38:25 +02:00
|
|
|
if (addr >= 0x0f && addr < 0x4c)
|
2016-06-26 00:34:39 +02:00
|
|
|
return;
|
2017-06-02 01:38:25 +02:00
|
|
|
|
|
|
|
|
switch (addr)
|
|
|
|
|
{
|
|
|
|
|
case 0x00: case 0x01: case 0x02: case 0x03:
|
|
|
|
|
case 0x08: case 0x09: case 0x0a: case 0x0b:
|
|
|
|
|
case 0x0e:
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
case 0x04: /*Command register*/
|
|
|
|
|
val &= 0x08;
|
|
|
|
|
val |= 0x07;
|
|
|
|
|
break;
|
|
|
|
|
case 0x05:
|
|
|
|
|
val = 0;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 0x06: /*Status*/
|
|
|
|
|
val = 0;
|
|
|
|
|
break;
|
|
|
|
|
case 0x07:
|
|
|
|
|
val = 0x02;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 0x40:
|
|
|
|
|
if (!((val ^ card_sio[addr]) & 0x40))
|
2016-12-23 03:16:24 +01:00
|
|
|
{
|
2017-06-02 01:38:25 +02:00
|
|
|
return;
|
|
|
|
|
}
|
2016-12-23 03:16:24 +01:00
|
|
|
|
2017-06-02 01:38:25 +02:00
|
|
|
if (val & 0x40)
|
|
|
|
|
{
|
|
|
|
|
dma_alias_remove();
|
2016-12-23 03:16:24 +01:00
|
|
|
}
|
2017-06-02 01:38:25 +02:00
|
|
|
else
|
2016-12-23 03:16:24 +01:00
|
|
|
{
|
2017-06-02 01:38:25 +02:00
|
|
|
dma_alias_set();
|
|
|
|
|
}
|
|
|
|
|
break;
|
2016-12-23 03:16:24 +01:00
|
|
|
|
2017-06-02 01:38:25 +02:00
|
|
|
case 0x4f:
|
|
|
|
|
if (!((val ^ card_sio[addr]) & 0x40))
|
|
|
|
|
{
|
|
|
|
|
return;
|
2016-12-23 03:16:24 +01:00
|
|
|
}
|
2017-06-02 01:38:25 +02:00
|
|
|
|
|
|
|
|
if (val & 0x40)
|
|
|
|
|
{
|
|
|
|
|
port_92_add();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
port_92_remove();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case 0x60:
|
|
|
|
|
if (val & 0x80)
|
|
|
|
|
pci_set_irq_routing(PCI_INTA, PCI_IRQ_DISABLED);
|
|
|
|
|
else
|
|
|
|
|
pci_set_irq_routing(PCI_INTA, val & 0xf);
|
|
|
|
|
break;
|
|
|
|
|
case 0x61:
|
|
|
|
|
if (val & 0x80)
|
|
|
|
|
pci_set_irq_routing(PCI_INTC, PCI_IRQ_DISABLED);
|
|
|
|
|
else
|
|
|
|
|
pci_set_irq_routing(PCI_INTC, val & 0xf);
|
|
|
|
|
break;
|
|
|
|
|
case 0x62:
|
|
|
|
|
if (val & 0x80)
|
|
|
|
|
pci_set_irq_routing(PCI_INTB, PCI_IRQ_DISABLED);
|
|
|
|
|
else
|
|
|
|
|
pci_set_irq_routing(PCI_INTB, val & 0xf);
|
|
|
|
|
break;
|
|
|
|
|
case 0x63:
|
|
|
|
|
if (val & 0x80)
|
|
|
|
|
pci_set_irq_routing(PCI_INTD, PCI_IRQ_DISABLED);
|
|
|
|
|
else
|
|
|
|
|
pci_set_irq_routing(PCI_INTD, val & 0xf);
|
|
|
|
|
break;
|
2016-06-26 00:34:39 +02:00
|
|
|
}
|
2017-06-02 01:38:25 +02:00
|
|
|
card_sio[addr] = val;
|
2016-06-26 00:34:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint8_t sio_read(int func, int addr, void *priv)
|
|
|
|
|
{
|
|
|
|
|
if (func > 0)
|
2017-06-02 01:38:25 +02:00
|
|
|
return 0xff;
|
2016-06-26 00:34:39 +02:00
|
|
|
|
2017-06-02 01:38:25 +02:00
|
|
|
return card_sio[addr];
|
2016-06-26 00:34:39 +02:00
|
|
|
}
|
|
|
|
|
|
2017-01-31 20:39:36 +01:00
|
|
|
static int trc_reg = 0;
|
2016-12-23 03:16:24 +01:00
|
|
|
|
2017-01-31 20:39:36 +01:00
|
|
|
uint8_t trc_read(uint16_t port, void *priv)
|
|
|
|
|
{
|
|
|
|
|
return trc_reg & 0xfb;
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-05 01:49:42 +02:00
|
|
|
void trc_reset(uint8_t val)
|
2017-01-31 20:39:36 +01:00
|
|
|
{
|
|
|
|
|
int i = 0;
|
|
|
|
|
|
2017-05-05 01:49:42 +02:00
|
|
|
if (val & 2)
|
2017-01-31 20:39:36 +01:00
|
|
|
{
|
2017-05-05 01:49:42 +02:00
|
|
|
if (pci_reset_handler.pci_master_reset)
|
2017-01-31 20:39:36 +01:00
|
|
|
{
|
2017-05-05 01:49:42 +02:00
|
|
|
pci_reset_handler.pci_master_reset();
|
|
|
|
|
}
|
2017-01-31 20:39:36 +01:00
|
|
|
|
2017-05-05 01:49:42 +02:00
|
|
|
if (pci_reset_handler.pci_set_reset)
|
|
|
|
|
{
|
|
|
|
|
pci_reset_handler.pci_set_reset();
|
|
|
|
|
}
|
2017-01-31 20:39:36 +01:00
|
|
|
|
2017-05-05 01:49:42 +02:00
|
|
|
fdc_hard_reset();
|
2017-01-31 20:39:36 +01:00
|
|
|
|
2017-05-05 01:49:42 +02:00
|
|
|
if (pci_reset_handler.super_io_reset)
|
|
|
|
|
{
|
|
|
|
|
pci_reset_handler.super_io_reset();
|
|
|
|
|
}
|
2017-01-31 20:39:36 +01:00
|
|
|
|
2017-05-05 01:49:42 +02:00
|
|
|
resetide();
|
|
|
|
|
for (i = 0; i < CDROM_NUM; i++)
|
|
|
|
|
{
|
|
|
|
|
if (!cdrom_drives[i].bus_type)
|
2017-01-31 20:39:36 +01:00
|
|
|
{
|
2017-05-05 01:49:42 +02:00
|
|
|
cdrom_reset(i);
|
2017-01-31 20:39:36 +01:00
|
|
|
}
|
|
|
|
|
}
|
2017-05-05 01:49:42 +02:00
|
|
|
|
|
|
|
|
port_92_reset();
|
|
|
|
|
keyboard_at_reset();
|
|
|
|
|
}
|
|
|
|
|
resetx86();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void trc_write(uint16_t port, uint8_t val, void *priv)
|
|
|
|
|
{
|
|
|
|
|
pclog("TRC Write: %02X\n", val);
|
|
|
|
|
if (!(trc_reg & 4) && (val & 4))
|
|
|
|
|
{
|
|
|
|
|
trc_reset(val);
|
2017-01-31 20:39:36 +01:00
|
|
|
}
|
|
|
|
|
trc_reg = val & 0xfd;
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-21 19:16:23 +02:00
|
|
|
void trc_init(void)
|
2017-01-31 20:39:36 +01:00
|
|
|
{
|
|
|
|
|
trc_reg = 0;
|
|
|
|
|
|
|
|
|
|
io_sethandler(0x0cf9, 0x0001, trc_read, NULL, NULL, trc_write, NULL, NULL, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void sio_reset(void)
|
2016-06-26 00:34:39 +02:00
|
|
|
{
|
|
|
|
|
memset(card_sio, 0, 256);
|
|
|
|
|
card_sio[0x00] = 0x86; card_sio[0x01] = 0x80; /*Intel*/
|
2017-06-02 01:38:25 +02:00
|
|
|
card_sio[0x02] = 0x84; card_sio[0x03] = 0x04; /*82378IB (SIO)*/
|
2016-06-26 00:34:39 +02:00
|
|
|
card_sio[0x04] = 0x07; card_sio[0x05] = 0x00;
|
2017-06-02 01:38:25 +02:00
|
|
|
card_sio[0x06] = 0x00; card_sio[0x07] = 0x02;
|
|
|
|
|
card_sio[0x08] = 0x03; /*A0 stepping*/
|
|
|
|
|
|
|
|
|
|
card_sio[0x40] = 0x20; card_sio[0x41] = 0x00;
|
|
|
|
|
card_sio[0x42] = 0x04; card_sio[0x43] = 0x00;
|
|
|
|
|
card_sio[0x44] = 0x20; card_sio[0x45] = 0x10;
|
|
|
|
|
card_sio[0x46] = 0x0f; card_sio[0x47] = 0x00;
|
|
|
|
|
card_sio[0x48] = 0x01; card_sio[0x49] = 0x10;
|
|
|
|
|
card_sio[0x4a] = 0x10; card_sio[0x4b] = 0x0f;
|
|
|
|
|
card_sio[0x4c] = 0x56; card_sio[0x4d] = 0x40;
|
|
|
|
|
card_sio[0x4e] = 0x07; card_sio[0x4f] = 0x4f;
|
|
|
|
|
card_sio[0x54] = 0x00; card_sio[0x55] = 0x00; card_sio[0x56] = 0x00;
|
|
|
|
|
card_sio[0x60] = 0x80; card_sio[0x61] = 0x80; card_sio[0x62] = 0x80; card_sio[0x63] = 0x80;
|
|
|
|
|
card_sio[0x80] = 0x78; card_sio[0x81] = 0x00;
|
|
|
|
|
card_sio[0xa0] = 0x08;
|
|
|
|
|
card_sio[0xa8] = 0x0f;
|
2016-06-26 00:34:39 +02:00
|
|
|
}
|
2016-12-23 03:16:24 +01:00
|
|
|
|
2017-06-02 01:38:25 +02:00
|
|
|
void sio_init(int card, int pci_a, int pci_b, int pci_c, int pci_d)
|
2016-12-23 03:16:24 +01:00
|
|
|
{
|
|
|
|
|
pci_add_specific(card, sio_read, sio_write, NULL);
|
2017-06-02 01:38:25 +02:00
|
|
|
|
2017-01-31 20:39:36 +01:00
|
|
|
sio_reset();
|
2016-12-23 03:16:24 +01:00
|
|
|
|
2017-01-31 20:39:36 +01:00
|
|
|
trc_init();
|
2016-12-23 03:16:24 +01:00
|
|
|
|
|
|
|
|
port_92_reset();
|
|
|
|
|
|
|
|
|
|
port_92_add();
|
|
|
|
|
|
|
|
|
|
dma_alias_set();
|
2017-01-31 20:39:36 +01:00
|
|
|
|
|
|
|
|
pci_reset_handler.pci_set_reset = sio_reset;
|
2017-06-02 01:38:25 +02:00
|
|
|
|
|
|
|
|
if (pci_a)
|
|
|
|
|
pci_set_card_routing(pci_a, PCI_INTA);
|
|
|
|
|
if (pci_b)
|
|
|
|
|
pci_set_card_routing(pci_b, PCI_INTB);
|
|
|
|
|
if (pci_c)
|
|
|
|
|
pci_set_card_routing(pci_c, PCI_INTC);
|
|
|
|
|
if (pci_d)
|
|
|
|
|
pci_set_card_routing(pci_d, PCI_INTD);
|
2016-12-23 03:16:24 +01:00
|
|
|
}
|