From 08be348bef6b19b9f7509503e6d29d1c68f02fd6 Mon Sep 17 00:00:00 2001 From: Vighnesh Iyer Date: Wed, 16 Feb 2022 17:01:19 -0800 Subject: [PATCH] simple test runs, returns 1337, debugging --- src/main/cc/mm.cc | 27 ++++++++++++--------------- src/main/cc/mm.h | 14 +++++++------- src/main/cc/top.cc | 21 +++++++++++---------- 3 files changed, 30 insertions(+), 32 deletions(-) diff --git a/src/main/cc/mm.cc b/src/main/cc/mm.cc index 922b496ab..ae6fb15fd 100644 --- a/src/main/cc/mm.cc +++ b/src/main/cc/mm.cc @@ -17,38 +17,35 @@ mm_magic_t::mm_magic_t(size_t size, size_t word_size): dummy_data.resize(word_size); } -mm_magic_t::~mm_magic_t() -{ +mm_magic_t::~mm_magic_t() { delete [] data; } -void mm_magic_t::write(uint64_t addr, char *data) { +void mm_magic_t::write(uint64_t addr, uint8_t *data) { addr %= this->size; - char* base = this->data + addr; + uint8_t* base = this->data + addr; memcpy(base, data, word_size); printf("Writing to addr %lx\n", addr); } -void mm_magic_t::write(uint64_t addr, char *data, uint64_t strb, uint64_t size) -{ +void mm_magic_t::write(uint64_t addr, uint8_t *data, uint64_t strb, uint64_t size) { strb &= ((1L << size) - 1) << (addr % word_size); addr %= this->size; - char *base = this->data + addr; + uint8_t *base = this->data + addr; for (int i = 0; i < word_size; i++) { if (strb & 1) base[i] = data[i]; strb >>= 1; } } -std::vector mm_magic_t::read(uint64_t addr) -{ +std::vector mm_magic_t::read(uint64_t addr) { addr %= this->size; - char *base = this->data + addr; - printf("Reading from addr %lx\n", addr); - return std::vector(base, base + word_size); + uint8_t *base = this->data + addr; + // printf("Reading from addr %lx\n", addr); + return std::vector(base, base + word_size); } void mm_magic_t::tick( @@ -96,7 +93,7 @@ void mm_magic_t::tick( } if (w_fire) { - write(store_addr, (char*)w_data, w_strb, store_size); + write(store_addr, (uint8_t*)w_data, w_strb, store_size); store_addr += store_size; store_count--; @@ -123,7 +120,7 @@ void mm_magic_t::tick( } void mm_magic_t::load_mem(const char* fn, const uint64_t base_addr) { - int start = 0; + uint64_t start = base_addr; std::ifstream in(fn); if (!in) { std::cerr << "could not open " << fn << std::endl; @@ -135,7 +132,7 @@ void mm_magic_t::load_mem(const char* fn, const uint64_t base_addr) { { #define parse_nibble(c) ((c) >= 'a' ? (c)-'a'+10 : (c)-'0') for (int i = line.length()-2, j = 0; i >= 0; i -= 2, j++) { - mem[start + j] = (parse_nibble(line[i]) << 4) | parse_nibble(line[i+1]); + this->data[start + j] = (parse_nibble(line[i]) << 4) | parse_nibble(line[i+1]); } start += line.length()/2; } diff --git a/src/main/cc/mm.h b/src/main/cc/mm.h index a474efeff..cd6110809 100644 --- a/src/main/cc/mm.h +++ b/src/main/cc/mm.h @@ -10,10 +10,10 @@ struct mm_rresp_t { uint64_t id; - std::vector data; + std::vector data; bool last; - mm_rresp_t(uint64_t id, std::vector data, bool last) + mm_rresp_t(uint64_t id, std::vector data, bool last) { this->id = id; this->data = data; @@ -33,7 +33,7 @@ class mm_magic_t mm_magic_t(size_t size, size_t word_size); ~mm_magic_t(); void init(size_t sz, int word_size); - char* get_data() { return data; } + uint8_t* get_data() { return data; } size_t get_size() { return size; } bool ar_ready() { return true; } @@ -73,9 +73,9 @@ class mm_magic_t bool b_ready ); - void write(uint64_t addr, char *data); - void write(uint64_t addr, char *data, uint64_t strb, uint64_t size); - std::vector read(uint64_t addr); + void write(uint64_t addr, uint8_t *data); + void write(uint64_t addr, uint8_t *data, uint64_t strb, uint64_t size); + std::vector read(uint64_t addr); void load_mem(const char* fn, const uint64_t base_addr); private: @@ -88,7 +88,7 @@ class mm_magic_t uint64_t store_id; uint64_t store_size; uint64_t store_count; - std::vector dummy_data; + std::vector dummy_data; std::queue bresp; std::queue rresp; diff --git a/src/main/cc/top.cc b/src/main/cc/top.cc index 4eb364570..dc481795a 100644 --- a/src/main/cc/top.cc +++ b/src/main/cc/top.cc @@ -25,7 +25,8 @@ VerilatedVcdC* tfp; mm_magic_t* mem; // target memory // TODO Provide command-line options like vcd filename, timeout count, etc. -const long timeout = 100000000L; +//const long timeout = 100000000L; +const long timeout = 100000L; void tick() { top->clock = 1; @@ -82,7 +83,7 @@ int main(int argc, char** argv) { Verilated::commandArgs(argc, argv); // Remember args top = new VTile; // target design mem = new mm_magic_t(1L << 32, 8); // target memory - load_mem(mem->get_data(), (const char*)(argv[1])); // load hex + mem->load_mem((const char*)(argv[1]), 0x80000000UL); // load hex #if VM_TRACE // If verilator was invoked with --trace Verilated::traceEverOn(true); // Verilator must compute traced signals @@ -102,13 +103,12 @@ int main(int argc, char** argv) { // start top->reset = 0; - top->io_host_fromhost_bits = 0; - top->io_host_fromhost_valid = 0; do { tick(); - } while(!top->io_host_tohost && main_time < timeout); + } while(main_time < timeout); + //} while(!top->io_host_tohost && main_time < timeout); - int retcode = top->io_host_tohost >> 1; + //int retcode = top->io_host_tohost >> 1; // Run for 10 more clocks for (size_t i = 0 ; i < 10 ; i++) { @@ -122,9 +122,9 @@ int main(int argc, char** argv) { } else { cerr << "Simulation completed at time " << main_time << " (cycle " << main_time / 10 << ")"<< endl; - if (retcode) { - cerr << "TOHOST = " << retcode << endl; - } + //if (retcode) { + //cerr << "TOHOST = " << retcode << endl; + //} } #if VM_TRACE @@ -136,6 +136,7 @@ int main(int argc, char** argv) { cout << "Finishing simulation!\n"; - return retcode == 0 ? EXIT_SUCCESS : EXIT_FAILURE; + //return retcode == 0 ? EXIT_SUCCESS : EXIT_FAILURE; + return 0; }