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()
44 l_in
, l_out
= mmu
.l_in
, mmu
.l_out
45 d_in
, d_out
= dcache
.d_in
, dcache
.d_out
46 i_in
, i_out
= icache
.i_in
, icache
.i_out
# FetchToICache, ICacheToDecode
48 # link mmu, dcache and icache together
49 m
.d
.comb
+= dcache
.m_in
.eq(mmu
.d_out
) # MMUToDCacheType
50 m
.d
.comb
+= icache
.m_in
.eq(mmu
.i_out
) # MMUToICacheType
51 m
.d
.comb
+= mmu
.d_in
.eq(dcache
.m_out
) # DCacheToMMUType
53 # link ldst and MMU together
54 comb
+= l_in
.eq(ldst
.m_out
)
55 comb
+= ldst
.m_in
.eq(l_out
)
60 test_exceptions
= True
65 def _test_loadstore1_invalid(dut
, mem
):
66 mmu
= dut
.submodules
.mmu
67 pi
= dut
.submodules
.ldst
.pi
70 print("=== test invalid ===")
73 ld_data
, exctype
, exc
= yield from pi_ld(pi
, addr
, 8, msr_pr
=1)
74 print("ld_data", ld_data
, exctype
, exc
)
75 assert (exctype
== "slow")
79 print("=== test invalid done ===")
84 def _test_loadstore1(dut
, mem
):
85 mmu
= dut
.submodules
.mmu
86 pi
= dut
.submodules
.ldst
.pi
87 ldst
= dut
.submodules
.ldst
# to get at DAR (NOT part of PortInterface)
90 yield mmu
.rin
.prtbl
.eq(0x1000000) # set process table
94 data
= 0xf553b658ba7e1f51
97 yield from pi_st(pi
, addr
, data
, 8, msr_pr
=1)
100 ld_data
, exctype
, exc
= yield from pi_ld(pi
, addr
, 8, msr_pr
=1)
101 assert ld_data
== 0xf553b658ba7e1f51
102 assert exctype
is None
104 ld_data
, exctype
, exc
= yield from pi_ld(pi
, addr
, 8, msr_pr
=1)
105 assert ld_data
== 0xf553b658ba7e1f51
106 assert exctype
is None
108 print("do_dcbz ===============")
109 yield from pi_st(pi
, addr
, data
, 8, msr_pr
=1, is_dcbz
=1)
110 print("done_dcbz ===============")
113 ld_data
, exctype
, exc
= yield from pi_ld(pi
, addr
, 8, msr_pr
=1)
114 print("ld_data after dcbz")
117 assert exctype
is None
120 print("=== alignment error (ld) ===")
122 ld_data
, exctype
, exc
= yield from pi_ld(pi
, addr
, 8, msr_pr
=1)
124 alignment
= exc
.alignment
125 happened
= exc
.happened
126 yield # wait for dsr to update
132 assert (happened
== 1)
133 assert (alignment
== 1)
135 assert (exctype
== "fast")
136 yield from wait_busy(pi
, debug
="pi_ld_E_alignment_error")
137 # wait is only needed in case of in exception here
138 print("=== alignment error test passed (ld) ===")
140 # take some cycles in between so that gtkwave separates out
147 print("=== alignment error (st) ===")
149 exctype
, exc
= yield from pi_st(pi
, addr
,0, 8, msr_pr
=1)
151 alignment
= exc
.alignment
152 happened
= exc
.happened
156 assert (happened
== 1)
157 assert (alignment
==1)
159 assert (exctype
== "fast")
160 #???? yield from wait_busy(pi, debug="pi_st_E_alignment_error")
161 # wait is only needed in case of in exception here
162 print("=== alignment error test passed (st) ===")
166 print("=== no alignment error (ld) ===")
168 ld_data
, exctype
, exc
= yield from pi_ld(pi
, addr
, 8, msr_pr
=1)
169 print("ld_data", ld_data
, exctype
, exc
)
171 alignment
= exc
.alignment
172 happened
= exc
.happened
176 assert (happened
== 0)
177 assert (alignment
== 0)
178 print("=== no alignment error done (ld) ===")
181 addrs
= [0x456920,0xa7a180,0x299420,0x1d9d60]
184 print("== RANDOM addr ==",hex(addr
))
185 ld_data
, exctype
, exc
= yield from pi_ld(pi
, addr
, 8, msr_pr
=1)
186 print("ld_data[RANDOM]",ld_data
,exc
,addr
)
187 assert (exctype
== None)
190 print("== RANDOM addr ==",hex(addr
))
191 exc
= yield from pi_st(pi
, addr
,0xFF*addr
, 8, msr_pr
=1)
192 assert (exctype
== None)
194 # readback written data and compare
196 print("== RANDOM addr ==",hex(addr
))
197 ld_data
, exctype
, exc
= yield from pi_ld(pi
, addr
, 8, msr_pr
=1)
198 print("ld_data[RANDOM_READBACK]",ld_data
,exc
,addr
)
199 assert (exctype
== None)
200 assert (ld_data
== 0xFF*addr
)
202 print("== RANDOM addr done ==")
207 def test_loadstore1():
209 m
, cmpi
= setup_mmu()
211 mem
= pagetables
.test1
217 sim
.add_sync_process(wrap(_test_loadstore1(m
, mem
)))
218 sim
.add_sync_process(wrap(wb_get(cmpi
.wb_bus(), mem
)))
219 with sim
.write_vcd('test_loadstore1.vcd'):
223 def test_loadstore1_invalid():
225 m
, cmpi
= setup_mmu()
233 sim
.add_sync_process(wrap(_test_loadstore1_invalid(m
, mem
)))
234 sim
.add_sync_process(wrap(wb_get(cmpi
.wb_bus(), mem
)))
235 with sim
.write_vcd('test_loadstore1_invalid.vcd'):
239 if __name__
== '__main__':
241 test_loadstore1_invalid()