From a59c031ca0521bfb00bfc5f8f65af45c89804a37 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/cli/cli.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/cli') diff --git a/src/cli/cli.cc b/src/cli/cli.cc index 0729e00..c9f83e9 100644 --- a/src/cli/cli.cc +++ b/src/cli/cli.cc @@ -116,7 +116,7 @@ void Cli::load(Accessor accessor, int address) void Cli::store(Accessor accessor, int data, int address) { Response r = this->cache->write(accessor, data, address); - std::cout << r << " to " << accessor << " storing " << data << " in" + std::cout << r << " to " << accessor << " storing " << data << " in " << address << std::endl; } @@ -209,7 +209,7 @@ void Cli::initialize() if (this->cache != nullptr) delete this->cache; - Dram *d = new Dram(MEM_SIZE, MEM_DELAY); + Dram *d = new Dram(MEM_LINES, MEM_DELAY); this->cache = new Cache(d, L1_CACHE_DELAY); this->cycle = 1; } -- cgit v1.2.3 From 979723533989a38660ece630b9e458cb3aa61bda Mon Sep 17 00:00:00 2001 From: bd Date: Tue, 11 Mar 2025 17:24:49 -0400 Subject: clarify macro names, implement load in CLI, fix many display issues --- src/cli/cli.cc | 8 ++++---- src/storage/cache.cc | 2 +- src/utils/utils.cc | 4 ++-- tests/utils.cc | 16 ++++++++-------- 4 files changed, 15 insertions(+), 15 deletions(-) (limited to 'src/cli') diff --git a/src/cli/cli.cc b/src/cli/cli.cc index d90edef..8dc7e2e 100644 --- a/src/cli/cli.cc +++ b/src/cli/cli.cc @@ -104,10 +104,10 @@ void Cli::load(Accessor accessor, int address) const auto default_fill = std::cout.fill(); signed int data; - // Response r = this->cache->read_word(accessor, address, data); - // std::cout << r << " to " << accessor << " reading " << address << std::endl; - // if (r == OK) - // std::cout << "\tGot:" << std::hex << data; + 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.flags(default_flags); std::cout.fill(default_fill); diff --git a/src/storage/cache.cc b/src/storage/cache.cc index a73390b..14a6e61 100644 --- a/src/storage/cache.cc +++ b/src/storage/cache.cc @@ -135,7 +135,7 @@ void Cache::fetch_resource(int expected) r = this->lower->write_line( L1CACHE, actual, ((index << LINE_SPEC) + - (meta->at(0) << (L1_CACHE_SPEC + LINE_SPEC)))); + (meta->at(0) << (L1_CACHE_LINE_SPEC + LINE_SPEC)))); if (r == OK) { meta->at(1) = -1; } diff --git a/src/utils/utils.cc b/src/utils/utils.cc index b5a4d55..87ce488 100644 --- a/src/utils/utils.cc +++ b/src/utils/utils.cc @@ -31,7 +31,7 @@ const std::string string_format(const char *const zcFormat, ...) int wrap_address(int address) { if (address < 0){ - return ((address % MEM_SIZE) + MEM_SIZE) % MEM_SIZE; + return ((address % MEM_LINES) + MEM_LINES) % MEM_LINES; } - return address % MEM_SIZE; + return address % MEM_LINES; } diff --git a/tests/utils.cc b/tests/utils.cc index f0e4c24..900db1a 100644 --- a/tests/utils.cc +++ b/tests/utils.cc @@ -24,21 +24,21 @@ TEST_CASE("Parse arbitrary fields # two", "[cache]") TEST_CASE("wrap address outside upper bound", "[utils]") { - int address = MEM_SIZE + 25; + int address = MEM_LINES + 25; int wrapped = wrap_address(address); REQUIRE(wrapped == 25); } TEST_CASE("wrap address inside upper bound", "[utils]") { - int address = MEM_SIZE - 25; + int address = MEM_LINES - 25; int wrapped = wrap_address(address); - REQUIRE(wrapped == MEM_SIZE - 25); + REQUIRE(wrapped == MEM_LINES - 25); } TEST_CASE("wrap address at upper bound", "[utils]") { - int address = MEM_SIZE; + int address = MEM_LINES; int wrapped = wrap_address(address); REQUIRE(wrapped == 0); } @@ -47,14 +47,14 @@ TEST_CASE("wrap address lower than 0 with magnitude lesser than mem size", "[uti { int address = -10; int wrapped = wrap_address(address); - REQUIRE(wrapped == MEM_SIZE - 10); + REQUIRE(wrapped == MEM_LINES - 10); } TEST_CASE("wrap address lower than 0 but with magnitude greater than mem size", "[utils]") { - int address = -(MEM_SIZE + 10); + int address = -(MEM_LINES + 10); int wrapped = wrap_address(address); - REQUIRE(wrapped == MEM_SIZE - 10); + REQUIRE(wrapped == MEM_LINES - 10); } TEST_CASE("wrap address at 0", "[utils]") @@ -62,4 +62,4 @@ TEST_CASE("wrap address at 0", "[utils]") int address = 0; int wrapped = wrap_address(address); REQUIRE(wrapped == 0); -} \ No newline at end of file +} -- cgit v1.2.3 From 1e095065907c2ab7b3a9705fab7c44e60361e035 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/cli') 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