1 from openpower
.simulator
.program
import Program
2 from openpower
.test
.common
import TestCase
6 from nmigen
import Module
, Signal
7 from nmigen
.back
.pysim
import Simulator
, Delay
, Settle
8 from nmutil
.formaltest
import FHDLTestCase
10 from soc
.simple
.issuer
import TestIssuer
11 from openpower
.endian
import bigendian
14 from soc
.config
.test
.test_loadstore
import TestMemPspec
15 from soc
.simple
.test
.test_core
import (setup_regs
, check_regs
,
18 from soc
.fu
.compunits
.test
.test_compunit
import (check_sim_memory
,
21 from soc
.simple
.test
.test_runner
import setup_i_memory
23 from pathlib
import Path
26 sys
.setrecursionlimit(10**6)
29 class BinaryTestCase(FHDLTestCase
):
32 def __init__(self
, name
="general"):
33 super().__init
__(name
)
36 @unittest.skip("a bit big")
37 def test_binary(self
):
38 with
Program("1.bin", bigendian
) as program
:
39 self
.run_tst_program(program
)
41 @unittest.skipUnless(Path("hello_world.bin").exists(),
42 "missing hello_world.bin")
43 def test_binary(self
):
44 with
Program("hello_world.bin", bigendian
) as program
:
45 self
.run_tst_program(program
)
47 def run_tst_program(self
, prog
):
48 initial_regs
= [0] * 32
49 tc
= TestCase(prog
, self
.test_name
, initial_regs
, None, 0,
52 self
.test_data
.append(tc
)
55 class TestRunner(FHDLTestCase
):
56 def __init__(self
, tst_data
):
57 super().__init
__("binary_runner")
58 self
.test_data
= tst_data
60 def binary_runner(self
):
67 pspec
= TestMemPspec(ldst_ifacetype
='test_bare_wb',
68 imem_ifacetype
='test_bare_wb',
72 imem_test_depth
=32768,
73 dmem_test_depth
=32768)
74 m
.submodules
.issuer
= issuer
= TestIssuer(pspec
)
75 imem
= issuer
.imem
._get
_memory
()
77 pdecode2
= core
.pdecode2
80 comb
+= issuer
.pc_i
.data
.eq(pc_i
)
81 comb
+= issuer
.pc_i
.ok
.eq(pc_i_ok
)
82 comb
+= issuer
.go_insn_i
.eq(go_insn_i
)
90 for test
in self
.test_data
:
93 yield core
.bigendian_i
.eq(bigendian
)
94 yield core
.core_start_i
.eq(1)
96 yield core
.core_start_i
.eq(0)
100 program
= test
.program
101 self
.subTest(test
.name
)
102 print("regs", test
.regs
)
103 print("sprs", test
.sprs
)
105 print("mem", test
.mem
)
106 print("msr", test
.msr
)
107 print("assem", program
.assembly
)
108 instructions
= list(program
.generate_instructions())
110 print("instructions", len(instructions
))
112 pc
= 0 # start of memory
114 yield from setup_i_memory(imem
, pc
, instructions
)
115 # blech! put the same listing into the data memory
116 data_mem
= get_l0_mem(l0
)
117 yield from setup_i_memory(data_mem
, pc
, instructions
)
118 yield from setup_regs(core
, test
)
125 # start the instruction
126 yield go_insn_i
.eq(1)
128 yield pc_i_ok
.eq(0) # don't change PC from now on
129 yield go_insn_i
.eq(0) # and don't issue a new insn
130 yield from wait_for_busy_hi(core
)
133 # wait until executed
134 ins
= yield core
.raw_opcode_i
135 pc
= yield issuer
.pc_o
136 print("instruction: 0x%x @ %x" % (ins
& 0xffffffff, pc
))
137 yield from wait_for_busy_clear(core
)
139 terminated
= yield core
.core_terminated_o
140 print("terminated", terminated
)
142 terminated
= yield core
.core_terminated_o
147 # yield from check_regs(self, sim, core, test, code)
150 # yield from check_sim_memory(self, l0, sim, code)
152 sim
.add_sync_process(process
)
153 with sim
.write_vcd("binary_issuer_simulator.vcd",
158 if __name__
== "__main__":
159 unittest
.main(exit
=False)
160 suite
= unittest
.TestSuite()
161 suite
.addTest(TestRunner(BinaryTestCase
.test_data
))
163 runner
= unittest
.TextTestRunner()