add reporting of PC and instruction being executed to verilator
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Wed, 5 Jan 2022 16:39:02 +0000 (16:39 +0000)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Wed, 5 Jan 2022 16:39:02 +0000 (16:39 +0000)
Makefile
core.vhdl
core_dummy.vhdl
fpga/top-generic.vhdl
soc.vhdl
verilator/microwatt-verilator.cpp

index 5bd396d660043c60b1300fdb7f9c2bcf55d00a5b..9fc51ca41f6ef5543dae0bbe444005020e2d3928 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -232,7 +232,7 @@ microwatt-verilator: microwatt.v verilator/microwatt-verilator.cpp verilator/uar
            -Wno-COMBDLY  \
            -Wno-CASEINCOMPLETE \
            -Wno-WIDTH \
-       # --trace
+       # --trace \
        #    --unroll-count 256 \
        #    --output-split 5000 \
        #    --output-split-cfuncs 500 \
index 41b7b45d2c69e6ee45451a707c01d07007d94e64..b33086b7a30e98b0f9b99b412616b77df1ad0722 100644 (file)
--- a/core.vhdl
+++ b/core.vhdl
@@ -40,7 +40,12 @@ entity core is
 
        ext_irq         : in std_ulogic;
 
-       terminated_out   : out std_logic
+       terminated_out   : out std_logic;
+
+    -- for verilator debugging
+    nia_req: out std_ulogic;
+    nia: out std_ulogic_vector(63 downto 0);
+    insn: out std_ulogic_vector(31 downto 0)
         );
 end core;
 
@@ -435,7 +440,13 @@ begin
     log_data(150) <= '0';
     log_data(139 downto 135) <= "00000";
 
+    -- snoop and report instruction being executed
+    nia <= icache_to_decode1.nia;
+    insn <= icache_to_decode1.insn;
+    nia_req <= icache_to_decode1.valid and fetch1_to_icache.sequential;
+
     debug_0: entity work.core_debug
+
         generic map (
             LOG_LENGTH => LOG_LENGTH
             )
index ae5d49bfc0b9f9585940c0a67eb920aee0e187f0..9ceab195b446c1be022d62a448237d9a19bd28f1 100644 (file)
@@ -40,7 +40,12 @@ entity core is
 
        ext_irq         : in std_ulogic;
 
-       terminated_out   : out std_logic
+       terminated_out   : out std_logic;
+
+    -- for verilator debugging
+    nia_req: out std_ulogic;
+    nia: out std_ulogic_vector(63 downto 0);
+    insn: out std_ulogic_vector(31 downto 0)
         );
 end core;
 
index 6c23dd70f2a1c3cb3d971da41d1c7f7084cc970e..4524a368f7475d242413f7826decc2fa267d1b9b 100644 (file)
@@ -36,7 +36,13 @@ entity toplevel is
     bram_addr : out std_logic_vector(log2ceil(MEMORY_SIZE) - 3- 1 downto 0);
     bram_di   : out std_logic_vector(63 downto 0);
     bram_do   : in std_logic_vector(63 downto 0);
-    bram_sel  : out std_logic_vector(7 downto 0)
+    bram_sel  : out std_logic_vector(7 downto 0);
+
+    -- for verilator debugging
+    nia_req: out std_ulogic;
+    nia: out std_ulogic_vector(63 downto 0);
+    insn: out std_ulogic_vector(31 downto 0)
+
        );
 end entity toplevel;
 
@@ -104,7 +110,10 @@ begin
         bram_addr           => bram_addr,
         bram_di             => bram_di,
         bram_do             => bram_do,
-        bram_sel            => bram_sel
+        bram_sel            => bram_sel,
+        nia_req           => nia_req,
+        nia               => nia,
+        insn              => insn
            );
 
 end architecture behaviour;
index 9ab2babd177505f4de515a4f8cffbf569afda9e2..8440f54db46ee7224a2ef8e586d9882783b02b45 100644 (file)
--- a/soc.vhdl
+++ b/soc.vhdl
@@ -117,7 +117,12 @@ entity soc is
         spi_flash_sdat_i  : in  std_ulogic_vector(SPI_FLASH_DLINES-1 downto 0) := (others => '1');
 
        -- DRAM controller signals
-       alt_reset    : in std_ulogic := '0'
+       alt_reset    : in std_ulogic := '0';
+
+    -- for verilator debugging
+    nia_req: out std_ulogic;
+    nia: out std_ulogic_vector(63 downto 0);
+    insn: out std_ulogic_vector(31 downto 0)
        );
 end entity soc;
 
@@ -267,7 +272,11 @@ architecture behaviour of soc is
         dmi_wr      : in std_ulogic;
         dmi_ack         : out std_ulogic;
         ext_irq     : in std_ulogic;
-        terminated_out   : out std_logic
+        terminated_out   : out std_logic;
+        -- for verilator debugging
+        nia_req: out std_ulogic;
+        nia: out std_ulogic_vector(63 downto 0);
+        insn: out std_ulogic_vector(31 downto 0)
         );
     end component;
 begin
@@ -313,7 +322,10 @@ begin
            dmi_wr => dmi_wr,
            dmi_ack => dmi_core_ack,
            dmi_req => dmi_core_req,
-           ext_irq => core_ext_irq
+           ext_irq => core_ext_irq,
+        nia_req           => nia_req,
+        nia               => nia,
+        insn              => insn
            );
     end generate;
 
@@ -333,10 +345,14 @@ begin
            dmi_wr => dmi_wr,
            dmi_ack => dmi_core_ack,
            dmi_req => dmi_core_req,
-           ext_irq => core_ext_irq
+           ext_irq => core_ext_irq,
+        nia_req           => nia_req,
+        nia               => nia,
+        insn              => insn
            );
     end generate;
 
+
     -- Wishbone bus master arbiter & mux
     wb_masters_out <= (0 => wishbone_dcore_out,
                       1 => wishbone_icore_out,
index 93abe8a1d589f5567c5bb1cc6ff20bfb830e20fc..a409c6e1cc8c6f8f0bf1b038c5e3474836b80049 100644 (file)
@@ -196,15 +196,20 @@ int main(int argc, char **argv)
                top->uart0_rxd = uart_rx();
 
 #ifdef BRAM_DEBUG
+        if (top->nia_req) {
+            fprintf(dump, "pc %8x insn %8x\n", top->nia, top->insn);
+        }
         if (top->bram_we) {
-            fprintf(dump, "bram wr addr %08x dout %16lx sel %x ",
+            fprintf(dump, "                          " \
+                          "wr @ %08x do %16lx sel %02x ",
                     top->bram_addr, top->bram_di, top->bram_sel);
             ascii_dump((unsigned char*)&top->bram_di, 8, dump);
             fflush(dump);
         }
         // read on one clock delay
         if (top->bram_re) {
-            fprintf(dump, "bram rd addr %08x din %16lx sel %x ",
+            fprintf(dump, "                          " \
+                          "rd @ %08x di %16lx sel %02x ",
                     top->bram_addr, bram_do, top->bram_sel);
             ascii_dump((unsigned char*)&bram_do, 8, dump);
             fflush(dump);