1 from soc
.simulator
.program
import Program
2 from soc
.fu
.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
12 from soc
.config
.test
.test_loadstore
import TestMemPspec
13 from soc
.simple
.test
.test_core
import (setup_regs
, check_regs
,
16 from soc
.fu
.compunits
.test
.test_compunit
import (setup_test_memory
,
20 from soc
.simple
.test
.test_issuer
import setup_i_memory
23 sys
.setrecursionlimit(10**6)
26 class BinaryTestCase(FHDLTestCase
):
29 def __init__(self
, name
="general"):
30 super().__init
__(name
)
33 @unittest.skip("a bit big")
34 def test_binary(self
):
35 with
Program("1.bin") as program
:
36 self
.run_tst_program(program
)
38 def test_binary(self
):
39 with
Program("hello_world.bin") as program
:
40 self
.run_tst_program(program
)
42 def run_tst_program(self
, prog
):
43 initial_regs
= [0] * 32
44 tc
= TestCase(prog
, self
.test_name
, initial_regs
, None, 0,
47 self
.test_data
.append(tc
)
50 class TestRunner(FHDLTestCase
):
51 def __init__(self
, tst_data
):
52 super().__init
__("binary_runner")
53 self
.test_data
= tst_data
55 def binary_runner(self
):
61 pspec
= TestMemPspec(ldst_ifacetype
='test_bare_wb',
62 imem_ifacetype
='test_bare_wb',
66 imem_test_depth
=32768,
67 dmem_test_depth
=32768)
68 m
.submodules
.issuer
= issuer
= TestIssuer(pspec
)
69 imem
= issuer
.imem
._get
_memory
()
71 pdecode2
= core
.pdecode2
74 comb
+= issuer
.pc_i
.data
.eq(pc_i
)
75 comb
+= issuer
.go_insn_i
.eq(go_insn_i
)
83 for test
in self
.test_data
:
86 yield core
.bigendian_i
.eq(1)
87 yield core
.core_start_i
.eq(1)
89 yield core
.core_start_i
.eq(0)
93 program
= test
.program
94 self
.subTest(test
.name
)
95 print ("regs", test
.regs
)
96 print ("sprs", test
.sprs
)
98 print ("mem", test
.mem
)
99 print ("msr", test
.msr
)
100 print ("assem", program
.assembly
)
101 instructions
= list(program
.generate_instructions())
103 print ("instructions", len(instructions
))
105 pc
= 0 # start of memory
107 yield from setup_i_memory(imem
, pc
, instructions
)
108 # blech! put the same listing into the data memory
109 data_mem
= get_l0_mem(l0
)
110 yield from setup_i_memory(data_mem
, pc
, instructions
)
111 #yield from setup_test_memory(l0, sim)
112 yield from setup_regs(core
, test
)
115 yield issuer
.pc_i
.ok
.eq(1)
119 # start the instruction
120 yield go_insn_i
.eq(1)
122 yield issuer
.pc_i
.ok
.eq(0) # don't change PC from now on
123 yield go_insn_i
.eq(0) # and don't issue a new insn
124 yield from wait_for_busy_hi(core
)
127 # wait until executed
128 ins
= yield core
.raw_opcode_i
129 pc
= yield issuer
.pc_o
130 print("instruction: 0x%x @ %x" % (ins
& 0xffffffff, pc
))
131 yield from wait_for_busy_clear(core
)
133 terminated
= yield core
.core_terminated_o
134 print ("terminated", terminated
)
136 terminated
= yield core
.core_terminated_o
141 #yield from check_regs(self, sim, core, test, code)
144 #yield from check_sim_memory(self, l0, sim, code)
146 sim
.add_sync_process(process
)
147 with sim
.write_vcd("binary_issuer_simulator.vcd",
152 if __name__
== "__main__":
153 unittest
.main(exit
=False)
154 suite
= unittest
.TestSuite()
155 suite
.addTest(TestRunner(BinaryTestCase
.test_data
))
157 runner
= unittest
.TextTestRunner()