From bf8c97abbb93382eceb71c1d795f0c67ed1caf79 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sat, 7 May 2022 20:32:39 -0400 Subject: [PATCH] Permit TRAP, TRAPV and CHK to push the next PC rather than the current. --- InstructionSets/M68k/Executor.hpp | 5 +++-- .../M68k/Implementation/ExecutorImplementation.hpp | 4 ++-- .../M68k/Implementation/PerformImplementation.hpp | 6 +++--- OSBindings/Mac/Clock SignalTests/68000ComparativeTests.mm | 2 +- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/InstructionSets/M68k/Executor.hpp b/InstructionSets/M68k/Executor.hpp index 970da704e..769a1951a 100644 --- a/InstructionSets/M68k/Executor.hpp +++ b/InstructionSets/M68k/Executor.hpp @@ -39,13 +39,14 @@ template class Executor { // Flow control. void consume_cycles(int) {} - void raise_exception(int); - void stop(); void set_pc(uint32_t); void add_pc(uint32_t); void decline_branch() {} + + void raise_exception(int, bool use_current_instruction_pc = true); void did_update_status(); + void stop(); void bsr(uint32_t offset); void jsr(uint32_t offset); void link(Preinstruction instruction, uint32_t offset); diff --git a/InstructionSets/M68k/Implementation/ExecutorImplementation.hpp b/InstructionSets/M68k/Implementation/ExecutorImplementation.hpp index 6251a80b8..671583539 100644 --- a/InstructionSets/M68k/Implementation/ExecutorImplementation.hpp +++ b/InstructionSets/M68k/Implementation/ExecutorImplementation.hpp @@ -330,7 +330,7 @@ void Executor::set_state(const Registers &state) { // TODO: flow control, all below here. template -void Executor::raise_exception(int index) { +void Executor::raise_exception(int index, bool use_current_instruction_pc) { const uint32_t address = index << 2; // Grab the status to store, then switch into supervisor mode. @@ -339,7 +339,7 @@ void Executor::raise_exception(int index) { did_update_status(); // Push status and the program counter at instruction start. - bus_handler_.template write(sp.l - 4, instruction_address_); + bus_handler_.template write(sp.l - 4, use_current_instruction_pc ? instruction_address_ : program_counter_.l); bus_handler_.template write(sp.l - 6, status); sp.l -= 6; diff --git a/InstructionSets/M68k/Implementation/PerformImplementation.hpp b/InstructionSets/M68k/Implementation/PerformImplementation.hpp index 42cc8c73a..c2d3e6cc4 100644 --- a/InstructionSets/M68k/Implementation/PerformImplementation.hpp +++ b/InstructionSets/M68k/Implementation/PerformImplementation.hpp @@ -652,12 +652,12 @@ template < // TRAP, which is a nicer form of ILLEGAL. case Operation::TRAP: - flow_controller.raise_exception(src.l + 32); + flow_controller.raise_exception(src.l + 32, false); break; case Operation::TRAPV: { if(status.overflow_flag_) { - flow_controller.raise_exception(7); + flow_controller.raise_exception(7, false); } } break; @@ -683,7 +683,7 @@ template < } else { flow_controller.consume_cycles(12); } - flow_controller.raise_exception(6); + flow_controller.raise_exception(6, false); } } break; diff --git a/OSBindings/Mac/Clock SignalTests/68000ComparativeTests.mm b/OSBindings/Mac/Clock SignalTests/68000ComparativeTests.mm index 21d6327ef..9faf3c5b6 100644 --- a/OSBindings/Mac/Clock SignalTests/68000ComparativeTests.mm +++ b/OSBindings/Mac/Clock SignalTests/68000ComparativeTests.mm @@ -83,7 +83,7 @@ - (void)setUp { // To limit tests run to a subset of files and/or of tests, uncomment and fill in below. -// _fileSet = [NSSet setWithArray:@[@"link_unlk.json"]]; + _fileSet = [NSSet setWithArray:@[@"ext.json"]]; // _testSet = [NSSet setWithArray:@[@"NEGX 00c0"]]; // _fileSet = [NSSet setWithArray:@[@"jmp_jsr.json"]]; // _testSet = [NSSet setWithArray:@[@"CHK 41a8"]];