mirror of
https://github.com/TomHarte/CLK.git
synced 2025-02-02 01:31:15 +00:00
Fix indirect memory read/write
This commit is contained in:
parent
27d1df4699
commit
84ac68a58b
@ -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
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user