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
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 yield from dcbz(dut
, 4, 0, 3) # EA=7
72 ########################################
75 class TestLDSTCompUnitMMU(LDSTCompUnit
):
77 def __init__(self
, rwid
, pspec
):
78 from soc
.experiment
.l0_cache
import TstL0CacheBuffer
79 self
.l0
= l0
= TstL0CacheBuffer(pspec
)
81 LDSTCompUnit
.__init
__(self
, pi
, rwid
, 4)
83 def elaborate(self
, platform
):
84 m
= LDSTCompUnit
.elaborate(self
, platform
)
85 m
.submodules
.l0
= self
.l0
86 # link addr-go direct to rel
87 m
.d
.comb
+= self
.ad
.go_i
.eq(self
.ad
.rel_o
)
91 def test_scoreboard_mmu():
94 pspec
= TestMemPspec(ldst_ifacetype
='mmu_cache_wb',
95 imem_ifacetype
='bare_wb',
101 dut
= TestLDSTCompUnitMMU(16,pspec
)
102 vl
= rtlil
.convert(dut
, ports
=dut
.ports())
103 with
open("test_ldst_comp_mmu1.il", "w") as f
:
106 run_simulation(dut
, ldst_sim(dut
), vcd_name
='test_ldst_comp.vcd')
108 ########################################
109 class TestLDSTCompUnitRegSpecMMU(LDSTCompUnit
):
111 def __init__(self
, pspec
):
112 from soc
.experiment
.l0_cache
import TstL0CacheBuffer
113 from soc
.fu
.ldst
.pipe_data
import LDSTPipeSpec
114 regspec
= LDSTPipeSpec
.regspec
116 # use a LoadStore1 here
118 cmpi
= ConfigMemoryPortInterface(pspec
)
124 LDSTCompUnit
.__init
__(self
, ldst
.pi
, regspec
, 4)
126 def elaborate(self
, platform
):
127 m
= LDSTCompUnit
.elaborate(self
, platform
)
128 m
.submodules
.l0
= self
.l0
129 m
.submodules
.mmu
= self
.mmu
130 # link addr-go direct to rel
131 m
.d
.comb
+= self
.ad
.go_i
.eq(self
.ad
.rel_o
)
133 # link mmu and dcache together
134 dcache
= self
.l0
.dcache
136 m
.d
.comb
+= dcache
.m_in
.eq(mmu
.d_out
) # MMUToDCacheType
137 m
.d
.comb
+= mmu
.d_in
.eq(dcache
.m_out
) # DCacheToMMUType
139 # TODO: link wishbone bus
144 def test_scoreboard_regspec_mmu():
147 pspec
= TestMemPspec(ldst_ifacetype
='mmu_cache_wb',
148 imem_ifacetype
='bare_wb',
154 dut
= TestLDSTCompUnitRegSpecMMU(pspec
)
156 # TODO: setup pagetables for MMU
158 vl
= rtlil
.convert(dut
, ports
=dut
.ports())
159 with
open("test_ldst_comp_mmu2.il", "w") as f
:
162 run_simulation(dut
, ldst_sim(dut
), vcd_name
='test_ldst_regspec.vcd')
165 if __name__
== '__main__':
166 test_scoreboard_regspec_mmu()
167 #only one test for now -- test_scoreboard_mmu()