Skip to content
This repository has been archived by the owner on Aug 20, 2024. It is now read-only.

Commit

Permalink
simple test runs, returns 1337, debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
vighneshiyer committed Feb 17, 2022
1 parent 1c119c6 commit 08be348
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 32 deletions.
27 changes: 12 additions & 15 deletions src/main/cc/mm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<char> mm_magic_t::read(uint64_t addr)
{
std::vector<uint8_t> 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<char>(base, base + word_size);
uint8_t *base = this->data + addr;
// printf("Reading from addr %lx\n", addr);
return std::vector<uint8_t>(base, base + word_size);
}

void mm_magic_t::tick(
Expand Down Expand Up @@ -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--;

Expand All @@ -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;
Expand All @@ -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;
}
Expand Down
14 changes: 7 additions & 7 deletions src/main/cc/mm.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
struct mm_rresp_t
{
uint64_t id;
std::vector<char> data;
std::vector<uint8_t> data;
bool last;

mm_rresp_t(uint64_t id, std::vector<char> data, bool last)
mm_rresp_t(uint64_t id, std::vector<uint8_t> data, bool last)
{
this->id = id;
this->data = data;
Expand All @@ -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; }
Expand Down Expand Up @@ -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<char> 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<uint8_t> read(uint64_t addr);
void load_mem(const char* fn, const uint64_t base_addr);

private:
Expand All @@ -88,7 +88,7 @@ class mm_magic_t
uint64_t store_id;
uint64_t store_size;
uint64_t store_count;
std::vector<char> dummy_data;
std::vector<uint8_t> dummy_data;
std::queue<uint64_t> bresp;

std::queue<mm_rresp_t> rresp;
Expand Down
21 changes: 11 additions & 10 deletions src/main/cc/top.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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++) {
Expand All @@ -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
Expand All @@ -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;
}

0 comments on commit 08be348

Please sign in to comment.