2020-06-12 23:29:12 +02:00
|
|
|
/*
|
2022-11-13 16:37:58 -05: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.
|
2020-06-12 23:29:12 +02:00
|
|
|
*
|
2022-11-13 16:37:58 -05:00
|
|
|
* This file is part of the 86Box distribution.
|
2020-06-12 23:29:12 +02:00
|
|
|
*
|
2022-11-13 16:37:58 -05:00
|
|
|
* Emulation of Intel 82420EX chipset that acts as both the
|
|
|
|
|
* northbridge and the southbridge.
|
2020-06-12 23:29:12 +02:00
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
*
|
2022-11-13 16:37:58 -05:00
|
|
|
* Authors: Miran Grca, <mgrca8@gmail.com>
|
|
|
|
|
*
|
|
|
|
|
* Copyright 2020 Miran Grca.
|
2020-06-12 23:29:12 +02:00
|
|
|
*/
|
2023-08-24 16:59:57 +02:00
|
|
|
#define USE_DRB_HACK
|
2022-10-27 11:20:31 -04:00
|
|
|
#include <stdarg.h>
|
2020-06-12 23:29:12 +02:00
|
|
|
#include <stdint.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <wchar.h>
|
2022-10-27 11:20:31 -04:00
|
|
|
#define HAVE_STDARG_H
|
2020-06-12 23:29:12 +02:00
|
|
|
#include <86box/86box.h>
|
2022-07-16 04:08:13 +02:00
|
|
|
#include "cpu.h"
|
2020-06-12 23:29:12 +02:00
|
|
|
#include <86box/device.h>
|
|
|
|
|
#include <86box/io.h>
|
|
|
|
|
#include <86box/apm.h>
|
|
|
|
|
#include <86box/dma.h>
|
|
|
|
|
#include <86box/mem.h>
|
PIC rewrite, proper SMRAM API, complete SiS 471 rewrite and addition of 40x, 460, and 461, changes to mem.c/h, disabled Voodoo memory dumping on exit, bumped SDL Hardware scale quality to 2, bumped IDE/ATAPI drives to ATA-6, finally bumped emulator version to 3.0, redid the bus type ID's to allow for planned ATAPI hard disks, made SST flash set its high mappings to the correct address if the CPU is 16-bit, and added the SiS 401 AMI 486 Clone, AOpen Vi15G, and the Soyo 4SA2 (486 with SiS 496/497 that can boot from CD-ROM), assorted 286+ protected mode fixes (for slightly more accuracy), and fixes to 808x emulation (MS Word 1.0 and 1.10 for DOS now work correctly from floppy).
2020-10-14 23:15:01 +02:00
|
|
|
#include <86box/smram.h>
|
2020-06-12 23:29:12 +02:00
|
|
|
#include <86box/pci.h>
|
2023-04-11 23:21:52 +02:00
|
|
|
#include <86box/pic.h>
|
2020-06-12 23:29:12 +02:00
|
|
|
#include <86box/timer.h>
|
|
|
|
|
#include <86box/pit.h>
|
2023-06-26 12:47:04 -04:00
|
|
|
#include <86box/plat_unused.h>
|
2020-06-12 23:29:12 +02:00
|
|
|
#include <86box/port_92.h>
|
|
|
|
|
#include <86box/hdc_ide.h>
|
|
|
|
|
#include <86box/hdc.h>
|
|
|
|
|
#include <86box/machine.h>
|
2020-06-13 10:17:57 +02:00
|
|
|
#include <86box/chipset.h>
|
2020-06-26 18:05:27 -03:00
|
|
|
#include <86box/spd.h>
|
2023-07-12 00:32:21 +02:00
|
|
|
#ifndef USE_DRB_HACK
|
|
|
|
|
#include <86box/row.h>
|
|
|
|
|
#endif
|
2020-06-12 23:29:12 +02:00
|
|
|
|
2022-09-18 17:12:38 -04:00
|
|
|
#define MEM_STATE_SHADOW_R 0x01
|
|
|
|
|
#define MEM_STATE_SHADOW_W 0x02
|
|
|
|
|
#define MEM_STATE_SMRAM 0x04
|
2020-06-12 23:29:12 +02:00
|
|
|
|
2023-06-26 22:31:03 -04:00
|
|
|
typedef struct i420ex_t {
|
|
|
|
|
uint8_t has_ide;
|
|
|
|
|
uint8_t smram_locked;
|
2023-08-07 03:04:52 +02:00
|
|
|
uint8_t pci_slot;
|
|
|
|
|
uint8_t pad;
|
|
|
|
|
|
2023-06-26 22:31:03 -04:00
|
|
|
uint8_t regs[256];
|
2020-06-12 23:29:12 +02:00
|
|
|
|
2023-06-26 22:31:03 -04:00
|
|
|
uint16_t timer_base;
|
|
|
|
|
uint16_t timer_latch;
|
2020-06-12 23:29:12 +02:00
|
|
|
|
2022-09-18 17:12:38 -04:00
|
|
|
smram_t *smram;
|
PIC rewrite, proper SMRAM API, complete SiS 471 rewrite and addition of 40x, 460, and 461, changes to mem.c/h, disabled Voodoo memory dumping on exit, bumped SDL Hardware scale quality to 2, bumped IDE/ATAPI drives to ATA-6, finally bumped emulator version to 3.0, redid the bus type ID's to allow for planned ATAPI hard disks, made SST flash set its high mappings to the correct address if the CPU is 16-bit, and added the SiS 401 AMI 486 Clone, AOpen Vi15G, and the Soyo 4SA2 (486 with SiS 496/497 that can boot from CD-ROM), assorted 286+ protected mode fixes (for slightly more accuracy), and fixes to 808x emulation (MS Word 1.0 and 1.10 for DOS now work correctly from floppy).
2020-10-14 23:15:01 +02:00
|
|
|
|
2022-09-18 17:12:38 -04:00
|
|
|
double fast_off_period;
|
2020-06-12 23:29:12 +02:00
|
|
|
|
2023-06-26 22:31:03 -04:00
|
|
|
pc_timer_t timer;
|
|
|
|
|
pc_timer_t fast_off_timer;
|
2020-06-12 23:29:12 +02:00
|
|
|
|
2022-09-18 17:12:38 -04:00
|
|
|
apm_t *apm;
|
|
|
|
|
port_92_t *port_92;
|
2020-06-12 23:29:12 +02:00
|
|
|
} i420ex_t;
|
|
|
|
|
|
|
|
|
|
#ifdef ENABLE_I420EX_LOG
|
|
|
|
|
int i420ex_do_log = ENABLE_I420EX_LOG;
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
i420ex_log(const char *fmt, ...)
|
|
|
|
|
{
|
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
|
|
if (i420ex_do_log) {
|
2022-09-18 17:12:38 -04:00
|
|
|
va_start(ap, fmt);
|
|
|
|
|
pclog_ex(fmt, ap);
|
|
|
|
|
va_end(ap);
|
2020-06-12 23:29:12 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#else
|
2022-09-18 17:12:38 -04:00
|
|
|
# define i420ex_log(fmt, ...)
|
2020-06-12 23:29:12 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
i420ex_map(uint32_t addr, uint32_t size, int state)
|
|
|
|
|
{
|
|
|
|
|
switch (state & 3) {
|
2022-09-18 17:12:38 -04:00
|
|
|
case 0:
|
|
|
|
|
mem_set_mem_state_both(addr, size, MEM_READ_EXTANY | MEM_WRITE_EXTANY);
|
|
|
|
|
break;
|
|
|
|
|
case 1:
|
|
|
|
|
mem_set_mem_state_both(addr, size, MEM_READ_INTERNAL | MEM_WRITE_EXTANY);
|
|
|
|
|
break;
|
|
|
|
|
case 2:
|
|
|
|
|
mem_set_mem_state_both(addr, size, MEM_READ_EXTANY | MEM_WRITE_INTERNAL);
|
|
|
|
|
break;
|
|
|
|
|
case 3:
|
|
|
|
|
mem_set_mem_state_both(addr, size, MEM_READ_INTERNAL | MEM_WRITE_INTERNAL);
|
|
|
|
|
break;
|
2023-06-26 12:47:04 -04:00
|
|
|
default:
|
|
|
|
|
break;
|
2020-06-12 23:29:12 +02:00
|
|
|
}
|
|
|
|
|
flushmmucache_nopc();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2020-06-14 14:50:30 +02:00
|
|
|
i420ex_smram_handler_phase0(void)
|
2020-06-12 23:29:12 +02:00
|
|
|
{
|
|
|
|
|
/* Disable low extended SMRAM. */
|
PIC rewrite, proper SMRAM API, complete SiS 471 rewrite and addition of 40x, 460, and 461, changes to mem.c/h, disabled Voodoo memory dumping on exit, bumped SDL Hardware scale quality to 2, bumped IDE/ATAPI drives to ATA-6, finally bumped emulator version to 3.0, redid the bus type ID's to allow for planned ATAPI hard disks, made SST flash set its high mappings to the correct address if the CPU is 16-bit, and added the SiS 401 AMI 486 Clone, AOpen Vi15G, and the Soyo 4SA2 (486 with SiS 496/497 that can boot from CD-ROM), assorted 286+ protected mode fixes (for slightly more accuracy), and fixes to 808x emulation (MS Word 1.0 and 1.10 for DOS now work correctly from floppy).
2020-10-14 23:15:01 +02:00
|
|
|
smram_disable_all();
|
2020-06-12 23:29:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
i420ex_smram_handler_phase1(i420ex_t *dev)
|
|
|
|
|
{
|
2023-07-20 18:58:26 -04:00
|
|
|
const uint8_t *regs = (uint8_t *) dev->regs;
|
2020-06-12 23:29:12 +02:00
|
|
|
|
2023-05-11 03:02:36 -04:00
|
|
|
uint32_t host_base = 0x000a0000;
|
|
|
|
|
uint32_t ram_base = 0x000a0000;
|
|
|
|
|
uint32_t size = 0x00010000;
|
2020-06-12 23:29:12 +02:00
|
|
|
|
|
|
|
|
switch (regs[0x70] & 0x07) {
|
2023-06-26 12:47:04 -04:00
|
|
|
default:
|
2022-09-18 17:12:38 -04:00
|
|
|
case 0:
|
|
|
|
|
case 1:
|
|
|
|
|
host_base = ram_base = 0x00000000;
|
|
|
|
|
size = 0x00000000;
|
|
|
|
|
break;
|
|
|
|
|
case 2:
|
|
|
|
|
host_base = 0x000a0000;
|
|
|
|
|
ram_base = 0x000a0000;
|
|
|
|
|
break;
|
|
|
|
|
case 3:
|
|
|
|
|
host_base = 0x000b0000;
|
|
|
|
|
ram_base = 0x000b0000;
|
|
|
|
|
break;
|
|
|
|
|
case 4:
|
|
|
|
|
host_base = 0x000c0000;
|
|
|
|
|
ram_base = 0x000a0000;
|
|
|
|
|
break;
|
|
|
|
|
case 5:
|
|
|
|
|
host_base = 0x000d0000;
|
|
|
|
|
ram_base = 0x000a0000;
|
|
|
|
|
break;
|
|
|
|
|
case 6:
|
|
|
|
|
host_base = 0x000e0000;
|
|
|
|
|
ram_base = 0x000a0000;
|
|
|
|
|
break;
|
|
|
|
|
case 7:
|
|
|
|
|
host_base = 0x000f0000;
|
|
|
|
|
ram_base = 0x000a0000;
|
|
|
|
|
break;
|
2020-06-12 23:29:12 +02:00
|
|
|
}
|
|
|
|
|
|
PIC rewrite, proper SMRAM API, complete SiS 471 rewrite and addition of 40x, 460, and 461, changes to mem.c/h, disabled Voodoo memory dumping on exit, bumped SDL Hardware scale quality to 2, bumped IDE/ATAPI drives to ATA-6, finally bumped emulator version to 3.0, redid the bus type ID's to allow for planned ATAPI hard disks, made SST flash set its high mappings to the correct address if the CPU is 16-bit, and added the SiS 401 AMI 486 Clone, AOpen Vi15G, and the Soyo 4SA2 (486 with SiS 496/497 that can boot from CD-ROM), assorted 286+ protected mode fixes (for slightly more accuracy), and fixes to 808x emulation (MS Word 1.0 and 1.10 for DOS now work correctly from floppy).
2020-10-14 23:15:01 +02:00
|
|
|
smram_enable(dev->smram, host_base, ram_base, size,
|
2022-09-18 17:12:38 -04:00
|
|
|
(regs[0x70] & 0x70) == 0x40, !(regs[0x70] & 0x20));
|
2020-06-12 23:29:12 +02:00
|
|
|
}
|
|
|
|
|
|
2023-07-12 00:32:21 +02:00
|
|
|
#ifndef USE_DRB_HACK
|
|
|
|
|
static void
|
|
|
|
|
i420ex_drb_recalc(i420ex_t *dev)
|
|
|
|
|
{
|
2023-07-12 00:37:51 +02:00
|
|
|
uint32_t boundary;
|
2023-07-12 00:32:21 +02:00
|
|
|
|
2023-08-04 16:43:42 +02:00
|
|
|
for (int8_t i = 4; i >= 0; i--)
|
2023-07-12 00:32:21 +02:00
|
|
|
row_disable(i);
|
|
|
|
|
|
2023-06-09 23:46:54 -04:00
|
|
|
for (uint8_t i = 0; i <= 4; i++) {
|
|
|
|
|
boundary = ((uint32_t) dev->regs[0x60 + i]) & 0xff;
|
|
|
|
|
row_set_boundary(i, boundary);
|
2023-07-12 00:32:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
flushmmucache();
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
2020-06-12 23:29:12 +02:00
|
|
|
static void
|
|
|
|
|
i420ex_write(int func, int addr, uint8_t val, void *priv)
|
|
|
|
|
{
|
|
|
|
|
i420ex_t *dev = (i420ex_t *) priv;
|
|
|
|
|
|
|
|
|
|
if (func > 0)
|
2022-09-18 17:12:38 -04:00
|
|
|
return;
|
2020-06-12 23:29:12 +02:00
|
|
|
|
|
|
|
|
if (((addr >= 0x0f) && (addr < 0x4c)) && (addr != 0x40))
|
2022-09-18 17:12:38 -04:00
|
|
|
return;
|
2020-06-12 23:29:12 +02:00
|
|
|
|
|
|
|
|
switch (addr) {
|
2022-09-18 17:12:38 -04:00
|
|
|
case 0x05:
|
|
|
|
|
dev->regs[addr] = (val & 0x01);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 0x07:
|
|
|
|
|
dev->regs[addr] &= ~(val & 0xf0);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 0x40:
|
|
|
|
|
dev->regs[addr] = (val & 0x7f);
|
|
|
|
|
break;
|
|
|
|
|
case 0x44:
|
|
|
|
|
dev->regs[addr] = (val & 0x07);
|
|
|
|
|
break;
|
|
|
|
|
case 0x48:
|
|
|
|
|
dev->regs[addr] = (val & 0x3f);
|
|
|
|
|
if (dev->has_ide) {
|
|
|
|
|
ide_pri_disable();
|
|
|
|
|
switch (val & 0x03) {
|
|
|
|
|
case 0x01:
|
|
|
|
|
ide_set_base(0, 0x01f0);
|
|
|
|
|
ide_set_side(0, 0x03f6);
|
|
|
|
|
ide_pri_enable();
|
|
|
|
|
break;
|
|
|
|
|
case 0x02:
|
|
|
|
|
ide_set_base(0, 0x0170);
|
|
|
|
|
ide_set_side(0, 0x0376);
|
|
|
|
|
ide_pri_enable();
|
|
|
|
|
break;
|
2023-06-26 12:47:04 -04:00
|
|
|
default:
|
|
|
|
|
break;
|
2022-09-18 17:12:38 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 0x49:
|
|
|
|
|
case 0x53:
|
|
|
|
|
dev->regs[addr] = (val & 0x1f);
|
|
|
|
|
break;
|
|
|
|
|
case 0x4c:
|
|
|
|
|
case 0x51:
|
|
|
|
|
case 0x57:
|
|
|
|
|
case 0x68:
|
|
|
|
|
case 0x69:
|
|
|
|
|
dev->regs[addr] = val;
|
|
|
|
|
if (addr == 0x4c) {
|
|
|
|
|
dma_alias_remove();
|
|
|
|
|
if (!(val & 0x80))
|
|
|
|
|
dma_alias_set();
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 0x4d:
|
|
|
|
|
dev->regs[addr] = (dev->regs[addr] & 0xef) | (val & 0x10);
|
|
|
|
|
break;
|
|
|
|
|
case 0x4e:
|
|
|
|
|
dev->regs[addr] = (val & 0xf7);
|
|
|
|
|
break;
|
|
|
|
|
case 0x50:
|
|
|
|
|
dev->regs[addr] = (val & 0x0f);
|
|
|
|
|
break;
|
|
|
|
|
case 0x52:
|
|
|
|
|
dev->regs[addr] = (val & 0x7f);
|
|
|
|
|
break;
|
|
|
|
|
case 0x56:
|
|
|
|
|
dev->regs[addr] = (val & 0x3e);
|
|
|
|
|
break;
|
|
|
|
|
case 0x59: /* PAM0 */
|
|
|
|
|
if ((dev->regs[0x59] ^ val) & 0xf0) {
|
|
|
|
|
i420ex_map(0xf0000, 0x10000, val >> 4);
|
|
|
|
|
shadowbios = (val & 0x10);
|
|
|
|
|
}
|
|
|
|
|
dev->regs[0x59] = val & 0xf0;
|
|
|
|
|
break;
|
|
|
|
|
case 0x5a: /* PAM1 */
|
|
|
|
|
if ((dev->regs[0x5a] ^ val) & 0x0f)
|
|
|
|
|
i420ex_map(0xc0000, 0x04000, val & 0xf);
|
|
|
|
|
if ((dev->regs[0x5a] ^ val) & 0xf0)
|
|
|
|
|
i420ex_map(0xc4000, 0x04000, val >> 4);
|
|
|
|
|
dev->regs[0x5a] = val;
|
|
|
|
|
break;
|
|
|
|
|
case 0x5b: /*PAM2 */
|
|
|
|
|
if ((dev->regs[0x5b] ^ val) & 0x0f)
|
|
|
|
|
i420ex_map(0xc8000, 0x04000, val & 0xf);
|
|
|
|
|
if ((dev->regs[0x5b] ^ val) & 0xf0)
|
|
|
|
|
i420ex_map(0xcc000, 0x04000, val >> 4);
|
|
|
|
|
dev->regs[0x5b] = val;
|
|
|
|
|
break;
|
|
|
|
|
case 0x5c: /*PAM3 */
|
|
|
|
|
if ((dev->regs[0x5c] ^ val) & 0x0f)
|
|
|
|
|
i420ex_map(0xd0000, 0x04000, val & 0xf);
|
|
|
|
|
if ((dev->regs[0x5c] ^ val) & 0xf0)
|
|
|
|
|
i420ex_map(0xd4000, 0x04000, val >> 4);
|
|
|
|
|
dev->regs[0x5c] = val;
|
|
|
|
|
break;
|
|
|
|
|
case 0x5d: /* PAM4 */
|
|
|
|
|
if ((dev->regs[0x5d] ^ val) & 0x0f)
|
|
|
|
|
i420ex_map(0xd8000, 0x04000, val & 0xf);
|
|
|
|
|
if ((dev->regs[0x5d] ^ val) & 0xf0)
|
|
|
|
|
i420ex_map(0xdc000, 0x04000, val >> 4);
|
|
|
|
|
dev->regs[0x5d] = val;
|
|
|
|
|
break;
|
|
|
|
|
case 0x5e: /* PAM5 */
|
|
|
|
|
if ((dev->regs[0x5e] ^ val) & 0x0f)
|
|
|
|
|
i420ex_map(0xe0000, 0x04000, val & 0xf);
|
|
|
|
|
if ((dev->regs[0x5e] ^ val) & 0xf0)
|
|
|
|
|
i420ex_map(0xe4000, 0x04000, val >> 4);
|
|
|
|
|
dev->regs[0x5e] = val;
|
|
|
|
|
break;
|
|
|
|
|
case 0x5f: /* PAM6 */
|
|
|
|
|
if ((dev->regs[0x5f] ^ val) & 0x0f)
|
|
|
|
|
i420ex_map(0xe8000, 0x04000, val & 0xf);
|
|
|
|
|
if ((dev->regs[0x5f] ^ val) & 0xf0)
|
|
|
|
|
i420ex_map(0xec000, 0x04000, val >> 4);
|
|
|
|
|
dev->regs[0x5f] = val;
|
|
|
|
|
break;
|
|
|
|
|
case 0x60:
|
|
|
|
|
case 0x61:
|
|
|
|
|
case 0x62:
|
|
|
|
|
case 0x63:
|
|
|
|
|
case 0x64:
|
2023-07-12 00:32:21 +02:00
|
|
|
#ifdef USE_DRB_HACK
|
2022-09-18 17:12:38 -04:00
|
|
|
spd_write_drbs(dev->regs, 0x60, 0x64, 1);
|
2023-07-12 00:32:21 +02:00
|
|
|
#else
|
|
|
|
|
dev->regs[addr] = val;
|
|
|
|
|
i420ex_drb_recalc(dev);
|
|
|
|
|
#endif
|
2022-09-18 17:12:38 -04:00
|
|
|
break;
|
|
|
|
|
case 0x66:
|
|
|
|
|
case 0x67:
|
|
|
|
|
i420ex_log("Set IRQ routing: INT %c -> %02X\n", 0x41 + (addr & 0x01), val);
|
|
|
|
|
dev->regs[addr] = val & 0x8f;
|
|
|
|
|
if (val & 0x80)
|
|
|
|
|
pci_set_irq_routing(PCI_INTA + (addr & 0x01), PCI_IRQ_DISABLED);
|
|
|
|
|
else
|
|
|
|
|
pci_set_irq_routing(PCI_INTA + (addr & 0x01), val & 0xf);
|
|
|
|
|
break;
|
|
|
|
|
case 0x70: /* SMRAM */
|
|
|
|
|
i420ex_smram_handler_phase0();
|
|
|
|
|
if (dev->smram_locked)
|
|
|
|
|
dev->regs[0x70] = (dev->regs[0x70] & 0xdf) | (val & 0x20);
|
|
|
|
|
else {
|
|
|
|
|
dev->regs[0x70] = (dev->regs[0x70] & 0x88) | (val & 0x77);
|
|
|
|
|
dev->smram_locked = (val & 0x10);
|
|
|
|
|
if (dev->smram_locked)
|
|
|
|
|
dev->regs[0x70] &= 0xbf;
|
|
|
|
|
}
|
|
|
|
|
i420ex_smram_handler_phase1(dev);
|
|
|
|
|
break;
|
|
|
|
|
case 0xa0:
|
|
|
|
|
dev->regs[addr] = val & 0x1f;
|
|
|
|
|
apm_set_do_smi(dev->apm, !!(val & 0x01) && !!(dev->regs[0xa2] & 0x80));
|
|
|
|
|
switch ((val & 0x18) >> 3) {
|
|
|
|
|
case 0x00:
|
|
|
|
|
dev->fast_off_period = PCICLK * 32768.0 * 60000.0;
|
|
|
|
|
break;
|
|
|
|
|
case 0x01:
|
|
|
|
|
default:
|
|
|
|
|
dev->fast_off_period = 0.0;
|
|
|
|
|
break;
|
|
|
|
|
case 0x02:
|
|
|
|
|
dev->fast_off_period = PCICLK;
|
|
|
|
|
break;
|
|
|
|
|
case 0x03:
|
|
|
|
|
dev->fast_off_period = PCICLK * 32768.0;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
cpu_fast_off_count = cpu_fast_off_val + 1;
|
|
|
|
|
cpu_fast_off_period_set(cpu_fast_off_val, dev->fast_off_period);
|
|
|
|
|
break;
|
|
|
|
|
case 0xa2:
|
|
|
|
|
dev->regs[addr] = val & 0xff;
|
|
|
|
|
apm_set_do_smi(dev->apm, !!(dev->regs[0xa0] & 0x01) && !!(val & 0x80));
|
|
|
|
|
break;
|
|
|
|
|
case 0xaa:
|
|
|
|
|
dev->regs[addr] &= (val & 0xff);
|
|
|
|
|
break;
|
|
|
|
|
case 0xac:
|
|
|
|
|
case 0xae:
|
|
|
|
|
dev->regs[addr] = val & 0xff;
|
|
|
|
|
break;
|
|
|
|
|
case 0xa4:
|
|
|
|
|
dev->regs[addr] = val & 0xfb;
|
|
|
|
|
cpu_fast_off_flags = (cpu_fast_off_flags & 0xffffff00) | dev->regs[addr];
|
|
|
|
|
break;
|
|
|
|
|
case 0xa5:
|
|
|
|
|
dev->regs[addr] = val;
|
|
|
|
|
cpu_fast_off_flags = (cpu_fast_off_flags & 0xffff00ff) | (dev->regs[addr] << 8);
|
|
|
|
|
break;
|
|
|
|
|
case 0xa7:
|
|
|
|
|
dev->regs[addr] = val & 0xe0;
|
|
|
|
|
cpu_fast_off_flags = (cpu_fast_off_flags & 0x00ffffff) | (dev->regs[addr] << 24);
|
|
|
|
|
break;
|
|
|
|
|
case 0xa8:
|
|
|
|
|
dev->regs[addr] = val & 0xff;
|
|
|
|
|
cpu_fast_off_val = val;
|
|
|
|
|
cpu_fast_off_count = val + 1;
|
|
|
|
|
cpu_fast_off_period_set(cpu_fast_off_val, dev->fast_off_period);
|
|
|
|
|
break;
|
2023-06-26 12:47:04 -04:00
|
|
|
default:
|
|
|
|
|
break;
|
2020-06-12 23:29:12 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static uint8_t
|
|
|
|
|
i420ex_read(int func, int addr, void *priv)
|
|
|
|
|
{
|
2023-07-20 18:58:26 -04:00
|
|
|
const i420ex_t *dev = (i420ex_t *) priv;
|
|
|
|
|
uint8_t ret;
|
2020-06-12 23:29:12 +02:00
|
|
|
|
|
|
|
|
ret = 0xff;
|
|
|
|
|
|
|
|
|
|
if (func == 0)
|
|
|
|
|
ret = dev->regs[addr];
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
i420ex_reset_hard(void *priv)
|
|
|
|
|
{
|
|
|
|
|
i420ex_t *dev = (i420ex_t *) priv;
|
|
|
|
|
|
|
|
|
|
memset(dev->regs, 0, 256);
|
|
|
|
|
|
2022-09-18 17:12:38 -04:00
|
|
|
dev->regs[0x00] = 0x86;
|
|
|
|
|
dev->regs[0x01] = 0x80; /*Intel*/
|
|
|
|
|
dev->regs[0x02] = 0x86;
|
|
|
|
|
dev->regs[0x03] = 0x04; /*82378IB (I420EX)*/
|
2020-06-12 23:29:12 +02:00
|
|
|
dev->regs[0x04] = 0x07;
|
|
|
|
|
dev->regs[0x07] = 0x02;
|
|
|
|
|
|
|
|
|
|
dev->regs[0x4c] = 0x4d;
|
|
|
|
|
dev->regs[0x4e] = 0x03;
|
2023-04-11 23:21:52 +02:00
|
|
|
/* Bits 2:1 of register 50h are 00 is 25 MHz, and 01 if 33 MHz, 10 and 11 are reserved. */
|
2020-06-12 23:29:12 +02:00
|
|
|
if (cpu_busspeed >= 33333333)
|
2022-09-18 17:12:38 -04:00
|
|
|
dev->regs[0x50] |= 0x02;
|
2020-06-12 23:29:12 +02:00
|
|
|
dev->regs[0x51] = 0x80;
|
|
|
|
|
dev->regs[0x60] = dev->regs[0x61] = dev->regs[0x62] = dev->regs[0x63] = dev->regs[0x64] = 0x01;
|
2022-09-18 17:12:38 -04:00
|
|
|
dev->regs[0x66] = 0x80;
|
|
|
|
|
dev->regs[0x67] = 0x80;
|
|
|
|
|
dev->regs[0x69] = 0x02;
|
|
|
|
|
dev->regs[0xa0] = 0x08;
|
|
|
|
|
dev->regs[0xa8] = 0x0f;
|
2020-06-12 23:29:12 +02:00
|
|
|
|
|
|
|
|
mem_set_mem_state(0x000a0000, 0x00060000, MEM_READ_EXTANY | MEM_WRITE_EXTANY);
|
|
|
|
|
mem_set_mem_state_smm(0x000a0000, 0x00060000, MEM_READ_EXTANY | MEM_WRITE_EXTANY);
|
|
|
|
|
|
|
|
|
|
pci_set_irq_routing(PCI_INTA, PCI_IRQ_DISABLED);
|
|
|
|
|
pci_set_irq_routing(PCI_INTB, PCI_IRQ_DISABLED);
|
2021-06-06 23:59:05 +02:00
|
|
|
|
|
|
|
|
if (dev->has_ide)
|
2022-09-18 17:12:38 -04:00
|
|
|
ide_pri_disable();
|
2020-06-12 23:29:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2023-06-26 12:47:04 -04:00
|
|
|
i420ex_apm_out(UNUSED(uint16_t port), UNUSED(uint8_t val), void *priv)
|
2020-06-12 23:29:12 +02:00
|
|
|
{
|
2023-06-26 12:47:04 -04:00
|
|
|
i420ex_t *dev = (i420ex_t *) priv;
|
2020-06-12 23:29:12 +02:00
|
|
|
|
|
|
|
|
if (dev->apm->do_smi)
|
2022-09-18 17:12:38 -04:00
|
|
|
dev->regs[0xaa] |= 0x80;
|
2020-06-12 23:29:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
i420ex_fast_off_count(void *priv)
|
|
|
|
|
{
|
|
|
|
|
i420ex_t *dev = (i420ex_t *) priv;
|
|
|
|
|
|
|
|
|
|
cpu_fast_off_count--;
|
|
|
|
|
|
2022-07-16 03:21:09 +02:00
|
|
|
smi_raise();
|
|
|
|
|
dev->regs[0xaa] |= 0x20;
|
2020-06-12 23:29:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2023-06-26 22:31:03 -04:00
|
|
|
i420ex_reset(void *priv)
|
2020-06-12 23:29:12 +02:00
|
|
|
{
|
2023-06-26 22:31:03 -04:00
|
|
|
i420ex_t *dev = (i420ex_t *) priv;
|
2020-06-12 23:29:12 +02:00
|
|
|
|
2023-06-26 22:31:03 -04:00
|
|
|
i420ex_write(0, 0x48, 0x00, priv);
|
2021-06-06 23:59:05 +02:00
|
|
|
|
2023-04-11 23:21:52 +02:00
|
|
|
/* Disable the PIC mouse latch. */
|
2023-06-26 22:31:03 -04:00
|
|
|
i420ex_write(0, 0x4e, 0x03, priv);
|
2023-04-11 23:21:52 +02:00
|
|
|
|
2023-06-26 22:31:03 -04:00
|
|
|
for (uint8_t i = 0; i < 7; i++)
|
|
|
|
|
i420ex_write(0, 0x59 + i, 0x00, priv);
|
2020-06-12 23:29:12 +02:00
|
|
|
|
2023-06-26 22:31:03 -04:00
|
|
|
for (uint8_t i = 0; i <= 4; i++)
|
2023-07-12 00:32:21 +02:00
|
|
|
dev->regs[0x60 + i] = 0x01;
|
2020-06-12 23:29:12 +02:00
|
|
|
|
2022-09-18 17:12:38 -04:00
|
|
|
dev->regs[0x70] &= 0xef; /* Forcibly unlock the SMRAM register. */
|
2020-06-12 23:29:12 +02:00
|
|
|
dev->smram_locked = 0;
|
2023-06-26 22:31:03 -04:00
|
|
|
i420ex_write(0, 0x70, 0x00, priv);
|
2020-06-12 23:29:12 +02:00
|
|
|
|
|
|
|
|
mem_set_mem_state(0x000a0000, 0x00060000, MEM_READ_EXTANY | MEM_WRITE_EXTANY);
|
|
|
|
|
mem_set_mem_state_smm(0x000a0000, 0x00060000, MEM_READ_EXTANY | MEM_WRITE_EXTANY);
|
|
|
|
|
|
2023-06-26 22:31:03 -04:00
|
|
|
i420ex_write(0, 0xa0, 0x08, priv);
|
|
|
|
|
i420ex_write(0, 0xa2, 0x00, priv);
|
|
|
|
|
i420ex_write(0, 0xa4, 0x00, priv);
|
|
|
|
|
i420ex_write(0, 0xa5, 0x00, priv);
|
|
|
|
|
i420ex_write(0, 0xa6, 0x00, priv);
|
|
|
|
|
i420ex_write(0, 0xa7, 0x00, priv);
|
|
|
|
|
i420ex_write(0, 0xa8, 0x0f, priv);
|
2020-06-12 23:29:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2023-06-26 22:31:03 -04:00
|
|
|
i420ex_close(void *priv)
|
2020-06-12 23:29:12 +02:00
|
|
|
{
|
2023-06-26 22:31:03 -04:00
|
|
|
i420ex_t *dev = (i420ex_t *) priv;
|
2020-06-12 23:29:12 +02:00
|
|
|
|
PIC rewrite, proper SMRAM API, complete SiS 471 rewrite and addition of 40x, 460, and 461, changes to mem.c/h, disabled Voodoo memory dumping on exit, bumped SDL Hardware scale quality to 2, bumped IDE/ATAPI drives to ATA-6, finally bumped emulator version to 3.0, redid the bus type ID's to allow for planned ATAPI hard disks, made SST flash set its high mappings to the correct address if the CPU is 16-bit, and added the SiS 401 AMI 486 Clone, AOpen Vi15G, and the Soyo 4SA2 (486 with SiS 496/497 that can boot from CD-ROM), assorted 286+ protected mode fixes (for slightly more accuracy), and fixes to 808x emulation (MS Word 1.0 and 1.10 for DOS now work correctly from floppy).
2020-10-14 23:15:01 +02:00
|
|
|
smram_del(dev->smram);
|
|
|
|
|
|
2020-06-12 23:29:12 +02:00
|
|
|
free(dev);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
i420ex_speed_changed(void *priv)
|
|
|
|
|
{
|
|
|
|
|
i420ex_t *dev = (i420ex_t *) priv;
|
2022-09-18 17:12:38 -04:00
|
|
|
int te;
|
2020-06-12 23:29:12 +02:00
|
|
|
|
|
|
|
|
te = timer_is_enabled(&dev->timer);
|
|
|
|
|
|
|
|
|
|
timer_disable(&dev->timer);
|
|
|
|
|
if (te)
|
2022-09-18 17:12:38 -04:00
|
|
|
timer_set_delay_u64(&dev->timer, ((uint64_t) dev->timer_latch) * TIMER_USEC);
|
2020-06-12 23:29:12 +02:00
|
|
|
|
2023-08-19 05:26:49 +02:00
|
|
|
te = timer_is_on(&dev->fast_off_timer);
|
2020-06-12 23:29:12 +02:00
|
|
|
|
2021-06-06 23:59:05 +02:00
|
|
|
timer_stop(&dev->fast_off_timer);
|
|
|
|
|
if (te)
|
2022-09-18 17:12:38 -04:00
|
|
|
timer_on_auto(&dev->fast_off_timer, dev->fast_off_period);
|
2020-06-12 23:29:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void *
|
|
|
|
|
i420ex_init(const device_t *info)
|
|
|
|
|
{
|
|
|
|
|
i420ex_t *dev = (i420ex_t *) malloc(sizeof(i420ex_t));
|
|
|
|
|
memset(dev, 0, sizeof(i420ex_t));
|
|
|
|
|
|
PIC rewrite, proper SMRAM API, complete SiS 471 rewrite and addition of 40x, 460, and 461, changes to mem.c/h, disabled Voodoo memory dumping on exit, bumped SDL Hardware scale quality to 2, bumped IDE/ATAPI drives to ATA-6, finally bumped emulator version to 3.0, redid the bus type ID's to allow for planned ATAPI hard disks, made SST flash set its high mappings to the correct address if the CPU is 16-bit, and added the SiS 401 AMI 486 Clone, AOpen Vi15G, and the Soyo 4SA2 (486 with SiS 496/497 that can boot from CD-ROM), assorted 286+ protected mode fixes (for slightly more accuracy), and fixes to 808x emulation (MS Word 1.0 and 1.10 for DOS now work correctly from floppy).
2020-10-14 23:15:01 +02:00
|
|
|
dev->smram = smram_add();
|
|
|
|
|
|
2023-08-07 03:04:52 +02:00
|
|
|
pci_add_card(PCI_ADD_NORTHBRIDGE, i420ex_read, i420ex_write, dev, &dev->pci_slot);
|
2020-06-12 23:29:12 +02:00
|
|
|
|
2021-06-06 23:59:05 +02:00
|
|
|
dev->has_ide = info->local;
|
2020-06-12 23:29:12 +02:00
|
|
|
|
|
|
|
|
timer_add(&dev->fast_off_timer, i420ex_fast_off_count, dev, 0);
|
|
|
|
|
|
|
|
|
|
cpu_fast_off_flags = 0x00000000;
|
|
|
|
|
|
2022-09-18 17:12:38 -04:00
|
|
|
cpu_fast_off_val = dev->regs[0xa8];
|
2020-06-12 23:29:12 +02:00
|
|
|
cpu_fast_off_count = cpu_fast_off_val + 1;
|
|
|
|
|
|
2022-07-16 03:21:09 +02:00
|
|
|
cpu_register_fast_off_handler(&dev->fast_off_timer);
|
|
|
|
|
|
2020-06-12 23:29:12 +02:00
|
|
|
dev->apm = device_add(&apm_pci_device);
|
|
|
|
|
/* APM intercept handler to update 82420EX SMI status on APM SMI. */
|
|
|
|
|
io_sethandler(0x00b2, 0x0001, NULL, NULL, NULL, i420ex_apm_out, NULL, NULL, dev);
|
|
|
|
|
|
|
|
|
|
dev->port_92 = device_add(&port_92_pci_device);
|
|
|
|
|
|
|
|
|
|
dma_alias_set();
|
|
|
|
|
|
|
|
|
|
device_add(&ide_pci_2ch_device);
|
2021-06-06 23:59:05 +02:00
|
|
|
|
2023-07-12 00:32:21 +02:00
|
|
|
#ifndef USE_DRB_HACK
|
|
|
|
|
row_device.local = 4 | (1 << 8) | (0x01 << 16) | (8 << 24);
|
|
|
|
|
device_add((const device_t *) &row_device);
|
|
|
|
|
#endif
|
|
|
|
|
|
2021-06-06 23:59:05 +02:00
|
|
|
i420ex_reset_hard(dev);
|
2020-06-12 23:29:12 +02:00
|
|
|
|
|
|
|
|
return dev;
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-13 09:21:08 -04:00
|
|
|
const device_t i420ex_device = {
|
2022-09-18 17:12:38 -04:00
|
|
|
.name = "Intel 82420EX",
|
2022-03-13 09:21:08 -04:00
|
|
|
.internal_name = "i420ex",
|
2022-09-18 17:12:38 -04:00
|
|
|
.flags = DEVICE_PCI,
|
|
|
|
|
.local = 0x00,
|
|
|
|
|
.init = i420ex_init,
|
|
|
|
|
.close = i420ex_close,
|
|
|
|
|
.reset = i420ex_reset,
|
2022-03-13 09:21:08 -04:00
|
|
|
{ .available = NULL },
|
|
|
|
|
.speed_changed = i420ex_speed_changed,
|
2022-09-18 17:12:38 -04:00
|
|
|
.force_redraw = NULL,
|
|
|
|
|
.config = NULL
|
2020-06-12 23:29:12 +02:00
|
|
|
};
|
2021-06-06 23:59:05 +02:00
|
|
|
|
2022-03-13 09:21:08 -04:00
|
|
|
const device_t i420ex_ide_device = {
|
2022-09-18 17:12:38 -04:00
|
|
|
.name = "Intel 82420EX (With IDE)",
|
2022-03-13 09:21:08 -04:00
|
|
|
.internal_name = "i420ex_ide",
|
2022-09-18 17:12:38 -04:00
|
|
|
.flags = DEVICE_PCI,
|
|
|
|
|
.local = 0x01,
|
|
|
|
|
.init = i420ex_init,
|
|
|
|
|
.close = i420ex_close,
|
|
|
|
|
.reset = i420ex_reset,
|
2022-03-13 09:21:08 -04:00
|
|
|
{ .available = NULL },
|
|
|
|
|
.speed_changed = i420ex_speed_changed,
|
2022-09-18 17:12:38 -04:00
|
|
|
.force_redraw = NULL,
|
|
|
|
|
.config = NULL
|
2021-06-06 23:59:05 +02:00
|
|
|
};
|