1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-11-26 08:49:37 +00:00

Avoid access issues if there's no index.

This commit is contained in:
Thomas Harte 2023-10-08 13:50:36 -04:00
parent 6f768d9a3d
commit 0d2af80f7f

View File

@ -203,7 +203,7 @@ void add(IntT &destination, IntT source, Status &status) {
} }
template <Model model, DataSize data_size, typename InstructionT, typename RegistersT, typename MemoryT> template <Model model, DataSize data_size, typename InstructionT, typename RegistersT, typename MemoryT>
typename DataSizeType<data_size>::type *resolve(InstructionT &instruction, Source source, DataPointer pointer, RegistersT &registers, MemoryT &memory) { typename DataSizeType<data_size>::type *resolve(InstructionT &instruction, Source source, DataPointer pointer, RegistersT &registers, MemoryT &memory, typename DataSizeType<data_size>::type *none = nullptr) {
// Rules: // Rules:
// //
// * if this is a memory access, set target_address and break; // * if this is a memory access, set target_address and break;
@ -266,23 +266,26 @@ typename DataSizeType<data_size>::type *resolve(InstructionT &instruction, Sourc
case Source::Immediate: // TODO (here the use of a pointer falls down?) 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. // TODO: non-word indexes and bases in the next two cases.
address = *resolve<model, DataSize::Word>(instruction, pointer.index(), pointer, registers, memory); case Source::Indirect: {
uint16_t zero = 0;
address = *resolve<model, DataSize::Word>(instruction, pointer.index(), pointer, registers, memory, &zero);
if constexpr (is_32bit(model)) { if constexpr (is_32bit(model)) {
address <<= pointer.scale(); address <<= pointer.scale();
} }
address += instruction.offset() + *resolve<model, DataSize::Word>(instruction, pointer.base(), pointer, registers, memory); address += instruction.offset() + *resolve<model, DataSize::Word>(instruction, pointer.base(), pointer, registers, memory);
break; } break;
case Source::IndirectNoBase: // TODO: non-word indexes and bases. case Source::IndirectNoBase: {
address = *resolve<model, DataSize::Word>(instruction, pointer.index(), pointer, registers, memory); uint16_t zero = 0;
address = *resolve<model, DataSize::Word>(instruction, pointer.index(), pointer, registers, memory, &zero);
if constexpr (is_32bit(model)) { if constexpr (is_32bit(model)) {
address <<= pointer.scale(); address <<= pointer.scale();
} }
address += instruction.offset(); address += instruction.offset();
break; } break;
case Source::DirectAddress: case Source::DirectAddress:
address = instruction.offset(); address = instruction.offset();