1 from nmigen
import Module
, Signal
3 from nmutil
.sim_tmp_alternative
import Simulator
, Settle
5 from nmigen
.cli
import rtlil
7 from openpower
.decoder
.isa
.caller
import ISACaller
, special_sprs
8 from openpower
.decoder
.power_decoder
import (create_pdecode
)
9 from openpower
.decoder
.power_decoder2
import (PowerDecode2
)
10 from openpower
.decoder
.power_enums
import (XER_bits
, Function
, MicrOp
, CryIn
)
11 from openpower
.decoder
.selectable_int
import SelectableInt
12 from openpower
.simulator
.program
import Program
13 from openpower
.decoder
.isa
.all
import ISA
14 from openpower
.endian
import bigendian
15 from openpower
.consts
import MSR
18 from openpower
.test
.common
import (
19 TestAccumulatorBase
, skip_case
, TestCase
, ALUHelpers
)
22 from soc
.fu
.div
.test
.helper
import (log_rand
, get_cu_inputs
,
23 set_alu_inputs
, DivTestHelper
)
25 from soc
.simple
.core
import NonProductionCore
26 from soc
.config
.test
.test_loadstore
import TestMemPspec
27 from soc
.simple
.test
.test_core
import (setup_regs
, check_regs
,
34 class MMUTestCase(TestAccumulatorBase
):
35 # MMU handles MTSPR, MFSPR, DCBZ and TLBIE.
36 # other instructions here -> must be load/store
38 def case_mfspr_after_invalid_load(self
):
39 lst
= [ # TODO -- set SPR on both sinulator and port interface
40 "mfspr 1, 18", # DSISR to reg 1
41 "mfspr 2, 19", # DAR to reg 2
42 # TODO -- verify returned sprvals
45 initial_regs
= [0] * 32
47 # THOSE are currently broken -- initial_sprs = {'DSISR': 0x12345678, 'DAR': 0x87654321}
49 self
.add_case(Program(lst
, bigendian
),
50 initial_regs
, initial_sprs
)
52 # def case_ilang(self):
53 # pspec = SPRPipeSpec(id_wid=2, parent_pspec=None)
54 # alu = SPRBasePipe(pspec)
55 # vl = rtlil.convert(alu, ports=alu.ports())
56 # with open("trap_pipeline.il", "w") as f:
60 class TestRunner(unittest
.TestCase
):
61 def __init__(self
, test_data
):
62 super().__init
__("run_all")
63 self
.test_data
= test_data
65 def execute(self
, core
, instruction
, pdecode2
, test
):
66 program
= test
.program
67 sim
= ISA(pdecode2
, test
.regs
, test
.sprs
, test
.cr
,
70 gen
= program
.generate_instructions()
71 instructions
= list(zip(gen
, program
.assembly
.splitlines()))
76 while index
< len(instructions
):
77 ins
, code
= instructions
[index
]
79 print("pc %08x instr: %08x" % (pc
, ins
& 0xffffffff))
83 so
= 1 if sim
.spr
['XER'][XER_bits
['SO']] else 0
84 ov
= 1 if sim
.spr
['XER'][XER_bits
['OV']] else 0
85 ov32
= 1 if sim
.spr
['XER'][XER_bits
['OV32']] else 0
86 print("before: so/ov/32", so
, ov
, ov32
)
88 # ask the decoder to decode this binary data (endian'd)
89 yield pdecode2
.dec
.bigendian
.eq(bigendian
) # little / big?
90 yield pdecode2
.state
.msr
.eq(msr
) # set MSR in pdecode2
91 yield pdecode2
.state
.pc
.eq(pc
) # set PC in pdecode2
92 yield instruction
.eq(ins
) # raw binary instr.
95 yield from setup_regs(pdecode2
, core
, test
)
97 opname
= code
.split(' ')[0]
98 yield from sim
.call(opname
)
102 print("pc after %08x" % (pc
))
104 fsm
= core
.fus
.fus
["mmu0"].alu
106 vld
= yield fsm
.n
.o_valid
110 print("not valid -- hang")
111 vld
= yield fsm
.n
.o_valid
119 instruction
= Signal(32)
121 pdecode
= create_pdecode()
123 m
.submodules
.pdecode2
= pdecode2
= PowerDecode2(pdecode
)
125 pspec
= TestMemPspec(ldst_ifacetype
='testpi',
131 m
.submodules
.core
= core
= NonProductionCore(pspec
132 # XXX NO absolutely do not do this.
133 # all options must go into the pspec
134 # , microwatt_mmu=True
137 comb
+= pdecode2
.dec
.raw_opcode_in
.eq(instruction
)
143 for test
in self
.test_data
:
144 print("test", test
.name
)
145 print("sprs", test
.sprs
)
146 program
= test
.program
147 with self
.subTest(test
.name
):
148 yield from self
.execute(core
, instruction
, pdecode2
, test
)
150 sim
.add_sync_process(process
)
151 with sim
.write_vcd("mmu_ldst_simulator.vcd", "mmu_ldst_simulator.gtkw",
156 if __name__
== "__main__":
157 unittest
.main(exit
=False)
158 suite
= unittest
.TestSuite()
159 suite
.addTest(TestRunner(MMUTestCase().test_data
))
161 runner
= unittest
.TextTestRunner()