From 600bb09f172bb1c0fc109030136c8eac1e7432e9 Mon Sep 17 00:00:00 2001 From: OBattler Date: Sat, 18 Apr 2020 18:03:02 +0200 Subject: [PATCH] Added PS/2 Intel AMI keyboard controller type that always returns bit 6 of the input port as 1, fixes Intel Advanced/EV and Advanced/ZP SMM errors (with high-low beeps), and also IDE not found error behavior to fix IDE with some i686 BIOS'es. --- src/cpu_common/386_common.c | 7 ------- src/cpu_common/cpu.c | 3 ++- src/cpu_common/x86_ops_misc.h | 2 +- src/disk/hdc_ide.c | 15 +++++++------- src/include/86box/keyboard.h | 1 + src/intel_piix.c | 37 ++++++++++++++++------------------- src/keyboard_at.c | 30 ++++++++++++++++++++++------ src/machine/m_at_socket4_5.c | 4 ++-- src/win/win_crashdump.c | 2 +- 9 files changed, 56 insertions(+), 45 deletions(-) diff --git a/src/cpu_common/386_common.c b/src/cpu_common/386_common.c index d11257cce..c8b065c2a 100644 --- a/src/cpu_common/386_common.c +++ b/src/cpu_common/386_common.c @@ -1100,9 +1100,6 @@ enter_smm(int in_hlt) smm_in_hlt = in_hlt; CPU_BLOCK_END(); - - // if (smbase == 0x000a0000) - // leave_smm(); } @@ -1161,10 +1158,6 @@ leave_smm(void) else if (is_p6) /* Intel P6 (Pentium Pro, Pentium II, Celeron) */ smram_restore_state_p6(saved_state); - /* Maybe we need this? */ - // if (smbase == 0x00030000) - // smbase = 0x000a0000; - in_smm = 0; mem_mapping_recalc(0x00030000, 0x00020000); mem_mapping_recalc(0x000a0000, 0x00060000); diff --git a/src/cpu_common/cpu.c b/src/cpu_common/cpu.c index 5005fd5e4..bff70e6b1 100644 --- a/src/cpu_common/cpu.c +++ b/src/cpu_common/cpu.c @@ -2377,7 +2377,6 @@ void cpu_ven_reset(void) void cpu_RDMSR() { - cpu_log("RDMSR %08X\n", ECX); switch (machines[machine].cpu[cpu_manufacturer].cpus[cpu_effective].cpu_type) { case CPU_WINCHIP: @@ -2850,6 +2849,8 @@ i686_invalid_rdmsr: } break; } + + cpu_log("RDMSR %08X %08X%08X\n", ECX, EDX, EAX); } void cpu_WRMSR() diff --git a/src/cpu_common/x86_ops_misc.h b/src/cpu_common/x86_ops_misc.h index 16a628fd1..8f23e503a 100644 --- a/src/cpu_common/x86_ops_misc.h +++ b/src/cpu_common/x86_ops_misc.h @@ -625,7 +625,7 @@ static int opHLT(uint32_t fetchdat) CPU_BLOCK_END(); PREFETCH_RUN(100, 1, -1, 0,0,0,0, 0); - + return 0; } diff --git a/src/disk/hdc_ide.c b/src/disk/hdc_ide.c index 374f9d0c5..4b2e46b13 100644 --- a/src/disk/hdc_ide.c +++ b/src/disk/hdc_ide.c @@ -671,8 +671,8 @@ loadhd(ide_t *ide, int d, const wchar_t *fn) return; } - ide->spt = hdd[d].spt; - ide->hpc = hdd[d].hpc; + ide->spt = ide->cfg_spt = hdd[d].spt; + ide->hpc = ide->cfg_hpc = hdd[d].hpc; ide->tracks = hdd[d].tracks; ide->type = IDE_HDD; ide->hdd_num = d; @@ -1183,7 +1183,7 @@ ide_writew(uint16_t addr, uint16_t val, void *priv) ch = dev->cur_dev; ide = ide_drives[ch]; - /* ide_log("ide_writew %04X %04X from %04X(%08X):%08X\n", addr, val, CS, cs, cpu_state.pc); */ + ide_log("ide_writew %04X %04X from %04X(%08X):%08X\n", addr, val, CS, cs, cpu_state.pc); addr &= 0x7; @@ -1216,7 +1216,7 @@ ide_writel(uint16_t addr, uint32_t val, void *priv) ch = dev->cur_dev; ide = ide_drives[ch]; - /* ide_log("ide_writel %04X %08X from %04X(%08X):%08X\n", addr, val, CS, cs, cpu_state.pc); */ + ide_log("ide_writel %04X %08X from %04X(%08X):%08X\n", addr, val, CS, cs, cpu_state.pc); addr &= 0x7; @@ -1905,7 +1905,7 @@ ide_readw(uint16_t addr, void *priv) break; } - /* ide_log("ide_readw(%04X, %08X) = %04X\n", addr, priv, temp); */ + ide_log("ide_readw(%04X, %08X) = %04X\n", addr, priv, temp); return temp; } @@ -1940,7 +1940,7 @@ ide_readl(uint16_t addr, void *priv) break; } - /* ide_log("ide_readl(%04X, %08X) = %04X\n", addr, priv, temp); */ + ide_log("ide_readl(%04X, %08X) = %04X\n", addr, priv, temp); return temp; } @@ -2596,7 +2596,8 @@ ide_board_setup(int board) dev->mdma_mode = (1 << ide_get_max(dev, TYPE_PIO)); dev->error = 1; - dev->cfg_spt = dev->cfg_hpc = 0; + if (dev->type != IDE_HDD) + dev->cfg_spt = dev->cfg_hpc = 0; } } diff --git a/src/include/86box/keyboard.h b/src/include/86box/keyboard.h index 429e14712..d90fff256 100644 --- a/src/include/86box/keyboard.h +++ b/src/include/86box/keyboard.h @@ -81,6 +81,7 @@ extern const device_t keyboard_ps2_mca_2_device; extern const device_t keyboard_ps2_quadtel_device; extern const device_t keyboard_ps2_pci_device; extern const device_t keyboard_ps2_ami_pci_device; +extern const device_t keyboard_ps2_intel_ami_pci_device; #endif extern void keyboard_init(void); diff --git a/src/intel_piix.c b/src/intel_piix.c index ebd3d83ff..8e83e0f0e 100644 --- a/src/intel_piix.c +++ b/src/intel_piix.c @@ -1371,8 +1371,6 @@ piix_close(void *p) static void *piix_init(const device_t *info) { - CPU *cpu_s = &machines[machine].cpu[cpu_manufacturer].cpus[cpu]; - piix_t *dev = (piix_t *) malloc(sizeof(piix_t)); memset(dev, 0, sizeof(piix_t)); @@ -1443,13 +1441,13 @@ static void 1000 = 150 MHz, 1010 = 200 MHz, 1100 = 180 MHz, 1110 = ??? MHz; 1001 = 75 MHz, 1011 = 100 MHz, 1101 = 90 MHz, 1111 = ??? MHz */ - if (cpu_busspeed <= 0x40000000) + if (cpu_busspeed <= 40000000) dev->readout_regs[1] |= 0x30; - else if ((cpu_busspeed > 0x40000000) && (cpu_busspeed <= 0x50000000)) + else if ((cpu_busspeed > 40000000) && (cpu_busspeed <= 50000000)) dev->readout_regs[1] |= 0x00; - else if ((cpu_busspeed > 0x50000000) && (cpu_busspeed <= 0x60000000)) + else if ((cpu_busspeed > 50000000) && (cpu_busspeed <= 60000000)) dev->readout_regs[1] |= 0x20; - else if (cpu_busspeed > 0x60000000) + else if (cpu_busspeed > 60000000) dev->readout_regs[1] |= 0x10; if (cpu_dmulti <= 1.5) @@ -1467,7 +1465,7 @@ static void dev->board_config[0] = 0xff; dev->board_config[0] = 0x00; /* Register 0x0079: */ - /* Bit 7: 0 = Keep password, 0 = Clear password. */ + /* Bit 7: 0 = Clear password, 1 = Keep password. */ /* Bit 6: 0 = NVRAM cleared by jumper, 1 = NVRAM normal. */ /* Bit 5: 0 = CMOS Setup disabled, 1 = CMOS Setup enabled. */ /* Bit 4: External CPU clock (Switch 8). */ @@ -1476,22 +1474,21 @@ static void /* 60 MHz: Switch 7 = On, Switch 8 = Off. */ /* 66 MHz: Switch 7 = Off, Switch 8 = On. */ /* Bit 2: 0 = On-board audio absent, 1 = On-board audio present. */ - /* Bit 0: 0 = 1.5x multiplier, 0 = 2x multiplier. */ + /* Bit 0: 0 = 1.5x multiplier, 1 = 2x multiplier (Switch 6). */ + /* NOTE: A bit is read as 1 if switch is off, and as 0 if switch is on. */ dev->board_config[1] = 0xe0; - if ((cpu_s->rspeed == 75000000) && (cpu_busspeed == 50000000)) + + if (cpu_busspeed <= 50000000) + dev->board_config[1] |= 0x10; + else if ((cpu_busspeed > 50000000) && (cpu_busspeed <= 60000000)) + dev->board_config[1] |= 0x18; + else if (cpu_busspeed > 60000000) + dev->board_config[1] |= 0x00; + + if (cpu_dmulti <= 1.5) dev->board_config[1] |= 0x01; - else if ((cpu_s->rspeed == 90000000) && (cpu_busspeed == 60000000)) - dev->board_config[1] |= (0x01 | 0x08); - else if ((cpu_s->rspeed == 100000000) && (cpu_busspeed == 50000000)) - dev->board_config[1] |= 0x00; - else if ((cpu_s->rspeed == 100000000) && (cpu_busspeed == 66666666)) - dev->board_config[1] |= (0x01 | 0x10); - else if ((cpu_s->rspeed == 120000000) && (cpu_busspeed == 60000000)) - dev->board_config[1] |= 0x08; - else if ((cpu_s->rspeed == 133333333) && (cpu_busspeed == 66666666)) - dev->board_config[1] |= 0x10; else - dev->board_config[1] |= 0x10; /* TODO: how are the overdrive processors configured? */ + dev->board_config[1] |= 0x00; return dev; } diff --git a/src/keyboard_at.c b/src/keyboard_at.c index a24c1fea2..dc2a01378 100644 --- a/src/keyboard_at.c +++ b/src/keyboard_at.c @@ -85,7 +85,8 @@ #define KBC_VEN_XI8088 0x14 #define KBC_VEN_IBM_PS1 0x18 #define KBC_VEN_ACER 0x1c -#define KBC_VEN_MASK 0x1c +#define KBC_VEN_INTEL_AMI 0x20 +#define KBC_VEN_MASK 0x3c typedef struct { @@ -1074,6 +1075,7 @@ write_cmd(atkbd_t *dev, uint8_t val) /* ISA AT keyboard controllers use bit 5 for keyboard mode (1 = PC/XT, 2 = AT); PS/2 (and EISA/PCI) keyboard controllers use it as the PS/2 mouse enable switch. */ if (((dev->flags & KBC_VEN_MASK) == KBC_VEN_AMI) || + ((dev->flags & KBC_VEN_MASK) == KBC_VEN_INTEL_AMI) || ((dev->flags & KBC_TYPE_MASK) >= KBC_TYPE_PS2_NOREF)) { keyboard_mode &= ~CCB_PCMODE; @@ -1133,7 +1135,7 @@ static uint8_t write64_generic(void *priv, uint8_t val) { atkbd_t *dev = (atkbd_t *)priv; - uint8_t current_drive; + uint8_t current_drive, fixed_bits; switch (val) { case 0xa4: /* check if password installed */ @@ -1206,17 +1208,21 @@ write64_generic(void *priv, uint8_t val) #ifdef ENABLE_KEYBOARD_AT_LOG kbd_log("ATkbd: read input port\n"); #endif + fixed_bits = 4; + /* The SMM handlers of Intel AMI Pentium BIOS'es expect bit 6 to be set. */ + if ((dev->flags & KBC_VEN_MASK) == KBC_VEN_INTEL_AMI) + fixed_bits |= 0x40; if ((dev->flags & KBC_VEN_MASK) == KBC_VEN_IBM_PS1) { current_drive = fdc_get_current_drive(); - add_data(dev, dev->input_port | 4 | (fdd_is_525(current_drive) ? 0x40 : 0x00)); + add_data(dev, dev->input_port | fixed_bits | (fdd_is_525(current_drive) ? 0x40 : 0x00)); dev->input_port = ((dev->input_port + 1) & 3) | (dev->input_port & 0xfc) | (fdd_is_525(current_drive) ? 0x40 : 0x00); } else { if ((dev->flags & KBC_TYPE_MASK) >= KBC_TYPE_PS2_NOREF) - add_data(dev, (dev->input_port | 4) & 0xef); + add_data(dev, (dev->input_port | fixed_bits) & 0xef); else - add_data(dev, dev->input_port | 4); + add_data(dev, dev->input_port | fixed_bits); dev->input_port = ((dev->input_port + 1) & 3) | (dev->input_port & 0xfc); } @@ -1774,7 +1780,8 @@ kbd_write(uint16_t port, uint8_t val, void *priv) if (mouse_write && ((dev->flags & KBC_TYPE_MASK) >= KBC_TYPE_PS2_NOREF)) mouse_write(val, mouse_p); else if (!mouse_write && ((dev->flags & KBC_TYPE_MASK) >= KBC_TYPE_PS2_NOREF) && - ((dev->flags & KBC_VEN_MASK) == KBC_VEN_AMI)) + (((dev->flags & KBC_VEN_MASK) == KBC_VEN_AMI) || + ((dev->flags & KBC_VEN_MASK) == KBC_VEN_INTEL_AMI))) keyboard_at_adddata_mouse(0xff); break; @@ -2413,6 +2420,7 @@ kbd_init(const device_t *info) break; case KBC_VEN_AMI: + case KBC_VEN_INTEL_AMI: dev->write60_ven = write60_ami; dev->write64_ven = write64_ami; break; @@ -2574,6 +2582,16 @@ const device_t keyboard_ps2_ami_pci_device = { NULL, NULL, NULL }; +const device_t keyboard_ps2_intel_ami_pci_device = { + "PS/2 Keyboard (AMI)", + DEVICE_PCI, + KBC_TYPE_PS2_NOREF | KBC_VEN_INTEL_AMI, + kbd_init, + kbd_close, + kbd_reset, + NULL, NULL, NULL +}; + const device_t keyboard_ps2_acer_device = { "PS/2 Keyboard (Acer 90M002A)", DEVICE_PCI, diff --git a/src/machine/m_at_socket4_5.c b/src/machine/m_at_socket4_5.c index aa32c2fc6..b86c3fe4b 100644 --- a/src/machine/m_at_socket4_5.c +++ b/src/machine/m_at_socket4_5.c @@ -278,7 +278,7 @@ machine_at_endeavor_init(const machine_t *model) if (gfxcard == VID_INTERNAL) device_add(&s3_phoenix_trio64_onboard_pci_device); - device_add(&keyboard_ps2_ami_pci_device); + device_add(&keyboard_ps2_intel_ami_pci_device); device_add(&i430fx_device); device_add(&piix_device); device_add(&pc87306_device); @@ -314,7 +314,7 @@ machine_at_zappa_init(const machine_t *model) pci_register_slot(0x0E, PCI_CARD_NORMAL, 3, 4, 1, 2); pci_register_slot(0x0F, PCI_CARD_NORMAL, 2, 3, 4, 1); pci_register_slot(0x07, PCI_CARD_SOUTHBRIDGE, 0, 0, 0, 0); - device_add(&keyboard_ps2_ami_pci_device); + device_add(&keyboard_ps2_intel_ami_pci_device); device_add(&i430fx_device); device_add(&piix_device); device_add(&pc87306_device); diff --git a/src/win/win_crashdump.c b/src/win/win_crashdump.c index 6ca80963d..e1123c1e5 100644 --- a/src/win/win_crashdump.c +++ b/src/win/win_crashdump.c @@ -145,7 +145,7 @@ LONG CALLBACK MakeCrashDump(PEXCEPTION_POINTERS ExceptionInfo) hMods[i], &modInfo, sizeof(MODULEINFO)); /* If the exception address is in the range of this module.. */ if ( (ExceptionInfo->ExceptionRecord->ExceptionAddress >= modInfo.lpBaseOfDll) && - (ExceptionInfo->ExceptionRecord->ExceptionAddress < (modInfo.lpBaseOfDll + modInfo.SizeOfImage))) { + (ExceptionInfo->ExceptionRecord->ExceptionAddress < (void*)((char*)modInfo.lpBaseOfDll + modInfo.SizeOfImage))) { /* ...this is the module we're looking for! */ ipModule = hMods[i]; break;