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 def wait_for_debug(sig
, event
, wait
=True, test1st
=False):
29 print("wait for", sig
, v
, wait
, test1st
)
30 if test1st
and bool(v
) == wait
:
35 yield Display("waiting for "+event
)
39 # if RA = 0 then b <- 0 RA needs to be read if RA = 0
41 # EA <- b + (RB) RB needs to be read
42 # verify that EA is correct first
43 def dcbz(dut
, ra
, zero_a
, rb
):
44 print("LD_part", ra
, zero_a
, rb
)
45 yield dut
.oper_i
.insn_type
.eq(MicrOp
.OP_DCBZ
)
46 yield dut
.src1_i
.eq(ra
)
47 yield dut
.src2_i
.eq(rb
)
48 yield dut
.oper_i
.zero_a
.eq(zero_a
)
49 yield dut
.issue_i
.eq(1)
51 yield dut
.issue_i
.eq(0)
54 # set up operand flags
56 if not zero_a
: # no zero-a means RA needs to be read
59 # wait for the operands (RA, RB, or both)
61 yield dut
.rd
.go_i
.eq(rd
)
62 yield from wait_for_debug(dut
.rd
.rel_o
,"operands (RA, RB, or both)")
63 yield dut
.rd
.go_i
.eq(0)
67 yield from dcbz(dut
, 4, 0, 3) # EA=7
70 ########################################
73 class TestLDSTCompUnitMMU(LDSTCompUnit
):
75 def __init__(self
, rwid
, pspec
):
76 from soc
.experiment
.l0_cache
import TstL0CacheBuffer
77 self
.l0
= l0
= TstL0CacheBuffer(pspec
)
79 LDSTCompUnit
.__init
__(self
, pi
, rwid
, 4)
81 def elaborate(self
, platform
):
82 m
= LDSTCompUnit
.elaborate(self
, platform
)
83 m
.submodules
.l0
= self
.l0
84 # link addr-go direct to rel
85 m
.d
.comb
+= self
.ad
.go_i
.eq(self
.ad
.rel_o
)
89 def test_scoreboard_mmu():
92 pspec
= TestMemPspec(ldst_ifacetype
='mmu_cache_wb',
93 imem_ifacetype
='bare_wb',
99 dut
= TestLDSTCompUnitMMU(16,pspec
)
100 vl
= rtlil
.convert(dut
, ports
=dut
.ports())
101 with
open("test_ldst_comp_mmu1.il", "w") as f
:
104 run_simulation(dut
, ldst_sim(dut
), vcd_name
='test_ldst_comp.vcd')
106 ########################################
107 class TestLDSTCompUnitRegSpecMMU(LDSTCompUnit
):
109 def __init__(self
, pspec
):
110 from soc
.experiment
.l0_cache
import TstL0CacheBuffer
111 from soc
.fu
.ldst
.pipe_data
import LDSTPipeSpec
112 regspec
= LDSTPipeSpec
.regspec
113 self
.l0
= l0
= TstL0CacheBuffer(pspec
) #this is wrong, see setup_mmu
116 LDSTCompUnit
.__init
__(self
, pi
, regspec
, 4)
118 def elaborate(self
, platform
):
119 m
= LDSTCompUnit
.elaborate(self
, platform
)
120 m
.submodules
.l0
= self
.l0
121 m
.submodules
.mmu
= self
.mmu
122 # link addr-go direct to rel
123 m
.d
.comb
+= self
.ad
.go_i
.eq(self
.ad
.rel_o
)
125 # link mmu and dcache together
126 dcache
= self
.l0
.pimem
.dcache
128 m
.d
.comb
+= dcache
.m_in
.eq(mmu
.d_out
) # MMUToDCacheType
129 m
.d
.comb
+= mmu
.d_in
.eq(dcache
.m_out
) # DCacheToMMUType
135 def test_scoreboard_regspec_mmu():
138 pspec
= TestMemPspec(ldst_ifacetype
='mmu_cache_wb',
139 imem_ifacetype
='bare_wb',
145 dut
= TestLDSTCompUnitRegSpecMMU(pspec
)
147 # TODO: setup pagetables for MMU
149 vl
= rtlil
.convert(dut
, ports
=dut
.ports())
150 with
open("test_ldst_comp_mmu2.il", "w") as f
:
153 run_simulation(dut
, ldst_sim(dut
), vcd_name
='test_ldst_regspec.vcd')
156 if __name__
== '__main__':
157 test_scoreboard_regspec_mmu()
158 #only one test for now -- test_scoreboard_mmu()