From ff03a2f7b16ee43a591e0747621862c9ef75f41d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Ko=C4=8D=C3=AD?= Date: Thu, 5 Apr 2018 11:41:50 +0200 Subject: Use whole words in memory --- qtmips_machine/memory.h | 36 ++++++++++++++++-------------------- 1 file changed, 16 insertions(+), 20 deletions(-) (limited to 'qtmips_machine/memory.h') diff --git a/qtmips_machine/memory.h b/qtmips_machine/memory.h index 525ca56..8dea63c 100644 --- a/qtmips_machine/memory.h +++ b/qtmips_machine/memory.h @@ -11,6 +11,7 @@ namespace machine { class MemoryAccess : public QObject { Q_OBJECT public: + // Note: hword and word methods are throwing away lowest bits so unaligned access is ignored without error. void write_byte(std::uint32_t offset, std::uint8_t value); void write_hword(std::uint32_t offset, std::uint16_t value); void write_word(std::uint32_t offset, std::uint32_t value); @@ -30,12 +31,12 @@ public: void write_ctl(enum AccessControl ctl, std::uint32_t offset, std::uint32_t value); std::uint32_t read_ctl(enum AccessControl ctl, std::uint32_t offset) const; -signals: - void byte_change(std::uint32_t address, std::uint32_t value); - protected: - virtual void wbyte(std::uint32_t offset, std::uint8_t value) = 0; - virtual std::uint8_t rbyte(std::uint32_t offset) const = 0; + virtual void wword(std::uint32_t offset, std::uint32_t value) = 0; + virtual std::uint32_t rword(std::uint32_t offset) const = 0; + +private: + static int sh_nth(std::uint32_t offset); }; class MemorySection : public MemoryAccess { @@ -44,30 +45,25 @@ public: MemorySection(const MemorySection&); ~MemorySection(); - void wbyte(std::uint32_t offset, std::uint8_t value); - std::uint8_t rbyte(std::uint32_t offset) const; + void wword(std::uint32_t offset, std::uint32_t value); + std::uint32_t rword(std::uint32_t offset) const; void merge(MemorySection&); std::uint32_t length() const; - const std::uint8_t* data() const; + const std::uint32_t* data() const; bool operator==(const MemorySection&) const; bool operator!=(const MemorySection&) const; private: std::uint32_t len; - std::uint8_t *dt; + std::uint32_t *dt; }; -////////////////////////////////////////////////////////////////////////////// -/// Some optimalization options -// How big memory sections will be (2^8=256) -#define MEMORY_SECTION_BITS 8 -// How deep memory lookup tree will be -#define MEMORY_TREE_H 4 -////////////////////////////////////////////////////////////////////////////// - -union MemoryTree; +union MemoryTree { + union MemoryTree *mt; + MemorySection *sec; +}; class Memory : public MemoryAccess { Q_OBJECT @@ -79,8 +75,8 @@ public: void reset(const Memory&); MemorySection *get_section(std::uint32_t address, bool create) const; // returns section containing given address - void wbyte(std::uint32_t address, std::uint8_t value); - std::uint8_t rbyte(std::uint32_t address) const; + void wword(std::uint32_t address, std::uint32_t value); + std::uint32_t rword(std::uint32_t address) const; bool operator==(const Memory&) const; bool operator!=(const Memory&) const; -- cgit v1.2.3