From 21278d028c823926ab60109b5b443d46d243660f Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sun, 10 Mar 2024 21:56:19 -0400 Subject: [PATCH] Correct unaligned accesses. --- Machines/Acorn/Archimedes/Archimedes.cpp | 10 ++++++++++ OSBindings/Mac/Clock SignalTests/ARMDecoderTests.mm | 7 +++++++ 2 files changed, 17 insertions(+) diff --git a/Machines/Acorn/Archimedes/Archimedes.cpp b/Machines/Acorn/Archimedes/Archimedes.cpp index 5b976baa5..3535853d2 100644 --- a/Machines/Acorn/Archimedes/Archimedes.cpp +++ b/Machines/Acorn/Archimedes/Archimedes.cpp @@ -290,6 +290,10 @@ struct Memory { bool write(uint32_t address, IntT source, InstructionSet::ARM::Mode mode, bool trans) { (void)trans; + if constexpr (std::is_same_v) { + address &= static_cast(~3); + } + // if(address == 0x0200002c && address < 0x04000000) { // if(address == 0x02000074) { // printf("%08x <- %08x\n", address, source); @@ -363,6 +367,12 @@ struct Memory { template bool read(uint32_t address, IntT &source, InstructionSet::ARM::Mode mode, bool trans) { + // Unaligned addresses are presented on the bus, but in an Archimedes + // the bus will ignore the low two bits. + if constexpr (std::is_same_v) { + address &= static_cast(~3); + } + (void)trans; // logger.info().append("R %08x", address); diff --git a/OSBindings/Mac/Clock SignalTests/ARMDecoderTests.mm b/OSBindings/Mac/Clock SignalTests/ARMDecoderTests.mm index a78530b97..0b6960de6 100644 --- a/OSBindings/Mac/Clock SignalTests/ARMDecoderTests.mm +++ b/OSBindings/Mac/Clock SignalTests/ARMDecoderTests.mm @@ -65,6 +65,9 @@ struct Memory { struct MemoryLedger { template bool write(uint32_t address, IntT source, Mode, bool) { + if constexpr (std::is_same_v) { + address &= static_cast(~3); + } if(write_pointer == writes.size() || writes[write_pointer].size != sizeof(IntT) || writes[write_pointer].address != address || writes[write_pointer].value != source) { return false; } @@ -74,6 +77,10 @@ struct MemoryLedger { template bool read(uint32_t address, IntT &source, Mode, bool) { + if constexpr (std::is_same_v) { + address &= static_cast(~3); + } + if(read_pointer == reads.size() || reads[read_pointer].size != sizeof(IntT) || reads[read_pointer].address != address) { return false; }