96abda8d836f7da9e8d38e4904207f2a232a4f39
1 from nmigen
import Module
, Signal
, Cat
2 from nmigen
.back
.pysim
import Simulator
, Delay
, Settle
3 from nmutil
.formaltest
import FHDLTestCase
4 from nmigen
.cli
import rtlil
6 from soc
.decoder
.isa
.caller
import special_sprs
7 from soc
.decoder
.power_decoder
import create_pdecode
8 from soc
.decoder
.power_decoder2
import PowerDecode2
9 from soc
.decoder
.isa
.all
import ISA
10 from soc
.decoder
.power_enums
import Function
, XER_bits
13 from soc
.simple
.core
import NonProductionCore
14 from soc
.experiment
.compalu_multi
import find_ok
# hack
16 # test with ALU data and Logical data
17 from soc
.fu
.alu
.test
.test_pipe_caller
import ALUTestCase
18 from soc
.fu
.logical
.test
.test_pipe_caller
import LogicalTestCase
19 from soc
.fu
.shift_rot
.test
.test_pipe_caller
import ShiftRotTestCase
20 from soc
.fu
.cr
.test
.test_pipe_caller
import CRTestCase
21 from soc
.fu
.branch
.test
.test_pipe_caller
import BranchTestCase
24 def set_issue(core
, dec2
, sim
):
25 yield core
.issue_i
.eq(1)
27 yield core
.issue_i
.eq(0)
29 busy_o
= yield core
.busy_o
36 def wait_for_busy_clear(cu
):
38 busy_o
= yield cu
.busy_o
45 class TestRunner(FHDLTestCase
):
46 def __init__(self
, tst_data
):
47 super().__init
__("run_all")
48 self
.test_data
= tst_data
53 instruction
= Signal(32)
56 m
.submodules
.core
= core
= NonProductionCore()
57 pdecode
= core
.pdecode
58 pdecode2
= core
.pdecode2
60 comb
+= pdecode2
.dec
.raw_opcode_in
.eq(instruction
)
61 comb
+= core
.ivalid_i
.eq(ivalid_i
)
67 yield core
.issue_i
.eq(0)
70 for test
in self
.test_data
:
72 program
= test
.program
73 self
.subTest(test
.name
)
74 sim
= ISA(pdecode2
, test
.regs
, test
.sprs
, test
.cr
)
75 gen
= program
.generate_instructions()
76 instructions
= list(zip(gen
, program
.assembly
.splitlines()))
78 # set up INT regfile, "direct" write (bypass rd/write ports)
80 yield core
.regs
.int.regs
[i
].reg
.eq(test
.regs
[i
])
82 # set up CR regfile, "direct" write across all CRs
84 print ("cr reg", hex(cr
))
86 cri
= (cr
>>(i
*4)) & 0xf
87 print ("cr reg", hex(cri
), i
,
88 core
.regs
.cr
.regs
[i
].reg
.shape())
89 yield core
.regs
.cr
.regs
[i
].reg
.eq(cri
)
91 # set up XER. "direct" write (bypass rd/write ports)
93 print ("sprs", test
.sprs
)
94 if special_sprs
['XER'] in test
.sprs
:
95 xer
= test
.sprs
[special_sprs
['XER']]
96 sobit
= xer
[XER_bits
['SO']].asint()
97 yield xregs
.regs
[xregs
.SO
].reg
.eq(sobit
)
98 cabit
= xer
[XER_bits
['CA']].asint()
99 ca32bit
= xer
[XER_bits
['CA32']].asint()
100 yield xregs
.regs
[xregs
.CA
].reg
.eq(Cat(cabit
, ca32bit
))
101 ovbit
= xer
[XER_bits
['OV']].asint()
102 ov32bit
= xer
[XER_bits
['OV32']].asint()
103 yield xregs
.regs
[xregs
.OV
].reg
.eq(Cat(ovbit
, ov32bit
))
105 yield xregs
.regs
[xregs
.SO
].reg
.eq(0)
106 yield xregs
.regs
[xregs
.OV
].reg
.eq(0)
107 yield xregs
.regs
[xregs
.CA
].reg
.eq(0)
109 index
= sim
.pc
.CIA
.value
//4
110 while index
< len(instructions
):
111 ins
, code
= instructions
[index
]
113 print("0x{:X}".format(ins
& 0xffffffff))
116 # ask the decoder to decode this binary data (endian'd)
117 yield pdecode2
.dec
.bigendian
.eq(0) # little / big?
118 yield instruction
.eq(ins
) # raw binary instr.
121 #fn_unit = yield pdecode2.e.fn_unit
122 #fuval = self.funit.value
123 #self.assertEqual(fn_unit & fuval, fuval)
125 # set operand and get inputs
126 yield from set_issue(core
, pdecode2
, sim
)
129 yield from wait_for_busy_clear(core
)
134 # call simulated operation
135 opname
= code
.split(' ')[0]
136 yield from sim
.call(opname
)
137 index
= sim
.pc
.CIA
.value
//4
142 rval
= yield core
.regs
.int.regs
[i
].reg
144 print ("int regs", list(map(hex, intregs
)))
146 simregval
= sim
.gpr
[i
].asint()
147 self
.assertEqual(simregval
, intregs
[i
],
148 "int reg %d not equal %s" % (i
, repr(code
)))
150 sim
.add_sync_process(process
)
151 with sim
.write_vcd("core_simulator.vcd", "core_simulator.gtkw",
156 if __name__
== "__main__":
157 unittest
.main(exit
=False)
158 suite
= unittest
.TestSuite()
159 suite
.addTest(TestRunner(CRTestCase
.test_data
))
160 suite
.addTest(TestRunner(ShiftRotTestCase
.test_data
))
161 suite
.addTest(TestRunner(LogicalTestCase
.test_data
))
162 suite
.addTest(TestRunner(ALUTestCase
.test_data
))
163 suite
.addTest(TestRunner(BranchTestCase
.test_data
))
165 runner
= unittest
.TextTestRunner()