1
0
mirror of https://github.com/TomHarte/CLK.git synced 2025-08-05 08:26:28 +00:00

Ensure that reads can only read, accept that source is sometimes written to. E.g. XCHG.

This commit is contained in:
Thomas Harte
2023-10-31 15:06:19 -04:00
parent 02af08ffd2
commit 1d479ec2d7
3 changed files with 208 additions and 170 deletions

View File

@@ -179,7 +179,16 @@ struct Memory {
return write_back_value_;
}
}
return access<IntT, type>(segment, address, Tag::Accessed);
auto &value = access<IntT, type>(segment, address, Tag::Accessed);
// For testing purposes: if the CPU indicated it'll only be reading, copy the requested value into a temporary
// location so that any writes will be discarded.
if(type == AccessType::Read) {
*reinterpret_cast<IntT *>(&read_value_) = value;
return *reinterpret_cast<IntT *>(&read_value_);
}
return value;
}
template <typename IntT>
@@ -196,6 +205,7 @@ struct Memory {
static constexpr uint32_t NoWriteBack = 0; // A low byte address of 0 can't require write-back.
uint32_t write_back_address_[2] = {NoWriteBack, NoWriteBack};
uint16_t write_back_value_;
uint16_t read_value_;
};
struct IO {
template <typename IntT> void out([[maybe_unused]] uint16_t port, [[maybe_unused]] IntT value) {}
@@ -385,6 +395,8 @@ struct FailedExecution {
return hexInstruction;
};
EACCES;
const auto decoded = decoder.decode(data.data(), data.size());
const bool sizeMatched = decoded.first == data.size();
if(assert) {