diff options
author | Pavel Pisa <pisa@cmp.felk.cvut.cz> | 2019-02-03 23:03:59 +0100 |
---|---|---|
committer | Pavel Pisa <pisa@cmp.felk.cvut.cz> | 2019-02-03 23:03:59 +0100 |
commit | 361f5aab10d72e2200dfc7985a1511044b987db8 (patch) | |
tree | 02688761a1dc29731c0fc069a2d89205a867a8ef /qtmips_machine/memory.cpp | |
parent | 55e1bc746a45118e14554c957b4ee4663039d9af (diff) | |
download | qtmips-361f5aab10d72e2200dfc7985a1511044b987db8.tar.gz qtmips-361f5aab10d72e2200dfc7985a1511044b987db8.tar.bz2 qtmips-361f5aab10d72e2200dfc7985a1511044b987db8.zip |
Correct memory view updates for uncached and write-through case.
Signed-off-by: Pavel Pisa <pisa@cmp.felk.cvut.cz>
Diffstat (limited to 'qtmips_machine/memory.cpp')
-rw-r--r-- | qtmips_machine/memory.cpp | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/qtmips_machine/memory.cpp b/qtmips_machine/memory.cpp index 3b47ca7..77f2909 100644 --- a/qtmips_machine/memory.cpp +++ b/qtmips_machine/memory.cpp @@ -10,20 +10,20 @@ using namespace machine; #define SH_NTH_16(OFFSET) (((OFFSET) & 0b10) * 16) #endif -void MemoryAccess::write_byte(std::uint32_t offset, std::uint8_t value) { +bool MemoryAccess::write_byte(std::uint32_t offset, std::uint8_t value) { int nth = SH_NTH_8(offset); std::uint32_t mask = 0xff << nth; // Mask for n-th byte - wword(offset, (rword(offset) & ~mask) | (((std::uint32_t)value << nth) & mask)); + return wword(offset, (rword(offset) & ~mask) | (((std::uint32_t)value << nth) & mask)); } -void MemoryAccess::write_hword(std::uint32_t offset, std::uint16_t value) { +bool MemoryAccess::write_hword(std::uint32_t offset, std::uint16_t value) { int nth = SH_NTH_16(offset); std::uint32_t mask = 0xffff << nth; // Mask for n-th half-word - wword(offset, (rword(offset) & ~mask) | (((std::uint32_t)value << nth) & mask)); + return wword(offset, (rword(offset) & ~mask) | (((std::uint32_t)value << nth) & mask)); } -void MemoryAccess::write_word(std::uint32_t offset, std::uint32_t value) { - wword(offset, value); +bool MemoryAccess::write_word(std::uint32_t offset, std::uint32_t value) { + return wword(offset, value); } std::uint8_t MemoryAccess::read_byte(std::uint32_t offset) const { @@ -101,11 +101,14 @@ MemorySection::~MemorySection() { delete this->dt; } -void MemorySection::wword(std::uint32_t offset, std::uint32_t value) { +bool MemorySection::wword(std::uint32_t offset, std::uint32_t value) { + bool changed; offset = offset >> 2; if (offset >= this->len) throw QTMIPS_EXCEPTION(OutOfMemoryAccess, "Trying to write outside of the memory section", QString("Accessing using offset: ") + QString(offset)); + changed = this->dt[offset] != value; this->dt[offset] = value; + return changed; } std::uint32_t MemorySection::rword(std::uint32_t offset) const { @@ -206,9 +209,14 @@ MemorySection *Memory::get_section(std::uint32_t address, bool create) const { #define SECTION_OFFSET_MASK(ADDR) (ADDR & GENMASK(MEMORY_SECTION_BITS, 2)) -void Memory::wword(std::uint32_t address, std::uint32_t value) { +bool Memory::wword(std::uint32_t address, std::uint32_t value) { + bool changed; MemorySection *section = this->get_section(address, true); - section->write_word(SECTION_OFFSET_MASK(address), value); + changed = section->write_word(SECTION_OFFSET_MASK(address), value); + write_counter++; + if (changed) + change_counter++; + return changed; } std::uint32_t Memory::rword(std::uint32_t address) const { |