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.
|
|
|
|
|
*
|
2018-10-02 22:54:28 +02:00
|
|
|
* Version: @(#)intel_sio.c 1.0.9 2018/10/02
|
2017-05-30 03:38:38 +02:00
|
|
|
*
|
2017-08-24 01:14:39 -04:00
|
|
|
* Authors: Sarah Walker, <http://pcem-emulator.co.uk/>
|
2017-06-02 01:38:25 +02:00
|
|
|
* Miran Grca, <mgrca8@gmail.com>
|
2017-11-05 01:57:04 -05:00
|
|
|
*
|
2018-04-25 23:51:13 +02:00
|
|
|
* Copyright 2008-2018 Sarah Walker.
|
|
|
|
|
* Copyright 2016-2018 Miran Grca.
|
2017-05-30 03:38:38 +02:00
|
|
|
*/
|
2017-09-25 04:31:20 -04:00
|
|
|
#include <stdint.h>
|
2018-04-25 23:51:13 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
2016-06-26 00:34:39 +02:00
|
|
|
#include <string.h>
|
2017-09-25 04:31:20 -04:00
|
|
|
#include <wchar.h>
|
2018-04-25 23:51:13 +02:00
|
|
|
#include "device.h"
|
2016-06-26 00:34:39 +02:00
|
|
|
#include "io.h"
|
2017-09-04 01:52:29 -04:00
|
|
|
#include "dma.h"
|
2016-06-26 00:34:39 +02:00
|
|
|
#include "mem.h"
|
|
|
|
|
#include "pci.h"
|
2017-09-04 01:52:29 -04:00
|
|
|
#include "intel_sio.h"
|
2016-06-26 00:34:39 +02:00
|
|
|
|
2017-08-24 01:14:39 -04:00
|
|
|
|
2018-04-25 23:51:13 +02:00
|
|
|
typedef struct
|
|
|
|
|
{
|
|
|
|
|
uint8_t regs[256];
|
|
|
|
|
} sio_t;
|
2016-06-26 00:34:39 +02:00
|
|
|
|
2017-08-24 01:14:39 -04:00
|
|
|
|
2018-04-25 23:51:13 +02:00
|
|
|
static void
|
|
|
|
|
sio_write(int func, int addr, uint8_t val, void *priv)
|
2016-06-26 00:34:39 +02:00
|
|
|
{
|
2018-04-25 23:51:13 +02:00
|
|
|
sio_t *dev = (sio_t *) priv;
|
|
|
|
|
|
|
|
|
|
if (func > 0)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (addr >= 0x0f && addr < 0x4c)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
switch (addr) {
|
|
|
|
|
case 0x00: case 0x01: case 0x02: case 0x03:
|
|
|
|
|
case 0x08: case 0x09: case 0x0a: case 0x0b:
|
|
|
|
|
case 0x0e:
|
2017-06-16 06:44:11 +02:00
|
|
|
return;
|
2017-06-02 01:38:25 +02:00
|
|
|
|
2018-04-25 23:51:13 +02:00
|
|
|
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 ^ dev->regs[addr]) & 0x40))
|
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();
|
|
|
|
|
else
|
|
|
|
|
dma_alias_set();
|
|
|
|
|
break;
|
2016-12-23 03:16:24 +01:00
|
|
|
|
2018-04-25 23:51:13 +02:00
|
|
|
case 0x4f:
|
|
|
|
|
if (!((val ^ dev->regs[addr]) & 0x40))
|
2017-06-02 01:38:25 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (val & 0x40)
|
|
|
|
|
port_92_add();
|
|
|
|
|
else
|
|
|
|
|
port_92_remove();
|
2018-04-25 23:51:13 +02:00
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
dev->regs[addr] = val;
|
2016-06-26 00:34:39 +02:00
|
|
|
}
|
|
|
|
|
|
2017-08-24 01:14:39 -04:00
|
|
|
|
2018-04-25 23:51:13 +02:00
|
|
|
static uint8_t
|
|
|
|
|
sio_read(int func, int addr, void *priv)
|
2016-06-26 00:34:39 +02:00
|
|
|
{
|
2018-04-25 23:51:13 +02:00
|
|
|
sio_t *dev = (sio_t *) priv;
|
|
|
|
|
uint8_t ret;
|
|
|
|
|
|
|
|
|
|
ret = 0xff;
|
|
|
|
|
|
|
|
|
|
if (func == 0)
|
|
|
|
|
ret = dev->regs[addr];
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-26 00:34:39 +02:00
|
|
|
|
2018-04-25 23:51:13 +02:00
|
|
|
static void
|
|
|
|
|
sio_reset(void *priv)
|
|
|
|
|
{
|
|
|
|
|
sio_t *dev = (sio_t *) priv;
|
|
|
|
|
|
|
|
|
|
memset(dev->regs, 0, 256);
|
|
|
|
|
|
|
|
|
|
dev->regs[0x00] = 0x86; dev->regs[0x01] = 0x80; /*Intel*/
|
|
|
|
|
dev->regs[0x02] = 0x84; dev->regs[0x03] = 0x04; /*82378IB (SIO)*/
|
|
|
|
|
dev->regs[0x04] = 0x07; dev->regs[0x05] = 0x00;
|
|
|
|
|
dev->regs[0x06] = 0x00; dev->regs[0x07] = 0x02;
|
|
|
|
|
dev->regs[0x08] = 0x03; /*A0 stepping*/
|
|
|
|
|
|
|
|
|
|
dev->regs[0x40] = 0x20; dev->regs[0x41] = 0x00;
|
|
|
|
|
dev->regs[0x42] = 0x04; dev->regs[0x43] = 0x00;
|
|
|
|
|
dev->regs[0x44] = 0x20; dev->regs[0x45] = 0x10;
|
|
|
|
|
dev->regs[0x46] = 0x0f; dev->regs[0x47] = 0x00;
|
|
|
|
|
dev->regs[0x48] = 0x01; dev->regs[0x49] = 0x10;
|
|
|
|
|
dev->regs[0x4a] = 0x10; dev->regs[0x4b] = 0x0f;
|
|
|
|
|
dev->regs[0x4c] = 0x56; dev->regs[0x4d] = 0x40;
|
|
|
|
|
dev->regs[0x4e] = 0x07; dev->regs[0x4f] = 0x4f;
|
|
|
|
|
dev->regs[0x54] = 0x00; dev->regs[0x55] = 0x00; dev->regs[0x56] = 0x00;
|
|
|
|
|
dev->regs[0x60] = 0x80; dev->regs[0x61] = 0x80; dev->regs[0x62] = 0x80; dev->regs[0x63] = 0x80;
|
|
|
|
|
dev->regs[0x80] = 0x78; dev->regs[0x81] = 0x00;
|
|
|
|
|
dev->regs[0xa0] = 0x08;
|
|
|
|
|
dev->regs[0xa8] = 0x0f;
|
|
|
|
|
|
|
|
|
|
pci_set_irq_routing(PCI_INTA, PCI_IRQ_DISABLED);
|
|
|
|
|
pci_set_irq_routing(PCI_INTB, PCI_IRQ_DISABLED);
|
|
|
|
|
pci_set_irq_routing(PCI_INTC, PCI_IRQ_DISABLED);
|
|
|
|
|
pci_set_irq_routing(PCI_INTD, PCI_IRQ_DISABLED);
|
2016-06-26 00:34:39 +02:00
|
|
|
}
|
|
|
|
|
|
2017-08-24 01:14:39 -04:00
|
|
|
|
2018-04-25 23:51:13 +02:00
|
|
|
static void
|
|
|
|
|
sio_close(void *p)
|
2016-06-26 00:34:39 +02:00
|
|
|
{
|
2018-04-25 23:51:13 +02:00
|
|
|
sio_t *sio = (sio_t *)p;
|
|
|
|
|
|
|
|
|
|
free(sio);
|
2016-06-26 00:34:39 +02:00
|
|
|
}
|
2016-12-23 03:16:24 +01:00
|
|
|
|
2017-08-24 01:14:39 -04:00
|
|
|
|
2018-04-25 23:51:13 +02:00
|
|
|
static void
|
|
|
|
|
*sio_init(const device_t *info)
|
2016-12-23 03:16:24 +01:00
|
|
|
{
|
2018-04-25 23:51:13 +02:00
|
|
|
sio_t *sio = (sio_t *) malloc(sizeof(sio_t));
|
|
|
|
|
memset(sio, 0, sizeof(sio_t));
|
|
|
|
|
|
|
|
|
|
pci_add_card(2, sio_read, sio_write, sio);
|
2017-06-02 01:38:25 +02:00
|
|
|
|
2018-04-25 23:51:13 +02:00
|
|
|
sio_reset(sio);
|
2016-12-23 03:16:24 +01:00
|
|
|
|
2018-04-25 23:51:13 +02:00
|
|
|
port_92_reset();
|
2016-12-23 03:16:24 +01:00
|
|
|
|
2018-04-25 23:51:13 +02:00
|
|
|
port_92_add();
|
2016-12-23 03:16:24 +01:00
|
|
|
|
2018-04-25 23:51:13 +02:00
|
|
|
dma_alias_set();
|
2017-01-31 20:39:36 +01:00
|
|
|
|
2018-04-25 23:51:13 +02:00
|
|
|
return sio;
|
2016-12-23 03:16:24 +01:00
|
|
|
}
|
2018-04-25 23:51:13 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
const device_t sio_device =
|
|
|
|
|
{
|
|
|
|
|
"Intel 82378IB (SIO)",
|
|
|
|
|
DEVICE_PCI,
|
|
|
|
|
0,
|
|
|
|
|
sio_init,
|
|
|
|
|
sio_close,
|
|
|
|
|
NULL,
|
|
|
|
|
NULL,
|
|
|
|
|
NULL,
|
|
|
|
|
NULL,
|
|
|
|
|
NULL
|
|
|
|
|
};
|