From 7c226db9f04de7061596b98763dc408d601d74e1 Mon Sep 17 00:00:00 2001 From: bd Date: Tue, 11 Mar 2025 11:54:21 -0400 Subject: Clarify size of mem and cache in definitions, CLI print invalid tags --- src/storage/dram.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/storage/dram.cc') diff --git a/src/storage/dram.cc b/src/storage/dram.cc index e755c2a..d239cb1 100644 --- a/src/storage/dram.cc +++ b/src/storage/dram.cc @@ -80,13 +80,13 @@ std::ostream &operator<<(std::ostream &os, const Dram &d) const auto default_flags = std::cout.flags(); const auto default_fill = std::cout.fill(); - std::vector> data = d.view(0, MEM_SIZE); + std::vector> data = d.view(0, MEM_LINES); - os << " " << std::setfill(' ') << std::setw(MEM_SPEC + 2) << "INDEX" + os << " " << std::setfill(' ') << std::setw(MEM_LINE_SPEC + 2) << "INDEX" << " | " << std::setfill(' ') << std::setw((8 + 3) * 4 - 1) << "DATA" << std::endl; - for (int i = 0; i < MEM_SIZE; ++i) { - os << " 0b" << std::setw(MEM_SPEC) << std::bitset(i) << " | "; + for (int i = 0; i < MEM_LINES; ++i) { + os << " 0b" << std::setw(MEM_LINE_SPEC) << std::bitset(i) << " | "; for (int j = 0; j < LINE_SIZE; ++j) { os << "0x" << std::setfill('0') << std::setw(8) << std::hex << data.at(i).at(j) << ' '; -- cgit v1.2.3 From 97173af3651138db50cc42df25b474af2b6ece43 Mon Sep 17 00:00:00 2001 From: bd Date: Tue, 11 Mar 2025 12:00:09 -0400 Subject: Pad memory address output with trailing zeros --- src/storage/dram.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/storage/dram.cc') diff --git a/src/storage/dram.cc b/src/storage/dram.cc index d239cb1..8513147 100644 --- a/src/storage/dram.cc +++ b/src/storage/dram.cc @@ -82,11 +82,11 @@ std::ostream &operator<<(std::ostream &os, const Dram &d) std::vector> data = d.view(0, MEM_LINES); - os << " " << std::setfill(' ') << std::setw(MEM_LINE_SPEC + 2) << "INDEX" + os << " " << std::setfill(' ') << std::setw(MEM_LINE_SPEC + 2 + LINE_SPEC) << "ADDRESS" << " | " << std::setfill(' ') << std::setw((8 + 3) * 4 - 1) << "DATA" << std::endl; for (int i = 0; i < MEM_LINES; ++i) { - os << " 0b" << std::setw(MEM_LINE_SPEC) << std::bitset(i) << " | "; + os << " 0b" << std::setw(MEM_LINE_SPEC+LINE_SPEC) << left << std::bitset(i) << " | "; for (int j = 0; j < LINE_SIZE; ++j) { os << "0x" << std::setfill('0') << std::setw(8) << std::hex << data.at(i).at(j) << ' '; -- cgit v1.2.3 From df803d2ccc6a3e1e112cc88feb6c8b84743073b6 Mon Sep 17 00:00:00 2001 From: bd Date: Tue, 11 Mar 2025 17:33:27 -0400 Subject: Call memory wrapping functions properly --- src/cli/cli.cc | 4 +++- src/storage/dram.cc | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) (limited to 'src/storage/dram.cc') diff --git a/src/cli/cli.cc b/src/cli/cli.cc index 8dc7e2e..41ac57c 100644 --- a/src/cli/cli.cc +++ b/src/cli/cli.cc @@ -100,6 +100,7 @@ void Cli::help() void Cli::load(Accessor accessor, int address) { + address = wrap_address(address); const auto default_flags = std::cout.flags(); const auto default_fill = std::cout.fill(); @@ -107,7 +108,7 @@ void Cli::load(Accessor accessor, int address) Response r = this->cache->read_word(accessor, address, data); std::cout << r << " to " << accessor << " reading " << address << std::endl; if (r == OK) - std::cout << " Got:" << std::hex << data << std::endl; + std::cout << " Got: " << std::hex << data << std::endl; std::cout.flags(default_flags); std::cout.fill(default_fill); @@ -115,6 +116,7 @@ void Cli::load(Accessor accessor, int address) void Cli::store(Accessor accessor, int data, int address) { + address = wrap_address(address); Response r = this->cache->write_word(accessor, data, address); std::cout << r << " to " << accessor << " storing " << data << " in " << address << std::endl; diff --git a/src/storage/dram.cc b/src/storage/dram.cc index c244da5..60b4ae5 100644 --- a/src/storage/dram.cc +++ b/src/storage/dram.cc @@ -6,6 +6,7 @@ #include #include #include +#include Dram::Dram(int lines, int delay) { @@ -22,6 +23,7 @@ Dram::~Dram() { delete this->data; } void Dram::do_write(signed int data, int address) { + address = wrap_address(address); int line = address / LINE_SIZE; int word = address % LINE_SIZE; @@ -31,18 +33,21 @@ void Dram::do_write(signed int data, int address) void Dram::do_write_line( std::array data_line, int address) { + address = wrap_address(address); int line = address / LINE_SIZE; this->data->at(line) = data_line; } void Dram::do_read(std::array &data_line, int address) { + address = wrap_address(address); int line = address / LINE_SIZE; data_line = this->data->at(line); } void Dram::do_read_word(signed int &data, int address) { + address = wrap_address(address); int line = address / LINE_SIZE; int word = address % LINE_SIZE; data = this->data->at(line).at(word); -- cgit v1.2.3 From 1400c65a1d19f96fff8b4a0e98fcd9ed792f4883 Mon Sep 17 00:00:00 2001 From: bd Date: Tue, 11 Mar 2025 19:52:30 -0400 Subject: Fix issue where fetch_resource did not update cache data --- src/storage/cache.cc | 22 ++++++++++++---------- src/storage/dram.cc | 6 ++++-- 2 files changed, 16 insertions(+), 12 deletions(-) (limited to 'src/storage/dram.cc') diff --git a/src/storage/cache.cc b/src/storage/cache.cc index ea90f50..4842ed5 100644 --- a/src/storage/cache.cc +++ b/src/storage/cache.cc @@ -120,12 +120,12 @@ void Cache::fetch_resource(int expected) { Response r = OK; int tag, index, offset; - std::array actual; + std::array *actual; std::array *meta; get_bit_fields(expected, &tag, &index, &offset); meta = &this->meta.at(index); - actual = this->data->at(index); + actual = &this->data->at(index); if (meta->at(0) != tag) { // address not in cache @@ -133,7 +133,7 @@ void Cache::fetch_resource(int expected) // occupant is dirty // writing line to DRam in case of dirty cache eviction r = this->lower->write_line( - L1CACHE, actual, + L1CACHE, *actual, ((index << LINE_SPEC) + (meta->at(0) << (L1_CACHE_LINE_SPEC + LINE_SPEC)))); if (r == OK) { @@ -141,7 +141,7 @@ void Cache::fetch_resource(int expected) r = WAIT; } } else { - r = this->lower->read_line(L1CACHE, expected, actual); + r = this->lower->read_line(L1CACHE, expected, *actual); if (r == OK) { meta->at(0) = tag; } @@ -166,16 +166,16 @@ std::ostream &operator<<(std::ostream &os, const Cache &c) std::vector> data = c.view(0, L1_CACHE_LINES); std::array, L1_CACHE_LINES> meta = c.get_meta(); - std::cout << "FOO " << meta.at(31)[0]; - os << " " << std::setfill(' ') << std::setw(L1_CACHE_LINE_SPEC + 2) << "INDEX" + os << " " << std::setfill(' ') << std::setw(L1_CACHE_LINE_SPEC + 2) + << "INDEX" << " | " << std::setfill(' ') << std::setw((8 + 3) * 4 - 1) << "DATA" << " | " << std::setfill(' ') << std::setw(MEM_LINE_SPEC - L1_CACHE_LINE_SPEC + 2) << "TAG" << " | D" << std::endl; for (int i = 0; i < L1_CACHE_LINES; ++i) { - os << " 0b" << std::setw(L1_CACHE_LINE_SPEC) << std::bitset(i) - << " | "; + os << " 0b" << std::setw(L1_CACHE_LINE_SPEC) + << std::bitset(i) << " | "; for (int j = 0; j < LINE_SIZE; ++j) { os << "0x" << std::setfill('0') << std::setw(8) << std::hex << data.at(i).at(j) << " "; @@ -183,9 +183,11 @@ std::ostream &operator<<(std::ostream &os, const Cache &c) os << "| 0b" << std::setfill(' '); if (meta.at(i)[0] < 0) - os << std::setfill('?') << std::setw(MEM_LINE_SPEC - L1_CACHE_LINE_SPEC) << ""; + os << std::setfill('?') + << std::setw(MEM_LINE_SPEC - L1_CACHE_LINE_SPEC) << ""; else - os << std::bitset(meta.at(i)[0]); + os << std::bitset( + meta.at(i)[0]); os << " | " << (int)(meta.at(i)[0] >= 0) << std::endl; } diff --git a/src/storage/dram.cc b/src/storage/dram.cc index 60b4ae5..56eec47 100644 --- a/src/storage/dram.cc +++ b/src/storage/dram.cc @@ -143,11 +143,13 @@ std::ostream &operator<<(std::ostream &os, const Dram &d) std::vector> data = d.view(0, MEM_LINES); - os << " " << std::setfill(' ') << std::setw(MEM_LINE_SPEC + 2 + LINE_SPEC) << "ADDRESS" + os << " " << std::setfill(' ') << std::setw(MEM_LINE_SPEC + 2 + LINE_SPEC) + << "ADDRESS" << " | " << std::setfill(' ') << std::setw((8 + 3) * 4 - 1) << "DATA" << std::endl; for (int i = 0; i < MEM_LINES; ++i) { - os << " 0b" << std::setw(MEM_LINE_SPEC+LINE_SPEC) << left << std::bitset(i) << " | "; + os << " 0b" << std::setw(MEM_LINE_SPEC + LINE_SPEC) << left + << std::bitset(i) << " | "; for (int j = 0; j < LINE_SIZE; ++j) { os << "0x" << std::setfill('0') << std::setw(8) << std::hex << data.at(i).at(j) << ' '; -- cgit v1.2.3