no python files to be committed in isafunctions
[openpower-isa.git] / src / openpower / decoder / isa / test_caller.py
index 8fd5e5fd76d23fd82f98f518c7a831b90289e876..8d2c0020c9d23a0ad311dce95e967a658dec074a 100644 (file)
@@ -10,12 +10,87 @@ from openpower.decoder.isa.caller import ISACaller, inject
 from openpower.decoder.selectable_int import SelectableInt
 from openpower.decoder.orderedset import OrderedSet
 from openpower.decoder.isa.all import ISA
+from nmutil.formaltest import FHDLTestCase
 
 
 class Register:
     def __init__(self, num):
         self.num = num
 
+
+class ISATestRunner(FHDLTestCase):
+    def __init__(self, tst_data, include_fp=True):
+        super().__init__("run_all")
+        self.test_data = tst_data
+        self.include_fp = include_fp
+
+    def run_all(self):
+        m = Module()
+        comb = m.d.comb
+        instruction = Signal(32)
+
+        pdecode = create_pdecode(include_fp=self.include_fp)
+        m.submodules.pdecode2 = pdecode2 = PowerDecode2(pdecode)
+
+        comb += pdecode2.dec.raw_opcode_in.eq(instruction)
+        sim = Simulator(m)
+
+        def process():
+
+            for test in self.test_data:
+
+                with self.subTest(test.name):
+                    generator = test.program
+
+                    gen = list(generator.generate_instructions())
+                    insncode = generator.assembly.splitlines()
+                    instructions = list(zip(gen, insncode))
+
+                    simulator = ISA(pdecode2, test.regs,
+                                    test.sprs,
+                                    test.cr,
+                                    initial_insns=gen, respect_pc=True,
+                                    initial_svstate=test.svstate,
+                                    initial_mem=test.mem,
+                                    fpregfile=None,
+                                    disassembly=insncode,
+                                    bigendian=0,
+                                    mmu=False)
+
+                    print ("GPRs")
+                    simulator.gpr.dump()
+                    print ("FPRs")
+                    simulator.fpr.dump()
+
+                    yield pdecode2.dec.bigendian.eq(0)  # little / big?
+                    pc = simulator.pc.CIA.value
+                    index = pc//4
+                    while index < len(instructions):
+                        print("instr pc", pc)
+                        try:
+                            yield from simulator.setup_one()
+                        except KeyError:  # instruction not in imem: stop
+                            break
+                        yield Settle()
+
+                        ins, code = instructions[index]
+                        print("    0x{:X}".format(ins & 0xffffffff))
+                        opname = code.split(' ')[0]
+                        print(code, opname)
+
+                        # ask the decoder to decode this binary data (endian'd)
+                        yield from simulator.execute_one()
+                        pc = simulator.pc.CIA.value
+                        index = pc//4
+
+        # run simulator multiple times, using the same PowerDecoder2,
+        # with multiple sub-tests
+        sim.add_process(process)
+        with sim.write_vcd("simulator.vcd", "simulator.gtkw",
+                           traces=[]):
+            sim.run()
+
+
 def run_tst(generator, initial_regs, initial_sprs=None, svstate=0, mmu=False,
                                      initial_cr=0, mem=None,
                                      initial_fprs=None):
@@ -45,6 +120,11 @@ def run_tst(generator, initial_regs, initial_sprs=None, svstate=0, mmu=False,
 
     def process():
 
+        print ("GPRs")
+        simulator.gpr.dump()
+        print ("FPRs")
+        simulator.fpr.dump()
+
         yield pdecode2.dec.bigendian.eq(0)  # little / big?
         pc = simulator.pc.CIA.value
         index = pc//4