1 # test case for LOAD / STORE Computation Unit using MMU
3 from nmigen
.compat
.sim
import run_simulation
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 soc
.fu
.regspec
import RegSpecAPI
13 from openpower
.decoder
.power_enums
import MicrOp
, Function
, LDSTMode
14 from soc
.fu
.ldst
.ldst_input_record
import CompLDSTOpSubset
15 from openpower
.decoder
.power_decoder2
import Data
16 from openpower
.consts
import MSR
18 from soc
.experiment
.compalu_multi
import go_record
, CompUnitRecord
19 from soc
.experiment
.l0_cache
import PortInterface
20 from soc
.experiment
.pimem
import LDSTException
21 from soc
.experiment
.compldst_multi
import LDSTCompUnit
, load
, store
22 from soc
.config
.test
.test_loadstore
import TestMemPspec
24 from soc
.experiment
.mmu
import MMU
25 from nmutil
.util
import Display
27 from soc
.config
.loadstore
import ConfigMemoryPortInterface
29 def wait_for_debug(sig
, event
, wait
=True, test1st
=False):
31 print("wait for", sig
, v
, wait
, test1st
)
32 if test1st
and bool(v
) == wait
:
37 yield Display("waiting for "+event
)
41 # if RA = 0 then b <- 0 RA needs to be read if RA = 0
43 # EA <- b + (RB) RB needs to be read
44 # verify that EA is correct first
45 def dcbz(dut
, ra
, zero_a
, rb
):
46 print("LD_part", ra
, zero_a
, rb
)
47 yield dut
.oper_i
.insn_type
.eq(MicrOp
.OP_DCBZ
)
48 yield dut
.src1_i
.eq(ra
)
49 yield dut
.src2_i
.eq(rb
)
50 yield dut
.oper_i
.zero_a
.eq(zero_a
)
51 yield dut
.issue_i
.eq(1)
53 yield dut
.issue_i
.eq(0)
56 # set up operand flags
58 if not zero_a
: # no zero-a means RA needs to be read
61 # wait for the operands (RA, RB, or both)
63 yield dut
.rd
.go_i
.eq(rd
)
64 yield from wait_for_debug(dut
.rd
.rel_o
,"operands (RA, RB, or both)")
65 yield dut
.rd
.go_i
.eq(0)
69 # same thing as soc/src/soc/experiment/test/test_dcbz_pi.py
71 yield dut
.mmu
.rin
.prtbl
.eq(0x1000000) # set process table
72 ###yield from dcbz(dut, 4, 0, 3) # EA=7
74 data
= 0xf553b658ba7e1f51
76 yield from store(dut
, addr
, 0, data
, 0)
78 yield from load(dut
, 4, 0, 2) #FIXME
80 ld_data = yield from pi_ld(pi, addr, 8, msr_pr=0)
81 assert ld_data == 0xf553b658ba7e1f51
82 ld_data = yield from pi_ld(pi, addr, 8, msr_pr=0)
83 assert ld_data == 0xf553b658ba7e1f51
87 ########################################
90 class TestLDSTCompUnitMMU(LDSTCompUnit
):
92 def __init__(self
, rwid
, pspec
):
93 from soc
.experiment
.l0_cache
import TstL0CacheBuffer
94 self
.l0
= l0
= TstL0CacheBuffer(pspec
)
96 LDSTCompUnit
.__init
__(self
, pi
, rwid
, 4)
98 def elaborate(self
, platform
):
99 m
= LDSTCompUnit
.elaborate(self
, platform
)
100 m
.submodules
.l0
= self
.l0
101 # link addr-go direct to rel
102 m
.d
.comb
+= self
.ad
.go_i
.eq(self
.ad
.rel_o
)
106 def test_scoreboard_mmu():
109 pspec
= TestMemPspec(ldst_ifacetype
='mmu_cache_wb',
110 imem_ifacetype
='bare_wb',
116 dut
= TestLDSTCompUnitMMU(16,pspec
)
117 vl
= rtlil
.convert(dut
, ports
=dut
.ports())
118 with
open("test_ldst_comp_mmu1.il", "w") as f
:
121 run_simulation(dut
, ldst_sim(dut
), vcd_name
='test_ldst_comp.vcd')
122 #TODO add wb runner here
125 ########################################
126 class TestLDSTCompUnitRegSpecMMU(LDSTCompUnit
):
128 def __init__(self
, pspec
):
129 from soc
.experiment
.l0_cache
import TstL0CacheBuffer
130 from soc
.fu
.ldst
.pipe_data
import LDSTPipeSpec
131 regspec
= LDSTPipeSpec
.regspec
133 # use a LoadStore1 here
135 cmpi
= ConfigMemoryPortInterface(pspec
)
141 LDSTCompUnit
.__init
__(self
, ldst
.pi
, regspec
, 4)
143 def elaborate(self
, platform
):
144 m
= LDSTCompUnit
.elaborate(self
, platform
)
145 m
.submodules
.l0
= self
.l0
146 m
.submodules
.mmu
= self
.mmu
147 # link addr-go direct to rel
148 m
.d
.comb
+= self
.ad
.go_i
.eq(self
.ad
.rel_o
)
150 # link mmu and dcache together
151 dcache
= self
.l0
.dcache
153 m
.d
.comb
+= dcache
.m_in
.eq(mmu
.d_out
) # MMUToDCacheType
154 m
.d
.comb
+= mmu
.d_in
.eq(dcache
.m_out
) # DCacheToMMUType
156 # TODO: link wishbone bus
161 def test_scoreboard_regspec_mmu():
164 pspec
= TestMemPspec(ldst_ifacetype
='mmu_cache_wb',
165 imem_ifacetype
='bare_wb',
171 dut
= TestLDSTCompUnitRegSpecMMU(pspec
)
173 # TODO: setup pagetables for MMU
175 vl
= rtlil
.convert(dut
, ports
=dut
.ports())
176 with
open("test_ldst_comp_mmu2.il", "w") as f
:
179 run_simulation(dut
, ldst_sim(dut
), vcd_name
='test_ldst_regspec.vcd')
182 if __name__
== '__main__':
183 test_scoreboard_regspec_mmu()
184 #only one test for now -- test_scoreboard_mmu()