WB_WRRD = 7
-def read_dmi_addr(dmi_addr):
+def read_dmi_addr(dut, dmi_addr):
# write DMI address
yield from jtag_read_write_reg(dut, DMI_ADDR, 8, dmi_addr)
# read DMI register
return (yield from jtag_read_write_reg(dut, DMI_READ, 64))
-def writeread_dmi_addr(dmi_addr, data):
+def writeread_dmi_addr(dut, dmi_addr, data):
# write DMI address
yield from jtag_read_write_reg(dut, DMI_ADDR, 8, dmi_addr)
####### JTAG to DMI Setup (stop, reset) ######
- yield from read_dmi_addr(dut, DMI_ADDR, 8, DBGCore.CTRL)
+ yield from read_dmi_addr(dut, DBGCore.CTRL)
# read DMI CTRL reg
status = yield from read_dmi_addr(dut, DBGCore.CTRL)
print ("dmi ctrl status", bin(status))
# write DMI CTRL register - STOP and RESET
- status = yield from writeread_dmi_addr(dut, DBCCore.CTRL, 0b011)
+ status = yield from writeread_dmi_addr(dut, DBGCore.CTRL, 0b011)
print ("dmi ctrl status", hex(status))
assert status == 4 # returned old value (nice! cool feature!)
while True:
status = yield from read_dmi_addr(dut, DBGCore.STAT)
print ("dmi ctrl status", bin(status))
- if status & DBGStat.STOPPED:
+ if (status & (1<<DBGStat.STOPPED)) or (status & (1<<DBGStat.TERM)):
break
####### JTAG to Wishbone ######
####### JTAG to DMI Setup (IC-Reset, start) ######
# write DMI CTRL register - ICRESET
- status = yield from writeread_dmi_addr(dut, DBCCore.CTRL, DBGCtrl.ICRESET)
+ status = yield from writeread_dmi_addr(dut, DBGCore.CTRL,
+ 1<<DBGCtrl.ICRESET)
print ("dmi ctrl status", hex(status))
# write DMI CTRL register - START
- status = yield from writeread_dmi_addr(dut, DBCCore.CTRL, DBGCtrl.START)
+ status = yield from writeread_dmi_addr(dut, DBGCore.CTRL,
+ 1<<DBGCtrl.START)
print ("dmi ctrl status", hex(status))
# read STAT just for info
for i in range(4):
status = yield from read_dmi_addr(dut, DBGCore.STAT)
- print ("dmi ctrl status", bin(status))
+ print ("dmi stat status", bin(status))
####### done - tell dmi_sim to stop (otherwise it won't) ########
"""DMI "simulator" process for nmigen tests
"""
-from soc.debug.dmi import DBGCore
+from soc.debug.dmi import DBGCore, DBGCtrl, DBGStat
def dmi_sim(dut):
wen = yield dmi.we_i
addr = yield dmi.addr_i
print (" dmi wen, addr", wen, addr)
+
+ # Control read
if addr == DBGCore.CTRL and wen == 0:
print (" read ctrl reg", ctrl_reg)
yield dmi.dout.eq(ctrl_reg)
yield dmi.ack_o.eq(1)
yield
yield dmi.ack_o.eq(0)
+
+ # Control write
elif addr == DBGCore.CTRL and wen == 1:
- ctrl_reg = (yield dmi.din)
- print (" write ctrl reg", ctrl_reg)
+ stat = (yield dmi.din)
+ if (stat & (1<<DBGCtrl.STOP)):
+ ctrl_reg |= (1<<DBGStat.STOPPED)
+ ctrl_reg &= ~(1<<DBGStat.STOPPING)
+ if (stat & (1<<DBGCtrl.START)):
+ ctrl_reg = 0
+ print (" write ctrl reg", stat, ctrl_reg)
yield dmi.ack_o.eq(1)
yield
yield dmi.ack_o.eq(0)
+
+ # allow MSR write
elif addr == DBGCore.MSR and wen == 0:
print (" read msr reg")
yield dmi.dout.eq(0xdeadbeef) # test MSR value