From f0f2dba67f81d80bd5ad3c699e967884c50e4503 Mon Sep 17 00:00:00 2001 From: Olof Kindgren Date: Sun, 15 Jan 2023 22:28:19 +0100 Subject: [PATCH] Add PC tracing capability This adds the --trace_pc option to dump the PC after each instruction to a file called trace.bin --- bench/servant_sim.v | 11 ++++++++--- bench/servant_tb.cpp | 9 +++++++++ bench/servant_tb.v | 7 ++++++- servant.core | 5 +++++ 4 files changed, 28 insertions(+), 4 deletions(-) diff --git a/bench/servant_sim.v b/bench/servant_sim.v index d924bbbf..a21de057 100644 --- a/bench/servant_sim.v +++ b/bench/servant_sim.v @@ -1,8 +1,10 @@ `default_nettype none module servant_sim - (input wire wb_clk, - input wire wb_rst, - output wire q); + (input wire wb_clk, + input wire wb_rst, + output wire [31:0] pc_adr, + output wire pc_vld, + output wire q); parameter memfile = ""; parameter memsize = 8192; @@ -26,4 +28,7 @@ module servant_sim .align (align[0:0])) dut(wb_clk, wb_rst, q); + assign pc_adr = dut.wb_ibus_adr; + assign pc_vld = dut.wb_ibus_ack; + endmodule diff --git a/bench/servant_tb.cpp b/bench/servant_tb.cpp index 1eb6d39f..b2248473 100644 --- a/bench/servant_tb.cpp +++ b/bench/servant_tb.cpp @@ -1,3 +1,4 @@ +#include #include #include @@ -110,6 +111,11 @@ int main(int argc, char **argv, char **env) signal(SIGINT, INThandler); + int tf = 0; + const char *arg_trace_pc = Verilated::commandArgsPlusMatch("trace_pc="); + if (arg_trace_pc[0]) + tf = open("trace.bin", O_WRONLY | O_CREAT | O_TRUNC, S_IRWXU); + vluint64_t timeout = 0; const char *arg_timeout = Verilated::commandArgsPlusMatch("timeout="); if (arg_timeout[0]) @@ -137,6 +143,8 @@ int main(int argc, char **argv, char **env) } else { do_gpio(&gpio_context, top->q); } + if (tf && top->wb_clk && top->pc_vld) + write(tf, (void *)&top->pc_adr, 4); if (timeout && (main_time >= timeout)) { printf("Timeout: Exiting at time %lu\n", main_time); done = true; @@ -146,6 +154,7 @@ int main(int argc, char **argv, char **env) main_time+=31.25; } + close(tf); if (tfp) tfp->close(); exit(0); diff --git a/bench/servant_tb.v b/bench/servant_tb.v index b3ea4713..0ca27e67 100644 --- a/bench/servant_tb.v +++ b/bench/servant_tb.v @@ -21,6 +21,11 @@ module servant_tb; #(.memfile (memfile), .memsize (memsize), .with_csr (with_csr)) - dut(wb_clk, wb_rst, q); + dut + (.wb_clk (wb_clk), + .wb_rst (wb_rst), + .pc_adr (), + .pc_vld (), + .q (q)); endmodule diff --git a/servant.core b/servant.core index f00650cf..ea73c1da 100644 --- a/servant.core +++ b/servant.core @@ -512,6 +512,7 @@ targets: - memsize - signature - timeout + - trace_pc - uart_baudrate - vcd - vcd_start @@ -587,6 +588,10 @@ parameters: datatype : int paramtype : plusarg + trace_pc: + datatype : bool + paramtype : plusarg + uart_baudrate: datatype : int description : Treat q output as an UART with the specified baudrate (0 or omitted parameter disables UART decoding)