cleanup, rename python scripts

This commit is contained in:
Matthew 2024-06-03 23:21:40 -05:00
parent 0a6e7080dc
commit 2e0c286017
2 changed files with 32 additions and 38 deletions

View File

@ -29,44 +29,14 @@
# OpenOCD also supports tcl commands directly
import atexit
import re
import time
from telnetlib import Telnet
debug = False
XLEN = 64 # TODO: infer this value from the MISA
tapname = "cvw.cpu" # this is set via the openocd config. It can be found by running `scan_chain`
# TODO: if JTAG clk is fast enough, need to check for busy between absract commands
def main():
global tn
with Telnet("127.0.0.1", 4444) as tn:
read() # clear welcome message from read buffer
activate_dm() # necessary if openocd init is disabled
status()
halt()
GPR = dump_GPR()
print(GPR)
check_errors()
print(f"PCM: '{read_data("PCM")}'")
resume()
status()
#clear_abstrcmd_err()
#write_data("READDATAM", "0xAA0987210000FFFF")
#print(f"READDATAM'{read_data("READDATAM")}'")
#print(f"WRITEDATAM: '{read_data("WRITEDATAM")}'")
#print(f"IEUADRM: '{read_data("IEUADRM")}'")
#write_data("TRAPM", "0x0")
#print(f"INSTRVALIDM: '{read_data("INSTRVALIDM")}'")
#print(f"MEMRWM: '{read_data("MEMRWM")}'")
#write_data("MEMRWM", "0x3")
#write_data("PCM", "0x100000")
#dmi_reset()
#clear_abstrcmd_err()
def dump_GPR():
gpr = {}
for i in range(1,32):
@ -303,18 +273,42 @@ def read():
return data
def interrogate():
global XLEN
global tapname
write("scan_chain")
raw = tn.read_until(b"> ").decode('ascii')
scan_chain = raw.replace("\r", "").replace("> ", "")
scan_chain = [tap for tap in scan_chain.split("\n")[2:] if tap]
if len(scan_chain) > 1:
print(f"Found multiple taps. Selecting tap #0\n{raw}")
scan_chain = scan_chain[0]
tapname = re.search("\d\s+(.+?)\s+", scan_chain).group(1)
print(f"DM tapname: {tapname}")
write("riscv info")
info = tn.read_until(b"> ").decode('ascii').replace("\r", "").replace("> ", "").split("\n")
for line in info:
if XLEN := re.search("hart.xlen\s+(\d+)", line).group(1):
XLEN = int(XLEN)
break
print(f"XLEN: {XLEN}")
def init():
global tn
tn = Telnet("127.0.0.1", 4444)
atexit.register(cleanup)
read() # clear welcome message from read buffer
interrogate()
activate_dm()
# TODO: query misa and get gpr count
# TODO: query gpr count
def cleanup():
tn.close()
# 6.1.4 dtmcs errinfo translation table
errinfo_translations = {
0 : "not implemented",
@ -397,8 +391,5 @@ nonstandard_register_lengths = {
"INSTRM" : 32,
"MEMRWM" : 2,
"INSTRVALIDM" : 1,
#"READDATAM" : P.LLEN
#"READDATAM" : P.LLEN # TODO: find LLEN
}
if __name__ == "__main__":
main()

View File

@ -1,7 +1,8 @@
import random
import time
from hw_interface import *
import hw_debug_interface
from hw_debug_interface import *
random_stimulus = False
@ -10,6 +11,8 @@ def main():
reg_addrs = list(registers.keys())
init()
global XLEN
XLEN = hw_debug_interface.XLEN
reset_dm()
reset_hart()
@ -65,7 +68,7 @@ def main():
except Exception as e:
raise e
if rdata != test_reg_data[r]:
raise Exception(f"Register {r} read did not return correct data: {rdata} != {test_reg_data[r]}")
print(f"Error: register {r} read did not return correct data: {rdata} != {test_reg_data[r]}")
else:
print(f"Read {rdata} from {r}")