From e44af58d6360cf58d60e9f83a2f18b1804f45495 Mon Sep 17 00:00:00 2001 From: "colin.liang" Date: Fri, 13 Jan 2023 14:49:21 +0800 Subject: [PATCH] Refine hex file index from verialtor c code. --- Makefile | 4 ++-- testbench.cc | 15 +++++++++++---- testbench_wb.v | 10 +++------- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/Makefile b/Makefile index c9a71da..075520f 100644 --- a/Makefile +++ b/Makefile @@ -27,8 +27,8 @@ test_wb_vcd: testbench_wb.vvp firmware/firmware.hex $(VVP) -N $< +vcd +trace +noerror test_verilator: testbench_verilator firmware/firmware.hex - ./testbench_verilator 0 - ./testbench_verilator 1 + ./testbench_verilator firmware/firmware.hex + ./testbench_verilator dhrystone/dhry.hex testbench_verilator: testbench_wb.v picorv32.v testbench.cc $(VERILATOR) --cc --exe -Wno-lint -trace --top-module picorv32_wrapper testbench_wb.v picorv32.v testbench.cc \ diff --git a/testbench.cc b/testbench.cc index 154e3bd..b8b8d98 100644 --- a/testbench.cc +++ b/testbench.cc @@ -11,10 +11,17 @@ int main(int argc, char** argv, char** env) { Verilated::commandArgs(argc, argv); Vpicorv32_wrapper* top = new Vpicorv32_wrapper; - if (argc > 0 && argv[1][0] == '1') - top->testcase = 1; - else - top->testcase = 0; + std::string hexfile; + if (argc > 1) { + hexfile = std::string(argv[1]); + } else { + hexfile = std::string("firmware/firmware.hex"); + } + auto hex = (uint8_t*)(top->hex_file.data()); + auto csr = hexfile.c_str(); + for (int i = 0; i < hexfile.size(); i += 1) { + *(hex + (128 - i)) = *(uint8_t*)(csr + i); + } // Tracing (vcd) VerilatedVcdC* tfp = NULL; diff --git a/testbench_wb.v b/testbench_wb.v index b44e7bd..27b18ce 100644 --- a/testbench_wb.v +++ b/testbench_wb.v @@ -62,7 +62,7 @@ module picorv32_wrapper #( output trap, output trace_valid, output [35:0] trace_data, - input testcase + input [1024:0] hex_file ); wire exit; reg [31:0] irq = 0; @@ -98,13 +98,9 @@ module picorv32_wrapper #( .wb_rst_i(wb_rst), ); - reg [1023:0] firmware_file; initial begin - if (!testcase) firmware_file = "firmware/firmware.hex"; - else firmware_file = "dhrystone/dhry.hex"; - // if (!$value$plusargs("firmware=%s", firmware_file)) - // firmware_file = "firmware/firmware.hex"; - $readmemh(firmware_file, uut.memory); + $readmemh(hex_file, uut.memory); + $display("HEX File : %s", hex_file); end integer cycle_counter;