Repository navigation
fix: Maupiti Island (was: "fix: (cpu): HLT waits for interrupt instead of stopping emulation") - #2465
maximilien-noal wants to merge 3 commits into
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
The halted idle path skips CPU-cycle breakpoint checks, permanently missing exact-count breakpoints and bypassing the maximum-cycle failsafe, so a missing IRQ can hang the HLT test indefinitely.
1 open issue
What changed in this PR
Updates interpreter HLT behavior so DOS programs can wait for hardware interrupts without terminating emulation, while retaining an option for legacy stop-on-HLT behavior.
Changes:
- Adds halted CPU state and threads
HltStopsEmulationthrough configuration and test-machine setup. - Excludes post-HLT successors from generated-method structural edges.
- Preserves AX, DX, and DS around BIOS timer hooks, adds an ASM regression scenario, and updates BIOS-layout expectations.
Validation was limited to static review; no builds or tests were run.
| File | Description |
|---|---|
| tests/Spice86.Tests/Spice86Creator.cs | Updated as part of this pull request. |
| tests/Spice86.Tests/Resources/RtcTests/Makefile | Updated as part of this pull request. |
| tests/Spice86.Tests/Resources/RtcTests/bios_timer_hook_registers.asm | Updated as part of this pull request. |
| tests/Spice86.Tests/Resources/cpuTests/res/DumpedListing/intchain.txt | Updated as part of this pull request. |
| tests/Spice86.Tests/Resources/cpuTests/res/DumpedListing/bootstrap_host_requested_batch_slash_path.txt | Updated as part of this pull request. |
| tests/Spice86.Tests/Resources/cpuTests/res/DumpedListing/batch_vol_prints_label.txt | Updated as part of this pull request. |
| tests/Spice86.Tests/Resources/cpuTests/res/DumpedListing/batch_vol_drive_argument.txt | Updated as part of this pull request. |
| tests/Spice86.Tests/Resources/cpuTests/res/DumpedListing/batch_vol_cdrom_label.txt | Updated as part of this pull request. |
| tests/Spice86.Tests/Resources/cpuTests/res/DumpedListing/batch_ver_prints.txt | Updated as part of this pull request. |
| tests/Spice86.Tests/Resources/cpuTests/res/DumpedListing/batch_type_missing_file_error.txt | Updated as part of this pull request. |
| tests/Spice86.Tests/Resources/cpuTests/res/DumpedListing/batch_type_displays_file.txt | Updated as part of this pull request. |
| tests/Spice86.Tests/Resources/cpuTests/res/DumpedListing/batch_time_set_value.txt | Updated as part of this pull request. |
| tests/Spice86.Tests/Resources/cpuTests/res/DumpedListing/batch_time_prints.txt | Updated as part of this pull request. |
| tests/Spice86.Tests/Resources/cpuTests/res/DumpedListing/batch_time_host_sync.txt | Updated as part of this pull request. |
| tests/Spice86.Tests/Resources/cpuTests/res/DumpedListing/batch_time_help.txt | Updated as part of this pull request. |
| tests/Spice86.Tests/Resources/cpuTests/res/DumpedListing/batch_set_prompt_unsupported.txt | Updated as part of this pull request. |
| tests/Spice86.Tests/Resources/cpuTests/res/DumpedListing/batch_set_enumerates_environment.txt | Updated as part of this pull request. |
| tests/Spice86.Tests/Resources/cpuTests/res/DumpedListing/batch_rmdir_alias.txt | Updated as part of this pull request. |
| tests/Spice86.Tests/Resources/cpuTests/res/DumpedListing/batch_rename_alias.txt | Updated as part of this pull request. |
| tests/Spice86.Tests/Resources/cpuTests/res/DumpedListing/batch_ren_wildcard.txt | Updated as part of this pull request. |
| tests/Spice86.Tests/Resources/cpuTests/res/DumpedListing/batch_ren_single_file.txt | Updated as part of this pull request. |
| tests/Spice86.Tests/Resources/cpuTests/res/DumpedListing/batch_ren_missing_target.txt | Updated as part of this pull request. |
| tests/Spice86.Tests/Resources/cpuTests/res/DumpedListing/batch_ren_missing_error.txt | Updated as part of this pull request. |
| tests/Spice86.Tests/Resources/cpuTests/res/DumpedListing/batch_rd_removes_directory.txt | Updated as part of this pull request. |
| tests/Spice86.Tests/Resources/cpuTests/res/DumpedListing/batch_rd_missing_error.txt | Updated as part of this pull request. |
| tests/Spice86.Tests/Resources/cpuTests/res/DumpedListing/batch_multi_output_tight.txt | Updated as part of this pull request. |
| tests/Spice86.Tests/Resources/cpuTests/res/DumpedListing/batch_multi_output_spaces_before_gt.txt | Updated as part of this pull request. |
| tests/Spice86.Tests/Resources/cpuTests/res/DumpedListing/batch_multi_output_padded_targets.txt | Updated as part of this pull request. |
| tests/Spice86.Tests/Resources/cpuTests/res/DumpedListing/batch_move_wildcard.txt | Updated as part of this pull request. |
| tests/Spice86.Tests/Resources/cpuTests/res/DumpedListing/batch_move_to_directory.txt | Updated as part of this pull request. |
| tests/Spice86.Tests/Resources/cpuTests/res/DumpedListing/batch_move_rename.txt | Updated as part of this pull request. |
| tests/Spice86.Tests/Resources/cpuTests/res/DumpedListing/batch_move_missing_source.txt | Updated as part of this pull request. |
| tests/Spice86.Tests/Resources/cpuTests/res/DumpedListing/batch_mkdir_alias.txt | Updated as part of this pull request. |
| tests/Spice86.Tests/Resources/cpuTests/res/DumpedListing/batch_md_existing_error.txt | Updated as part of this pull request. |
| tests/Spice86.Tests/Resources/cpuTests/res/DumpedListing/batch_md_creates_directory.txt | Updated as part of this pull request. |
| tests/Spice86.Tests/Resources/cpuTests/res/DumpedListing/batch_invalid_redirect_no_file.txt | Updated as part of this pull request. |
| tests/Spice86.Tests/Resources/cpuTests/res/DumpedListing/batch_invalid_redirect_launch_lt_gt.txt | Updated as part of this pull request. |
| tests/Spice86.Tests/Resources/cpuTests/res/DumpedListing/batch_invalid_redirect_launch_bar_lt.txt | Updated as part of this pull request. |
| tests/Spice86.Tests/Resources/cpuTests/res/DumpedListing/batch_invalid_redirect_launch_bar_gt.txt | Updated as part of this pull request. |
| tests/Spice86.Tests/Resources/cpuTests/res/DumpedListing/batch_invalid_redirect_gt_bar.txt | Updated as part of this pull request. |
| tests/Spice86.Tests/Resources/cpuTests/res/DumpedListing/batch_invalid_redirect_double_lt.txt | Updated as part of this pull request. |
| tests/Spice86.Tests/Resources/cpuTests/res/DumpedListing/batch_invalid_redirect_double_gt.txt | Updated as part of this pull request. |
| tests/Spice86.Tests/Resources/cpuTests/res/DumpedListing/batch_invalid_redirect_double_bar.txt | Updated as part of this pull request. |
| tests/Spice86.Tests/Resources/cpuTests/res/DumpedListing/batch_invalid_redirect_bar_gt.txt | Updated as part of this pull request. |
| tests/Spice86.Tests/Resources/cpuTests/res/DumpedListing/batch_imgmount_internal_precedence.txt | Updated as part of this pull request. |
| tests/Spice86.Tests/Resources/cpuTests/res/DumpedListing/batch_for_wildcard_del.txt | Updated as part of this pull request. |
| tests/Spice86.Tests/Resources/cpuTests/res/DumpedListing/batch_for_quoted_parenthesis.txt | Updated as part of this pull request. |
| tests/Spice86.Tests/Resources/cpuTests/res/DumpedListing/batch_for_malformed_single_percent.txt | Updated as part of this pull request. |
| tests/Spice86.Tests/Resources/cpuTests/res/DumpedListing/batch_for_malformed_no_variable.txt | Updated as part of this pull request. |
| tests/Spice86.Tests/Resources/cpuTests/res/DumpedListing/batch_for_malformed_no_in.txt | Updated as part of this pull request. |
| tests/Spice86.Tests/Resources/cpuTests/res/DumpedListing/batch_for_malformed_no_body.txt | Updated as part of this pull request. |
| tests/Spice86.Tests/Resources/cpuTests/res/DumpedListing/batch_for_bare_star.txt | Updated as part of this pull request. |
| tests/Spice86.Tests/Resources/cpuTests/res/DumpedListing/batch_erase_alias.txt | Updated as part of this pull request. |
| tests/Spice86.Tests/Resources/cpuTests/res/DumpedListing/batch_echo_spacing_space_before_gt.txt | Updated as part of this pull request. |
| tests/Spice86.Tests/Resources/cpuTests/res/DumpedListing/batch_echo_redirect.txt | Updated as part of this pull request. |
| tests/Spice86.Tests/Resources/cpuTests/res/DumpedListing/batch_echo_on_status.txt | Updated as part of this pull request. |
| tests/Spice86.Tests/Resources/cpuTests/res/DumpedListing/batch_echo_off_status.txt | Updated as part of this pull request. |
| tests/Spice86.Tests/Resources/cpuTests/res/DumpedListing/batch_echo_off_inner_batch.txt | Updated as part of this pull request. |
| tests/Spice86.Tests/Resources/cpuTests/res/DumpedListing/batch_echo_leading_spaces.txt | Updated as part of this pull request. |
| tests/Spice86.Tests/Resources/cpuTests/res/DumpedListing/batch_echo_dot_text.txt | Updated as part of this pull request. |
| tests/Spice86.Tests/Resources/cpuTests/res/DumpedListing/batch_echo_dot_blank.txt | Updated as part of this pull request. |
| tests/Spice86.Tests/Resources/cpuTests/res/DumpedListing/batch_dir_with_pattern.txt | Updated as part of this pull request. |
| tests/Spice86.Tests/Resources/cpuTests/res/DumpedListing/batch_dir_sort_on.txt | Updated as part of this pull request. |
| tests/Spice86.Tests/Resources/cpuTests/res/DumpedListing/batch_dir_lists_files.txt | Updated as part of this pull request. |
| tests/Spice86.Tests/Resources/cpuTests/res/DumpedListing/batch_dir_bare_format.txt | Updated as part of this pull request. |
| tests/Spice86.Tests/Resources/cpuTests/res/DumpedListing/batch_dir_ad_directories.txt | Updated as part of this pull request. |
| tests/Spice86.Tests/Resources/cpuTests/res/DumpedListing/batch_delete_alias.txt | Updated as part of this pull request. |
| tests/Spice86.Tests/Resources/cpuTests/res/DumpedListing/batch_del_wildcard.txt | Updated as part of this pull request. |
| tests/Spice86.Tests/Resources/cpuTests/res/DumpedListing/batch_del_single_file.txt | Updated as part of this pull request. |
| tests/Spice86.Tests/Resources/cpuTests/res/DumpedListing/batch_del_missing_error.txt | Updated as part of this pull request. |
| tests/Spice86.Tests/Resources/cpuTests/res/DumpedListing/batch_date_set_value.txt | Updated as part of this pull request. |
| tests/Spice86.Tests/Resources/cpuTests/res/DumpedListing/batch_date_prints.txt | Updated as part of this pull request. |
| tests/Spice86.Tests/Resources/cpuTests/res/DumpedListing/batch_date_host_sync.txt | Updated as part of this pull request. |
| tests/Spice86.Tests/Resources/cpuTests/res/DumpedListing/batch_date_help.txt | Updated as part of this pull request. |
| tests/Spice86.Tests/Resources/cpuTests/res/DumpedListing/batch_copy_wildcard.txt | Updated as part of this pull request. |
| tests/Spice86.Tests/Resources/cpuTests/res/DumpedListing/batch_copy_to_directory.txt | Updated as part of this pull request. |
| tests/Spice86.Tests/Resources/cpuTests/res/DumpedListing/batch_copy_switches.txt | Updated as part of this pull request. |
| tests/Spice86.Tests/Resources/cpuTests/res/DumpedListing/batch_copy_single_file.txt | Updated as part of this pull request. |
| tests/Spice86.Tests/Resources/cpuTests/res/DumpedListing/batch_copy_missing_source.txt | Updated as part of this pull request. |
| tests/Spice86.Tests/Resources/cpuTests/res/DumpedListing/batch_copy_concat_two.txt | Updated as part of this pull request. |
| tests/Spice86.Tests/Resources/cpuTests/res/DumpedListing/batch_copy_concat_three.txt | Updated as part of this pull request. |
| tests/Spice86.Tests/Resources/cpuTests/res/DumpedListing/batch_cd_no_args.txt | Updated as part of this pull request. |
| tests/Spice86.Tests/Resources/cpuTests/res/DumpedListing/batch_cd_dotdot_parent.txt | Updated as part of this pull request. |
| tests/Spice86.Tests/Resources/cpuTests/res/DumpedListing/batch_cd_dot_stays.txt | Updated as part of this pull request. |
| tests/Spice86.Tests/Resources/cpuTests/res/DumpedListing/batch_cd_changes_directory.txt | Updated as part of this pull request. |
| tests/Spice86.Tests/Resources/cpuTests/res/DumpedListing/batch_cd_backslash_root.txt | Updated as part of this pull request. |
| tests/Spice86.Tests/MachineTest.cs | Updated as part of this pull request. |
| tests/Spice86.Tests/CpuTests/SingleStepTests/SingleStepTestMinimalMachine.cs | Updated as part of this pull request. |
| tests/Spice86.Tests/CfgCpu/CfgNodeExecutionCompilerTest.cs | Updated as part of this pull request. |
| tests/Spice86.Tests/CallbackNumbersTest.cs | Updated as part of this pull request. |
| tests/Spice86.Tests/AsmFixtures/BiosDeviceScenarioCatalog.cs | Updated as part of this pull request. |
| src/Spice86/Spice86DependencyInjection.cs | Updated as part of this pull request. |
| src/Spice86.Core/Emulator/ReverseEngineer/CfgCodeGeneration/Ir/IrLifter.cs | Updated as part of this pull request. |
| src/Spice86.Core/Emulator/InterruptHandlers/Timer/TimerInt8Handler.cs | Updated as part of this pull request. |
| src/Spice86.Core/Emulator/CPU/State.cs | Updated as part of this pull request. |
| src/Spice86.Core/Emulator/CPU/CfgCpu/InstructionExecutor/InstructionExecutionHelper.cs | Updated as part of this pull request. |
| src/Spice86.Core/CLI/Configuration.cs | Updated as part of this pull request. |
Review effort: Balanced
cedbed3 to
3953ad1
Compare
5eeef6b to
95bcdc5
Compare
95bcdc5 to
35aeca8
Compare
89f75e8 to
bfd4c57
Compare
| mov dx, 0 | ||
| sti | ||
| hlt | ||
| mov [0], dx ; only the wait-mode run reaches here: the handler set dx to 1 |
There was a problem hiding this comment.
If I look at the generated code, this line is never reached.
I wonder if hlt shouldnt be an infinite wait loop with a jump dispatcher in mode where hlt doesnt cause emulator exit
Match DOSBox Staging: with IF=1, HLT idles until an IRQ is delivered. Add --HltStopsEmulation to keep the old behavior (used by tests). Skip HLT successor in IrLifter. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The HLT idle path skipped CPU_CYCLES breakpoints, so exact-count breakpoints and the test max-cycle failsafe never fired while waiting for an IRQ. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- hlt.asm: STI; HLT wait program registered as the "hlt" scenario in the generated-code catalogue: discovery, machine goldens, generated source (return Hlt()), compile and generated run with oracle. - hltmask.asm: masked-PIC wait program for the cycle-breakpoint-while-halted check. - HltStopsEmulation is now an AsmRunSettings option, wired through Spice86Creator, with a .hltwait golden-key suffix when non-default. - MachineTest: TestHlt, TestHltWaitsForHardwareInterrupt and TestHltCycleBreakpointTriggersWhileHalted (interpreted and JIT). Remove HltTest.cs. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
bfd4c57 to
ab611a0
Compare
| InterruptFlag = true; | ||
| CheckExternalEvents(biosSegment, 0x0031); | ||
| // F000:0031 hlt | ||
| return Hlt(); |
There was a problem hiding this comment.
This seems to be the 1st hlt in the listing, others are not generated

Description of Changes
State.IsHalted) until a hardware interrupt is delivered, instead of stopping emulation. Cycles still advance while halted, and CPU_CYCLES breakpoints are checked on each idle step (somonitor breakCyclesand the test max-cycle failsafe still fire). HLT with IF=0 still stops emulation.CfgCpu.HandleExternalInterruptsplit: newDeliverExternalInterruptclearsIsHaltedon delivery.--HltStopsEmulationtoggles the previous behavior (HLT always stops emulation). ASM test fixtures and SingleStepTest enable it, since for them HLT is the expected end-of-program marker.IrLifter: the CFG successor after HLT is not treated as a method successor (generatedHlt()exits), fixing "Successor not in blocks" in the code-generator dump.HltTest):hlt.asmis thehltscenario of the generated-code catalogue (discovery, machine goldens, generated source ending inreturn Hlt(), compile, generated run with oracle);hltmask.asmcovers the CPU cycle breakpoint firing while the CPU is halted;TestHltWaitsForHardwareInterruptcovers the wait-for-IRQ behavior (IRQ0 handler runs while halted, program resumes past the HLT), both interpreted and JIT.Rationale behind Changes
Maupiti Island exited right after the V (VGA) / C (clavier) prompts. Its PIT calibration routine hooks IRQ0 and runs
sti; hltto wait for the timer tick; Spice86 stopped on any HLT. DOSBox Staging (CPU_HLT/hlt_decode) idles until an interrupt changes CS:IP. This PR matches that behavior by default.It runs now:
Known limitation: generated C# code still exits on HLT.
Suggested Testing Steps
dotnet build tests/Spice86.Tests: succeeded (0 warnings, 0 errors) after the ASM-fixture commit.dotnet test tests/Spice86.Tests --no-build -- --filter-not-class '*SingleStepTest*': 8264 passed, 1 failed — the failure isCfgNodeExecutionCompilerTest.Compile_SecondCallPreventsStaleSwap, a 30-second timing-window test that passes in isolation and as a class (load-dependent flake; the follow-up commit changes test infrastructure only).