1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-07-04 18:29:40 +00:00

Fix indirect memory read/write

This commit is contained in:
Thomas Harte 2022-02-27 18:43:00 -05:00
parent 27d1df4699
commit 84ac68a58b
2 changed files with 21 additions and 6 deletions

View File

@ -12,6 +12,8 @@
#include "Instruction.hpp"
#include "Model.hpp"
#include <cassert>
namespace InstructionSet {
namespace x86 {
@ -132,13 +134,25 @@ template <Model model, typename RegistersT, typename MemoryT> class DataPointerR
if constexpr (model >= Model::i80386) {
index <<= pointer.scale();
} else {
assert(!pointer.scale());
}
// TODO: verify application of memory_mask here.
value = memory.template read<DataT>(
instruction.data_segment(),
(base & memory_mask) + (index & memory_mask)
);
const uint32_t address = (base & memory_mask) + (index & memory_mask);
if constexpr (is_write) {
value = memory.template read<DataT>(
instruction.data_segment(),
address
);
} else {
memory.template write<DataT>(
instruction.data_segment(),
address,
value
);
}
}
}
#undef ALLREGS

View File

@ -27,7 +27,7 @@ using namespace InstructionSet::x86;
- (void)testX {
const DataPointer pointer(
Source::eAX, Source::eDI, 2
Source::eAX, Source::eDI, 0
);
struct Registers {
@ -49,6 +49,7 @@ using namespace InstructionSet::x86;
template<typename DataT> DataT read(Source segment, uint32_t address) {
(void)segment;
(void)address;
printf("Access at %d\n", address);
return 0;
}
template<typename DataT> void write(Source, uint32_t, DataT) {
@ -65,7 +66,7 @@ using namespace InstructionSet::x86;
registers,
memory,
instruction,
instruction.source()
pointer
);
printf("%d\n", value);