1 # test case for LOAD / STORE Computation Unit using MMU
3 from nmigen
.back
.pysim
import Simulator
, Delay
, Settle
, Tick
4 from nmigen
.cli
import verilog
, rtlil
5 from nmigen
import Module
, Signal
, Mux
, Cat
, Elaboratable
, Array
, Repl
6 from nmigen
.hdl
.rec
import Record
, Layout
8 from nmutil
.latch
import SRLatch
, latchregister
9 from nmutil
.byterev
import byte_reverse
10 from nmutil
.extend
import exts
11 from nmutil
.util
import wrap
12 from soc
.fu
.regspec
import RegSpecAPI
14 from openpower
.decoder
.power_enums
import MicrOp
, Function
, LDSTMode
15 from soc
.fu
.ldst
.ldst_input_record
import CompLDSTOpSubset
16 from openpower
.decoder
.power_decoder2
import Data
17 from openpower
.consts
import MSR
19 from soc
.experiment
.compalu_multi
import go_record
, CompUnitRecord
20 from soc
.experiment
.l0_cache
import PortInterface
21 from soc
.experiment
.pimem
import LDSTException
22 from soc
.experiment
.compldst_multi
import LDSTCompUnit
, load
, store
23 from soc
.config
.test
.test_loadstore
import TestMemPspec
25 from soc
.experiment
.mmu
import MMU
26 from nmutil
.util
import Display
28 from soc
.config
.loadstore
import ConfigMemoryPortInterface
29 from soc
.experiment
.test
import pagetables
30 from soc
.experiment
.test
.test_wishbone
import wb_get
32 #new unit added to this test case
33 from soc
.fu
.mmu
.pipe_data
import MMUPipeSpec
34 from soc
.fu
.mmu
.fsm
import FSMMMUStage
36 #for sending instructions to the FSM
37 from openpower
.consts
import MSR
38 from openpower
.decoder
.power_fields
import DecodeFields
39 from openpower
.decoder
.power_fieldsn
import SignalBitRange
40 from openpower
.decoder
.power_decoder2
import decode_spr_num
41 from openpower
.decoder
.power_enums
import MicrOp
44 yield dut
.fsm
.p
.i_data
.ctx
.op
.eq(MicrOp
.OP_TLBIE
)
45 yield dut
.fsm
.p
.valid_i
.eq(1)
47 yield dut
.fsm
.p
.valid_i
.eq(0)
52 yield Display("OP_TLBIE test done")
55 yield dut
.mmu
.rin
.prtbl
.eq(0x1000000) # set process table
57 data
= 0xFF #just a single byte for this test
58 #data = 0xf553b658ba7e1f51
60 yield from store(dut
, addr
, 0, data
, 0)
62 ld_data
, data_ok
, ld_addr
= yield from load(dut
, addr
, 0, 0)
63 print(data
,data_ok
,ld_addr
)
66 yield from test_TLBIE(dut
)
70 -- not testing dzbz here --
73 print("doing dcbz/store with data 0 .....")
74 yield from store_debug(dut, addr, 0, data, 0, dcbz=True) #hangs
76 ld_data, data_ok, ld_addr = yield from load(dut, addr, 0, 0)
77 print(data,data_ok,ld_addr)
81 print("dzbz test passed")
84 dut
.stop
= True # stop simulation
86 ########################################
89 class TestLDSTCompUnitMMUFSM(LDSTCompUnit
):
91 def __init__(self
, rwid
, pspec
):
92 from soc
.experiment
.l0_cache
import TstL0CacheBuffer
93 self
.l0
= l0
= TstL0CacheBuffer(pspec
)
95 LDSTCompUnit
.__init
__(self
, pi
, rwid
, 4)
97 def elaborate(self
, platform
):
98 m
= LDSTCompUnit
.elaborate(self
, platform
)
99 m
.submodules
.l0
= self
.l0
100 # link addr-go direct to rel
101 m
.d
.comb
+= self
.ad
.go_i
.eq(self
.ad
.rel_o
)
105 def test_scoreboard_mmu():
108 pspec
= TestMemPspec(ldst_ifacetype
='mmu_cache_wb',
109 imem_ifacetype
='bare_wb',
115 dut
= TestLDSTCompUnit(16,pspec
)
116 vl
= rtlil
.convertMMUFSM(dut
, ports
=dut
.ports())
117 with
open("test_ldst_comp_mmu1.il", "w") as f
:
120 run_simulation(dut
, ldst_sim(dut
), vcd_name
='test_ldst_comp.vcd')
122 ########################################
123 class TestLDSTCompUnitRegSpecMMUFSM(LDSTCompUnit
):
125 def __init__(self
, pspec
):
126 from soc
.experiment
.l0_cache
import TstL0CacheBuffer
127 from soc
.fu
.ldst
.pipe_data
import LDSTPipeSpec
128 regspec
= LDSTPipeSpec
.regspec
130 # use a LoadStore1 here
132 cmpi
= ConfigMemoryPortInterface(pspec
)
139 pipe_spec
= MMUPipeSpec(id_wid
=2)
140 self
.fsm
= FSMMMUStage(pipe_spec
)
142 self
.fsm
.set_ldst_interface(ldst
)
144 LDSTCompUnit
.__init
__(self
, ldst
.pi
, regspec
, 4)
146 def elaborate(self
, platform
):
147 m
= LDSTCompUnit
.elaborate(self
, platform
)
148 m
.submodules
.l0
= self
.l0
149 m
.submodules
.mmu
= self
.mmu
150 m
.submodules
.fsm
= self
.fsm
151 # link addr-go direct to rel
152 m
.d
.comb
+= self
.ad
.go_i
.eq(self
.ad
.rel_o
)
154 # link mmu and dcache together
155 dcache
= self
.l0
.dcache
157 m
.d
.comb
+= dcache
.m_in
.eq(mmu
.d_out
) # MMUToDCacheType
158 m
.d
.comb
+= mmu
.d_in
.eq(dcache
.m_out
) # DCacheToMMUType
162 def test_scoreboard_regspec_mmufsm():
167 pspec
= TestMemPspec(ldst_ifacetype
='mmu_cache_wb',
168 imem_ifacetype
='bare_wb',
174 dut
= TestLDSTCompUnitRegSpecMMUFSM(pspec
)
176 m
.submodules
.dut
= dut
181 dut
.mem
= pagetables
.test1
184 sim
.add_sync_process(wrap(ldst_sim(dut
))) # rename ?
185 sim
.add_sync_process(wrap(wb_get(dut
)))
186 with sim
.write_vcd('test_scoreboard_regspec_mmufsm.vcd'):
190 if __name__
== '__main__':
191 test_scoreboard_regspec_mmufsm()
192 #only one test for now -- test_scoreboard_mmu()