From 1126b91af5bd2d4477b3e78e8c648b3a512b24f7 Mon Sep 17 00:00:00 2001 From: Pavel Pisa Date: Thu, 7 Feb 2019 18:26:45 +0100 Subject: Added method to retrieve memory location status. It can inform if given location is cached or if given range is invalid in address space. Signed-off-by: Pavel Pisa --- qtmips_machine/cache.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'qtmips_machine/cache.cpp') 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; -- cgit v1.2.3