diff --git a/Processors/68000Mk2/Implementation/68000Mk2Implementation.hpp b/Processors/68000Mk2/Implementation/68000Mk2Implementation.hpp index 519ba8cdd..3de565497 100644 --- a/Processors/68000Mk2/Implementation/68000Mk2Implementation.hpp +++ b/Processors/68000Mk2/Implementation/68000Mk2Implementation.hpp @@ -12,6 +12,8 @@ #include #include +#include "../../../InstructionSets/M68k/ExceptionVectors.hpp" + namespace CPU { namespace MC68000Mk2 { @@ -31,6 +33,9 @@ enum ExecutionState: int { StoreOperand, StoreOperand_l, + StandardException, + BusOrAddressErrorException, + // Specific addressing mode fetches. FetchAddressRegisterIndirect_bw, @@ -70,6 +75,11 @@ enum ExecutionState: int { MOVEwAddressRegisterIndirectWithPostincrement, SABCD_PreDec, + + CHK, + CHK_no_trap, + CHK_was_over, + CHK_was_under, }; // MARK: - The state machine. @@ -240,6 +250,47 @@ void Processor( + instruction_, operand_[0], operand_[1], status_, *static_cast(this)); + + // Proper next state will have been set by the flow controller + // call-in; just allow dispatch to whatever it was. + break; + + BeginState(CHK_no_trap): + IdleBus(3); // nn n + MoveToState(Decode); + + BeginState(CHK_was_over): + IdleBus(2); // nn + instruction_address_.l = program_counter_.l - 4; + exception_vector_ = InstructionSet::M68k::Exception::CHK; + MoveToState(StandardException); + + BeginState(CHK_was_under): + IdleBus(3); // n nn + instruction_address_.l = program_counter_.l - 4; + exception_vector_ = InstructionSet::M68k::Exception::CHK; + MoveToState(StandardException); + // Various states TODO. #define TODOState(x) \ BeginState(x): [[fallthrough]]; -// TODOState(FetchImmediateData_l); + TODOState(BusOrAddressErrorException); #undef TODOState @@ -845,6 +942,16 @@ void ProcessorBase::did_update_status() { is_supervisor_ = int(status_.is_supervisor); } +void ProcessorBase::did_chk(bool was_under, bool was_over) { + if(was_over) { + state_ = CHK_was_over; + } else if(was_under) { + state_ = CHK_was_under; + } else { + state_ = CHK_no_trap; + } +} + // MARK: - External state. template diff --git a/Processors/68000Mk2/Implementation/68000Mk2Storage.hpp b/Processors/68000Mk2/Implementation/68000Mk2Storage.hpp index 4dc3a0481..b24dc693d 100644 --- a/Processors/68000Mk2/Implementation/68000Mk2Storage.hpp +++ b/Processors/68000Mk2/Implementation/68000Mk2Storage.hpp @@ -38,7 +38,7 @@ struct ProcessorBase: public InstructionSet::M68k::NullFlowController { InstructionSet::M68k::Preinstruction instruction_; uint16_t opcode_; uint8_t operand_flags_; - uint32_t instruction_address_; + SlicedInt32 instruction_address_; // Register state. InstructionSet::M68k::Status status_; @@ -81,6 +81,12 @@ struct ProcessorBase: public InstructionSet::M68k::NullFlowController { /// a data select). uint32_t temporary_address_ = 0; + /// A record of the exception to trigger. + int exception_vector_ = 0; + + /// Transient storage for exception processing. + SlicedInt16 captured_status_; + // Flow controller... all TODO. using Preinstruction = InstructionSet::M68k::Preinstruction; @@ -91,28 +97,28 @@ struct ProcessorBase: public InstructionSet::M68k::NullFlowController { template void did_mulu(IntT) {} template void did_muls(IntT) {} - void did_chk(bool, bool) {} - void did_shift(int) {} + inline void did_chk(bool, bool); + inline void did_shift(int) {} template void did_divu(uint32_t, uint32_t) {} template void did_divs(int32_t, int32_t) {} - void did_bit_op(int) {} + inline void did_bit_op(int) {} inline void did_update_status(); template void complete_bcc(bool, IntT) {} - void complete_dbcc(bool, bool, int16_t) {} - void bsr(uint32_t) {} - void jsr(uint32_t) {} - void jmp(uint32_t) {} - void rtr() {} - void rte() {} - void rts() {} - void stop() {} - void reset() {} - void link(Preinstruction, uint32_t) {} - void unlink(uint32_t &) {} - void pea(uint32_t) {} - void move_to_usp(uint32_t) {} - void move_from_usp(uint32_t &) {} - void tas(Preinstruction, uint32_t) {} + inline void complete_dbcc(bool, bool, int16_t) {} + inline void bsr(uint32_t) {} + inline void jsr(uint32_t) {} + inline void jmp(uint32_t) {} + inline void rtr() {} + inline void rte() {} + inline void rts() {} + inline void stop() {} + inline void reset() {} + inline void link(Preinstruction, uint32_t) {} + inline void unlink(uint32_t &) {} + inline void pea(uint32_t) {} + inline void move_to_usp(uint32_t) {} + inline void move_from_usp(uint32_t &) {} + inline void tas(Preinstruction, uint32_t) {} template void movep(Preinstruction, uint32_t, uint32_t) {} template void movem_toM(Preinstruction, uint32_t, uint32_t) {} template void movem_toR(Preinstruction, uint32_t, uint32_t) {}