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 "Instruction.hpp"
|
||||||
#include "Model.hpp"
|
#include "Model.hpp"
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
namespace InstructionSet {
|
namespace InstructionSet {
|
||||||
namespace x86 {
|
namespace x86 {
|
||||||
|
|
||||||
@ -132,13 +134,25 @@ template <Model model, typename RegistersT, typename MemoryT> class DataPointerR
|
|||||||
|
|
||||||
if constexpr (model >= Model::i80386) {
|
if constexpr (model >= Model::i80386) {
|
||||||
index <<= pointer.scale();
|
index <<= pointer.scale();
|
||||||
|
} else {
|
||||||
|
assert(!pointer.scale());
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: verify application of memory_mask here.
|
// TODO: verify application of memory_mask here.
|
||||||
value = memory.template read<DataT>(
|
const uint32_t address = (base & memory_mask) + (index & memory_mask);
|
||||||
instruction.data_segment(),
|
|
||||||
(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
|
#undef ALLREGS
|
||||||
|
@ -27,7 +27,7 @@ using namespace InstructionSet::x86;
|
|||||||
|
|
||||||
- (void)testX {
|
- (void)testX {
|
||||||
const DataPointer pointer(
|
const DataPointer pointer(
|
||||||
Source::eAX, Source::eDI, 2
|
Source::eAX, Source::eDI, 0
|
||||||
);
|
);
|
||||||
|
|
||||||
struct Registers {
|
struct Registers {
|
||||||
@ -49,6 +49,7 @@ using namespace InstructionSet::x86;
|
|||||||
template<typename DataT> DataT read(Source segment, uint32_t address) {
|
template<typename DataT> DataT read(Source segment, uint32_t address) {
|
||||||
(void)segment;
|
(void)segment;
|
||||||
(void)address;
|
(void)address;
|
||||||
|
printf("Access at %d\n", address);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
template<typename DataT> void write(Source, uint32_t, DataT) {
|
template<typename DataT> void write(Source, uint32_t, DataT) {
|
||||||
@ -65,7 +66,7 @@ using namespace InstructionSet::x86;
|
|||||||
registers,
|
registers,
|
||||||
memory,
|
memory,
|
||||||
instruction,
|
instruction,
|
||||||
instruction.source()
|
pointer
|
||||||
);
|
);
|
||||||
|
|
||||||
printf("%d\n", value);
|
printf("%d\n", value);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user