The WIN_DRIVE_DIAGNOSTICS command now behaves correctly (but I'm redoing the IDE emulation anyway);

The IBM PS/2 Model 486 now uses its own rom set ID;
The AHA-154x and Buslogic SCSI controllers no longer stop scanning for mailboxes when in aggressive round robin mode;
PIC interrupt processing fixes - no more IRQ-caused triple faults in Windows 98 SE.
This commit is contained in:
OBattler
2017-09-08 00:17:49 +02:00
parent 17d9c5c463
commit 40e7a0efab
10 changed files with 240 additions and 156 deletions

259
src/pic.c
View File

@@ -1,5 +1,6 @@
#include "ibm.h"
#include "io.h"
#include "pci.h"
#include "pic.h"
#include "pit.h"
@@ -18,14 +19,14 @@ void pic_updatepending()
if (AT)
{
if ((pic2.pend&~pic2.mask)&~pic2.mask2)
pic.pend |= (1 << 2);
pic.pend |= pic.icw3;
else
pic.pend &= ~(1 << 2);
pic.pend &= ~pic.icw3;
}
pic_intpending = (pic.pend & ~pic.mask) & ~pic.mask2;
if (AT)
{
if (!((pic.mask | pic.mask2) & (1 << 2)))
if (!((pic.mask | pic.mask2) & pic.icw3))
{
temp_pending = ((pic2.pend&~pic2.mask)&~pic2.mask2);
temp_pending <<= 8;
@@ -66,6 +67,25 @@ void pic_update_mask(uint8_t *mask, uint8_t ins)
}
}
static int picint_is_level(uint16_t irq)
{
if (PCI)
{
return pci_irq_is_level(irq);
}
else
{
if (irq < 8)
{
return (pic.icw1 & 8) ? 1 : 0;
}
else
{
return (pic2.icw1 & 8) ? 1 : 0;
}
}
}
static void pic_autoeoi()
{
int c;
@@ -79,8 +99,16 @@ static void pic_autoeoi()
if (AT)
{
if (c == 2 && (pic2.pend&~pic2.mask)&~pic2.mask2)
pic.pend |= (1 << 2);
if (((1 << c) == pic.icw3) && (pic2.pend&~pic2.mask)&~pic2.mask2)
pic.pend |= pic.icw3;
}
if ((pic_current & (1 << c)) && picint_is_level(c))
{
if (((1 << c) != pic.icw3) || !AT)
{
pic.pend |= 1 << c;
}
}
pic_updatepending();
@@ -106,6 +134,8 @@ void pic_write(uint16_t addr, uint8_t val, void *priv)
else pic.icw=2;
break;
case 2: /*ICW3*/
pic.icw3 = val;
pclog("PIC1 ICW3 now %02X\n", val);
if (pic.icw1&1) pic.icw=3;
else pic.icw=0;
break;
@@ -134,9 +164,18 @@ void pic_write(uint16_t addr, uint8_t val, void *priv)
pic_update_mask(&pic.mask2, pic.ins);
if (AT)
{
if ((val&7) == 2 && (pic2.pend&~pic2.mask)&~pic2.mask2)
pic.pend |= (1 << 2);
if (((val&7) == pic2.icw3) && (pic2.pend&~pic2.mask)&~pic2.mask2)
pic.pend |= pic.icw3;
}
if ((pic_current & (1 << (val & 7))) && picint_is_level(val & 7))
{
if ((((1 << (val & 7)) != pic.icw3) || !AT))
{
pic.pend |= 1 << (val & 7);
}
}
pic_updatepending();
}
else
@@ -150,8 +189,16 @@ void pic_write(uint16_t addr, uint8_t val, void *priv)
if (AT)
{
if (c == 2 && (pic2.pend&~pic2.mask)&~pic2.mask2)
pic.pend |= (1 << 2);
if (((1 << c) == pic.icw3) && (pic2.pend&~pic2.mask)&~pic2.mask2)
pic.pend |= pic.icw3;
}
if ((pic_current & (1 << c)) && picint_is_level(c))
{
if ((((1 << c) != pic.icw3) || !AT))
{
pic.pend |= 1 << c;
}
}
if (c==1 && keywaiting)
@@ -195,6 +242,12 @@ static void pic2_autoeoi()
pic2.ins &= ~(1 << c);
pic_update_mask(&pic2.mask2, pic2.ins);
if (pic_current & (0x100 << c) && picint_is_level(c + 8))
{
pic2.pend |= (1 << c);
pic.pend |= (1 << pic2.icw3);
}
pic_updatepending();
return;
}
@@ -219,6 +272,8 @@ void pic2_write(uint16_t addr, uint8_t val, void *priv)
else pic2.icw=2;
break;
case 2: /*ICW3*/
pic2.icw3 = val;
pclog("PIC2 ICW3 now %02X\n", val);
if (pic2.icw1&1) pic2.icw=3;
else pic2.icw=0;
break;
@@ -246,6 +301,12 @@ void pic2_write(uint16_t addr, uint8_t val, void *priv)
pic2.ins&=~(1<<(val&7));
pic_update_mask(&pic2.mask2, pic2.ins);
if (pic_current & (0x100 << (val & 7)) && picint_is_level((val & 7) + 8))
{
pic2.pend |= (1 << (val & 7));
pic.pend |= (1 << pic2.icw3);
}
pic_updatepending();
}
else
@@ -256,7 +317,13 @@ void pic2_write(uint16_t addr, uint8_t val, void *priv)
{
pic2.ins &= ~(1<<c);
pic_update_mask(&pic2.mask2, pic2.ins);
if (pic_current & (0x100 << c) && picint_is_level(c + 8))
{
pic2.pend |= (1 << c);
pic.pend |= (1 << pic2.icw3);
}
pic_updatepending();
return;
}
@@ -290,76 +357,98 @@ void clearpic()
pic_updatepending();
}
void picint(uint16_t num)
{
if (AT && (num == (1 << 2)))
num = 1 << 9;
if (num>0xFF)
{
if (!AT)
{
return;
}
pic2.pend|=(num>>8);
if ((pic2.pend&~pic2.mask)&~pic2.mask2)
pic.pend |= (1 << 2);
}
else
{
pic.pend|=num;
}
/* if (num == 0x40)
{
pclog("picint : PEND now %02X %02X\n", pic.pend, pic2.pend);
} */
pic_updatepending();
/* if (num == 0x40)
{
pclog("Processing FDC interrupt, pending: %s, previously pending: %s, masked: %s, masked (2): %s, T: %s, I: %s\n", (pic_intpending & num) ? "yes" : "no", (old_pend & num) ? "yes" : "no", (pic.mask & num) ? "yes" : "no", (pic.mask2 & num) ? "yes" : "no", (flags & 0x100) ? "yes" : "no", (flags&I_FLAG) ? "yes" : "no");
} */
}
void picintlevel(uint16_t num)
void picint_common(uint16_t num, int level)
{
int c = 0;
while (!(num & (1 << c))) c++;
if (AT && (c == 2))
{
c = 9;
if (!num)
{
/* pclog("Attempting to raise null IRQ\n"); */
return;
}
if (AT && (num == pic.icw3) && (pic.icw3 == 4))
{
num = 1 << 9;
}
if (!(pic_current & num))
}
while (!(num & (1 << c))) c++;
if (AT && (num == pic.icw3) && (pic.icw3 != 4))
{
/* pclog("Attempting to raise cascaded IRQ %i\n"); */
return;
}
if (!(pic_current & num) || !level)
{
pic_current |= num;
if (num>0xFF)
{
/* pclog("Raising IRQ %i\n", c); */
if (level)
{
pic_current |= num;
}
if (num>0xFF)
{
if (!AT)
{
return;
}
pic2.pend|=(num>>8);
}
else
{
pic.pend|=num;
}
}
pic_updatepending();
pic2.pend|=(num>>8);
if ((pic2.pend&~pic2.mask)&~pic2.mask2)
{
pic.pend |= (1 << pic2.icw3);
}
}
else
{
pic.pend|=num;
}
pic_updatepending();
}
}
void picint(uint16_t num)
{
picint_common(num, 0);
}
void picintlevel(uint16_t num)
{
picint_common(num, 1);
}
void picintc(uint16_t num)
{
int c = 0;
if (!num)
{
/* pclog("Attempting to lower null IRQ\n"); */
return;
while (!(num & (1 << c))) c++;
if (AT && (c == 2))
{
c = 9;
}
if (AT && (num == pic.icw3) && (pic.icw3 == 4))
{
num = 1 << 9;
}
pic_current &= ~num;
}
while (!(num & (1 << c))) c++;
if (AT && (num == pic.icw3) && (pic.icw3 != 4))
{
/* pclog("Attempting to lower cascaded IRQ %i\n"); */
return;
}
if (pic_current & num)
{
pic_current &= ~num;
}
/* pclog("Lowering IRQ %i\n", c); */
if (num > 0xff)
{
@@ -370,7 +459,9 @@ void picintc(uint16_t num)
pic2.pend &= ~(num >> 8);
if (!((pic2.pend&~pic2.mask)&~pic2.mask2))
pic.pend &= ~(1 << 2);
{
pic.pend &= ~(1 << pic2.icw3);
}
}
else
{
@@ -394,20 +485,17 @@ static uint8_t pic_process_interrupt(PIC* target_pic, int c)
int pic_int = c & 7;
int pic_int_num = 1 << pic_int;
int pic_cur_num = 1 << c;
/* int pic_cur_num = 1 << c; */
if (pending & pic_int_num)
{
if (!(pic_current & pic_cur_num))
{
target_pic->pend &= ~pic_int_num;
}
target_pic->pend &= ~pic_int_num;
target_pic->ins |= pic_int_num;
pic_update_mask(&target_pic->mask2, target_pic->ins);
if (c >= 8)
{
pic.ins |= (1 << 2); /*Cascade IRQ*/
pic.ins |= (1 << pic2.icw3); /*Cascade IRQ*/
pic_update_mask(&pic.mask2, pic.ins);
}
@@ -433,47 +521,34 @@ static uint8_t pic_process_interrupt(PIC* target_pic, int c)
uint8_t picinterrupt()
{
int c;
int c, d;
uint8_t ret;
uint8_t irq2_pending = (pic.pend & ~pic.mask) & (1 << 2);
for (c = 0; c <= 1; c++)
for (c = 0; c <= 7; c++)
{
ret = pic_process_interrupt(&pic, c);
if (ret != 0xFF) return ret;
}
if (irq2_pending)
{
if (AT)
if (AT && ((1 << c) == pic.icw3))
{
for (c = 8; c <= 15; c++)
for (d = 8; d <= 15; d++)
{
ret = pic_process_interrupt(&pic2, c);
pclog("Processing IRQ %i: %02X\n", c, ret);
ret = pic_process_interrupt(&pic2, d);
if (ret != 0xFF) return ret;
}
}
else
{
ret = pic_process_interrupt(&pic, 2);
ret = pic_process_interrupt(&pic, c);
if (ret != 0xFF) return ret;
}
}
for (c = 3; c <= 7; c++)
{
ret = pic_process_interrupt(&pic, c);
if (ret != 0xFF) return ret;
}
return 0xFF;
}
void dumppic()
{
pclog("PIC1 : MASK %02X PEND %02X INS %02X VECTOR %02X\n",pic.mask,pic.pend,pic.ins,pic.vector);
pclog("PIC1 : MASK %02X PEND %02X INS %02X LEVEL %02X VECTOR %02X CASCADE %02X\n", pic.mask, pic.pend, pic.ins, (pic.icw1 & 8) ? 1 : 0, pic.vector, pic.icw3);
if (AT)
{
pclog("PIC2 : MASK %02X PEND %02X INS %02X VECTOR %02X\n",pic2.mask,pic2.pend,pic2.ins,pic2.vector);
pclog("PIC2 : MASK %02X PEND %02X INS %02X LEVEL %02X VECTOR %02X CASCADE %02X\n", pic2.mask, pic2.pend, pic2.ins, (pic2.icw1 & 8) ? 1 : 0, pic2.vector, pic2.icw3);
}
}