The Windows IOCTL code now correctly gets the allocated length for the CDB for the READ DVD STRUCTURE command, fixes crashes with Windows 98 SE and ME;
Fixed a few I/O handler adding/removing related bugs in the Intel PIIX/PIIX3, UMC UM8699F Super I/O chip, Sound Blaster DSP, and Realtek 8019AS codes; The code in io.c now uses linked lists, I had to do this to properly fix the I/O handler mess with the Realtek RTL8019AS on the Award 430VX PCI (which was causing an emulator crash at POST).
This commit is contained in:
385
src/io.c
385
src/io.c
@@ -8,17 +8,18 @@
|
||||
*
|
||||
* Implement I/O ports and their operations.
|
||||
*
|
||||
* Version: @(#)io.c 1.0.1 2017/12/16
|
||||
* Version: @(#)io.c 1.0.2 2018/02/01
|
||||
*
|
||||
* Authors: Sarah Walker, <http://pcem-emulator.co.uk/>
|
||||
* Miran Grca, <mgrca8@gmail.com>
|
||||
* Fred N. van Kempen, <decwiz@yahoo.com>
|
||||
*
|
||||
* Copyright 2008-2017 Sarah Walker.
|
||||
* Copyright 2016,2017 Miran Grca.
|
||||
* Copyright 2008-2018 Sarah Walker.
|
||||
* Copyright 2016-2018 Miran Grca.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <wchar.h>
|
||||
#include "86box.h"
|
||||
@@ -29,36 +30,22 @@
|
||||
#define NPORTS 65536 /* PC/AT supports 64K ports */
|
||||
|
||||
|
||||
/*
|
||||
* This should be redone using a
|
||||
*
|
||||
* typedef struct _io_ {
|
||||
* uint8_t (*inb)(uint16_t addr, void *priv);
|
||||
* uint16_t (*inw)(uint16_t addr, void *priv);
|
||||
* uint32_t (*inl)(uint16_t addr, void *priv);
|
||||
*
|
||||
* void (*outb)(uint16_t addr, uint8_t val, void *priv);
|
||||
* void (*outw)(uint16_t addr, uint16_t val, void *priv);
|
||||
* void (*outl)(uint16_t addr, uint32_t val, void *priv);
|
||||
*
|
||||
* void *priv;
|
||||
*
|
||||
* struct _io_ *next;
|
||||
* } io_t;
|
||||
*
|
||||
* at some point. We keep one base entry per I/O port, and if
|
||||
* more than one entry is needed (some ports are like that),
|
||||
* we just add a handler to the list for that port.
|
||||
*/
|
||||
static uint8_t (*port_inb[NPORTS][2])(uint16_t addr, void *priv);
|
||||
static uint16_t (*port_inw[NPORTS][2])(uint16_t addr, void *priv);
|
||||
static uint32_t (*port_inl[NPORTS][2])(uint16_t addr, void *priv);
|
||||
typedef struct _io_ {
|
||||
uint8_t (*inb)(uint16_t addr, void *priv);
|
||||
uint16_t (*inw)(uint16_t addr, void *priv);
|
||||
uint32_t (*inl)(uint16_t addr, void *priv);
|
||||
|
||||
static void (*port_outb[NPORTS][2])(uint16_t addr, uint8_t val, void *priv);
|
||||
static void (*port_outw[NPORTS][2])(uint16_t addr, uint16_t val, void *priv);
|
||||
static void (*port_outl[NPORTS][2])(uint16_t addr, uint32_t val, void *priv);
|
||||
void (*outb)(uint16_t addr, uint8_t val, void *priv);
|
||||
void (*outw)(uint16_t addr, uint16_t val, void *priv);
|
||||
void (*outl)(uint16_t addr, uint32_t val, void *priv);
|
||||
|
||||
static void *port_priv[NPORTS][2];
|
||||
void *priv;
|
||||
|
||||
struct _io_ *prev, *next;
|
||||
} io_t;
|
||||
|
||||
int initialized = 0;
|
||||
io_t *io[NPORTS], *io_last[NPORTS];
|
||||
|
||||
|
||||
#ifdef IO_CATCH
|
||||
@@ -75,25 +62,45 @@ void
|
||||
io_init(void)
|
||||
{
|
||||
int c;
|
||||
io_t *p, *q;
|
||||
|
||||
if (!initialized) {
|
||||
for (c=0; c<NPORTS; c++)
|
||||
io[c] = NULL;
|
||||
initialized = 1;
|
||||
}
|
||||
|
||||
pclog("IO: initializing\n");
|
||||
for (c=0; c<NPORTS; c++) {
|
||||
if (io_last[c]) {
|
||||
/* Port c has at least one handler. */
|
||||
p = io_last[c];
|
||||
/* After this loop, p will have the pointer to the first handler. */
|
||||
while (p) {
|
||||
q = p->prev;
|
||||
free(p);
|
||||
p = q;
|
||||
}
|
||||
p = NULL;
|
||||
}
|
||||
|
||||
#ifdef IO_CATCH
|
||||
port_inb[c][0] = port_inb[c][1] = null_inb;
|
||||
port_outb[c][0] = port_outb[c][1] = null_outb;
|
||||
port_inw[c][0] = port_inw[c][1] = null_inw;
|
||||
port_outw[c][0] = port_outw[c][1] = null_outw;
|
||||
port_inl[c][0] = port_inl[c][1] = null_inl;
|
||||
port_outl[c][0] = port_outl[c][1] = null_outl;
|
||||
/* io[c] should be the only handler, pointing at the NULL catch handler. */
|
||||
p = (io_t *) malloc(sizeof(io_t));
|
||||
memset(p, 0, sizeof(io_t));
|
||||
io[c] = p;
|
||||
p->next = NULL;
|
||||
p->prev = NULL;
|
||||
p->inb = null_inb;
|
||||
p->outb = null_outb;
|
||||
p->inw = null_inw;
|
||||
p->outw = null_outw;
|
||||
p->inl = null_inl;
|
||||
p->outl = null_outl;
|
||||
p->priv = NULL;
|
||||
#else
|
||||
port_inb[c][0] = port_inb[c][1] = NULL;
|
||||
port_outb[c][0] = port_outb[c][1] = NULL;
|
||||
port_inw[c][0] = port_inw[c][1] = NULL;
|
||||
port_outw[c][0] = port_outw[c][1] = NULL;
|
||||
port_inl[c][0] = port_inl[c][1] = NULL;
|
||||
port_outl[c][0] = port_outl[c][1] = NULL;
|
||||
/* io[c] should be NULL. */
|
||||
io[c] = NULL;
|
||||
#endif
|
||||
port_priv[c][0] = port_priv[c][1] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,33 +116,32 @@ io_sethandler(uint16_t base, int size,
|
||||
void *priv)
|
||||
{
|
||||
int c;
|
||||
io_t *p, *q = NULL;
|
||||
|
||||
for (c=0; c<size; c++) {
|
||||
if (!port_inb[base+c][0] && !port_inw[base+c][0] &&
|
||||
!port_inl[base+c][0] && !port_outb[base+c][0] &&
|
||||
!port_outw[base+c][0] && !port_outl[base+c][0]) {
|
||||
port_inb[base+c][0] = inb;
|
||||
port_inw[base+c][0] = inw;
|
||||
port_inl[base+c][0] = inl;
|
||||
|
||||
port_outb[base+c][0] = outb;
|
||||
port_outw[base+c][0] = outw;
|
||||
port_outl[base+c][0] = outl;
|
||||
|
||||
port_priv[base+c][0] = priv;
|
||||
} else if (!port_inb[base+c][1] && !port_inw[base+c][1] &&
|
||||
!port_inl[base+c][1] && !port_outb[base+c][1] &&
|
||||
!port_outw[base+c][1] && !port_outl[base+c][1]) {
|
||||
port_inb[base+c][1] = inb;
|
||||
port_inw[base+c][1] = inw;
|
||||
port_inl[base+c][1] = inl;
|
||||
|
||||
port_outb[base+c][1] = outb;
|
||||
port_outw[base+c][1] = outw;
|
||||
port_outl[base+c][1] = outl;
|
||||
|
||||
port_priv[base+c][1] = priv;
|
||||
for (c = 0; c < size; c++) {
|
||||
p = io_last[base + c];
|
||||
q = (io_t *) malloc(sizeof(io_t));
|
||||
memset(q, 0, sizeof(io_t));
|
||||
if (p) {
|
||||
p->next = q;
|
||||
q->prev = p;
|
||||
} else {
|
||||
io[base + c] = q;
|
||||
q->prev = NULL;
|
||||
}
|
||||
|
||||
q->inb = inb;
|
||||
q->inw = inw;
|
||||
q->inl = inl;
|
||||
|
||||
q->outb = outb;
|
||||
q->outw = outw;
|
||||
q->outl = outl;
|
||||
|
||||
q->priv = priv;
|
||||
q->next = NULL;
|
||||
|
||||
io_last[base + c] = q;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -151,37 +157,30 @@ io_removehandler(uint16_t base, int size,
|
||||
void *priv)
|
||||
{
|
||||
int c;
|
||||
io_t *p;
|
||||
|
||||
for (c=0; c<size; c++) {
|
||||
if (port_priv[base+c][0] == priv) {
|
||||
if (port_inb[base+c][0] == inb)
|
||||
port_inb[ base + c][0] = NULL;
|
||||
if (port_inw[base+c][0] == inw)
|
||||
port_inw[ base + c][0] = NULL;
|
||||
if (port_inl[base+c][0] == inl)
|
||||
port_inl[base+c][0] = NULL;
|
||||
if (port_outb[base+c][0] == outb)
|
||||
port_outb[base + c][0] = NULL;
|
||||
if (port_outw[base+c][0] == outw)
|
||||
port_outw[base + c][0] = NULL;
|
||||
if (port_outl[base+c][0] == outl)
|
||||
port_outl[base+c][0] = NULL;
|
||||
port_priv[base+c][0] = NULL;
|
||||
}
|
||||
if (port_priv[base+c][1] == priv) {
|
||||
if (port_inb[base+c][1] == inb)
|
||||
port_inb[ base+c][1] = NULL;
|
||||
if (port_inw[base+c][1] == inw)
|
||||
port_inw[ base+c][1] = NULL;
|
||||
if (port_inl[base+c][1] == inl)
|
||||
port_inl[base+c][1] = NULL;
|
||||
if (port_outb[base+c][1] == outb)
|
||||
port_outb[base+c][1] = NULL;
|
||||
if (port_outw[base+c][1] == outw)
|
||||
port_outw[base+c][1] = NULL;
|
||||
if (port_outl[base+c][1] == outl)
|
||||
port_outl[base+c][1] = NULL;
|
||||
port_priv[base+c][1] = NULL;
|
||||
for (c = 0; c < size; c++) {
|
||||
p = io[base + c];
|
||||
if (!p)
|
||||
continue;
|
||||
while(p) {
|
||||
if ((p->inb == inb) && (p->inw == inw) &&
|
||||
(p->inl == inl) && (p->outb == outb) &&
|
||||
(p->outw == outw) && (p->outl == outl) &&
|
||||
(p->priv == priv)) {
|
||||
if (p->prev)
|
||||
p->prev->next = p->next;
|
||||
else
|
||||
io[base + c] = p->next;
|
||||
if (p->next)
|
||||
p->next->prev = p->prev;
|
||||
else
|
||||
io_last[base + c] = p->prev;
|
||||
free(p);
|
||||
p = NULL;
|
||||
break;
|
||||
}
|
||||
p = p->next;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -199,32 +198,30 @@ io_sethandler_interleaved(uint16_t base, int size,
|
||||
void *priv)
|
||||
{
|
||||
int c;
|
||||
io_t *p, *q;
|
||||
|
||||
size <<= 2;
|
||||
for (c=0; c<size; c+=2) {
|
||||
if (!port_inb[base+c][0] && !port_inw[base+c][0] &&
|
||||
!port_inl[base+c][0] && !port_outb[base+c][0] &&
|
||||
!port_outw[base+c][0] && !port_outl[base+c][0]) {
|
||||
port_inb[ base + c][0] = inb;
|
||||
port_inw[ base + c][0] = inw;
|
||||
port_inl[ base + c][0] = inl;
|
||||
port_outb[base + c][0] = outb;
|
||||
port_outw[base + c][0] = outw;
|
||||
port_outl[base + c][0] = outl;
|
||||
port_priv[base + c][0] = priv;
|
||||
} else if (!port_inb[base+c][1] && !port_inw[base+c][1] &&
|
||||
!port_inl[base+c][1] && !port_outb[base+c][1] &&
|
||||
!port_outw[base+c][1] && !port_outl[base+c][1]) {
|
||||
port_inb[ base + c][1] = inb;
|
||||
port_inw[ base + c][1] = inw;
|
||||
port_inl[ base + c][1] = inl;
|
||||
|
||||
port_outb[base + c][1] = outb;
|
||||
port_outw[base + c][1] = outw;
|
||||
port_outl[base + c][1] = outl;
|
||||
|
||||
port_priv[base + c][1] = priv;
|
||||
p = last_handler(base + c);
|
||||
q = (io_t *) malloc(sizeof(io_t));
|
||||
memset(q, 0, sizeof(io_t));
|
||||
if (p) {
|
||||
p->next = q;
|
||||
q->prev = p;
|
||||
} else {
|
||||
io[base + c] = q;
|
||||
q->prev = NULL;
|
||||
}
|
||||
|
||||
q->inb = inb;
|
||||
q->inw = inw;
|
||||
q->inl = inl;
|
||||
|
||||
q->outb = outb;
|
||||
q->outw = outw;
|
||||
q->outl = outl;
|
||||
|
||||
q->priv = priv;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -240,38 +237,26 @@ io_removehandler_interleaved(uint16_t base, int size,
|
||||
void *priv)
|
||||
{
|
||||
int c;
|
||||
io_t *p;
|
||||
|
||||
size <<= 2;
|
||||
for (c=0; c<size; c+=2) {
|
||||
if (port_priv[base+c][0] == priv) {
|
||||
if (port_inb[base+c][0] == inb)
|
||||
port_inb[base+c][0] = NULL;
|
||||
if (port_inw[base+c][0] == inw)
|
||||
port_inw[base+c][0] = NULL;
|
||||
if (port_inl[base+c][0] == inl)
|
||||
port_inl[base+c][0] = NULL;
|
||||
if (port_outb[base+c][0] == outb)
|
||||
port_outb[base+c][0] = NULL;
|
||||
if (port_outw[base+c][0] == outw)
|
||||
port_outw[base+c][0] = NULL;
|
||||
if (port_outl[base+c][0] == outl)
|
||||
port_outl[base+c][0] = NULL;
|
||||
port_priv[base+c][0] = NULL;
|
||||
}
|
||||
if (port_priv[base+c][1] == priv) {
|
||||
if (port_inb[base+c][1] == inb)
|
||||
port_inb[base+c][1] = NULL;
|
||||
if (port_inw[base+c][1] == inw)
|
||||
port_inw[base+c][1] = NULL;
|
||||
if (port_inl[base+c][1] == inl)
|
||||
port_inl[base+c][1] = NULL;
|
||||
if (port_outb[base+c][1] == outb)
|
||||
port_outb[base+c][1] = NULL;
|
||||
if (port_outw[base+c][1] == outw)
|
||||
port_outw[base+c][1] = NULL;
|
||||
if (port_outl[base+c][1] == outl)
|
||||
port_outl[base+c][1] = NULL;
|
||||
port_priv[base+c][1] = NULL;
|
||||
for (c = 0; c < size; c += 2) {
|
||||
p = io[base + c];
|
||||
if (!p)
|
||||
return;
|
||||
while(p) {
|
||||
if ((p->inb == inb) && (p->inw == inw) &&
|
||||
(p->inl == inl) && (p->outb == outb) &&
|
||||
(p->outw == outw) && (p->outl == outl) &&
|
||||
(p->priv == priv)) {
|
||||
if (p->prev)
|
||||
p->prev->next = p->next;
|
||||
if (p->next)
|
||||
p->next->prev = p->prev;
|
||||
free(p);
|
||||
break;
|
||||
}
|
||||
p = p->next;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -282,11 +267,16 @@ uint8_t
|
||||
inb(uint16_t port)
|
||||
{
|
||||
uint8_t r = 0xff;
|
||||
io_t *p;
|
||||
|
||||
if (port_inb[port][0])
|
||||
r &= port_inb[port][0](port, port_priv[port][0]);
|
||||
if (port_inb[port][1])
|
||||
r &= port_inb[port][1](port, port_priv[port][1]);
|
||||
p = io[port];
|
||||
if (p) {
|
||||
while(p) {
|
||||
if (p->inb)
|
||||
r &= p->inb(port, p->priv);
|
||||
p = p->next;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef IO_TRACE
|
||||
if (CS == IO_TRACE)
|
||||
@@ -300,25 +290,38 @@ inb(uint16_t port)
|
||||
void
|
||||
outb(uint16_t port, uint8_t val)
|
||||
{
|
||||
if (port_outb[port][0])
|
||||
port_outb[port][0](port, val, port_priv[port][0]);
|
||||
if (port_outb[port][1])
|
||||
port_outb[port][1](port, val, port_priv[port][1]);
|
||||
io_t *p;
|
||||
|
||||
if (io[port]) {
|
||||
p = io[port];
|
||||
while(p) {
|
||||
if (p->outb)
|
||||
p->outb(port, val, p->priv);
|
||||
p = p->next;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef IO_TRACE
|
||||
if (CS == IO_TRACE)
|
||||
pclog("IOTRACE(%04X): outb(%04x,%02x)\n", IO_TRACE, port, val);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
uint16_t
|
||||
inw(uint16_t port)
|
||||
{
|
||||
if (port_inw[port][0])
|
||||
return(port_inw[port][0](port, port_priv[port][0]));
|
||||
if (port_inw[port][1])
|
||||
return(port_inw[port][1](port, port_priv[port][1]));
|
||||
io_t *p;
|
||||
|
||||
p = io[port];
|
||||
if (p) {
|
||||
while(p) {
|
||||
if (p->inw)
|
||||
return p->inw(port, p->priv);
|
||||
p = p->next;
|
||||
}
|
||||
}
|
||||
|
||||
return(inb(port) | (inb(port + 1) << 8));
|
||||
}
|
||||
@@ -327,27 +330,39 @@ inw(uint16_t port)
|
||||
void
|
||||
outw(uint16_t port, uint16_t val)
|
||||
{
|
||||
if (port_outw[port][0]) {
|
||||
port_outw[port][0](port, val, port_priv[port][0]);
|
||||
return;
|
||||
}
|
||||
if (port_outw[port][1]) {
|
||||
port_outw[port][1](port, val, port_priv[port][1]);
|
||||
return;
|
||||
io_t *p;
|
||||
|
||||
p = io[port];
|
||||
if (p) {
|
||||
while(p) {
|
||||
if (p->outw) {
|
||||
p->outw(port, val, p->priv);
|
||||
return;
|
||||
}
|
||||
p = p->next;
|
||||
}
|
||||
}
|
||||
|
||||
outb(port,val);
|
||||
outb(port+1,val>>8);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
uint32_t
|
||||
inl(uint16_t port)
|
||||
{
|
||||
if (port_inl[port][0])
|
||||
return(port_inl[port][0](port, port_priv[port][0]));
|
||||
if (port_inl[port][1])
|
||||
return(port_inl[port][1](port, port_priv[port][1]));
|
||||
io_t *p;
|
||||
|
||||
p = io[port];
|
||||
if (p) {
|
||||
while(p) {
|
||||
if (p->inl)
|
||||
return p->inl(port, p->priv);
|
||||
p = p->next;
|
||||
}
|
||||
}
|
||||
|
||||
return(inw(port) | (inw(port + 2) << 16));
|
||||
}
|
||||
@@ -356,15 +371,21 @@ inl(uint16_t port)
|
||||
void
|
||||
outl(uint16_t port, uint32_t val)
|
||||
{
|
||||
if (port_outl[port][0]) {
|
||||
port_outl[port][0](port, val, port_priv[port][0]);
|
||||
return;
|
||||
}
|
||||
if (port_outl[port][1]) {
|
||||
port_outl[port][1](port, val, port_priv[port][1]);
|
||||
return;
|
||||
io_t *p;
|
||||
|
||||
p = io[port];
|
||||
if (p) {
|
||||
while(p) {
|
||||
if (p->outl) {
|
||||
p->outl(port, val, p->priv);
|
||||
return;
|
||||
}
|
||||
p = p->next;
|
||||
}
|
||||
}
|
||||
|
||||
outw(port, val);
|
||||
outw(port + 2, val >> 16);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user