1 from nmigen
import Module
, Signal
2 from nmigen
.sim
import Simulator
, Settle
3 from openpower
.decoder
.isa
.caller
import ISACaller
4 from openpower
.decoder
.power_decoder
import create_pdecode
5 from openpower
.decoder
.power_decoder2
import (PowerDecode2
)
6 from openpower
.simulator
.program
import Program
7 from openpower
.decoder
.isa
.caller
import ISACaller
, inject
8 from openpower
.decoder
.isa
.all
import ISA
9 from openpower
.test
.state
import TestState
10 from nmutil
.formaltest
import FHDLTestCase
14 def __init__(self
, num
):
18 class ISATestRunner(FHDLTestCase
):
19 def __init__(self
, tst_data
, include_fp
=True):
20 super().__init
__("run_all")
21 self
.test_data
= tst_data
22 self
.include_fp
= include_fp
27 instruction
= Signal(32)
29 pdecode
= create_pdecode(include_fp
=self
.include_fp
)
30 m
.submodules
.pdecode2
= pdecode2
= PowerDecode2(pdecode
)
32 comb
+= pdecode2
.dec
.raw_opcode_in
.eq(instruction
)
37 for test
in self
.test_data
:
39 with self
.subTest(test
.name
):
40 generator
= test
.program
42 gen
= list(generator
.generate_instructions())
43 insncode
= generator
.assembly
.splitlines()
44 instructions
= list(zip(gen
, insncode
))
46 simulator
= ISA(pdecode2
, test
.regs
,
49 initial_insns
=gen
, respect_pc
=True,
50 initial_svstate
=test
.svstate
,
62 yield pdecode2
.dec
.bigendian
.eq(0) # little / big?
63 pc
= simulator
.pc
.CIA
.value
65 while index
< len(instructions
):
68 yield from simulator
.setup_one()
69 except KeyError: # instruction not in imem: stop
73 ins
, code
= instructions
[index
]
74 print(" 0x%x" % (ins
& 0xffffffff))
75 opname
= code
.split(' ')[0]
78 # ask the decoder to decode this binary data (endian'd)
79 yield from simulator
.execute_one()
80 pc
= simulator
.pc
.CIA
.value
83 # run simulator multiple times, using the same PowerDecoder2,
84 # with multiple sub-tests
85 sim
.add_process(process
)
86 with sim
.write_vcd("simulator.vcd", "simulator.gtkw",
91 def check_regs(dut
, sim
, expected
, test
, code
):
92 # create the two states and compare
93 testdic
= {'sim': sim
, 'expected': expected
}
94 yield from teststate_check_regs(dut
, testdic
, test
, code
)
97 def run_tst(generator
, initial_regs
,
108 use_syscall_emu
=False): # (dut, code)
109 if initial_sprs
is None:
113 instruction
= Signal(32)
116 pdecode
= create_pdecode(include_fp
=initial_fprs
is not None)
117 pdecode2
= PowerDecode2(pdecode
)
118 m
.submodules
.pdecode2
= pdecode2
120 gen
= list(generator
.generate_instructions())
121 insncode
= generator
.assembly
.splitlines()
122 instructions
= list(zip(gen
, insncode
))
124 simulator
= ISA(pdecode2
, initial_regs
, initial_sprs
, initial_cr
,
125 initial_insns
=gen
, respect_pc
=True,
126 initial_svstate
=svstate
,
128 initial_msr
=initial_msr
,
129 fpregfile
=initial_fprs
,
130 disassembly
=insncode
,
133 use_mmap_mem
=use_mmap_mem
,
134 use_syscall_emu
=use_syscall_emu
)
135 comb
+= pdecode2
.dec
.raw_opcode_in
.eq(instruction
)
138 process_state
= state
147 yield pdecode2
.dec
.bigendian
.eq(0) # little / big?
148 pc
= simulator
.pc
.CIA
.value
150 while index
< len(instructions
):
151 print("instr pc", pc
)
153 yield from simulator
.setup_one()
154 except KeyError: # indicates instruction not in imem: stop
158 ins
, code
= instructions
[index
]
159 print(" 0x%x" % (ins
& 0xffffffff))
160 opname
= code
.split(' ')[0]
163 # ask the decoder to decode this binary data (endian'd)
164 yield from simulator
.execute_one()
165 pc
= simulator
.pc
.CIA
.value
168 # use this to test against expected (static) results at end of run
169 if process_state
is not None:
170 (dut
, code
) = process_state
171 simulator
.state
= yield from TestState("sim", simulator
, dut
, code
)
173 sim
.add_process(process
)
174 with sim
.write_vcd("simulator.vcd", "simulator.gtkw",