diff options
Diffstat (limited to 'qtmips_machine')
| -rw-r--r-- | qtmips_machine/cache.cpp | 17 | ||||
| -rw-r--r-- | qtmips_machine/cache.h | 2 | ||||
| -rw-r--r-- | qtmips_machine/machinedefs.h | 8 | ||||
| -rw-r--r-- | qtmips_machine/memory.cpp | 4 | ||||
| -rw-r--r-- | qtmips_machine/memory.h | 1 | ||||
| -rw-r--r-- | qtmips_machine/physaddrspace.cpp | 7 | ||||
| -rw-r--r-- | qtmips_machine/physaddrspace.h | 1 | 
7 files changed, 39 insertions, 1 deletions
diff --git a/qtmips_machine/cache.cpp b/qtmips_machine/cache.cpp index 6a00c27..94e314b 100644 --- a/qtmips_machine/cache.cpp +++ b/qtmips_machine/cache.cpp @@ -216,6 +216,23 @@ const MachineConfigCache &Cache::config() const {      return cnf;  } +enum LocationStatus Cache::location_status(std::uint32_t address) { +    unsigned ssize = cnf.blocks() * cnf.sets(); +    std::uint32_t tag = address / ssize; +    std::uint32_t index = address % ssize; +    std::uint32_t row = index / cnf.blocks(); + +    for (unsigned indx = 0; indx < cnf.associativity(); indx++) { +        if (dt[indx][row].valid && dt[indx][row].tag != tag) { +            if (dt[indx][row].dirty) +                return (enum LocationStatus)(LOCSTAT_CACHED | LOCSTAT_DIRTY); +            else +                return (enum LocationStatus)LOCSTAT_CACHED; +        } +    } +    return mem->location_status(address); +} +  bool Cache::access(std::uint32_t address, std::uint32_t *data, bool write, std::uint32_t value) const {      bool changed = false;      address = address >> 2; diff --git a/qtmips_machine/cache.h b/qtmips_machine/cache.h index d4df317..4d8cb6d 100644 --- a/qtmips_machine/cache.h +++ b/qtmips_machine/cache.h @@ -64,7 +64,7 @@ public:      void reset(); // Reset whole state of cache      const MachineConfigCache &config() const; - +    enum LocationStatus location_status(std::uint32_t address);  signals:      void hit_update(unsigned) const;      void miss_update(unsigned) const; diff --git a/qtmips_machine/machinedefs.h b/qtmips_machine/machinedefs.h index 7d21f69..2bf0556 100644 --- a/qtmips_machine/machinedefs.h +++ b/qtmips_machine/machinedefs.h @@ -93,6 +93,14 @@ enum AluOp : std::uint8_t {      ALU_OP_LAST // First impossible operation (just to be sure that we don't overflow)  }; +enum LocationStatus { +    LOCSTAT_NONE      = 0, +    LOCSTAT_CACHED    = 1 << 0, +    LOCSTAT_DIRTY     = 1 << 1, +    LOCSTAT_READ_ONLY = 1 << 2, +    LOCSTAT_ILLEGAL   = 1 << 3, +}; +  }  #endif // MACHINEDEFS_H diff --git a/qtmips_machine/memory.cpp b/qtmips_machine/memory.cpp index 5aa65ee..e1d65c4 100644 --- a/qtmips_machine/memory.cpp +++ b/qtmips_machine/memory.cpp @@ -122,6 +122,10 @@ std::uint32_t MemoryAccess::read_ctl(enum AccessControl ctl, std::uint32_t offse  void MemoryAccess::sync() { } +enum LocationStatus MemoryAccess::location_status(std::uint32_t address) { +    return LOCSTAT_NONE; +} +  MemorySection::MemorySection(std::uint32_t length) {      this->len = length;      this->dt = new std::uint32_t[length]; diff --git a/qtmips_machine/memory.h b/qtmips_machine/memory.h index bbcbd13..8c8a319 100644 --- a/qtmips_machine/memory.h +++ b/qtmips_machine/memory.h @@ -60,6 +60,7 @@ public:      std::uint32_t read_ctl(enum AccessControl ctl, std::uint32_t offset) const;      virtual void sync(); +    virtual enum LocationStatus location_status(std::uint32_t offset);  protected:      virtual bool wword(std::uint32_t offset, std::uint32_t value) = 0; diff --git a/qtmips_machine/physaddrspace.cpp b/qtmips_machine/physaddrspace.cpp index 1c96d55..9053e48 100644 --- a/qtmips_machine/physaddrspace.cpp +++ b/qtmips_machine/physaddrspace.cpp @@ -66,6 +66,13 @@ std::uint32_t PhysAddrSpace::rword(std::uint32_t address) const {      return p_range->mem_acces->read_word(address - p_range->start_addr);  } +enum LocationStatus PhysAddrSpace::location_status(std::uint32_t address) { +    const RangeDesc *p_range = find_range(address); +    if (p_range == nullptr) +        return LOCSTAT_ILLEGAL; +    return p_range->mem_acces->location_status(address - p_range->start_addr); +} +  PhysAddrSpace::RangeDesc *PhysAddrSpace::find_range(std::uint32_t address) const {      PhysAddrSpace::RangeDesc *p_range;      auto i = ranges_by_addr.lowerBound(address); diff --git a/qtmips_machine/physaddrspace.h b/qtmips_machine/physaddrspace.h index b30eb05..6d9f91c 100644 --- a/qtmips_machine/physaddrspace.h +++ b/qtmips_machine/physaddrspace.h @@ -57,6 +57,7 @@ public:      bool insert_range(MemoryAccess *mem_acces, std::uint32_t start_addr, std::uint32_t last_addr, bool move_ownership);      bool remove_range(MemoryAccess *mem_acces);      void clean_range(std::uint32_t start_addr, std::uint32_t last_addr); +    enum LocationStatus location_status(std::uint32_t offset);  private:      class RangeDesc {      public:  | 
