From 0d2af80f7f020e7dbe595965115527412c59f326 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sun, 8 Oct 2023 13:50:36 -0400 Subject: [PATCH] Avoid access issues if there's no index. --- .../Implementation/PerformImplementation.hpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/InstructionSets/x86/Implementation/PerformImplementation.hpp b/InstructionSets/x86/Implementation/PerformImplementation.hpp index e64042c4f..ce0ae512d 100644 --- a/InstructionSets/x86/Implementation/PerformImplementation.hpp +++ b/InstructionSets/x86/Implementation/PerformImplementation.hpp @@ -203,7 +203,7 @@ void add(IntT &destination, IntT source, Status &status) { } template -typename DataSizeType::type *resolve(InstructionT &instruction, Source source, DataPointer pointer, RegistersT ®isters, MemoryT &memory) { +typename DataSizeType::type *resolve(InstructionT &instruction, Source source, DataPointer pointer, RegistersT ®isters, MemoryT &memory, typename DataSizeType::type *none = nullptr) { // Rules: // // * if this is a memory access, set target_address and break; @@ -266,23 +266,26 @@ typename DataSizeType::type *resolve(InstructionT &instruction, Sourc case Source::Immediate: // TODO (here the use of a pointer falls down?) - case Source::None: return nullptr; + case Source::None: return none; - case Source::Indirect: // TODO: non-word indexes and bases. - address = *resolve(instruction, pointer.index(), pointer, registers, memory); + // TODO: non-word indexes and bases in the next two cases. + case Source::Indirect: { + uint16_t zero = 0; + address = *resolve(instruction, pointer.index(), pointer, registers, memory, &zero); if constexpr (is_32bit(model)) { address <<= pointer.scale(); } address += instruction.offset() + *resolve(instruction, pointer.base(), pointer, registers, memory); - break; + } break; - case Source::IndirectNoBase: // TODO: non-word indexes and bases. - address = *resolve(instruction, pointer.index(), pointer, registers, memory); + case Source::IndirectNoBase: { + uint16_t zero = 0; + address = *resolve(instruction, pointer.index(), pointer, registers, memory, &zero); if constexpr (is_32bit(model)) { address <<= pointer.scale(); } address += instruction.offset(); - break; + } break; case Source::DirectAddress: address = instruction.offset();