single-step and print out PC using DMI in litex sim
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Tue, 4 Aug 2020 12:06:06 +0000 (13:06 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Tue, 4 Aug 2020 12:06:06 +0000 (13:06 +0100)
src/soc/litex/florent/sim.py

index d9046f759c80023ca2d54a7b6e7dcce7f2fe9aec..54db61133e6ea4795907e2e49fff70bef24acba4 100755 (executable)
@@ -51,6 +51,11 @@ class LibreSoCSim(SoCCore):
         dmi_wen = Signal(1)
         dmi_req = Signal(1)
 
+        # debug log out
+        dbg_addr = Signal(3)
+        dbg_dout = Signal(64)
+        dbg_msg = Signal(1)
+
         uptime = Signal(64)
         # increment counter, Stop after 100000 cycles
         uptime = Signal(64)
@@ -72,6 +77,19 @@ class LibreSoCSim(SoCCore):
                     )
                  ),
                 ),
+            ),
+            If(dmi_req & ~dmi_wen,
+                (self.cpu.dmi_addr.eq(dmi_addr),   # DMI Addr
+                 self.cpu.dmi_req.eq(1),    # DMI request
+                 self.cpu.dmi_wr.eq(0),    # DMI read
+                 If(self.cpu.dmi_ack,
+                    (NextState("IDLE"),
+                     NextValue(dbg_addr, dmi_addr),
+                     NextValue(dbg_dout, self.cpu.dmi_dout),
+                     NextValue(dbg_msg, 1),
+                    )
+                 ),
+                ),
             )
         )
 
@@ -84,6 +102,13 @@ class LibreSoCSim(SoCCore):
             )
         )
 
+        # debug messages out
+        self.sync += If(dbg_msg,
+             (Display("[%06x] dbg: %1x, %016x", uptime, dbg_addr, dbg_dout),
+              dbg_msg.eq(0)
+             )
+        )
+
         # kick off a "stop"
         self.sync += If(uptime == 0,
             (dmi_addr.eq(0), # CTRL
@@ -94,7 +119,7 @@ class LibreSoCSim(SoCCore):
         )
 
         # loop every 1<<N cycles
-        cyclewid = 7
+        cyclewid = 8
 
         # kick off a "step"
         self.sync += If(uptime[0:cyclewid] == 4,
@@ -105,6 +130,14 @@ class LibreSoCSim(SoCCore):
             )
         )
 
+        # get the PC
+        self.sync += If(uptime[0:cyclewid] == 8,
+            (dmi_addr.eq(0b10), # NIA
+             dmi_req.eq(1),
+             dmi_wen.eq(0),
+            )
+        )
+
         # monitor ibus write
         self.sync += If(self.cpu.ibus.stb & self.cpu.ibus.ack &
                         self.cpu.ibus.we,