2018-05-21 19:04:05 +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.
|
|
|
|
|
*
|
|
|
|
|
* This file is part of the 86Box distribution.
|
|
|
|
|
*
|
|
|
|
|
* Implementation of the Intel PIC chip emulation.
|
|
|
|
|
*
|
2018-10-19 00:39:32 +02:00
|
|
|
* Version: @(#)pic.c 1.0.2 2018/10/17
|
2018-05-21 19:04:05 +02:00
|
|
|
*
|
|
|
|
|
* Author: Miran Grca, <mgrca8@gmail.com>
|
|
|
|
|
*
|
|
|
|
|
* Copyright 2016-2018 Miran Grca.
|
|
|
|
|
*/
|
|
|
|
|
#include <stdarg.h>
|
2017-09-25 04:31:20 -04:00
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <wchar.h>
|
2018-05-21 19:04:05 +02:00
|
|
|
#define HAVE_STDARG_H
|
2017-10-17 01:59:09 -04:00
|
|
|
#include "86box.h"
|
2017-11-02 02:28:00 -05:00
|
|
|
#include "machine/machine.h"
|
2016-06-26 00:34:39 +02:00
|
|
|
#include "io.h"
|
2017-09-08 00:17:49 +02:00
|
|
|
#include "pci.h"
|
2016-06-26 00:34:39 +02:00
|
|
|
#include "pic.h"
|
2017-05-05 01:49:42 +02:00
|
|
|
#include "pit.h"
|
2016-06-26 00:34:39 +02:00
|
|
|
|
2017-08-24 01:14:39 -04:00
|
|
|
|
2016-06-26 00:34:39 +02:00
|
|
|
int output;
|
|
|
|
|
int intclear;
|
|
|
|
|
int keywaiting=0;
|
|
|
|
|
int pic_intpending;
|
2017-05-29 01:18:32 +02:00
|
|
|
PIC pic, pic2;
|
2017-08-27 23:57:47 +02:00
|
|
|
uint16_t pic_current;
|
2017-05-29 01:18:32 +02:00
|
|
|
|
2017-08-24 01:14:39 -04:00
|
|
|
|
2018-05-21 19:04:05 +02:00
|
|
|
#ifdef ENABLE_PIC_LOG
|
|
|
|
|
int pic_do_log = ENABLE_PIC_LOG;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2018-10-19 00:39:32 +02:00
|
|
|
pic_log(const char *fmt, ...)
|
2016-06-26 00:34:39 +02:00
|
|
|
{
|
2018-05-21 19:04:05 +02:00
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
|
|
if (pic_do_log) {
|
2018-10-19 00:39:32 +02:00
|
|
|
va_start(ap, fmt);
|
|
|
|
|
pclog_ex(fmt, ap);
|
2018-05-21 19:04:05 +02:00
|
|
|
va_end(ap);
|
|
|
|
|
}
|
2016-06-26 00:34:39 +02:00
|
|
|
}
|
2018-10-19 00:39:32 +02:00
|
|
|
#else
|
|
|
|
|
#define pic_log(fmt, ...)
|
|
|
|
|
#endif
|
2016-06-26 00:34:39 +02:00
|
|
|
|
|
|
|
|
|
2018-05-21 19:04:05 +02:00
|
|
|
void
|
|
|
|
|
pic_updatepending()
|
2016-06-26 00:34:39 +02:00
|
|
|
{
|
2018-05-21 19:04:05 +02:00
|
|
|
uint16_t temp_pending = 0;
|
|
|
|
|
if (AT) {
|
|
|
|
|
if ((pic2.pend&~pic2.mask)&~pic2.mask2)
|
|
|
|
|
pic.pend |= pic.icw3;
|
|
|
|
|
else
|
|
|
|
|
pic.pend &= ~pic.icw3;
|
|
|
|
|
}
|
|
|
|
|
pic_intpending = (pic.pend & ~pic.mask) & ~pic.mask2;
|
|
|
|
|
if (AT) {
|
|
|
|
|
if (!((pic.mask | pic.mask2) & pic.icw3)) {
|
|
|
|
|
temp_pending = ((pic2.pend&~pic2.mask)&~pic2.mask2);
|
|
|
|
|
temp_pending <<= 8;
|
|
|
|
|
pic_intpending |= temp_pending;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
pic_log("pic_intpending = %i %02X %02X %02X %02X\n", pic_intpending, pic.ins, pic.pend, pic.mask, pic.mask2);
|
|
|
|
|
pic_log(" %02X %02X %02X %02X %i %i\n", pic2.ins, pic2.pend, pic2.mask, pic2.mask2, ((pic.mask | pic.mask2) & (1 << 2)), ((pic2.pend&~pic2.mask)&~pic2.mask2));
|
2016-06-26 00:34:39 +02:00
|
|
|
}
|
|
|
|
|
|
2018-05-21 19:04:05 +02:00
|
|
|
|
|
|
|
|
void
|
|
|
|
|
pic_reset()
|
2016-06-26 00:34:39 +02:00
|
|
|
{
|
2018-05-21 19:04:05 +02:00
|
|
|
pic.icw=0;
|
|
|
|
|
pic.mask=0xFF;
|
|
|
|
|
pic.mask2=0;
|
|
|
|
|
pic.pend=pic.ins=0;
|
|
|
|
|
pic.vector=8;
|
|
|
|
|
pic.read=1;
|
|
|
|
|
pic2.icw=0;
|
|
|
|
|
pic2.mask=0xFF;
|
|
|
|
|
pic.mask2=0;
|
|
|
|
|
pic2.pend=pic2.ins=0;
|
|
|
|
|
pic_intpending = 0;
|
2016-06-26 00:34:39 +02:00
|
|
|
}
|
|
|
|
|
|
2018-05-21 19:04:05 +02:00
|
|
|
|
|
|
|
|
void
|
|
|
|
|
pic_update_mask(uint8_t *mask, uint8_t ins)
|
2017-09-08 00:17:49 +02:00
|
|
|
{
|
2018-05-21 19:04:05 +02:00
|
|
|
int c;
|
|
|
|
|
*mask = 0;
|
|
|
|
|
for (c = 0; c < 8; c++) {
|
|
|
|
|
if (ins & (1 << c)) {
|
|
|
|
|
*mask = 0xff << c;
|
|
|
|
|
return;
|
2017-09-08 00:17:49 +02:00
|
|
|
}
|
2018-05-21 19:04:05 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
2017-09-08 00:17:49 +02:00
|
|
|
else
|
2018-05-21 19:04:05 +02:00
|
|
|
return (pic2.icw1 & 8) ? 1 : 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
pic_autoeoi()
|
|
|
|
|
{
|
|
|
|
|
int c;
|
|
|
|
|
|
|
|
|
|
for (c = 0; c < 8; c++) {
|
|
|
|
|
if (pic.ins & ( 1 << c)) {
|
|
|
|
|
pic.ins &= ~(1 << c);
|
|
|
|
|
pic_update_mask(&pic.mask2, pic.ins);
|
|
|
|
|
|
|
|
|
|
if (AT) {
|
|
|
|
|
if (((1 << c) == pic.icw3) && (pic2.pend&~pic2.mask)&~pic2.mask2)
|
|
|
|
|
pic.pend |= pic.icw3;
|
2017-09-08 00:17:49 +02:00
|
|
|
}
|
2018-05-21 19:04:05 +02:00
|
|
|
|
|
|
|
|
if ((pic_current & (1 << c)) && picint_is_level(c)) {
|
|
|
|
|
if (((1 << c) != pic.icw3) || !AT)
|
|
|
|
|
pic.pend |= 1 << c;
|
2017-09-08 00:17:49 +02:00
|
|
|
}
|
2018-05-21 19:04:05 +02:00
|
|
|
|
|
|
|
|
pic_updatepending();
|
|
|
|
|
return;
|
2017-09-08 00:17:49 +02:00
|
|
|
}
|
2018-05-21 19:04:05 +02:00
|
|
|
}
|
2017-09-08 00:17:49 +02:00
|
|
|
}
|
|
|
|
|
|
2018-05-21 19:04:05 +02:00
|
|
|
|
|
|
|
|
void
|
|
|
|
|
pic_write(uint16_t addr, uint8_t val, void *priv)
|
2016-06-26 00:34:39 +02:00
|
|
|
{
|
2018-05-21 19:04:05 +02:00
|
|
|
int c;
|
|
|
|
|
if (addr&1) {
|
|
|
|
|
switch (pic.icw) {
|
|
|
|
|
case 0: /*OCW1*/
|
|
|
|
|
pic.mask=val;
|
|
|
|
|
pic_updatepending();
|
|
|
|
|
break;
|
|
|
|
|
case 1: /*ICW2*/
|
|
|
|
|
pic.vector=val&0xF8;
|
|
|
|
|
if (pic.icw1 & 2) pic.icw=3;
|
|
|
|
|
else pic.icw=2;
|
|
|
|
|
break;
|
|
|
|
|
case 2: /*ICW3*/
|
|
|
|
|
pic.icw3 = val;
|
|
|
|
|
pic_log("PIC1 ICW3 now %02X\n", val);
|
|
|
|
|
if (pic.icw1 & 1) pic.icw=3;
|
|
|
|
|
else pic.icw=0;
|
|
|
|
|
break;
|
|
|
|
|
case 3: /*ICW4*/
|
|
|
|
|
pic.icw4 = val;
|
|
|
|
|
pic.icw=0;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (val & 16) { /*ICW1*/
|
|
|
|
|
pic.mask = 0;
|
|
|
|
|
pic.mask2=0;
|
|
|
|
|
pic.icw=1;
|
|
|
|
|
pic.icw1=val;
|
|
|
|
|
pic.ins = 0;
|
|
|
|
|
pic_updatepending();
|
|
|
|
|
}
|
|
|
|
|
else if (!(val & 8)) { /*OCW2*/
|
|
|
|
|
if ((val & 0xE0) == 0x60) {
|
|
|
|
|
pic.ins &= ~(1 << (val & 7));
|
|
|
|
|
pic_update_mask(&pic.mask2, pic.ins);
|
|
|
|
|
if (AT) {
|
|
|
|
|
if (((val&7) == pic2.icw3) && (pic2.pend&~pic2.mask)&~pic2.mask2)
|
|
|
|
|
pic.pend |= pic.icw3;
|
2017-09-08 00:17:49 +02:00
|
|
|
}
|
|
|
|
|
|
2018-05-21 19:04:05 +02:00
|
|
|
if ((pic_current & (1 << (val & 7))) && picint_is_level(val & 7)) {
|
|
|
|
|
if ((((1 << (val & 7)) != pic.icw3) || !AT))
|
|
|
|
|
pic.pend |= 1 << (val & 7);
|
2016-12-28 23:34:00 +01:00
|
|
|
}
|
2016-06-26 00:34:39 +02:00
|
|
|
|
2018-05-21 19:04:05 +02:00
|
|
|
pic_updatepending();
|
|
|
|
|
} else {
|
|
|
|
|
for (c = 0; c < 8; c++) {
|
|
|
|
|
if (pic.ins & (1 << c)) {
|
|
|
|
|
pic.ins &= ~(1 << c);
|
|
|
|
|
pic_update_mask(&pic.mask2, pic.ins);
|
2016-06-26 00:34:39 +02:00
|
|
|
|
2018-05-21 19:04:05 +02:00
|
|
|
if (AT) {
|
|
|
|
|
if (((1 << c) == pic.icw3) && (pic2.pend&~pic2.mask)&~pic2.mask2)
|
|
|
|
|
pic.pend |= pic.icw3;
|
|
|
|
|
}
|
2017-09-08 00:17:49 +02:00
|
|
|
|
2018-05-21 19:04:05 +02:00
|
|
|
if ((pic_current & (1 << c)) && picint_is_level(c)) {
|
|
|
|
|
if ((((1 << c) != pic.icw3) || !AT))
|
|
|
|
|
pic.pend |= 1 << c;
|
2017-09-08 00:17:49 +02:00
|
|
|
}
|
2018-05-21 19:04:05 +02:00
|
|
|
|
|
|
|
|
if (c==1 && keywaiting)
|
|
|
|
|
intclear&=~1;
|
|
|
|
|
pic_updatepending();
|
|
|
|
|
return;
|
2016-12-28 05:53:00 +01:00
|
|
|
}
|
2018-05-21 19:04:05 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else { /*OCW3*/
|
|
|
|
|
if (val & 2)
|
|
|
|
|
pic.read=(val & 1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-08 00:17:49 +02:00
|
|
|
|
2018-05-21 19:04:05 +02:00
|
|
|
uint8_t
|
|
|
|
|
pic_read(uint16_t addr, void *priv)
|
|
|
|
|
{
|
|
|
|
|
if (addr & 1) {
|
|
|
|
|
pic_log("Read PIC mask %02X\n", pic.mask);
|
|
|
|
|
return pic.mask;
|
|
|
|
|
}
|
|
|
|
|
if (pic.read) {
|
|
|
|
|
pic_log("Read PIC ins %02X\n", pic.ins);
|
|
|
|
|
return pic.ins | (pic2.ins ? 4 : 0);
|
|
|
|
|
}
|
|
|
|
|
return pic.pend;
|
2016-06-26 00:34:39 +02:00
|
|
|
}
|
|
|
|
|
|
2018-05-21 19:04:05 +02:00
|
|
|
|
|
|
|
|
void
|
|
|
|
|
pic_init()
|
2016-06-26 00:34:39 +02:00
|
|
|
{
|
2018-05-21 19:04:05 +02:00
|
|
|
io_sethandler(0x0020, 0x0002, pic_read, NULL, NULL, pic_write, NULL, NULL, NULL);
|
2016-06-26 00:34:39 +02:00
|
|
|
}
|
|
|
|
|
|
2018-05-21 19:04:05 +02:00
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
pic2_autoeoi()
|
2016-06-26 00:34:39 +02:00
|
|
|
{
|
2018-05-21 19:04:05 +02:00
|
|
|
int c;
|
|
|
|
|
|
|
|
|
|
for (c = 0; c < 8; c++) {
|
|
|
|
|
if (pic2.ins & (1 << c)) {
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-06-26 00:34:39 +02:00
|
|
|
}
|
|
|
|
|
|
2018-05-21 19:04:05 +02:00
|
|
|
|
|
|
|
|
void
|
|
|
|
|
pic2_write(uint16_t addr, uint8_t val, void *priv)
|
2016-06-26 00:34:39 +02:00
|
|
|
{
|
2018-05-21 19:04:05 +02:00
|
|
|
int c;
|
|
|
|
|
if (addr & 1) {
|
|
|
|
|
switch (pic2.icw) {
|
|
|
|
|
case 0: /*OCW1*/
|
|
|
|
|
pic2.mask=val;
|
|
|
|
|
pic_updatepending();
|
|
|
|
|
break;
|
|
|
|
|
case 1: /*ICW2*/
|
|
|
|
|
pic2.vector=val & 0xF8;
|
|
|
|
|
pic_log("PIC2 vector now: %02X\n", pic2.vector);
|
|
|
|
|
if (pic2.icw1 & 2) pic2.icw=3;
|
|
|
|
|
else pic2.icw=2;
|
|
|
|
|
break;
|
|
|
|
|
case 2: /*ICW3*/
|
|
|
|
|
pic2.icw3 = val;
|
|
|
|
|
pic_log("PIC2 ICW3 now %02X\n", val);
|
|
|
|
|
if (pic2.icw1 & 1) pic2.icw=3;
|
|
|
|
|
else pic2.icw=0;
|
|
|
|
|
break;
|
|
|
|
|
case 3: /*ICW4*/
|
|
|
|
|
pic2.icw4 = val;
|
|
|
|
|
pic2.icw=0;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (val & 16) { /*ICW1*/
|
|
|
|
|
pic2.mask = 0;
|
|
|
|
|
pic2.mask2=0;
|
|
|
|
|
pic2.icw=1;
|
|
|
|
|
pic2.icw1 = val;
|
|
|
|
|
pic2.ins = 0;
|
|
|
|
|
pic_updatepending();
|
|
|
|
|
} else if (!(val & 8)) { /*OCW2*/
|
|
|
|
|
if ((val & 0xE0) == 0x60) {
|
|
|
|
|
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));
|
2017-09-08 00:17:49 +02:00
|
|
|
pic.pend |= (1 << pic2.icw3);
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-21 19:04:05 +02:00
|
|
|
pic_updatepending();
|
|
|
|
|
} else {
|
|
|
|
|
for (c = 0; c < 8; c++) {
|
|
|
|
|
if (pic2.ins&(1<<c)) {
|
|
|
|
|
pic2.ins &= ~(1<<c);
|
|
|
|
|
pic_update_mask(&pic2.mask2, pic2.ins);
|
2016-06-26 00:34:39 +02:00
|
|
|
|
2018-05-21 19:04:05 +02:00
|
|
|
if (pic_current & (0x100 << c) && picint_is_level(c + 8)) {
|
|
|
|
|
pic2.pend |= (1 << c);
|
|
|
|
|
pic.pend |= (1 << pic2.icw3);
|
|
|
|
|
}
|
2017-09-08 00:17:49 +02:00
|
|
|
|
2018-05-21 19:04:05 +02:00
|
|
|
pic_updatepending();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else { /*OCW3*/
|
|
|
|
|
if (val & 2)
|
|
|
|
|
pic2.read=(val & 1);
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-06-26 00:34:39 +02:00
|
|
|
}
|
|
|
|
|
|
2018-05-21 19:04:05 +02:00
|
|
|
|
|
|
|
|
uint8_t
|
|
|
|
|
pic2_read(uint16_t addr, void *priv)
|
2016-06-26 00:34:39 +02:00
|
|
|
{
|
2018-05-21 19:04:05 +02:00
|
|
|
if (addr&1) {
|
2018-10-02 22:54:28 +02:00
|
|
|
pic_log("Read PIC2 mask %02X\n", pic2.mask);
|
2018-05-21 19:04:05 +02:00
|
|
|
return pic2.mask;
|
|
|
|
|
}
|
|
|
|
|
if (pic2.read) {
|
2018-10-02 22:54:28 +02:00
|
|
|
pic_log("Read PIC2 ins %02X\n", pic2.ins);
|
2018-05-21 19:04:05 +02:00
|
|
|
return pic2.ins;
|
|
|
|
|
}
|
2018-10-02 22:54:28 +02:00
|
|
|
pic_log("Read PIC2 pend %02X\n", pic2.pend);
|
2018-05-21 19:04:05 +02:00
|
|
|
return pic2.pend;
|
2016-06-26 00:34:39 +02:00
|
|
|
}
|
|
|
|
|
|
2018-05-21 19:04:05 +02:00
|
|
|
|
|
|
|
|
void
|
|
|
|
|
pic2_init()
|
2016-06-26 00:34:39 +02:00
|
|
|
{
|
2018-05-21 19:04:05 +02:00
|
|
|
io_sethandler(0x00a0, 0x0002, pic2_read, NULL, NULL, pic2_write, NULL, NULL, NULL);
|
2016-06-26 00:34:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2018-05-21 19:04:05 +02:00
|
|
|
void
|
|
|
|
|
clearpic()
|
2016-06-26 00:34:39 +02:00
|
|
|
{
|
2018-05-21 19:04:05 +02:00
|
|
|
pic.pend=pic.ins=pic_current=0;
|
|
|
|
|
pic_updatepending();
|
2016-06-26 00:34:39 +02:00
|
|
|
}
|
|
|
|
|
|
2018-05-21 19:04:05 +02:00
|
|
|
|
|
|
|
|
void
|
|
|
|
|
picint_common(uint16_t num, int level)
|
2016-06-26 00:34:39 +02:00
|
|
|
{
|
2018-05-21 19:04:05 +02:00
|
|
|
int c = 0;
|
2016-12-28 23:34:00 +01:00
|
|
|
|
2018-05-21 19:04:05 +02:00
|
|
|
if (!num) {
|
|
|
|
|
pic_log("Attempting to raise null IRQ\n");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2016-06-26 00:34:39 +02:00
|
|
|
|
2018-05-21 19:04:05 +02:00
|
|
|
if (AT && (num == pic.icw3) && (pic.icw3 == 4))
|
|
|
|
|
num = 1 << 9;
|
2017-09-08 00:17:49 +02:00
|
|
|
|
2018-05-21 19:04:05 +02:00
|
|
|
while (!(num & (1 << c)))
|
|
|
|
|
c++;
|
2017-09-08 00:17:49 +02:00
|
|
|
|
2018-05-21 19:04:05 +02:00
|
|
|
if (AT && (num == pic.icw3) && (pic.icw3 != 4)) {
|
|
|
|
|
pic_log("Attempting to raise cascaded IRQ %i\n");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2017-09-08 00:17:49 +02:00
|
|
|
|
2018-05-21 19:04:05 +02:00
|
|
|
if (!(pic_current & num) || !level) {
|
|
|
|
|
pic_log("Raising IRQ %i\n", c);
|
2017-09-08 00:17:49 +02:00
|
|
|
|
2018-05-21 19:04:05 +02:00
|
|
|
if (level)
|
|
|
|
|
pic_current |= num;
|
2017-09-08 00:17:49 +02:00
|
|
|
|
2018-05-21 19:04:05 +02:00
|
|
|
if (num>0xFF) {
|
|
|
|
|
if (!AT)
|
|
|
|
|
return;
|
2016-12-28 23:34:00 +01:00
|
|
|
|
2018-05-21 19:04:05 +02:00
|
|
|
pic2.pend|=(num>>8);
|
|
|
|
|
if ((pic2.pend&~pic2.mask)&~pic2.mask2)
|
|
|
|
|
pic.pend |= (1 << pic2.icw3);
|
|
|
|
|
} else
|
|
|
|
|
pic.pend|=num;
|
|
|
|
|
|
|
|
|
|
pic_updatepending();
|
|
|
|
|
}
|
2017-09-08 00:17:49 +02:00
|
|
|
}
|
|
|
|
|
|
2018-05-21 19:04:05 +02:00
|
|
|
|
|
|
|
|
void
|
|
|
|
|
picint(uint16_t num)
|
2017-09-08 00:17:49 +02:00
|
|
|
{
|
2018-05-21 19:04:05 +02:00
|
|
|
picint_common(num, 0);
|
2017-09-08 00:17:49 +02:00
|
|
|
}
|
|
|
|
|
|
2018-05-21 19:04:05 +02:00
|
|
|
|
|
|
|
|
void
|
|
|
|
|
picintlevel(uint16_t num)
|
2017-09-08 00:17:49 +02:00
|
|
|
{
|
2018-05-21 19:04:05 +02:00
|
|
|
picint_common(num, 1);
|
2016-06-26 00:34:39 +02:00
|
|
|
}
|
2017-09-08 00:17:49 +02:00
|
|
|
|
2018-05-21 19:04:05 +02:00
|
|
|
|
|
|
|
|
void
|
|
|
|
|
picintc(uint16_t num)
|
2016-06-26 00:34:39 +02:00
|
|
|
{
|
2018-05-21 19:04:05 +02:00
|
|
|
int c = 0;
|
2017-09-08 00:17:49 +02:00
|
|
|
|
2018-05-21 19:04:05 +02:00
|
|
|
if (!num) {
|
|
|
|
|
pic_log("Attempting to lower null IRQ\n");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2017-09-08 00:17:49 +02:00
|
|
|
|
2018-05-21 19:04:05 +02:00
|
|
|
if (AT && (num == pic.icw3) && (pic.icw3 == 4))
|
|
|
|
|
num = 1 << 9;
|
2017-09-08 00:17:49 +02:00
|
|
|
|
2018-05-21 19:04:05 +02:00
|
|
|
while (!(num & (1 << c)))
|
|
|
|
|
c++;
|
2017-09-08 00:17:49 +02:00
|
|
|
|
2018-05-21 19:04:05 +02:00
|
|
|
if (AT && (num == pic.icw3) && (pic.icw3 != 4)) {
|
|
|
|
|
pic_log("Attempting to lower cascaded IRQ %i\n");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2017-09-08 00:17:49 +02:00
|
|
|
|
2018-05-21 19:04:05 +02:00
|
|
|
if (pic_current & num)
|
|
|
|
|
pic_current &= ~num;
|
2017-09-08 00:17:49 +02:00
|
|
|
|
2018-05-21 19:04:05 +02:00
|
|
|
pic_log("Lowering IRQ %i\n", c);
|
2016-06-26 00:34:39 +02:00
|
|
|
|
2018-05-21 19:04:05 +02:00
|
|
|
if (num > 0xff) {
|
|
|
|
|
if (!AT)
|
|
|
|
|
return;
|
2016-06-26 00:34:39 +02:00
|
|
|
|
2018-05-21 19:04:05 +02:00
|
|
|
pic2.pend &= ~(num >> 8);
|
|
|
|
|
if (!((pic2.pend&~pic2.mask)&~pic2.mask2))
|
|
|
|
|
pic.pend &= ~(1 << pic2.icw3);
|
|
|
|
|
} else
|
|
|
|
|
pic.pend&=~num;
|
2017-09-07 01:52:36 +02:00
|
|
|
|
2018-05-21 19:04:05 +02:00
|
|
|
pic_updatepending();
|
|
|
|
|
}
|
2017-09-07 01:52:36 +02:00
|
|
|
|
|
|
|
|
|
2018-05-21 19:04:05 +02:00
|
|
|
static uint8_t
|
|
|
|
|
pic_process_interrupt(PIC* target_pic, int c)
|
2016-06-26 00:34:39 +02:00
|
|
|
{
|
2018-05-21 19:04:05 +02:00
|
|
|
uint8_t pending = target_pic->pend & ~target_pic->mask;
|
2017-08-27 23:57:47 +02:00
|
|
|
|
2018-05-21 19:04:05 +02:00
|
|
|
int pic_int = c & 7;
|
|
|
|
|
int pic_int_num = 1 << pic_int;
|
2017-08-27 23:57:47 +02:00
|
|
|
|
2018-05-21 19:04:05 +02:00
|
|
|
if (pending & pic_int_num) {
|
|
|
|
|
target_pic->pend &= ~pic_int_num;
|
|
|
|
|
target_pic->ins |= pic_int_num;
|
|
|
|
|
pic_update_mask(&target_pic->mask2, target_pic->ins);
|
2017-08-27 23:57:47 +02:00
|
|
|
|
2018-05-21 19:04:05 +02:00
|
|
|
if (c >= 8) {
|
|
|
|
|
pic.ins |= (1 << pic2.icw3); /*Cascade IRQ*/
|
|
|
|
|
pic_update_mask(&pic.mask2, pic.ins);
|
|
|
|
|
}
|
2016-06-26 00:34:39 +02:00
|
|
|
|
2018-05-21 19:04:05 +02:00
|
|
|
pic_updatepending();
|
2016-06-26 00:34:39 +02:00
|
|
|
|
2018-05-21 19:04:05 +02:00
|
|
|
if (target_pic->icw4 & 0x02)
|
|
|
|
|
(c >= 8) ? pic2_autoeoi() : pic_autoeoi();
|
2017-08-27 23:57:47 +02:00
|
|
|
|
2018-05-21 19:04:05 +02:00
|
|
|
if (!c)
|
|
|
|
|
pit_set_gate(&pit2, 0, 0);
|
2016-06-26 00:34:39 +02:00
|
|
|
|
2018-05-21 19:04:05 +02:00
|
|
|
return pic_int + target_pic->vector;
|
|
|
|
|
} else
|
|
|
|
|
return 0xFF;
|
2017-08-28 04:24:33 +02:00
|
|
|
}
|
|
|
|
|
|
2018-05-21 19:04:05 +02:00
|
|
|
|
|
|
|
|
uint8_t
|
|
|
|
|
picinterrupt()
|
2017-08-28 04:24:33 +02:00
|
|
|
{
|
2018-05-21 19:04:05 +02:00
|
|
|
int c, d;
|
|
|
|
|
uint8_t ret;
|
|
|
|
|
|
|
|
|
|
for (c = 0; c <= 7; c++) {
|
|
|
|
|
if (AT && ((1 << c) == pic.icw3)) {
|
|
|
|
|
for (d = 8; d <= 15; d++) {
|
|
|
|
|
ret = pic_process_interrupt(&pic2, d);
|
2017-08-28 04:24:33 +02:00
|
|
|
if (ret != 0xFF) return ret;
|
2018-05-21 19:04:05 +02:00
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
ret = pic_process_interrupt(&pic, c);
|
|
|
|
|
if (ret != 0xFF) return ret;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return 0xFF;
|
2016-06-26 00:34:39 +02:00
|
|
|
}
|
|
|
|
|
|
2018-05-21 19:04:05 +02:00
|
|
|
|
|
|
|
|
void
|
|
|
|
|
dumppic()
|
2016-06-26 00:34:39 +02:00
|
|
|
{
|
2018-05-21 19:04:05 +02:00
|
|
|
pic_log("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)
|
|
|
|
|
pic_log("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);
|
2016-06-26 00:34:39 +02:00
|
|
|
}
|