From 2ed8ad907c27cc8248fd94819b146150fa50db46 Mon Sep 17 00:00:00 2001 From: Adrien Moulin Date: Fri, 15 Jul 2022 23:42:40 +0200 Subject: [PATCH 01/28] ACPI: replace 3.58MHz timer with an overflow timer --- src/acpi.c | 95 ++++++++++++++++++++++++---------------- src/include/86box/acpi.h | 3 +- src/include/86box/pit.h | 2 +- src/pit.c | 1 - 4 files changed, 60 insertions(+), 41 deletions(-) diff --git a/src/acpi.c b/src/acpi.c index 11d991f63..c73440fa5 100644 --- a/src/acpi.c +++ b/src/acpi.c @@ -20,6 +20,7 @@ #include #include #include +#include #define HAVE_STDARG_H #include <86box/86box.h> #include "cpu.h" @@ -37,10 +38,11 @@ #include <86box/acpi.h> #include <86box/machine.h> #include <86box/i2c.h> - +#include <86box/video.h> int acpi_rtc_status = 0; +static double cpu_to_acpi; #ifdef ENABLE_ACPI_LOG int acpi_do_log = ENABLE_ACPI_LOG; @@ -61,6 +63,50 @@ acpi_log(const char *fmt, ...) #define acpi_log(fmt, ...) #endif +static uint64_t acpi_clock_get() { + return tsc * cpu_to_acpi; +} + +static uint32_t acpi_timer_get(acpi_t *dev) { + uint64_t clock = acpi_clock_get(); + if (dev->regs.timer32) + return clock & 0xffffffff; + else + return clock & 0xffffff; +} + +static double acpi_get_overflow_period(acpi_t *dev) { + uint64_t timer = acpi_clock_get(); + uint64_t overflow_time; + + if (dev->regs.timer32) { + overflow_time = (timer + 0x80000000LL) & ~0x7fffffffLL; + } else { + overflow_time = (timer + 0x800000LL) & ~0x7fffffLL; + } + + uint64_t time_to_overflow = overflow_time - timer; + + return ((double)time_to_overflow / (double)ACPI_TIMER_FREQ) * 1000000.0; +} + +static void +acpi_timer_overflow(void *priv) +{ + acpi_t *dev = (acpi_t *) priv; + dev->regs.pmsts |= TMROF_STS; + acpi_update_irq(dev); +} + +static void +acpi_timer_update(acpi_t *dev, bool enable) +{ + if (enable) { + timer_on_auto(&dev->timer, acpi_get_overflow_period(dev)); + } else { + timer_stop(&dev->timer); + } +} void acpi_update_irq(acpi_t *dev) @@ -84,6 +130,8 @@ acpi_update_irq(acpi_t *dev) else pci_clear_mirq(0xf0 | dev->irq_line, 1); } + + acpi_timer_update(dev, (dev->regs.pmen & TMROF_EN) && !(dev->regs.pmsts & TMROF_STS)); } @@ -145,7 +193,7 @@ acpi_reg_read_common_regs(int size, uint16_t addr, void *p) break; case 0x08: case 0x09: case 0x0a: case 0x0b: /* PMTMR - Power Management Timer Register (IO) */ - ret = (dev->regs.timer_val >> shift32) & 0xff; + ret = (acpi_timer_get(dev) >> shift32) & 0xff; #ifdef USE_DYNAREC if (cpu_use_dynarec) update_tsc(); @@ -1282,33 +1330,6 @@ acpi_update_aux_io_mapping(acpi_t *dev, uint32_t base, int chipset_en) } } - -static void -acpi_timer_count(void *priv) -{ - acpi_t *dev = (acpi_t *) priv; - int overflow; - uint32_t old; - - old = dev->regs.timer_val; - dev->regs.timer_val++; - - if (dev->regs.timer32) - overflow = (old ^ dev->regs.timer_val) & 0x80000000; - else { - dev->regs.timer_val &= 0x00ffffff; - overflow = (old ^ dev->regs.timer_val) & 0x00800000; - } - - if (overflow) { - dev->regs.pmsts |= TMROF_EN; - acpi_update_irq(dev); - } - - timer_advance_u64(&dev->timer, ACPICONST); -} - - static void acpi_timer_resume(void *priv) { @@ -1338,9 +1359,6 @@ void acpi_set_timer32(acpi_t *dev, uint8_t timer32) { dev->regs.timer32 = timer32; - - if (!dev->regs.timer32) - dev->regs.timer_val &= 0x00ffffff; } @@ -1524,9 +1542,12 @@ static void acpi_speed_changed(void *priv) { acpi_t *dev = (acpi_t *) priv; + cpu_to_acpi = ACPI_TIMER_FREQ / cpuclock; + bool timer_enabled = timer_is_enabled(&dev->timer); + timer_stop(&dev->timer); - timer_disable(&dev->timer); - timer_set_delay_u64(&dev->timer, ACPICONST); + if (timer_enabled) + timer_on_auto(&dev->timer, acpi_get_overflow_period(dev)); } @@ -1541,7 +1562,7 @@ acpi_close(void *priv) i2c_gpio_close(dev->i2c); } - timer_disable(&dev->timer); + timer_stop(&dev->timer); free(dev); } @@ -1556,6 +1577,7 @@ acpi_init(const device_t *info) if (dev == NULL) return(NULL); memset(dev, 0x00, sizeof(acpi_t)); + cpu_to_acpi = ACPI_TIMER_FREQ / cpuclock; dev->vendor = info->local; dev->irq_line = 9; @@ -1604,8 +1626,7 @@ acpi_init(const device_t *info) break; } - timer_add(&dev->timer, acpi_timer_count, dev, 0); - timer_set_delay_u64(&dev->timer, ACPICONST); + timer_add(&dev->timer, acpi_timer_overflow, dev, 0); timer_add(&dev->resume_timer, acpi_timer_resume, dev, 0); acpi_reset(dev); diff --git a/src/include/86box/acpi.h b/src/include/86box/acpi.h index 999909f1d..d12b45507 100644 --- a/src/include/86box/acpi.h +++ b/src/include/86box/acpi.h @@ -76,10 +76,9 @@ typedef struct devsts, glben, glbctl, devctl, padsts, paden, - gptren, gptimer, timer_val, + gptren, gptimer, gpo_val, gpi_val, extsmi_val, pad0; - uint64_t tmr_overflow_time; } acpi_regs_t; diff --git a/src/include/86box/pit.h b/src/include/86box/pit.h index c560fae12..e823794df 100644 --- a/src/include/86box/pit.h +++ b/src/include/86box/pit.h @@ -70,7 +70,7 @@ extern uint64_t PITCONST, ISACONST, HERCCONST, VGACONST1, VGACONST2, - RTCCONST, ACPICONST; + RTCCONST; extern int refresh_at_enable; diff --git a/src/pit.c b/src/pit.c index 28fc9b3c2..f19a1acf7 100644 --- a/src/pit.c +++ b/src/pit.c @@ -1039,7 +1039,6 @@ pit_set_clock(int clock) VGACONST1 = (uint64_t) (cpuclock / 25175000.0 * (double)(1ull << 32)); VGACONST2 = (uint64_t) (cpuclock / 28322000.0 * (double)(1ull << 32)); RTCCONST = (uint64_t) (cpuclock / 32768.0 * (double)(1ull << 32)); - ACPICONST = (uint64_t) (cpuclock / 3579545.0 * (double)(1ull << 32)); TIMER_USEC = (uint64_t)((cpuclock / 1000000.0) * (double)(1ull << 32)); From a8be5d1f188768bf7e09afc120a8a764345237e8 Mon Sep 17 00:00:00 2001 From: richardg867 Date: Fri, 15 Jul 2022 20:39:06 -0300 Subject: [PATCH 02/28] Jenkins: Dummy commit to test new webhook flow --- .ci/Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.ci/Jenkinsfile b/.ci/Jenkinsfile index fbb7fd081..55c2c254e 100644 --- a/.ci/Jenkinsfile +++ b/.ci/Jenkinsfile @@ -137,7 +137,7 @@ def removeDir(dir) { def runBuild(args) { if (isUnix()) - return sh(returnStatus: true, script: "chmod u+x \"$WORKSPACE/.ci/build.sh\" && exec \"$WORKSPACE/.ci/build.sh\" $args") + return sh(returnStatus: true, script: "chmod u+x '$WORKSPACE/.ci/build.sh' && exec '$WORKSPACE/.ci/build.sh' $args") else return bat(returnStatus: true, script: "C:\\msys64\\msys2_shell.cmd -msys2 -defterm -here -no-start -c 'exec \"\$(cygpath -u \\'%WORKSPACE%\\')/.ci/build.sh\" $args'") } From e9af11d9d9c439e9e0af049aeaac46ce89f6fa37 Mon Sep 17 00:00:00 2001 From: richardg867 Date: Fri, 15 Jul 2022 20:39:18 -0300 Subject: [PATCH 03/28] Jenkins: Second dummy commit to test new webhook flow --- .ci/Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.ci/Jenkinsfile b/.ci/Jenkinsfile index 55c2c254e..cb58e1fd8 100644 --- a/.ci/Jenkinsfile +++ b/.ci/Jenkinsfile @@ -130,7 +130,7 @@ def gitClone(repository, branch) { def removeDir(dir) { if (isUnix()) - return sh(returnStatus: true, script: "rm -rf \"$dir\"") + return sh(returnStatus: true, script: "rm -rf '$dir'") else return bat(returnStatus: true, script: "rd /s /q \"$dir\"") } From da5d45138684dcec616086a96a7b7e3c4ed536ba Mon Sep 17 00:00:00 2001 From: OBattler Date: Sat, 16 Jul 2022 02:45:46 +0200 Subject: [PATCH 04/28] Preparation for SMI# and NMI# changes. --- src/cpu/386.c | 3 --- src/cpu/386_common.c | 21 ++++++++++++++++++--- src/cpu/386_dynarec.c | 3 --- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/cpu/386.c b/src/cpu/386.c index 2484cbb66..5f30e1199 100644 --- a/src/cpu/386.c +++ b/src/cpu/386.c @@ -210,9 +210,6 @@ exec386(int cycs) loadcs(readmemw(0, addr + 2)); } } else if (nmi && nmi_enable && nmi_mask) { - if (is486 && (cpu_fast_off_flags & 0x20000000)) - cpu_fast_off_count = cpu_fast_off_val + 1; - cpu_state.oldpc = cpu_state.pc; x86_int(2); nmi_enable = 0; diff --git a/src/cpu/386_common.c b/src/cpu/386_common.c index 73a06f553..a88f892e1 100644 --- a/src/cpu/386_common.c +++ b/src/cpu/386_common.c @@ -1183,9 +1183,6 @@ enter_smm(int in_hlt) void enter_smm_check(int in_hlt) { - if (smi_line && (cpu_fast_off_flags & 0x80000000)) - cpu_fast_off_count = cpu_fast_off_val + 1; - if ((in_smm == 0) && smi_line) { #ifdef ENABLE_386_COMMON_LOG x386_common_log("SMI while not in SMM\n"); @@ -1840,6 +1837,24 @@ sysret(uint32_t fetchdat) } +void +raise_smi(void) +{ + if (is486 && (cpu_fast_off_flags & 0x80000000)) + cpu_fast_off_count = cpu_fast_off_val + 1; + + smi_line = 1; +} + + +void +raise_nmi(void) +{ + if (is486 && (cpu_fast_off_flags & 0x20000000)) + cpu_fast_off_count = cpu_fast_off_val + 1; +} + + #ifndef USE_DYNAREC /* This is for compatibility with new x87 code. */ void codegen_set_rounding_mode(int mode) diff --git a/src/cpu/386_dynarec.c b/src/cpu/386_dynarec.c index 46674fbc6..3e4d91ed2 100644 --- a/src/cpu/386_dynarec.c +++ b/src/cpu/386_dynarec.c @@ -819,9 +819,6 @@ exec386_dynarec(int cycs) if (smi_line) enter_smm_check(0); else if (nmi && nmi_enable && nmi_mask) { - if (is486 && (cpu_fast_off_flags & 0x20000000)) - cpu_fast_off_count = cpu_fast_off_val + 1; - #ifndef USE_NEW_DYNAREC oldcs = CS; #endif From 2c9bfa979ffb235e4f9cf858c1fb5776be823c13 Mon Sep 17 00:00:00 2001 From: OBattler Date: Sat, 16 Jul 2022 02:47:39 +0200 Subject: [PATCH 05/28] ALi M1489 and a CPU fix. --- src/chipset/ali1489.c | 2 +- src/cpu/386_common.c | 4 ++-- src/cpu/cpu.h | 3 +++ 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/chipset/ali1489.c b/src/chipset/ali1489.c index 5ba53f34c..c8e07c657 100644 --- a/src/chipset/ali1489.c +++ b/src/chipset/ali1489.c @@ -319,7 +319,7 @@ ali1489_write(uint16_t addr, uint8_t val, void *priv) smi_line = 1; break; case 0x10: - nmi = 1; + nmi_raise(); break; case 0x20: picint(1 << 15); diff --git a/src/cpu/386_common.c b/src/cpu/386_common.c index a88f892e1..1f5bfe3b5 100644 --- a/src/cpu/386_common.c +++ b/src/cpu/386_common.c @@ -1838,7 +1838,7 @@ sysret(uint32_t fetchdat) void -raise_smi(void) +smi_raise(void) { if (is486 && (cpu_fast_off_flags & 0x80000000)) cpu_fast_off_count = cpu_fast_off_val + 1; @@ -1848,7 +1848,7 @@ raise_smi(void) void -raise_nmi(void) +nmi_raise(void) { if (is486 && (cpu_fast_off_flags & 0x20000000)) cpu_fast_off_count = cpu_fast_off_val + 1; diff --git a/src/cpu/cpu.h b/src/cpu/cpu.h index c140cb7db..136a6c834 100644 --- a/src/cpu/cpu.h +++ b/src/cpu/cpu.h @@ -733,4 +733,7 @@ extern uint8_t do_translate, do_translate2; extern void reset_808x(int hard); +extern void smi_raise(); +extern void nmi_raise(); + #endif /*EMU_CPU_H*/ From 0cea9de7df0debeecdfc0473796e912578ce9fc4 Mon Sep 17 00:00:00 2001 From: OBattler Date: Sat, 16 Jul 2022 02:48:59 +0200 Subject: [PATCH 06/28] VIA PIPC and ALi M1489 fix. --- src/chipset/ali1489.c | 2 ++ src/chipset/via_pipc.c | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/chipset/ali1489.c b/src/chipset/ali1489.c index c8e07c657..9738baed3 100644 --- a/src/chipset/ali1489.c +++ b/src/chipset/ali1489.c @@ -197,7 +197,9 @@ ali1489_defaults(ali1489_t *dev) picintc(1 << 10); picintc(1 << 15); +#ifdef OLD_NMI_BEHAVIOR nmi = 0; +#endif smi_line = 0; in_smm = 0; diff --git a/src/chipset/via_pipc.c b/src/chipset/via_pipc.c index 076328a00..a415daa6f 100644 --- a/src/chipset/via_pipc.c +++ b/src/chipset/via_pipc.c @@ -728,8 +728,10 @@ pipc_fmnmi_read(uint16_t addr, void *priv) if (dev->ac97_regs[0][0x48] & 0x01) { if (dev->ac97_regs[0][0x48] & 0x04) smi_line = 0; +#ifdef OLD_NMI_BEHAVIOR else nmi = 0; +#endif } #endif @@ -790,7 +792,7 @@ pipc_fm_write(uint16_t addr, uint8_t val, void *priv) if (dev->ac97_regs[0][0x48] & 0x04) smi_line = 1; else - nmi = 1; + nmi_raise(); } } #else From 22a856634c398d7f1b38982343d5d33a1327e638 Mon Sep 17 00:00:00 2001 From: OBattler Date: Sat, 16 Jul 2022 02:50:53 +0200 Subject: [PATCH 07/28] Amstrad. --- src/machine/m_amstrad.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/machine/m_amstrad.c b/src/machine/m_amstrad.c index 27244189d..cac5a29d2 100644 --- a/src/machine/m_amstrad.c +++ b/src/machine/m_amstrad.c @@ -1068,7 +1068,9 @@ vid_in_200(uint16_t addr, void *priv) case 0x03dd: ret = vid->crtc_index; /* Read NMI reason */ vid->crtc_index &= 0x1f; /* Reset NMI reason */ +#ifdef OLD_NMI_BEHAVIOR nmi = 0; /* And reset NMI flag */ +#endif return(ret); case 0x03de: @@ -1106,7 +1108,7 @@ vid_out_200(uint16_t addr, uint8_t val, void *priv) if (!(vid->operation_ctrl & 0x40) && mda->crtcreg <= 11) { vid->crtc_index = 0x20 | (mda->crtcreg & 0x1f); if (vid->operation_ctrl & 0x80) - nmi = 1; + nmi_raise(); vid->reg_3df = val; return; } @@ -1127,7 +1129,7 @@ vid_out_200(uint16_t addr, uint8_t val, void *priv) vid->crtc_index &= 0x1F; vid->crtc_index |= 0x80; if (vid->operation_ctrl & 0x80) - nmi = 1; + nmi_raise(); return; /* CGA writes ============================================================== */ @@ -1138,7 +1140,7 @@ vid_out_200(uint16_t addr, uint8_t val, void *priv) if (!(vid->operation_ctrl & 0x40) && cga->crtcreg <= 11) { vid->crtc_index = 0x20 | (cga->crtcreg & 0x1f); if (vid->operation_ctrl & 0x80) - nmi = 1; + nmi_raise(); vid->reg_3df = val; return; } @@ -1160,7 +1162,7 @@ vid_out_200(uint16_t addr, uint8_t val, void *priv) vid->crtc_index &= 0x1f; vid->crtc_index |= 0x80; if (vid->operation_ctrl & 0x80) - nmi = 1; + nmi_raise(); else set_lcd_cols(val); return; @@ -1174,7 +1176,7 @@ vid_out_200(uint16_t addr, uint8_t val, void *priv) if (val & 0x80) { vid->operation_ctrl = val; vid->crtc_index |= 0x40; - nmi = 1; + nmi_raise(); return; } timer_disable(&vid->cga.timer); From 49f4b2c8fb2c263f6863d27e0d2497c28134859b Mon Sep 17 00:00:00 2001 From: OBattler Date: Sat, 16 Jul 2022 02:52:50 +0200 Subject: [PATCH 08/28] AudioPCI and GUS. --- src/sound/snd_audiopci.c | 4 +++- src/sound/snd_gus.c | 12 +++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/sound/snd_audiopci.c b/src/sound/snd_audiopci.c index 251fda72f..fe00038c7 100644 --- a/src/sound/snd_audiopci.c +++ b/src/sound/snd_audiopci.c @@ -306,7 +306,9 @@ es1371_reset(void *p) es1371_t *dev = (es1371_t *) p; int i; +#ifdef OLD_NMI_BEHAVIOR nmi = 0; +#endif /* Interrupt/Chip Select Control Register, Address 00H Addressable as byte, word, longword */ @@ -1240,7 +1242,7 @@ capture_event(es1371_t *dev, int type, int rw, uint16_t port) dev->legacy_ctrl &= ~LEGACY_EVENT_TYPE_RW; dev->legacy_ctrl |= ((port << LEGACY_EVENT_ADDR_SHIFT) & LEGACY_EVENT_ADDR_MASK); dev->legacy_ctrl &= ~LEGACY_INT; - nmi = 1; + nmi_raise(); } static void diff --git a/src/sound/snd_gus.c b/src/sound/snd_gus.c index 293be8915..2bef7edac 100644 --- a/src/sound/snd_gus.c +++ b/src/sound/snd_gus.c @@ -452,11 +452,15 @@ writegus(uint16_t addr, uint8_t val, void *p) gus->irqstatus &= ~8; if (!(val & 0x20)) { gus->ad_status &= ~0x18; +#ifdef OLD_NMI_BEHAVIOR nmi = 0; +#endif } if (!(val & 0x02)) { gus->ad_status &= ~0x01; +#ifdef OLD_NMI_BEHAVIOR nmi = 0; +#endif } gus->tctrl = val; gus->sb_ctrl = val; @@ -492,7 +496,7 @@ writegus(uint16_t addr, uint8_t val, void *p) gus->ad_status |= 0x01; if (gus->sb_ctrl & 0x02) { if (gus->sb_nmi) - nmi = 1; + nmi_raise(); else if (gus->irq != -1) picint(1 << gus->irq); } @@ -568,7 +572,7 @@ writegus(uint16_t addr, uint8_t val, void *p) gus->ad_status |= 0x08; if (gus->sb_ctrl & 0x20) { if (gus->sb_nmi) - nmi = 1; + nmi_raise(); else if (gus->irq != -1) picint(1 << gus->irq); } @@ -580,7 +584,7 @@ writegus(uint16_t addr, uint8_t val, void *p) gus->ad_status |= 0x10; if (gus->sb_ctrl & 0x20) { if (gus->sb_nmi) - nmi = 1; + nmi_raise(); else if (gus->irq != -1) picint(1 << gus->irq); } @@ -832,7 +836,9 @@ readgus(uint16_t addr, void *p) case 0x209: gus->ad_status &= ~0x01; +#ifdef OLD_NMI_BEHAVIOR nmi = 0; +#endif /*FALLTHROUGH*/ case 0x389: val = gus->ad_data; From d12b8b8c30a3c25539f5f09a44c8351c8004a0ea Mon Sep 17 00:00:00 2001 From: OBattler Date: Sat, 16 Jul 2022 02:53:26 +0200 Subject: [PATCH 09/28] Sigma. --- src/video/vid_sigma.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/video/vid_sigma.c b/src/video/vid_sigma.c index 9c5474de9..e340a7c52 100644 --- a/src/video/vid_sigma.c +++ b/src/video/vid_sigma.c @@ -208,7 +208,7 @@ sigma_out(uint16_t addr, uint8_t val, void *p) /* If set to NMI on video I/O... */ if (sigma->enable_nmi && (sigma->sigma_ctl & CTL_NMI)) { sigma->lastport |= 0x80; /* Card raised NMI */ - nmi = 1; + nmi_raise(); } /* For CRTC emulation, the card BIOS sets the value to be * read from port 0x3D1 like this */ @@ -245,7 +245,9 @@ sigma_out(uint16_t addr, uint8_t val, void *p) sigma->lastport &= 0x7F; return; case 0x2DC: /* Reset NMI */ +#idef OLD_NMI_BEHAVIOR nmi = 0; +#endif sigma->lastport &= 0x7F; return; case 0x2DD: /* Page in RAM at 0xC1800 */ From d68121ae898ae0d9d168d250efc5f77f04248242 Mon Sep 17 00:00:00 2001 From: OBattler Date: Sat, 16 Jul 2022 02:54:49 +0200 Subject: [PATCH 10/28] ACPI, APM, PIC, and USB. --- src/acpi.c | 8 ++++---- src/apm.c | 2 +- src/pic.c | 2 +- src/usb.c | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/acpi.c b/src/acpi.c index c73440fa5..470e24c41 100644 --- a/src/acpi.c +++ b/src/acpi.c @@ -144,12 +144,12 @@ acpi_raise_smi(void *priv, int do_smi) if ((dev->vendor == VEN_VIA) || (dev->vendor == VEN_VIA_596B)) { if ((!dev->regs.smi_lock || !dev->regs.smi_active)) { if (do_smi) - smi_line = 1; + smi_raise(); dev->regs.smi_active = 1; } } else if ((dev->vendor == VEN_INTEL) || (dev->vendor == VEN_ALI)) { if (do_smi) - smi_line = 1; + smi_raise(); /* Clear bit 16 of GLBCTL. */ if (dev->vendor == VEN_INTEL) dev->regs.glbctl &= ~0x00010000; @@ -157,7 +157,7 @@ acpi_raise_smi(void *priv, int do_smi) dev->regs.ali_soft_smi = 1; } else if (dev->vendor == VEN_SMC) { if (do_smi) - smi_line = 1; + smi_raise(); } } } @@ -1449,7 +1449,7 @@ acpi_apm_out(uint16_t port, uint8_t val, void *p) dev->apm->cmd = val; // acpi_raise_smi(dev, dev->apm->do_smi); if (dev->apm->do_smi) - smi_line = 1; + smi_raise(); dev->regs.ali_soft_smi = 1; } else if (port == 0x0003) dev->apm->stat = val; diff --git a/src/apm.c b/src/apm.c index 9bee70e78..3fe8d54c6 100644 --- a/src/apm.c +++ b/src/apm.c @@ -67,7 +67,7 @@ apm_out(uint16_t port, uint8_t val, void *p) if (port == 0x0000) { dev->cmd = val; if (dev->do_smi) - smi_line = 1; + smi_raise(); } else dev->stat = val; } diff --git a/src/pic.c b/src/pic.c index efe81f470..23f99945e 100644 --- a/src/pic.c +++ b/src/pic.c @@ -608,7 +608,7 @@ picint_common(uint16_t num, int level, int set) if (set) { if (smi_irq_mask & num) { - smi_line = 1; + smi_raise(); smi_irq_status |= num; } diff --git a/src/usb.c b/src/usb.c index 2f8f957b5..c70fc2d63 100644 --- a/src/usb.c +++ b/src/usb.c @@ -173,7 +173,7 @@ ohci_mmio_write(uint32_t addr, uint8_t val, void *p) if (val & 0x08) { dev->ohci_mmio[0x0f] = 0x40; if ((dev->ohci_mmio[0x13] & 0xc0) == 0xc0) - smi_line = 1; + smi_raise(); } /* bit HostControllerReset must be cleared for the controller to be seen as initialized */ From f6fef765d71cecda7362d9d85bf7d917f78465d3 Mon Sep 17 00:00:00 2001 From: OBattler Date: Sat, 16 Jul 2022 02:58:37 +0200 Subject: [PATCH 11/28] Chipsets. --- src/chipset/ali1489.c | 2 +- src/chipset/contaq_82c59x.c | 2 +- src/chipset/ims8848.c | 2 +- src/chipset/intel_420ex.c | 2 +- src/chipset/intel_piix.c | 2 +- src/chipset/intel_sio.c | 2 +- src/chipset/opti895.c | 2 +- src/chipset/sis_5511.c | 2 +- src/chipset/sis_5571.c | 2 +- src/chipset/sis_85c496.c | 2 +- src/chipset/sis_85c4xx.c | 2 +- src/chipset/sis_85c50x.c | 2 +- src/chipset/umc_8886.c | 2 +- src/chipset/via_pipc.c | 2 +- src/chipset/via_vt82c49x.c | 2 +- 15 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/chipset/ali1489.c b/src/chipset/ali1489.c index 9738baed3..921c7d082 100644 --- a/src/chipset/ali1489.c +++ b/src/chipset/ali1489.c @@ -318,7 +318,7 @@ ali1489_write(uint16_t addr, uint8_t val, void *priv) if (((val & 0x14) == 0x14) && !(old & 0x08) && (val & 0x08)) { switch (dev->regs[0x35] & 0x30) { case 0x00: - smi_line = 1; + smi_raise(); break; case 0x10: nmi_raise(); diff --git a/src/chipset/contaq_82c59x.c b/src/chipset/contaq_82c59x.c index 6763202d0..97c8716eb 100644 --- a/src/chipset/contaq_82c59x.c +++ b/src/chipset/contaq_82c59x.c @@ -242,7 +242,7 @@ contaq_82c59x_write(uint16_t addr, uint8_t val, void *priv) dev->regs[dev->index] = val; if (val & 0x80) { if (dev->regs[0x65] & 0x80) - smi_line = 1; + smi_raise(); dev->smi_status[0] |= 0x10; } break; diff --git a/src/chipset/ims8848.c b/src/chipset/ims8848.c index 10e87b530..35b1ef62b 100644 --- a/src/chipset/ims8848.c +++ b/src/chipset/ims8848.c @@ -230,7 +230,7 @@ ims8848_write(uint16_t addr, uint8_t val, void *priv) if (dev->idx == 0x1b) { ims8848_smram(dev); if (!(old & 0x10) && (val & 0x10)) - smi_line = 1; + smi_raise(); } else if (dev->idx == 0x1c) pci_set_irq_routing(PCI_INTA, (val >> 4) ? (val >> 4) : PCI_IRQ_DISABLED); break; diff --git a/src/chipset/intel_420ex.c b/src/chipset/intel_420ex.c index 187e6f636..8c8603efc 100644 --- a/src/chipset/intel_420ex.c +++ b/src/chipset/intel_420ex.c @@ -423,7 +423,7 @@ i420ex_fast_off_count(void *priv) cpu_fast_off_count--; if (cpu_fast_off_count == 0) { - smi_line = 1; + smi_raise(); dev->regs[0xaa] |= 0x20; cpu_fast_off_count = dev->regs[0xa8] + 1; } diff --git a/src/chipset/intel_piix.c b/src/chipset/intel_piix.c index 025862c44..55002405f 100644 --- a/src/chipset/intel_piix.c +++ b/src/chipset/intel_piix.c @@ -1334,7 +1334,7 @@ piix_fast_off_count(void *priv) cpu_fast_off_count--; if (cpu_fast_off_count == 0) { - smi_line = 1; + smi_raise(); dev->regs[0][0xaa] |= 0x20; cpu_fast_off_count = dev->regs[0][0xa8] + 1; } diff --git a/src/chipset/intel_sio.c b/src/chipset/intel_sio.c index ab535cb65..75aef516c 100644 --- a/src/chipset/intel_sio.c +++ b/src/chipset/intel_sio.c @@ -432,7 +432,7 @@ sio_fast_off_count(void *priv) cpu_fast_off_count--; if (cpu_fast_off_count == 0) { - smi_line = 1; + smi_raise(); dev->regs[0xaa] |= 0x20; cpu_fast_off_count = dev->regs[0xa8] + 1; } diff --git a/src/chipset/opti895.c b/src/chipset/opti895.c index 8efddb96d..9eb360e02 100644 --- a/src/chipset/opti895.c +++ b/src/chipset/opti895.c @@ -175,7 +175,7 @@ opti895_write(uint16_t addr, uint8_t val, void *priv) case 0xe1: if ((val & 0x08) && (dev->regs[0xe0] & 0x01)) { - smi_line = 1; + smi_raise(); dev->forced_green = 1; break; } diff --git a/src/chipset/sis_5511.c b/src/chipset/sis_5511.c index 63950d47a..d0900629d 100644 --- a/src/chipset/sis_5511.c +++ b/src/chipset/sis_5511.c @@ -225,7 +225,7 @@ sis_5511_write(int func, int addr, uint8_t val, void *priv) case 0x60: dev->pci_conf[addr] = val & 0x3e; if ((dev->pci_conf[0x68] & 1) && (val & 2)) { - smi_line = 1; + smi_raise(); dev->pci_conf[0x69] |= 1; } break; diff --git a/src/chipset/sis_5571.c b/src/chipset/sis_5571.c index 3f678d87b..2d9d92c8d 100644 --- a/src/chipset/sis_5571.c +++ b/src/chipset/sis_5571.c @@ -288,7 +288,7 @@ memory_pci_bridge_write(int func, int addr, uint8_t val, void *priv) if ((dev->pci_conf[0x9b] & 1) && !!(val & 2)) { - smi_line = 1; + smi_raise(); dev->pci_conf[0x9d] |= 1; } break; diff --git a/src/chipset/sis_85c496.c b/src/chipset/sis_85c496.c index b900d4443..36d1f2030 100644 --- a/src/chipset/sis_85c496.c +++ b/src/chipset/sis_85c496.c @@ -390,7 +390,7 @@ sis_85c49x_pci_write(int func, int addr, uint8_t val, void *priv) if (dev->pci_conf[0x80] & 0x10) picint(1 << smm_irq[dev->pci_conf[0x81] & 0x03]); else - smi_line = 1; + smi_raise(); smi_block = 1; dev->pci_conf[0xa0] |= 0x10; } diff --git a/src/chipset/sis_85c4xx.c b/src/chipset/sis_85c4xx.c index b705eb32e..508f653e2 100644 --- a/src/chipset/sis_85c4xx.c +++ b/src/chipset/sis_85c4xx.c @@ -104,7 +104,7 @@ sis_85c4xx_sw_smi_out(uint16_t port, uint8_t val, void *priv) if (dev->regs[0x18] & 0x02) { if (dev->regs[0x0b] & 0x10) - smi_line = 1; + smi_raise(); else picint(1 << ((dev->regs[0x0b] & 0x08) ? 15 : 12)); soft_reset_mask = 1; diff --git a/src/chipset/sis_85c50x.c b/src/chipset/sis_85c50x.c index 9d5dddebd..1c46074b1 100644 --- a/src/chipset/sis_85c50x.c +++ b/src/chipset/sis_85c50x.c @@ -176,7 +176,7 @@ sis_85c50x_write(int func, int addr, uint8_t val, void *priv) case 0x60: /* SMI */ if ((dev->pci_conf[0x68] & 0x01) && !(dev->pci_conf[addr] & 0x02) && (val & 0x02)) { dev->pci_conf[0x69] |= 0x01; - smi_line = 1; + smi_raise(); } dev->pci_conf[addr] = val & 0x3e; break; diff --git a/src/chipset/umc_8886.c b/src/chipset/umc_8886.c index 72dc8778b..ba11ba829 100644 --- a/src/chipset/umc_8886.c +++ b/src/chipset/umc_8886.c @@ -232,7 +232,7 @@ umc_8886_write(int func, int addr, uint8_t val, void *priv) if (dev->pci_conf_sb[0][0x46] & 0x40) picint(1 << ((dev->pci_conf_sb[0][0x46] & 0x80) ? 15 : 10)); else - smi_line = 1; + smi_raise(); dev->pci_conf_sb[0][0xa3] |= 0x04; } diff --git a/src/chipset/via_pipc.c b/src/chipset/via_pipc.c index a415daa6f..720ad7561 100644 --- a/src/chipset/via_pipc.c +++ b/src/chipset/via_pipc.c @@ -790,7 +790,7 @@ pipc_fm_write(uint16_t addr, uint8_t val, void *priv) /* Fire NMI/SMI if enabled. */ if (dev->ac97_regs[0][0x48] & 0x01) { if (dev->ac97_regs[0][0x48] & 0x04) - smi_line = 1; + smi_raise(); else nmi_raise(); } diff --git a/src/chipset/via_vt82c49x.c b/src/chipset/via_vt82c49x.c index 7efa76d01..f951741e7 100644 --- a/src/chipset/via_vt82c49x.c +++ b/src/chipset/via_vt82c49x.c @@ -234,7 +234,7 @@ vt82c49x_write(uint16_t addr, uint8_t val, void *priv) case 0x54: if ((dev->regs[0x5b] & 0x80) && (valxor & 0x01) && (val & 0x01)) { if (dev->regs[0x5b] & 0x20) - smi_line = 1; + smi_raise(); else picint(1 << 15); dev->regs[0x55] = 0x01; From e83d1e7ea376383573028111beb6dc03abdcb2c6 Mon Sep 17 00:00:00 2001 From: OBattler Date: Sat, 16 Jul 2022 02:59:15 +0200 Subject: [PATCH 12/28] OPTi 611. --- src/disk/hdc_ide_opti611.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/disk/hdc_ide_opti611.c b/src/disk/hdc_ide_opti611.c index 2cbf8e1a2..9a6bd9cd4 100644 --- a/src/disk/hdc_ide_opti611.c +++ b/src/disk/hdc_ide_opti611.c @@ -152,7 +152,7 @@ opti611_ide_write(uint16_t addr, uint8_t val, void *priv) uint8_t smibe = (addr & 0x0003); if (dev->regs[0x03] & 0x02) { - smi_line = 1; + smi_raise(); dev->regs[0x02] = smia9 | smia2 | smibe; dev->regs[0x04] = val; } @@ -169,7 +169,7 @@ opti611_ide_writew(uint16_t addr, uint16_t val, void *priv) uint8_t smibe = (addr & 0x0002) | 0x0001; if (dev->regs[0x03] & 0x02) { - smi_line = 1; + smi_raise(); dev->regs[0x02] = smia9 | smia2 | smibe; dev->regs[0x04] = 0x00; } @@ -185,7 +185,7 @@ opti611_ide_writel(uint16_t addr, uint32_t val, void *priv) uint8_t smia2 = (!!(addr & 0x0004)) << 4; if (dev->regs[0x03] & 0x02) { - smi_line = 1; + smi_raise(); dev->regs[0x02] = smia9 | smia2 | 0x0003; dev->regs[0x04] = 0x00; } @@ -202,7 +202,7 @@ opti611_ide_read(uint16_t addr, void *priv) uint8_t smibe = (addr & 0x0003); if (dev->regs[0x03] & 0x02) { - smi_line = 1; + smi_raise(); dev->regs[0x02] = smia9 | smia2 | smibe; dev->regs[0x04] = 0x00; } @@ -229,7 +229,7 @@ opti611_ide_readw(uint16_t addr, void *priv) } if (dev->regs[0x03] & 0x02) { - smi_line = 1; + smi_raise(); dev->regs[0x02] = smia9 | smia2 | smibe; dev->regs[0x04] = 0x00; } @@ -247,7 +247,7 @@ opti611_ide_readl(uint16_t addr, void *priv) uint8_t smia2 = (!!(addr & 0x0004)) << 4; if (dev->regs[0x03] & 0x02) { - smi_line = 1; + smi_raise(); dev->regs[0x02] = smia9 | smia2 | 0x0003; dev->regs[0x04] = 0x00; } From 2fd712d092465aaae7c25ec8734a75e8af87c470 Mon Sep 17 00:00:00 2001 From: OBattler Date: Sat, 16 Jul 2022 03:12:24 +0200 Subject: [PATCH 13/28] CPU changes. --- src/cpu/386_common.c | 34 ++++++++++++++++++++++++++++++++-- src/cpu/cpu.h | 4 ++++ 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/src/cpu/386_common.c b/src/cpu/386_common.c index 1f5bfe3b5..d7544b351 100644 --- a/src/cpu/386_common.c +++ b/src/cpu/386_common.c @@ -22,6 +22,7 @@ #include <86box/fdd.h> #include <86box/fdc.h> #include <86box/keyboard.h> +#include <86box/timer.h> #include "386_common.h" #include "x86_flags.h" #include "x86seg.h" @@ -71,6 +72,9 @@ int smm_in_hlt = 0, smi_block = 0; uint32_t addr64, addr64_2; uint32_t addr64a[8], addr64a_2[8]; +static timer_t *cpu_fast_off_timer = NULL; +static double *cpu_fast_off_period = NULL; + #define AMD_SYSCALL_EIP (msr.star & 0xFFFFFFFF) #define AMD_SYSCALL_SB ((msr.star >> 32) & 0xFFFF) @@ -1837,11 +1841,37 @@ sysret(uint32_t fetchdat) } +void +cpu_register_fast_off_handler(void *timer, double *period) +{ + cpu_fast_off_timer = (timer_t *) timer; + cpu_fast_off_period = period; +} + + +void +cpu_fast_off_advance(void) +{ + if (cpu_fast_off_period && (*cpu_fast_off_period != 0.0)) + timer_on_auto(cpu_fast_off_timer, *cpu_fast_off_period); +} + + +void +cpu_fast_off_period_set(uint16_t val, double period) +{ + if (cpu_fast_off_period) { + *cpu_fast_off_period = ((double) (val + 1)) * period; + cpu_fast_off_advance(); + } +} + + void smi_raise(void) { if (is486 && (cpu_fast_off_flags & 0x80000000)) - cpu_fast_off_count = cpu_fast_off_val + 1; + cpu_fast_off_advance(); smi_line = 1; } @@ -1851,7 +1881,7 @@ void nmi_raise(void) { if (is486 && (cpu_fast_off_flags & 0x20000000)) - cpu_fast_off_count = cpu_fast_off_val + 1; + cpu_fast_off_advance(); } diff --git a/src/cpu/cpu.h b/src/cpu/cpu.h index 136a6c834..61fd700d9 100644 --- a/src/cpu/cpu.h +++ b/src/cpu/cpu.h @@ -733,6 +733,10 @@ extern uint8_t do_translate, do_translate2; extern void reset_808x(int hard); +extern void cpu_register_fast_off_handler(void *timer, double *period); +extern void cpu_fast_off_advance(void); +extern void cpu_fast_off_period_set(uint16_t vla, double period); + extern void smi_raise(); extern void nmi_raise(); From c58360df3e3bf779ec47325c15000c62a70c3188 Mon Sep 17 00:00:00 2001 From: OBattler Date: Sat, 16 Jul 2022 03:21:09 +0200 Subject: [PATCH 14/28] Chipsets. --- src/chipset/intel_420ex.c | 21 +++++++-------------- src/chipset/intel_piix.c | 24 +++++++----------------- src/chipset/intel_sio.c | 23 +++++++---------------- 3 files changed, 21 insertions(+), 47 deletions(-) diff --git a/src/chipset/intel_420ex.c b/src/chipset/intel_420ex.c index 8c8603efc..1590bc34c 100644 --- a/src/chipset/intel_420ex.c +++ b/src/chipset/intel_420ex.c @@ -316,10 +316,8 @@ i420ex_write(int func, int addr, uint8_t val, void *priv) dev->fast_off_period = PCICLK * 32768.0; break; } - cpu_fast_off_count = dev->regs[0xa8] + 1; - timer_disable(&dev->fast_off_timer); - if (dev->fast_off_period != 0.0) - timer_on_auto(&dev->fast_off_timer, dev->fast_off_period); + 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; @@ -347,9 +345,7 @@ i420ex_write(int func, int addr, uint8_t val, void *priv) dev->regs[addr] = val & 0xff; cpu_fast_off_val = val; cpu_fast_off_count = val + 1; - timer_disable(&dev->fast_off_timer); - if (dev->fast_off_period != 0.0) - timer_on_auto(&dev->fast_off_timer, dev->fast_off_period); + cpu_fast_off_period_set(cpu_fast_off_val, dev->fast_off_period); break; } } @@ -422,13 +418,8 @@ i420ex_fast_off_count(void *priv) cpu_fast_off_count--; - if (cpu_fast_off_count == 0) { - smi_raise(); - dev->regs[0xaa] |= 0x20; - cpu_fast_off_count = dev->regs[0xa8] + 1; - } - - timer_on_auto(&dev->fast_off_timer, dev->fast_off_period); + smi_raise(); + dev->regs[0xaa] |= 0x20; } @@ -513,6 +504,8 @@ i420ex_init(const device_t *info) cpu_fast_off_val = dev->regs[0xa8]; cpu_fast_off_count = cpu_fast_off_val + 1; + cpu_register_fast_off_handler(&dev->fast_off_timer); + 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); diff --git a/src/chipset/intel_piix.c b/src/chipset/intel_piix.c index 55002405f..c0f28914b 100644 --- a/src/chipset/intel_piix.c +++ b/src/chipset/intel_piix.c @@ -628,10 +628,8 @@ piix_write(int func, int addr, uint8_t val, void *priv) dev->fast_off_period = PCICLK * 32768.0; break; } - cpu_fast_off_count = fregs[0xa8] + 1; - timer_disable(&dev->fast_off_timer); - if (dev->fast_off_period != 0.0) - timer_on_auto(&dev->fast_off_timer, dev->fast_off_period); + 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: @@ -679,9 +677,7 @@ piix_write(int func, int addr, uint8_t val, void *priv) fregs[addr] = val & 0xff; cpu_fast_off_val = val; cpu_fast_off_count = val + 1; - timer_disable(&dev->fast_off_timer); - if (dev->fast_off_period != 0.0) - timer_on_auto(&dev->fast_off_timer, dev->fast_off_period); + cpu_fast_off_period_set(cpu_fast_off_val, dev->fast_off_period); } break; case 0xaa: @@ -1331,15 +1327,8 @@ piix_fast_off_count(void *priv) { piix_t *dev = (piix_t *) priv; - cpu_fast_off_count--; - - if (cpu_fast_off_count == 0) { - smi_raise(); - dev->regs[0][0xaa] |= 0x20; - cpu_fast_off_count = dev->regs[0][0xa8] + 1; - } - - timer_on_auto(&dev->fast_off_timer, dev->fast_off_period); + smi_raise(); + dev->regs[0][0xaa] |= 0x20; } @@ -1446,7 +1435,7 @@ piix_speed_changed(void *priv) timer_stop(&dev->fast_off_timer); if (te) - timer_on_auto(&dev->fast_off_timer, dev->fast_off_period); + timer_on_auto(&dev->fast_off_timer, ((double) cpu_fast_off_val + 1) * dev->fast_off_period); } @@ -1510,6 +1499,7 @@ static void if (dev->type < 4) { cpu_fast_off_val = dev->regs[0][0xa8]; cpu_fast_off_count = cpu_fast_off_val + 1; + cpu_fast_off_register(&dev->fast_off_timer); } else cpu_fast_off_val = cpu_fast_off_count = 0; diff --git a/src/chipset/intel_sio.c b/src/chipset/intel_sio.c index 75aef516c..8c75e88c2 100644 --- a/src/chipset/intel_sio.c +++ b/src/chipset/intel_sio.c @@ -264,10 +264,8 @@ sio_write(int func, int addr, uint8_t val, void *priv) dev->fast_off_period = PCICLK * 32768.0; break; } - cpu_fast_off_count = dev->regs[0xa8] + 1; - timer_disable(&dev->fast_off_timer); - if (dev->fast_off_period != 0.0) - timer_on_auto(&dev->fast_off_timer, dev->fast_off_period); + 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: @@ -306,9 +304,7 @@ sio_write(int func, int addr, uint8_t val, void *priv) dev->regs[addr] = val & 0xff; cpu_fast_off_val = val; cpu_fast_off_count = val + 1; - timer_disable(&dev->fast_off_timer); - if (dev->fast_off_period != 0.0) - timer_on_auto(&dev->fast_off_timer, dev->fast_off_period); + cpu_fast_off_period_set(cpu_fast_off_val, dev->fast_off_period); break; } } @@ -429,15 +425,8 @@ sio_fast_off_count(void *priv) { sio_t *dev = (sio_t *) priv; - cpu_fast_off_count--; - - if (cpu_fast_off_count == 0) { - smi_raise(); - dev->regs[0xaa] |= 0x20; - cpu_fast_off_count = dev->regs[0xa8] + 1; - } - - timer_on_auto(&dev->fast_off_timer, dev->fast_off_period); + smi_raise(); + dev->regs[0xaa] |= 0x20; } @@ -513,6 +502,8 @@ sio_init(const device_t *info) if (dev->id == 0x03) { cpu_fast_off_val = dev->regs[0xa8]; cpu_fast_off_count = cpu_fast_off_val + 1; + + cpu_fast_off_register(&dev->fast_off_timer); } else cpu_fast_off_val = cpu_fast_off_count = 0; From a35c4aa67466e464c7ad9bc834c583f473a3fd2e Mon Sep 17 00:00:00 2001 From: OBattler Date: Sat, 16 Jul 2022 03:21:21 +0200 Subject: [PATCH 15/28] CPU changes. --- src/cpu/386_common.c | 25 ++++++++++++++++--------- src/cpu/cpu.h | 3 ++- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/cpu/386_common.c b/src/cpu/386_common.c index d7544b351..aa5a813b8 100644 --- a/src/cpu/386_common.c +++ b/src/cpu/386_common.c @@ -73,7 +73,7 @@ uint32_t addr64, addr64_2; uint32_t addr64a[8], addr64a_2[8]; static timer_t *cpu_fast_off_timer = NULL; -static double *cpu_fast_off_period = NULL; +static double cpu_fast_off_period = 0.0; #define AMD_SYSCALL_EIP (msr.star & 0xFFFFFFFF) @@ -1842,28 +1842,35 @@ sysret(uint32_t fetchdat) void -cpu_register_fast_off_handler(void *timer, double *period) +cpu_register_fast_off_handler(void *timer) { cpu_fast_off_timer = (timer_t *) timer; - cpu_fast_off_period = period; } void cpu_fast_off_advance(void) { - if (cpu_fast_off_period && (*cpu_fast_off_period != 0.0)) - timer_on_auto(cpu_fast_off_timer, *cpu_fast_off_period); + timer_disable(cpu_fast_off_timer); + if (cpu_fast_off_period != 0.0) + timer_on_auto(cpu_fast_off_timer, cpu_fast_off_period); } void cpu_fast_off_period_set(uint16_t val, double period) { - if (cpu_fast_off_period) { - *cpu_fast_off_period = ((double) (val + 1)) * period; - cpu_fast_off_advance(); - } + cpu_fast_off_period = ((double) (val + 1)) * period; + cpu_fast_off_advance(); +} + + +void +cpu_fast_off_reset(void) +{ + cpu_register_fast_off_handler(NULL); + cpu_fast_off_period = 0.0; + cpu_fast_off_advance(); } diff --git a/src/cpu/cpu.h b/src/cpu/cpu.h index 61fd700d9..6d66e1531 100644 --- a/src/cpu/cpu.h +++ b/src/cpu/cpu.h @@ -733,9 +733,10 @@ extern uint8_t do_translate, do_translate2; extern void reset_808x(int hard); -extern void cpu_register_fast_off_handler(void *timer, double *period); +extern void cpu_register_fast_off_handler(void *timer); extern void cpu_fast_off_advance(void); extern void cpu_fast_off_period_set(uint16_t vla, double period); +extern void cpu_fast_off_reset(void); extern void smi_raise(); extern void nmi_raise(); From f4ba136b976026f8bfee17366fe2b922619e79a5 Mon Sep 17 00:00:00 2001 From: OBattler Date: Sat, 16 Jul 2022 03:22:28 +0200 Subject: [PATCH 16/28] Machine. --- src/machine/machine.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/machine/machine.c b/src/machine/machine.c index 1549ce7c6..00516d8fb 100644 --- a/src/machine/machine.c +++ b/src/machine/machine.c @@ -105,6 +105,9 @@ machine_init_ex(int m) /* Reset any ISA memory cards. */ isamem_reset(); + + /* Reset the fast off stuff. */ + cpu_fast_off_reset(); } /* All good, boot the machine! */ From 27713f6557c99835be544719550aa68cd2fdbaa3 Mon Sep 17 00:00:00 2001 From: OBattler Date: Sat, 16 Jul 2022 03:22:41 +0200 Subject: [PATCH 17/28] More CPU. --- src/cpu/386_common.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/cpu/386_common.c b/src/cpu/386_common.c index aa5a813b8..bef9aa59a 100644 --- a/src/cpu/386_common.c +++ b/src/cpu/386_common.c @@ -1868,6 +1868,9 @@ cpu_fast_off_period_set(uint16_t val, double period) void cpu_fast_off_reset(void) { + if (cpu-fast_off_timer) + timer_disable(cpu_fast_off_timer); + cpu_register_fast_off_handler(NULL); cpu_fast_off_period = 0.0; cpu_fast_off_advance(); From 231afcbe11d3c66252a48e439d6f7070ba564009 Mon Sep 17 00:00:00 2001 From: OBattler Date: Sat, 16 Jul 2022 03:23:21 +0200 Subject: [PATCH 18/28] PIC. --- src/pic.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pic.c b/src/pic.c index 23f99945e..13c13d6df 100644 --- a/src/pic.c +++ b/src/pic.c @@ -223,7 +223,7 @@ find_best_interrupt(pic_t *dev) intr += 8; if (cpu_fast_off_flags & (1u << intr)) - cpu_fast_off_count = cpu_fast_off_val + 1; + cpu_fast_off_advance(); } return ret; From b97338144e253fc4c2cfe17d484e730077fabe82 Mon Sep 17 00:00:00 2001 From: richardg867 Date: Fri, 15 Jul 2022 22:59:49 -0300 Subject: [PATCH 19/28] Jenkins: Allow macOS to make source tarballs --- .ci/Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.ci/Jenkinsfile b/.ci/Jenkinsfile index cb58e1fd8..b0c865083 100644 --- a/.ci/Jenkinsfile +++ b/.ci/Jenkinsfile @@ -215,7 +215,7 @@ pipeline { /* Create source tarball. */ try { retry(10) { - node('Linux') { + node('Linux || macOS') { /* Run git clone. */ gitClone(repository[buildBranch], branch[buildBranch]) From a1744ddbd209c54bce97deb62e86a4bc617d38e6 Mon Sep 17 00:00:00 2001 From: richardg867 Date: Fri, 15 Jul 2022 23:04:36 -0300 Subject: [PATCH 20/28] Jenkins: Install and use gnutar on macOS for source tarballs --- .ci/build.sh | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/.ci/build.sh b/.ci/build.sh index eeb22c9c2..da4169516 100644 --- a/.ci/build.sh +++ b/.ci/build.sh @@ -52,8 +52,20 @@ make_tar() { # Install dependencies. if ! which tar xz > /dev/null 2>&1 then - which apt-get > /dev/null 2>&1 && DEBIAN_FRONTEND=noninteractive sudo apt-get install -y tar xz-utils + if which apt-get > /dev/null 2>&1 + then + sudo apt-get update + DEBIAN_FRONTEND=noninteractive sudo apt-get install -y tar xz-utils + sudo apt-get clean + elif which port > /dev/null 2>&1 + then + sudo port install gnutar xz + fi fi + + # Prefer gnutar on macOS. + local tar_cmd=tar + which gnutar > /dev/null 2>&1 && tar_cmd=gnutar # Determine the best supported compression type. local compression_flag= @@ -80,7 +92,7 @@ make_tar() { # --uid/gid (bsdtar) or even none at all (MSYS2 bsdtar). Account for such # flag differences by checking if they're mentioned on the help text. local ownership_flags= - local tar_help=$(tar --help 2>&1) + local tar_help=$("$tar_cmd" --help 2>&1) if echo $tar_help | grep -q -- --owner then local ownership_flags="--owner=0 --group=0" @@ -90,7 +102,7 @@ make_tar() { fi # Run tar. - tar -c $compression_flag -f "$1$compression_ext" $ownership_flags * + "$tar_cmd" -c $compression_flag -f "$1$compression_ext" $ownership_flags * return $? } From 63e52cb8327651d7e717f2ab36faeb47c33ed441 Mon Sep 17 00:00:00 2001 From: OBattler Date: Sat, 16 Jul 2022 04:06:46 +0200 Subject: [PATCH 21/28] Fixes to cpu/386_common.c. --- src/cpu/386_common.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cpu/386_common.c b/src/cpu/386_common.c index bef9aa59a..ca7888502 100644 --- a/src/cpu/386_common.c +++ b/src/cpu/386_common.c @@ -72,7 +72,7 @@ int smm_in_hlt = 0, smi_block = 0; uint32_t addr64, addr64_2; uint32_t addr64a[8], addr64a_2[8]; -static timer_t *cpu_fast_off_timer = NULL; +static pc_timer_t *cpu_fast_off_timer = NULL; static double cpu_fast_off_period = 0.0; @@ -1844,7 +1844,7 @@ sysret(uint32_t fetchdat) void cpu_register_fast_off_handler(void *timer) { - cpu_fast_off_timer = (timer_t *) timer; + cpu_fast_off_timer = (pc_timer_t *) timer; } @@ -1868,7 +1868,7 @@ cpu_fast_off_period_set(uint16_t val, double period) void cpu_fast_off_reset(void) { - if (cpu-fast_off_timer) + if (cpu_fast_off_timer) timer_disable(cpu_fast_off_timer); cpu_register_fast_off_handler(NULL); From 8a8d7857d36c769a4f220e4bf98806e695e55d7e Mon Sep 17 00:00:00 2001 From: OBattler Date: Sat, 16 Jul 2022 04:08:13 +0200 Subject: [PATCH 22/28] Two chipset .c files. --- src/chipset/intel_420ex.c | 1 + src/chipset/intel_sio.c | 1 + 2 files changed, 2 insertions(+) diff --git a/src/chipset/intel_420ex.c b/src/chipset/intel_420ex.c index 1590bc34c..11c66b833 100644 --- a/src/chipset/intel_420ex.c +++ b/src/chipset/intel_420ex.c @@ -19,6 +19,7 @@ #include #include #include <86box/86box.h> +#include "cpu.h" #include <86box/device.h> #include <86box/io.h> #include <86box/apm.h> diff --git a/src/chipset/intel_sio.c b/src/chipset/intel_sio.c index 8c75e88c2..10b1b7380 100644 --- a/src/chipset/intel_sio.c +++ b/src/chipset/intel_sio.c @@ -18,6 +18,7 @@ #include #include #include <86box/86box.h> +#include "cpu.h" #include <86box/device.h> #include <86box/io.h> #include <86box/apm.h> From dcd7cc904742cd38a195b63ee4b1a66aa3b3aead Mon Sep 17 00:00:00 2001 From: OBattler Date: Sat, 16 Jul 2022 04:09:49 +0200 Subject: [PATCH 23/28] And more. --- src/chipset/intel_piix.c | 2 +- src/chipset/intel_sio.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/chipset/intel_piix.c b/src/chipset/intel_piix.c index c0f28914b..f8302e854 100644 --- a/src/chipset/intel_piix.c +++ b/src/chipset/intel_piix.c @@ -1499,7 +1499,7 @@ static void if (dev->type < 4) { cpu_fast_off_val = dev->regs[0][0xa8]; cpu_fast_off_count = cpu_fast_off_val + 1; - cpu_fast_off_register(&dev->fast_off_timer); + cpu_register_fast_off_handler(&dev->fast_off_timer); } else cpu_fast_off_val = cpu_fast_off_count = 0; diff --git a/src/chipset/intel_sio.c b/src/chipset/intel_sio.c index 10b1b7380..bbc85662d 100644 --- a/src/chipset/intel_sio.c +++ b/src/chipset/intel_sio.c @@ -504,7 +504,7 @@ sio_init(const device_t *info) cpu_fast_off_val = dev->regs[0xa8]; cpu_fast_off_count = cpu_fast_off_val + 1; - cpu_fast_off_register(&dev->fast_off_timer); + cpu_register_fast_off_handler(&dev->fast_off_timer); } else cpu_fast_off_val = cpu_fast_off_count = 0; From 1b9c360bbe2ede16b306d1ea96b53c8425d489f3 Mon Sep 17 00:00:00 2001 From: OBattler Date: Sat, 16 Jul 2022 04:10:54 +0200 Subject: [PATCH 24/28] And Sigma. --- src/video/vid_sigma.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/video/vid_sigma.c b/src/video/vid_sigma.c index e340a7c52..154469317 100644 --- a/src/video/vid_sigma.c +++ b/src/video/vid_sigma.c @@ -245,7 +245,7 @@ sigma_out(uint16_t addr, uint8_t val, void *p) sigma->lastport &= 0x7F; return; case 0x2DC: /* Reset NMI */ -#idef OLD_NMI_BEHAVIOR +#ifdef OLD_NMI_BEHAVIOR nmi = 0; #endif sigma->lastport &= 0x7F; From 0ebf0e0ecea6153d2728b9952bbdc8000e4f067a Mon Sep 17 00:00:00 2001 From: richardg867 Date: Fri, 15 Jul 2022 23:12:27 -0300 Subject: [PATCH 25/28] Jenkins: Fix small typo in tarball script --- .ci/build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.ci/build.sh b/.ci/build.sh index da4169516..98dbf3e3f 100644 --- a/.ci/build.sh +++ b/.ci/build.sh @@ -65,7 +65,7 @@ make_tar() { # Prefer gnutar on macOS. local tar_cmd=tar - which gnutar > /dev/null 2>&1 && tar_cmd=gnutar + which gnutar > /dev/null 2>&1 && local tar_cmd=gnutar # Determine the best supported compression type. local compression_flag= From 00b63fe9b8777d9875c585980fbc5fef60a0476e Mon Sep 17 00:00:00 2001 From: richardg867 Date: Fri, 15 Jul 2022 23:17:07 -0300 Subject: [PATCH 26/28] Jenkins: More macOS stuff --- .ci/build.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.ci/build.sh b/.ci/build.sh index 98dbf3e3f..278e252d8 100644 --- a/.ci/build.sh +++ b/.ci/build.sh @@ -59,11 +59,12 @@ make_tar() { sudo apt-get clean elif which port > /dev/null 2>&1 then + sudo port selfupdate sudo port install gnutar xz fi fi - - # Prefer gnutar on macOS. + + # Use MacPorts gnutar (if installed) on macOS. local tar_cmd=tar which gnutar > /dev/null 2>&1 && local tar_cmd=gnutar From 549a8544a0a2b7507c7022d43c363d0746a71a74 Mon Sep 17 00:00:00 2001 From: OBattler Date: Sat, 16 Jul 2022 04:29:19 +0200 Subject: [PATCH 27/28] Rewrote the NVR periodic timer for better performance. --- src/nvr_at.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/nvr_at.c b/src/nvr_at.c index b164d948d..2bf8be383 100644 --- a/src/nvr_at.c +++ b/src/nvr_at.c @@ -496,6 +496,8 @@ timer_load_count(nvr_t *nvr) int c = nvr->regs[RTC_REGA] & REGA_RS; local_t *local = (local_t *) nvr->data; + timer_disable(&local->rtc_timer); + if ((nvr->regs[RTC_REGA] & 0x70) != 0x20) { local->state = 0; return; @@ -509,9 +511,11 @@ timer_load_count(nvr_t *nvr) break; case 1: case 2: local->count = 1 << (c + 6); + timer_set_delay_u64(&local->rtc_timer, (local->count) * RTCCONST); break; default: local->count = 1 << (c - 1); + timer_set_delay_u64(&local->rtc_timer, (local->count) * RTCCONST); break; } } @@ -523,20 +527,16 @@ timer_intr(void *priv) nvr_t *nvr = (nvr_t *)priv; local_t *local = (local_t *)nvr->data; - timer_advance_u64(&local->rtc_timer, RTCCONST); - if (local->state == 1) { - if (--local->count == 0) { - timer_load_count(nvr); + timer_load_count(nvr); - nvr->regs[RTC_REGC] |= REGC_PF; - if (nvr->regs[RTC_REGB] & REGB_PIE) { - nvr->regs[RTC_REGC] |= REGC_IRQF; + nvr->regs[RTC_REGC] |= REGC_PF; + if (nvr->regs[RTC_REGB] & REGB_PIE) { + nvr->regs[RTC_REGC] |= REGC_IRQF; - /* Generate an interrupt. */ - if (nvr->irq != -1) - picint(1 << nvr->irq); - } + /* Generate an interrupt. */ + if (nvr->irq != -1) + picint(1 << nvr->irq); } } } @@ -809,6 +809,7 @@ nvr_read(uint16_t addr, void *priv) return(ret); } + /* Secondary NVR write - used by SMC. */ static void nvr_sec_write(uint16_t addr, uint8_t val, void *priv) @@ -824,6 +825,7 @@ nvr_sec_read(uint16_t addr, void *priv) return nvr_read(0x72 + (addr & 1), priv); } + /* Reset the RTC state to 1980/01/01 00:00. */ static void nvr_reset(nvr_t *nvr) @@ -883,8 +885,7 @@ nvr_at_speed_changed(void *priv) nvr_t *nvr = (nvr_t *) priv; local_t *local = (local_t *) nvr->data; - timer_disable(&local->rtc_timer); - timer_set_delay_u64(&local->rtc_timer, RTCCONST); + timer_load_count(nvr); timer_disable(&local->update_timer); if (local->ecount > 0ULL) @@ -1081,7 +1082,6 @@ nvr_at_init(const device_t *info) nvr->regs[RTC_REGA] = (nvr->regs[RTC_REGA] & 0x8f) | 0x20; nvr_at_reset(nvr); timer_load_count(nvr); - timer_set_delay_u64(&local->rtc_timer, RTCCONST); /* Set up the I/O handler for this device. */ io_sethandler(0x0070, 2, From efdf003272097719a698e703391d8d8cbad0b877 Mon Sep 17 00:00:00 2001 From: richardg867 Date: Fri, 15 Jul 2022 23:43:00 -0300 Subject: [PATCH 28/28] Jenkins: Better document some stuff --- .ci/Jenkinsfile | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/.ci/Jenkinsfile b/.ci/Jenkinsfile index b0c865083..61330031a 100644 --- a/.ci/Jenkinsfile +++ b/.ci/Jenkinsfile @@ -113,9 +113,9 @@ def gitClone(repository, branch) { } else if (env.GIT_COMMIT != scmVars.GIT_COMMIT) { /* Checkout the commit read from the polling log. */ if (isUnix()) - sh returnStatus: true, script: "git checkout ${env.GIT_COMMIT}" + sh(returnStatus: true, script: "git checkout ${env.GIT_COMMIT}") else - bat returnStatus: true, script: "git checkout ${env.GIT_COMMIT}" + bat(returnStatus: true, script: "git checkout ${env.GIT_COMMIT}") } println "[-] Using git commit [${env.GIT_COMMIT}]" @@ -173,8 +173,10 @@ pipeline { steps { script { - /* Extract the polled commit from the polling log, so that git checkout can be used - to avoid JENKINS-20518 race conditions caused by two pushes too close together. */ + /* Extract the polled commit from the polling log, so that git checkout + can be used to avoid JENKINS-20518 race conditions caused by the + webhook being triggered more than once in a short period of time. + This is a backup strategy for FilterProxy's webhook queuing. */ node('master') { /* must run on master node to read polling log */ /* Ignore exceptions as this is not really critical. */ try {