1 from nmigen
import (C
, Module
, Signal
, Elaboratable
, Mux
, Cat
, Repl
, Signal
)
2 from nmigen
.cli
import main
3 from nmigen
.cli
import rtlil
4 from nmutil
.mask
import Mask
, masked
5 from nmutil
.util
import Display
6 from random
import randint
, seed
7 from nmigen
.sim
import Simulator
, Delay
, Settle
8 from nmutil
.util
import wrap
10 from soc
.config
.test
.test_pi2ls
import pi_ld
, pi_st
, pi_ldst
, wait_busy
11 #from soc.config.test.test_pi2ls import pi_st_debug
12 from soc
.config
.test
.test_loadstore
import TestMemPspec
13 from soc
.config
.loadstore
import ConfigMemoryPortInterface
15 from soc
.fu
.ldst
.loadstore
import LoadStore1
16 from soc
.experiment
.mmu
import MMU
17 from soc
.experiment
.test
import pagetables
19 from nmigen
.compat
.sim
import run_simulation
20 from random
import random
21 from openpower
.test
.wb_get
import wb_get
22 from openpower
.test
import wb_get
as wbget
29 pspec
= TestMemPspec(ldst_ifacetype
='mmu_cache_wb',
32 #disable_cache=True, # hmmm...
38 cmpi
= ConfigMemoryPortInterface(pspec
)
39 m
.submodules
.ldst
= ldst
= cmpi
.pi
40 m
.submodules
.mmu
= mmu
= MMU()
43 l_in
, l_out
= mmu
.l_in
, mmu
.l_out
44 d_in
, d_out
= dcache
.d_in
, dcache
.d_out
45 wb_out
, wb_in
= dcache
.wb_out
, dcache
.wb_in
47 # link mmu and dcache together
48 m
.d
.comb
+= dcache
.m_in
.eq(mmu
.d_out
) # MMUToDCacheType
49 m
.d
.comb
+= mmu
.d_in
.eq(dcache
.m_out
) # DCacheToMMUType
51 # link ldst and MMU together
52 comb
+= l_in
.eq(ldst
.m_out
)
53 comb
+= ldst
.m_in
.eq(l_out
)
58 test_exceptions
= True
63 def _test_loadstore1_invalid(dut
, mem
):
64 mmu
= dut
.submodules
.mmu
65 pi
= dut
.submodules
.ldst
.pi
68 print("=== test invalid ===")
71 ld_data
, exctype
, exc
= yield from pi_ld(pi
, addr
, 8, msr_pr
=1)
72 print("ld_data", ld_data
, exctype
, exc
)
73 assert (exctype
== "slow")
77 print("=== test invalid done ===")
82 def _test_loadstore1(dut
, mem
):
83 mmu
= dut
.submodules
.mmu
84 pi
= dut
.submodules
.ldst
.pi
85 ldst
= dut
.submodules
.ldst
# to get at DAR (NOT part of PortInterface)
88 yield mmu
.rin
.prtbl
.eq(0x1000000) # set process table
92 data
= 0xf553b658ba7e1f51
95 yield from pi_st(pi
, addr
, data
, 8, msr_pr
=1)
98 ld_data
, exctype
, exc
= yield from pi_ld(pi
, addr
, 8, msr_pr
=1)
99 assert ld_data
== 0xf553b658ba7e1f51
100 assert exctype
is None
102 ld_data
, exctype
, exc
= yield from pi_ld(pi
, addr
, 8, msr_pr
=1)
103 assert ld_data
== 0xf553b658ba7e1f51
104 assert exctype
is None
106 print("do_dcbz ===============")
107 yield from pi_st(pi
, addr
, data
, 8, msr_pr
=1, is_dcbz
=1)
108 print("done_dcbz ===============")
111 ld_data
, exctype
, exc
= yield from pi_ld(pi
, addr
, 8, msr_pr
=1)
112 print("ld_data after dcbz")
115 assert exctype
is None
118 print("=== alignment error (ld) ===")
120 ld_data
, exctype
, exc
= yield from pi_ld(pi
, addr
, 8, msr_pr
=1)
122 alignment
= exc
.alignment
123 happened
= exc
.happened
124 yield # wait for dsr to update
130 assert (happened
== 1)
131 assert (alignment
== 1)
133 assert (exctype
== "fast")
134 yield from wait_busy(pi
, debug
="pi_ld_E_alignment_error")
135 # wait is only needed in case of in exception here
136 print("=== alignment error test passed (ld) ===")
138 # take some cycles in between so that gtkwave separates out
145 print("=== alignment error (st) ===")
147 exctype
, exc
= yield from pi_st(pi
, addr
,0, 8, msr_pr
=1)
149 alignment
= exc
.alignment
150 happened
= exc
.happened
154 assert (happened
== 1)
155 assert (alignment
==1)
157 assert (exctype
== "fast")
158 #???? yield from wait_busy(pi, debug="pi_st_E_alignment_error")
159 # wait is only needed in case of in exception here
160 print("=== alignment error test passed (st) ===")
164 print("=== no alignment error (ld) ===")
166 ld_data
, exctype
, exc
= yield from pi_ld(pi
, addr
, 8, msr_pr
=1)
167 print("ld_data", ld_data
, exctype
, exc
)
169 alignment
= exc
.alignment
170 happened
= exc
.happened
174 assert (happened
== 0)
175 assert (alignment
== 0)
176 print("=== no alignment error done (ld) ===")
179 addrs
= [0x456920,0xa7a180,0x299420,0x1d9d60]
182 print("== RANDOM addr ==",hex(addr
))
183 ld_data
, exctype
, exc
= yield from pi_ld(pi
, addr
, 8, msr_pr
=1)
184 print("ld_data[RANDOM]",ld_data
,exc
,addr
)
185 assert (exctype
== None)
188 print("== RANDOM addr ==",hex(addr
))
189 exc
= yield from pi_st(pi
, addr
,0xFF*addr
, 8, msr_pr
=1)
190 assert (exctype
== None)
192 # readback written data and compare
194 print("== RANDOM addr ==",hex(addr
))
195 ld_data
, exctype
, exc
= yield from pi_ld(pi
, addr
, 8, msr_pr
=1)
196 print("ld_data[RANDOM_READBACK]",ld_data
,exc
,addr
)
197 assert (exctype
== None)
198 assert (ld_data
== 0xFF*addr
)
200 print("== RANDOM addr done ==")
205 def test_loadstore1():
207 m
, cmpi
= setup_mmu()
209 mem
= pagetables
.test1
215 sim
.add_sync_process(wrap(_test_loadstore1(m
, mem
)))
216 sim
.add_sync_process(wrap(wb_get(cmpi
.wb_bus(), mem
)))
217 with sim
.write_vcd('test_loadstore1.vcd'):
221 def test_loadstore1_invalid():
223 m
, cmpi
= setup_mmu()
231 sim
.add_sync_process(wrap(_test_loadstore1_invalid(m
, mem
)))
232 sim
.add_sync_process(wrap(wb_get(cmpi
.wb_bus(), mem
)))
233 with sim
.write_vcd('test_loadstore1_invalid.vcd'):
237 if __name__
== '__main__':
239 test_loadstore1_invalid()