Line 1... |
Line 1... |
#!/usr/bin/env python
|
#!/usr/bin/env python3
|
#
|
#
|
# This script generates a test include file from a set of "Fuse" test vectors.
|
# This script generates a test include file from a set of "Fuse" test vectors.
|
#
|
#
|
# Three common testing configurations are:
|
# Three common testing configurations are:
|
#
|
#
|
Line 60... |
Line 60... |
t1 = f1.read().splitlines()
|
t1 = f1.read().splitlines()
|
# Remove all tests until the one we need to start with. Tests are separated by empty lines.
|
# Remove all tests until the one we need to start with. Tests are separated by empty lines.
|
while t1[0].split(" ")[0]!=start_test:
|
while t1[0].split(" ")[0]!=start_test:
|
while len(t1.pop(0))>0:
|
while len(t1.pop(0))>0:
|
pass
|
pass
|
t1 = filter(None, t1) # Filter out empty lines
|
t1 = list(filter(None, t1)) # Filter out empty lines
|
|
|
with open(tests_expected) as f2:
|
with open(tests_expected) as f2:
|
t2 = f2.read().splitlines()
|
t2 = f2.read().splitlines()
|
while t2[0].split(" ")[0]!=start_test:
|
while t2[0].split(" ")[0]!=start_test:
|
while len(t2.pop(0))>0:
|
while len(t2.pop(0))>0:
|
Line 94... |
Line 94... |
# Create a file that should be included in the test_fuse source
|
# Create a file that should be included in the test_fuse source
|
ftest = open('test_fuse.vh', 'w')
|
ftest = open('test_fuse.vh', 'w')
|
ftest.write("// Automatically generated by genfuse.py\n\n")
|
ftest.write("// Automatically generated by genfuse.py\n\n")
|
|
|
# Initial pre-test state is reset and control signals asserted
|
# Initial pre-test state is reset and control signals asserted
|
|
ftest.write("force dut.resets_.clrpc=0;\n")
|
ftest.write("force dut.reg_file_.reg_gp_we=0;\n")
|
ftest.write("force dut.reg_file_.reg_gp_we=0;\n")
|
ftest.write("force dut.reg_control_.ctl_reg_sys_we=0;\n")
|
ftest.write("force dut.reg_control_.ctl_reg_sys_we=0;\n")
|
ftest.write("force dut.z80_top_ifc_n.fpga_reset=1;\n")
|
ftest.write("force dut.z80_top_ifc_n.fpga_reset=1;\n")
|
ftest.write("#2\n")
|
ftest.write("#2\n")
|
total_clks = total_clks + 2
|
total_clks = total_clks + 2
|
Line 108... |
Line 109... |
if len(t1)==0 or run_tests==0:
|
if len(t1)==0 or run_tests==0:
|
break
|
break
|
run_tests = run_tests-1
|
run_tests = run_tests-1
|
|
|
# Clear opcode register before starting a new instruction
|
# Clear opcode register before starting a new instruction
|
ftest.write(" force dut.instruction_reg_.ctl_ir_we=1;\n")
|
ftest.write(" force dut.ir_.ctl_ir_we=1;\n")
|
ftest.write(" force dut.instruction_reg_.db=0;\n")
|
ftest.write(" force dut.ir_.db=0;\n")
|
ftest.write("#2 release dut.instruction_reg_.ctl_ir_we;\n")
|
ftest.write("#2 release dut.ir_.ctl_ir_we;\n")
|
ftest.write(" release dut.instruction_reg_.db;\n")
|
ftest.write(" release dut.ir_.db;\n")
|
total_clks = total_clks + 2
|
total_clks = total_clks + 2
|
|
|
# Format of the test.in file:
|
# Format of the test.in file:
|
# <arbitrary test description>
|
# <arbitrary test description>
|
# AF BC DE HL AF' BC' DE' HL' IX IY SP PC
|
# AF BC DE HL AF' BC' DE' HL' IX IY SP PC
|
# I R IFF1 IFF2 IM <halted> <tstates>
|
# I R IFF1 IFF2 IM <halted> <tstates>
|
name = t1.pop(0)
|
name = t1.pop(0)
|
ftest.write("$fdisplay(f,\"Testing opcode " + name + "\");\n")
|
ftest.write("$fdisplay(f,\"Testing opcode " + name + "\");\n")
|
name = name.split(" ")[0]
|
name = name.split(" ")[0]
|
r = t1.pop(0).split(' ')
|
r = t1.pop(0).split(' ')
|
r = filter(None, r)
|
r = list(filter(None, r))
|
# 0 1 2 3 4 5 6 7 8 9 10 11 (index)
|
# 0 1 2 3 4 5 6 7 8 9 10 11 (index)
|
# AF BC DE HL AF' BC' DE' HL' IX IY SP PC
|
# AF BC DE HL AF' BC' DE' HL' IX IY SP PC
|
RegWrite("af", r[0])
|
RegWrite("af", r[0])
|
RegWrite("bc", r[1])
|
RegWrite("bc", r[1])
|
RegWrite("de", r[2])
|
RegWrite("de", r[2])
|
Line 140... |
Line 141... |
RegWrite("sp", r[10])
|
RegWrite("sp", r[10])
|
RegWrite("wz", "0000") # Initialize WZ with 0
|
RegWrite("wz", "0000") # Initialize WZ with 0
|
RegWrite("pc", r[11])
|
RegWrite("pc", r[11])
|
|
|
s = t1.pop(0).split(' ')
|
s = t1.pop(0).split(' ')
|
s = filter(None, s)
|
s = list(filter(None, s))
|
# 0 1 2 3 4 5 6 (index)
|
# 0 1 2 3 4 5 6 (index)
|
# I R IFF1 IFF2 IM <halted> <tstates?>
|
# I R IFF1 IFF2 IM <halted> <tstates?>
|
RegWrite("ir", s[0]+s[1])
|
RegWrite("ir", s[0]+s[1])
|
# TODO: Store IFF1/IFF2, IM, in_halt
|
# TODO: Store IFF1/IFF2, IM, in_halt
|
|
|
Line 168... |
Line 169... |
# used below after the opcode has executed (for IO writes)
|
# used below after the opcode has executed (for IO writes)
|
check_io = [] # List of check statements (for OUT instructions)
|
check_io = [] # List of check statements (for OUT instructions)
|
t2b = list(t2)
|
t2b = list(t2)
|
while True:
|
while True:
|
m = t2b.pop(0).split(' ')
|
m = t2b.pop(0).split(' ')
|
m = filter(None, m)
|
m = list(filter(None, m))
|
if len(m)==0 or m[0]=="-1":
|
if len(m)==0 or m[0]=="-1":
|
break
|
break
|
if len(m)==4 and m[1]=="PR":
|
if len(m)==4 and m[1]=="PR":
|
address = int(m[2],16)
|
address = int(m[2],16)
|
ftest.write(" io.IO[" + str(address) + "] = 8'h" + m[3] + ";\n")
|
ftest.write(" io.IO[" + str(address) + "] = 8'h" + m[3] + ";\n")
|
Line 184... |
Line 185... |
# Due to the instruction execution overlap, first 2T of an instruction may be writing
|
# Due to the instruction execution overlap, first 2T of an instruction may be writing
|
# value back to a general purpose register (like AF) and we need to prevent that.
|
# value back to a general purpose register (like AF) and we need to prevent that.
|
# Similarly, we let the execution continues 2T into the next instruction but we prevent
|
# Similarly, we let the execution continues 2T into the next instruction but we prevent
|
# it from writing to system registers so it cannot update PC and IR.
|
# it from writing to system registers so it cannot update PC and IR.
|
ftest.write(" force dut.z80_top_ifc_n.fpga_reset=0;\n")
|
ftest.write(" force dut.z80_top_ifc_n.fpga_reset=0;\n")
|
ftest.write(" force dut.address_latch_.abus=16'h" + r[11] +";\n")
|
ftest.write(" force dut.address_latch_.Q=16'h" + r[11] +";\n") # Force PC into the address latch
|
ftest.write(" release dut.reg_control_.ctl_reg_sys_we;\n")
|
ftest.write(" release dut.reg_control_.ctl_reg_sys_we;\n")
|
ftest.write(" release dut.reg_file_.reg_gp_we;\n")
|
ftest.write(" release dut.reg_file_.reg_gp_we;\n")
|
ftest.write("#3\n") # 1T (#2) overlaps the reset cycle
|
ftest.write("#3\n") # 1T (#2) overlaps the reset cycle
|
total_clks = total_clks + 3 # We borrow 1T (#2) to to force the PC to be what our test wants...
|
total_clks = total_clks + 3 # We borrow 1T (#2) to to force the PC to be what our test wants...
|
ftest.write(" release dut.address_latch_.abus;\n")
|
ftest.write(" release dut.address_latch_.Q;\n")
|
ftest.write("#1\n")
|
ftest.write("#1\n")
|
total_clks = total_clks + 1
|
total_clks = total_clks + 1
|
|
|
# Read and parse the tests expected list which contains the expected results of our run,
|
# Read and parse the tests expected list which contains the expected results of our run,
|
# including the number of clocks for a particular instruction
|
# including the number of clocks for a particular instruction
|
Line 205... |
Line 206... |
while True:
|
while True:
|
l = t2.pop(0)
|
l = t2.pop(0)
|
if l[0]!=' ':
|
if l[0]!=' ':
|
break
|
break
|
r = l.split(' ')
|
r = l.split(' ')
|
r = filter(None, r)
|
r = list(filter(None, r))
|
|
|
s = t2.pop(0).split(' ')
|
s = t2.pop(0).split(' ')
|
s = filter(None, s)
|
s = list(filter(None, s))
|
|
|
ticks = int(s[6]) * 2 - 2 # We return 1T (#2) that we borrowed to set PC
|
ticks = int(s[6]) * 2 - 2 # We return 1T (#2) that we borrowed to set PC
|
total_clks = total_clks + ticks
|
total_clks = total_clks + ticks
|
ftest.write("#" + str(ticks) + " // Execute\n")
|
ftest.write("#" + str(ticks) + " // Execute\n")
|
|
|
Line 262... |
Line 263... |
RegRead("ir", s[0]+s[1])
|
RegRead("ir", s[0]+s[1])
|
|
|
# Read memory configuration until an empty line or -1 at the end
|
# Read memory configuration until an empty line or -1 at the end
|
while True:
|
while True:
|
m = t2.pop(0).split(' ')
|
m = t2.pop(0).split(' ')
|
m = filter(None, m)
|
m = list(filter(None, m))
|
if len(m)==0 or m[0]=="-1":
|
if len(m)==0 or m[0]=="-1":
|
break
|
break
|
address = int(m.pop(0),16)
|
address = int(m.pop(0),16)
|
while True:
|
while True:
|
d = m.pop(0)
|
d = m.pop(0)
|