From 2b3900fd14c3de525e9e291947584b887bae0e56 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sat, 7 May 2022 08:15:26 -0400 Subject: [PATCH] Fix LINK A7. --- InstructionSets/M68k/Executor.hpp | 2 +- .../M68k/Implementation/ExecutorImplementation.hpp | 8 +++++--- .../M68k/Implementation/PerformImplementation.hpp | 2 +- InstructionSets/M68k/Instruction.hpp | 2 +- OSBindings/Mac/Clock SignalTests/68000ComparativeTests.mm | 2 +- 5 files changed, 9 insertions(+), 7 deletions(-) diff --git a/InstructionSets/M68k/Executor.hpp b/InstructionSets/M68k/Executor.hpp index 6c35cde9b..970da704e 100644 --- a/InstructionSets/M68k/Executor.hpp +++ b/InstructionSets/M68k/Executor.hpp @@ -48,7 +48,7 @@ template class Executor { void bsr(uint32_t offset); void jsr(uint32_t offset); - void link(uint32_t &address, uint32_t offset); + void link(Preinstruction instruction, uint32_t offset); void unlink(uint32_t &address); template void movep(Preinstruction instruction, uint32_t source, uint32_t dest); template void movem_toM(Preinstruction instruction, uint32_t source, uint32_t dest); diff --git a/InstructionSets/M68k/Implementation/ExecutorImplementation.hpp b/InstructionSets/M68k/Implementation/ExecutorImplementation.hpp index 5b232e632..03b1f0069 100644 --- a/InstructionSets/M68k/Implementation/ExecutorImplementation.hpp +++ b/InstructionSets/M68k/Implementation/ExecutorImplementation.hpp @@ -381,10 +381,12 @@ void Executor::jsr(uint32_t address) { } template -void Executor::link(uint32_t &address, uint32_t offset) { +void Executor::link(Preinstruction instruction, uint32_t offset) { + const auto reg = 8 + instruction.reg<0>(); + sp().l -= 4; - bus_handler_.template write(sp().l, address); - address = sp().l; + bus_handler_.template write(sp().l, registers_[reg].l); + registers_[reg] = sp(); sp().l += offset; } diff --git a/InstructionSets/M68k/Implementation/PerformImplementation.hpp b/InstructionSets/M68k/Implementation/PerformImplementation.hpp index 2f98a4b4a..42cc8c73a 100644 --- a/InstructionSets/M68k/Implementation/PerformImplementation.hpp +++ b/InstructionSets/M68k/Implementation/PerformImplementation.hpp @@ -781,7 +781,7 @@ template < */ case Operation::LINKw: - flow_controller.link(src.l, int16_t(dest.w)); + flow_controller.link(instruction, int16_t(dest.w)); break; case Operation::UNLINK: diff --git a/InstructionSets/M68k/Instruction.hpp b/InstructionSets/M68k/Instruction.hpp index b189259a9..bb81ab0fd 100644 --- a/InstructionSets/M68k/Instruction.hpp +++ b/InstructionSets/M68k/Instruction.hpp @@ -331,6 +331,7 @@ template uint8_t ope case Operation::CMPAw: case Operation::CMPAl: case Operation::CHK: case Operation::BTST: + case Operation::LINKw: return FetchOp1 | FetchOp2; // @@ -371,7 +372,6 @@ template uint8_t ope // Two-operand; read both, write source. // case Operation::DBcc: - case Operation::LINKw: return FetchOp1 | FetchOp2 | StoreOp1; // diff --git a/OSBindings/Mac/Clock SignalTests/68000ComparativeTests.mm b/OSBindings/Mac/Clock SignalTests/68000ComparativeTests.mm index bb54dd6e5..21d6327ef 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:@[@"rts.json", @"rtr.json"]]; +// _fileSet = [NSSet setWithArray:@[@"link_unlk.json"]]; // _testSet = [NSSet setWithArray:@[@"NEGX 00c0"]]; // _fileSet = [NSSet setWithArray:@[@"jmp_jsr.json"]]; // _testSet = [NSSet setWithArray:@[@"CHK 41a8"]];