From 1298e213ad20c1616889c909591eac57773cddb5 Mon Sep 17 00:00:00 2001 From: Paul Ehrlich Date: Fri, 24 May 2019 08:03:06 +0200 Subject: [PATCH 1/7] Update main.cpp more readable cpp code --- verilator/main.cpp | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/verilator/main.cpp b/verilator/main.cpp index 0ae030ab..6484476b 100644 --- a/verilator/main.cpp +++ b/verilator/main.cpp @@ -129,21 +129,21 @@ typedef struct { void preload_hex(Vpulpino_top *top, VerilatedVcdC *tfp, const char *filepath) { - FILE *fp = fopen(filepath, "r"); - char buf[255]; + std::ifstream inputFileStream("../pulpino/verilator/sw/wake.hex"); + std::string line; + std::vector data; + while(std::getline(inputFileStream, line)){ + std::istringstream lineStream(line); + HexData *elm = new HexData(); + char dummy; + lineStream >> std::hex >> elm->addr >> dummy >> elm->data; + data.push_back(elm); + + } + uint32_t spi_old_addr=0; uint32_t mem_start=0; - std::vector data; - - while (fgets(buf, 255, (FILE*) fp)) { - char *ptr; - HexData *elm = (HexData*)malloc(sizeof(HexData)); - ptr = strtok(buf, "_"); - elm->addr = (uint32_t)strtol(ptr, NULL, 16); - ptr = strtok(NULL, "_"); - elm->data = (uint32_t)strtol(ptr, NULL, 16); - data.push_back(elm); - } + printf("Preloading Instruction RAM\n"); spi_old_addr = data[0]->addr - 4; for (uint64_t i=0; i < data.size(); i++) { From ac3457bf04fc30440ff073db432efdb945094223 Mon Sep 17 00:00:00 2001 From: Paul Ehrlich Date: Fri, 24 May 2019 10:17:24 +0200 Subject: [PATCH 2/7] Update main.cpp removed hexdata struct --- verilator/main.cpp | 53 ++++++++++++++++++++-------------------------- 1 file changed, 23 insertions(+), 30 deletions(-) diff --git a/verilator/main.cpp b/verilator/main.cpp index 6484476b..2b90012d 100644 --- a/verilator/main.cpp +++ b/verilator/main.cpp @@ -121,45 +121,38 @@ void run_tick_clk(Vpulpino_top *tb, VerilatedVcdC *tfp) #endif } -typedef struct { - uint32_t addr; - uint32_t data; -} HexData; - void preload_hex(Vpulpino_top *top, VerilatedVcdC *tfp, const char *filepath) { - std::ifstream inputFileStream("../pulpino/verilator/sw/wake.hex"); + std::ifstream inputFileStream("../pulpino/verilator/sw/wake.hex"); std::string line; - std::vector data; + std::map mymap; while(std::getline(inputFileStream, line)){ std::istringstream lineStream(line); - HexData *elm = new HexData(); + uint32_t addr,data; char dummy; - lineStream >> std::hex >> elm->addr >> dummy >> elm->data; - data.push_back(elm); + lineStream >> std::hex >> addr >> dummy >> data; + mymap.insert ( std::pair(addr,data) ); + lineStream.close(); + } + uint32_t mem_start=0; + printf("Preloading Instruction RAM\n"); + std::map::iterator it = mymap.begin(); + for (it=mymap.begin(); it!=mymap.end(); ++it){ + if (it->first != (std::prev(it)->first + 4)) { + printf("prev address %x current addr %x\n", std::prev(it)->first, it->first); + printf("Preloading Data RAM\n"); + mem_start = it->first; + } + if (mem_start == 0) { + riscv->pulpino_top__DOT__core_region_i__DOT__instr_mem__DOT__sp_ram_wrap_i__DOT__sp_ram_i__DOT__mem[it->first/4] = it->second; + } else { + riscv->pulpino_top__DOT__core_region_i__DOT__data_mem__DOT__sp_ram_i__DOT__mem[(it->first - mem_start)/4] = it->second; + } } - - uint32_t spi_old_addr=0; - uint32_t mem_start=0; - - printf("Preloading Instruction RAM\n"); - spi_old_addr = data[0]->addr - 4; - for (uint64_t i=0; i < data.size(); i++) { - if (data[i]->addr != (spi_old_addr + 4)) { - printf("prev address %x current addr %x\n", spi_old_addr, data[i]->addr); - printf("Preloading Data RAM\n"); - mem_start = i; - } - if (mem_start == 0) { - top->pulpino_top__DOT__core_region_i__DOT__instr_mem__DOT__sp_ram_wrap_i__DOT__sp_ram_i__DOT__mem[i] = data[i]->data; - } else { - top->pulpino_top__DOT__core_region_i__DOT__data_mem__DOT__sp_ram_i__DOT__mem[i - mem_start] = data[i]->data; - } - spi_old_addr = data[i]->addr; - } - fclose(fp); + inputFileStream.close(); + } void raise_gpio(Vpulpino_top *top, VerilatedVcdC *tfp) From 62f7edadd83a2e7b76238685357879651bd597f1 Mon Sep 17 00:00:00 2001 From: Paul Ehrlich Date: Thu, 6 Jun 2019 17:06:58 +0200 Subject: [PATCH 3/7] Old compiler This file requires compiler and library support for the ISO C++ 2011 standard. This support is currently experimental, and must be enabled with the -std=c++11 or -std=gnu++11 compiler options. --- verilator/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/verilator/Makefile b/verilator/Makefile index cecb5278..e045e925 100644 --- a/verilator/Makefile +++ b/verilator/Makefile @@ -7,7 +7,7 @@ RTL=../rtl/pulpino_top.sv TOP=pulpino_top SIM=$(TOP)_sim.elf -CFLAGS=-Iobj_dir -I/usr/share/verilator/include -g3 +CFLAGS=-Iobj_dir -I/usr/share/verilator/include -g3 -std=c++11 VERICSRC=/usr/share/verilator/include/verilated_vcd_c.cpp \ /usr/share/verilator/include/verilated.cpp VFLAGS=-sv \ From 8088be158de2cc0407210cf69b3ebab990a76eb0 Mon Sep 17 00:00:00 2001 From: Paul Ehrlich Date: Thu, 6 Jun 2019 17:08:12 +0200 Subject: [PATCH 4/7] msys2 env. switched from /usr/share... to /mingw64/share... --- verilator/Makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/verilator/Makefile b/verilator/Makefile index e045e925..8cca1832 100644 --- a/verilator/Makefile +++ b/verilator/Makefile @@ -7,9 +7,9 @@ RTL=../rtl/pulpino_top.sv TOP=pulpino_top SIM=$(TOP)_sim.elf -CFLAGS=-Iobj_dir -I/usr/share/verilator/include -g3 -std=c++11 -VERICSRC=/usr/share/verilator/include/verilated_vcd_c.cpp \ - /usr/share/verilator/include/verilated.cpp +CFLAGS=-Iobj_dir -I/mingw64/share/verilator/include -g3 -std=c++11 +VERICSRC=/mingw64/share/verilator/include/verilated_vcd_c.cpp \ + /mingw64/share/verilator/include/verilated.cpp VFLAGS=-sv \ --trace \ --trace-max-array 8192 \ From 2d3cab99bb75ab4be23a6ebcd280bf228cc19d2d Mon Sep 17 00:00:00 2001 From: Paul Ehrlich Date: Thu, 6 Jun 2019 17:11:34 +0200 Subject: [PATCH 5/7] sigusr handling makes problems under windows/msys2 --- verilator/main.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/verilator/main.cpp b/verilator/main.cpp index 95905705..84b9982c 100644 --- a/verilator/main.cpp +++ b/verilator/main.cpp @@ -162,13 +162,13 @@ void raise_gpio(Vpulpino_top *top, VerilatedVcdC *tfp) top->gpio_in &= ~(1 << 16); } -static int raise_interrupt = 0; +/*static int raise_interrupt = 0; void sig_user_handler(int sig) { if (sig == SIGUSR1) { raise_interrupt = 1; } -} +}*/ void run_simulation(Vpulpino_top *top, VerilatedVcdC *tfp) { @@ -177,7 +177,7 @@ void run_simulation(Vpulpino_top *top, VerilatedVcdC *tfp) run_tick_clk(top, tfp); if (raise_interrupt == 1) { raise_gpio(top, tfp); - raise_interrupt = 0; + //raise_interrupt = 0; } } while ((top->gpio_out & (1 << 8)) == 0); } @@ -186,7 +186,7 @@ void read_user_input() { while (1) { getchar(); - kill(0, SIGUSR1); + //kill(0, SIGUSR1); } } @@ -242,15 +242,15 @@ int main(int argc, char **argv) { #endif reset(top, tfp); - preload_hex(top, tfp, "sw/wake.hex"); + preload_hex(top, tfp, "sw/helloworld.hex"); - signal(SIGUSR1, sig_user_handler); - pid_t pid = fork(); - if (pid == 0) { + //signal(SIGUSR1, sig_user_handler); + //pid_t pid = fork(); + //if (pid == 0) { read_user_input(); - } else { + /*} else { run_simulation(top, tfp); - } + }*/ #ifdef VM_TRACE if (tfp) tfp->close(); From 23c722cef1834638507a43768b246cfc69a3ea12 Mon Sep 17 00:00:00 2001 From: Paul Ehrlich Date: Thu, 6 Jun 2019 17:12:37 +0200 Subject: [PATCH 6/7] Update main.cpp --- verilator/main.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/verilator/main.cpp b/verilator/main.cpp index 84b9982c..3a3421c0 100644 --- a/verilator/main.cpp +++ b/verilator/main.cpp @@ -175,10 +175,10 @@ void run_simulation(Vpulpino_top *top, VerilatedVcdC *tfp) top->fetch_enable_i = 1; do { run_tick_clk(top, tfp); - if (raise_interrupt == 1) { + /*/if (raise_interrupt == 1) { raise_gpio(top, tfp); - //raise_interrupt = 0; - } + raise_interrupt = 0; + }*/ } while ((top->gpio_out & (1 << 8)) == 0); } From 4cd0bd6ee6abaf1bb6537e8173f44fd1aca888a4 Mon Sep 17 00:00:00 2001 From: Paul Ehrlich Date: Thu, 6 Jun 2019 17:17:33 +0200 Subject: [PATCH 7/7] Update main.cpp --- verilator/main.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/verilator/main.cpp b/verilator/main.cpp index 3a3421c0..12994090 100644 --- a/verilator/main.cpp +++ b/verilator/main.cpp @@ -246,11 +246,11 @@ int main(int argc, char **argv) { //signal(SIGUSR1, sig_user_handler); //pid_t pid = fork(); - //if (pid == 0) { + /*if (pid == 0) { read_user_input(); - /*} else { + } else {*/ run_simulation(top, tfp); - }*/ + //} #ifdef VM_TRACE if (tfp) tfp->close();