From 77b56c50e6466f18aee809edcad43d55660f0efb Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Fri, 13 May 2022 14:02:56 -0400 Subject: [PATCH] Ensure you can't trace into divide-by-zero, etc. --- InstructionSets/M68k/Executor.hpp | 3 +++ .../Implementation/ExecutorImplementation.hpp | 18 ++++++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/InstructionSets/M68k/Executor.hpp b/InstructionSets/M68k/Executor.hpp index d0663ddef..e9ca48b72 100644 --- a/InstructionSets/M68k/Executor.hpp +++ b/InstructionSets/M68k/Executor.hpp @@ -113,7 +113,10 @@ template class Executor { CPU::SlicedInt32 stack_pointers[2]; uint32_t instruction_address; uint16_t instruction_opcode; + + // Things that are ephemerally duplicative of Status. int active_stack_pointer = 0; + Status::FlagT should_trace = 0; // Bus state. int interrupt_input = 0; diff --git a/InstructionSets/M68k/Implementation/ExecutorImplementation.hpp b/InstructionSets/M68k/Implementation/ExecutorImplementation.hpp index 95dfd907b..add5cc1d9 100644 --- a/InstructionSets/M68k/Implementation/ExecutorImplementation.hpp +++ b/InstructionSets/M68k/Implementation/ExecutorImplementation.hpp @@ -69,6 +69,9 @@ void Executor::run_for_instructions(int count) { state_.status.trace_flag = 0; state_.did_update_status(); + // Ensure no tracing occurs into the exception. + state_.should_trace = 0; + // Push status and the program counter at instruction start. state_.template write(sp.l - 14, code); state_.template write(sp.l - 12, faulting_address); @@ -322,6 +325,14 @@ void Executor::State::run(int &count) { status.interrupt_level = interrupt_input; } + // Capture the trace bit, indicating whether to trace + // after this instruction. + // + // If an exception occurs, this value will be cleared, but + // it'll persist across mere status register changes for + // one instruction's duration. + should_trace = status.trace_flag; + // Read the next instruction. instruction_address = program_counter.l; instruction_opcode = read_pc(); @@ -345,10 +356,6 @@ void Executor::State::run(int &count) { } } - // Capture the trace bit, indicating whether to trace - // after this instruction. - const auto should_trace = status.trace_flag; - // Temporary storage. CPU::SlicedInt32 operand_[2]; EffectiveAddress effective_address_[2]; @@ -415,6 +422,9 @@ void Executor::State::raise_exception(int index) { write(sp.l - 6, previous_status); sp.l -= 6; + // Ensure no tracing occurs into the exception. + should_trace = 0; + // Fetch the new program counter. program_counter.l = read(address); }