3 based on Anton Blanchard microwatt dcache.vhdl
7 from enum
import Enum
, unique
9 from nmigen
import Module
, Signal
, Elaboratable
, Cat
, Repl
, Array
, Const
10 from nmigen
.cli
import main
11 from nmutil
.iocontrol
import RecordObject
12 from nmutil
.util
import wrap
13 from nmigen
.utils
import log2_int
14 from nmigen
.cli
import rtlil
17 from nmigen
.back
.pysim
import Simulator
, Delay
, Settle
19 from nmigen
.sim
.cxxsim
import Simulator
, Delay
, Settle
21 from soc
.experiment
.mem_types
import (LoadStore1ToDCacheType
,
22 DCacheToLoadStore1Type
,
26 from soc
.experiment
.wb_types
import (WB_ADDR_BITS
, WB_DATA_BITS
, WB_SEL_BITS
,
27 WBAddrType
, WBDataType
, WBSelType
,
28 WBMasterOut
, WBSlaveOut
,
29 WBMasterOutVector
, WBSlaveOutVector
,
30 WBIOMasterOut
, WBIOSlaveOut
)
32 from soc
.experiment
.cache_ram
import CacheRam
33 from soc
.experiment
.plru
import PLRU
36 # TODO: make these parameters of DCache at some point
37 LINE_SIZE
= 64 # Line size in bytes
38 NUM_LINES
= 32 # Number of lines in a set
39 NUM_WAYS
= 4 # Number of ways
40 TLB_SET_SIZE
= 64 # L1 DTLB entries per set
41 TLB_NUM_WAYS
= 2 # L1 DTLB number of sets
42 TLB_LG_PGSZ
= 12 # L1 DTLB log_2(page_size)
43 LOG_LENGTH
= 0 # Non-zero to enable log data collection
45 # BRAM organisation: We never access more than
46 # -- WB_DATA_BITS at a time so to save
47 # -- resources we make the array only that wide, and
48 # -- use consecutive indices for to make a cache "line"
50 # -- ROW_SIZE is the width in bytes of the BRAM
51 # -- (based on WB, so 64-bits)
52 ROW_SIZE
= WB_DATA_BITS
// 8;
54 # ROW_PER_LINE is the number of row (wishbone
55 # transactions) in a line
56 ROW_PER_LINE
= LINE_SIZE
// ROW_SIZE
58 # BRAM_ROWS is the number of rows in BRAM needed
59 # to represent the full dcache
60 BRAM_ROWS
= NUM_LINES
* ROW_PER_LINE
63 # Bit fields counts in the address
65 # REAL_ADDR_BITS is the number of real address
69 # ROW_BITS is the number of bits to select a row
70 ROW_BITS
= log2_int(BRAM_ROWS
)
72 # ROW_LINE_BITS is the number of bits to select
74 ROW_LINE_BITS
= log2_int(ROW_PER_LINE
)
76 # LINE_OFF_BITS is the number of bits for
77 # the offset in a cache line
78 LINE_OFF_BITS
= log2_int(LINE_SIZE
)
80 # ROW_OFF_BITS is the number of bits for
82 ROW_OFF_BITS
= log2_int(ROW_SIZE
)
84 # INDEX_BITS is the number if bits to
86 INDEX_BITS
= log2_int(NUM_LINES
)
88 # SET_SIZE_BITS is the log base 2 of the set size
89 SET_SIZE_BITS
= LINE_OFF_BITS
+ INDEX_BITS
91 # TAG_BITS is the number of bits of
92 # the tag part of the address
93 TAG_BITS
= REAL_ADDR_BITS
- SET_SIZE_BITS
95 # TAG_WIDTH is the width in bits of each way of the tag RAM
96 TAG_WIDTH
= TAG_BITS
+ 7 - ((TAG_BITS
+ 7) % 8)
98 # WAY_BITS is the number of bits to select a way
99 WAY_BITS
= log2_int(NUM_WAYS
)
101 # Example of layout for 32 lines of 64 bytes:
103 # .. tag |index| line |
105 # .. | |---| | ROW_LINE_BITS (3)
106 # .. | |--- - --| LINE_OFF_BITS (6)
107 # .. | |- --| ROW_OFF_BITS (3)
108 # .. |----- ---| | ROW_BITS (8)
109 # .. |-----| | INDEX_BITS (5)
110 # .. --------| | TAG_BITS (45)
112 TAG_RAM_WIDTH
= TAG_WIDTH
* NUM_WAYS
115 return Array(Signal(TAG_RAM_WIDTH
) for x
in range(NUM_LINES
))
117 def CacheValidBitsArray():
118 return Array(Signal(INDEX_BITS
) for x
in range(NUM_LINES
))
120 def RowPerLineValidArray():
121 return Array(Signal() for x
in range(ROW_PER_LINE
))
124 TLB_SET_BITS
= log2_int(TLB_SET_SIZE
)
125 TLB_WAY_BITS
= log2_int(TLB_NUM_WAYS
)
126 TLB_EA_TAG_BITS
= 64 - (TLB_LG_PGSZ
+ TLB_SET_BITS
)
127 TLB_TAG_WAY_BITS
= TLB_NUM_WAYS
* TLB_EA_TAG_BITS
129 TLB_PTE_WAY_BITS
= TLB_NUM_WAYS
* TLB_PTE_BITS
;
131 assert (LINE_SIZE
% ROW_SIZE
) == 0, "LINE_SIZE not multiple of ROW_SIZE"
132 assert (LINE_SIZE
% 2) == 0, "LINE_SIZE not power of 2"
133 assert (NUM_LINES
% 2) == 0, "NUM_LINES not power of 2"
134 assert (ROW_PER_LINE
% 2) == 0, "ROW_PER_LINE not power of 2"
135 assert ROW_BITS
== (INDEX_BITS
+ ROW_LINE_BITS
), "geometry bits don't add up"
136 assert (LINE_OFF_BITS
== ROW_OFF_BITS
+ ROW_LINE_BITS
), \
137 "geometry bits don't add up"
138 assert REAL_ADDR_BITS
== (TAG_BITS
+ INDEX_BITS
+ LINE_OFF_BITS
), \
139 "geometry bits don't add up"
140 assert REAL_ADDR_BITS
== (TAG_BITS
+ ROW_BITS
+ ROW_OFF_BITS
), \
141 "geometry bits don't add up"
142 assert 64 == WB_DATA_BITS
, "Can't yet handle wb width that isn't 64-bits"
143 assert SET_SIZE_BITS
<= TLB_LG_PGSZ
, "Set indexed by virtual address"
146 def TLBValidBitsArray():
147 return Array(Signal(TLB_NUM_WAYS
) for x
in range(TLB_SET_SIZE
))
150 return Array(Signal(TLB_EA_TAG_BITS
) for x
in range (TLB_NUM_WAYS
))
153 return Array(Signal(TLB_TAG_WAY_BITS
) for x
in range (TLB_SET_SIZE
))
156 return Array(Signal(TLB_PTE_WAY_BITS
) for x
in range(TLB_SET_SIZE
))
159 return Array(Signal(NUM_WAYS
) for x
in range(TLB_NUM_WAYS
))
161 # Cache RAM interface
163 return Array(Signal(WB_DATA_BITS
) for x
in range(NUM_WAYS
))
165 # PLRU output interface
167 return Array(Signal(WAY_BITS
) for x
in range(NUM_LINES
))
169 # TLB PLRU output interface
171 return Array(Signal(TLB_WAY_BITS
) for x
in range(TLB_SET_SIZE
))
173 # Helper functions to decode incoming requests
175 # Return the cache line index (tag index) for an address
177 return addr
[LINE_OFF_BITS
:SET_SIZE_BITS
]
179 # Return the cache row index (data memory) for an address
181 return addr
[ROW_OFF_BITS
:SET_SIZE_BITS
]
183 # Return the index of a row within a line
184 def get_row_of_line(row
):
185 return row
[:ROW_LINE_BITS
]
187 # Returns whether this is the last row of a line
188 def is_last_row_addr(addr
, last
):
189 return addr
[ROW_OFF_BITS
:LINE_OFF_BITS
] == last
191 # Returns whether this is the last row of a line
192 def is_last_row(row
, last
):
193 return get_row_of_line(row
) == last
195 # Return the next row in the current cache line. We use a
196 # dedicated function in order to limit the size of the
197 # generated adder to be only the bits within a cache line
198 # (3 bits with default settings)
200 row_v
= row
[0:ROW_LINE_BITS
] + 1
201 return Cat(row_v
[:ROW_LINE_BITS
], row
[ROW_LINE_BITS
:])
203 # Get the tag value from the address
205 return addr
[SET_SIZE_BITS
:REAL_ADDR_BITS
]
207 # Read a tag from a tag memory row
208 def read_tag(way
, tagset
):
209 return tagset
.word_select(way
, TAG_WIDTH
)[:TAG_BITS
]
211 # Read a TLB tag from a TLB tag memory row
212 def read_tlb_tag(way
, tags
):
213 return tags
.word_select(way
, TLB_EA_TAG_BITS
)
215 # Write a TLB tag to a TLB tag memory row
216 def write_tlb_tag(way
, tags
, tag
):
217 return read_tlb_tag(way
, tags
).eq(tag
)
219 # Read a PTE from a TLB PTE memory row
220 def read_tlb_pte(way
, ptes
):
221 return ptes
.word_select(way
, TLB_PTE_BITS
)
223 def write_tlb_pte(way
, ptes
, newpte
):
224 return read_tlb_pte(way
, ptes
).eq(newpte
)
227 # Record for storing permission, attribute, etc. bits from a PTE
228 class PermAttr(RecordObject
):
231 self
.reference
= Signal()
232 self
.changed
= Signal()
233 self
.nocache
= Signal()
235 self
.rd_perm
= Signal()
236 self
.wr_perm
= Signal()
239 def extract_perm_attr(pte
):
241 pa
.reference
= pte
[8]
250 # Type of operation on a "valid" input
254 OP_BAD
= 1 # NC cache hit, TLB miss, prot/RC failure
255 OP_STCX_FAIL
= 2 # conditional store w/o reservation
256 OP_LOAD_HIT
= 3 # Cache hit on load
257 OP_LOAD_MISS
= 4 # Load missing cache
258 OP_LOAD_NC
= 5 # Non-cachable load
259 OP_STORE_HIT
= 6 # Store hitting cache
260 OP_STORE_MISS
= 7 # Store missing cache
263 # Cache state machine
266 IDLE
= 0 # Normal load hit processing
267 RELOAD_WAIT_ACK
= 1 # Cache reload wait ack
268 STORE_WAIT_ACK
= 2 # Store wait ack
269 NC_LOAD_WAIT_ACK
= 3 # Non-cachable load wait ack
274 # In order to make timing, we use the BRAMs with
275 # an output buffer, which means that the BRAM
276 # output is delayed by an extra cycle.
278 # Thus, the dcache has a 2-stage internal pipeline
279 # for cache hits with no stalls.
281 # All other operations are handled via stalling
282 # in the first stage.
284 # The second stage can thus complete a hit at the same
285 # time as the first stage emits a stall for a complex op.
287 # Stage 0 register, basically contains just the latched request
289 class RegStage0(RecordObject
):
292 self
.req
= LoadStore1ToDCacheType()
293 self
.tlbie
= Signal()
294 self
.doall
= Signal()
295 self
.tlbld
= Signal()
296 self
.mmu_req
= Signal() # indicates source of request
299 class MemAccessRequest(RecordObject
):
303 self
.valid
= Signal()
305 self
.real_addr
= Signal(REAL_ADDR_BITS
)
306 self
.data
= Signal(64)
307 self
.byte_sel
= Signal(8)
308 self
.hit_way
= Signal(WAY_BITS
)
309 self
.same_tag
= Signal()
310 self
.mmu_req
= Signal()
313 # First stage register, contains state for stage 1 of load hits
314 # and for the state machine used by all other operations
315 class RegStage1(RecordObject
):
318 # Info about the request
319 self
.full
= Signal() # have uncompleted request
320 self
.mmu_req
= Signal() # request is from MMU
321 self
.req
= MemAccessRequest()
324 self
.hit_way
= Signal(WAY_BITS
)
325 self
.hit_load_valid
= Signal()
326 self
.hit_index
= Signal(INDEX_BITS
)
327 self
.cache_hit
= Signal()
330 self
.tlb_hit
= Signal()
331 self
.tlb_hit_way
= Signal(TLB_NUM_WAYS
)
332 self
.tlb_hit_index
= Signal(TLB_WAY_BITS
)
334 # 2-stage data buffer for data forwarded from writes to reads
335 self
.forward_data1
= Signal(64)
336 self
.forward_data2
= Signal(64)
337 self
.forward_sel1
= Signal(8)
338 self
.forward_valid1
= Signal()
339 self
.forward_way1
= Signal(WAY_BITS
)
340 self
.forward_row1
= Signal(ROW_BITS
)
341 self
.use_forward1
= Signal()
342 self
.forward_sel
= Signal(8)
344 # Cache miss state (reload state machine)
345 self
.state
= Signal(State
)
347 self
.write_bram
= Signal()
348 self
.write_tag
= Signal()
349 self
.slow_valid
= Signal()
350 self
.wb
= WBMasterOut()
351 self
.reload_tag
= Signal(TAG_BITS
)
352 self
.store_way
= Signal(WAY_BITS
)
353 self
.store_row
= Signal(ROW_BITS
)
354 self
.store_index
= Signal(INDEX_BITS
)
355 self
.end_row_ix
= Signal(log2_int(ROW_LINE_BITS
, False))
356 self
.rows_valid
= RowPerLineValidArray()
357 self
.acks_pending
= Signal(3)
358 self
.inc_acks
= Signal()
359 self
.dec_acks
= Signal()
361 # Signals to complete (possibly with error)
362 self
.ls_valid
= Signal()
363 self
.ls_error
= Signal()
364 self
.mmu_done
= Signal()
365 self
.mmu_error
= Signal()
366 self
.cache_paradox
= Signal()
368 # Signal to complete a failed stcx.
369 self
.stcx_fail
= Signal()
372 # Reservation information
373 class Reservation(RecordObject
):
376 self
.valid
= Signal()
377 self
.addr
= Signal(64-LINE_OFF_BITS
)
380 class DTLBUpdate(Elaboratable
):
382 self
.tlbie
= Signal()
383 self
.tlbwe
= Signal()
384 self
.doall
= Signal()
385 self
.updated
= Signal()
386 self
.v_updated
= Signal()
387 self
.tlb_hit
= Signal()
388 self
.tlb_req_index
= Signal(TLB_SET_BITS
)
390 self
.tlb_hit_way
= Signal(TLB_WAY_BITS
)
391 self
.tlb_tag_way
= Signal(TLB_TAG_WAY_BITS
)
392 self
.tlb_pte_way
= Signal(TLB_PTE_WAY_BITS
)
393 self
.repl_way
= Signal(TLB_WAY_BITS
)
394 self
.eatag
= Signal(TLB_EA_TAG_BITS
)
395 self
.pte_data
= Signal(TLB_PTE_BITS
)
397 self
.dv
= Signal(TLB_PTE_WAY_BITS
)
399 self
.tb_out
= Signal(TLB_TAG_WAY_BITS
)
400 self
.pb_out
= Signal(TLB_NUM_WAYS
)
401 self
.db_out
= Signal(TLB_PTE_WAY_BITS
)
403 def elaborate(self
, platform
):
408 tagset
= Signal(TLB_TAG_WAY_BITS
)
409 pteset
= Signal(TLB_PTE_WAY_BITS
)
411 tb_out
, pb_out
, db_out
= self
.tb_out
, self
.pb_out
, self
.db_out
413 with m
.If(self
.tlbie
& self
.doall
):
414 pass # clear all back in parent
415 with m
.Elif(self
.tlbie
):
416 with m
.If(self
.tlb_hit
):
417 comb
+= db_out
.eq(self
.dv
)
418 comb
+= db_out
.bit_select(self
.tlb_hit_way
, 1).eq(1)
419 comb
+= self
.v_updated
.eq(1)
421 with m
.Elif(self
.tlbwe
):
423 comb
+= tagset
.eq(self
.tlb_tag_way
)
424 comb
+= write_tlb_tag(self
.repl_way
, tagset
, self
.eatag
)
425 comb
+= tb_out
.eq(tagset
)
427 comb
+= pteset
.eq(self
.tlb_pte_way
)
428 comb
+= write_tlb_pte(self
.repl_way
, pteset
, self
.pte_data
)
429 comb
+= pb_out
.eq(pteset
)
431 comb
+= db_out
.bit_select(self
.repl_way
, 1).eq(1)
433 comb
+= self
.updated
.eq(1)
434 comb
+= self
.v_updated
.eq(1)
438 def dcache_request(self
, m
, r0
, ra
, req_index
, req_row
, req_tag
,
439 r0_valid
, r1
, cache_valid_bits
, replace_way
,
440 use_forward1_next
, use_forward2_next
,
441 req_hit_way
, plru_victim
, rc_ok
, perm_attr
,
442 valid_ra
, perm_ok
, access_ok
, req_op
, req_go
,
444 tlb_hit
, tlb_hit_way
, tlb_valid_way
, cache_tag_set
,
445 cancel_store
, req_same_tag
, r0_stall
, early_req_row
):
446 """Cache request parsing and hit detection
449 class DCachePendingHit(Elaboratable
):
451 def __init__(self
, tlb_pte_way
, tlb_valid_way
, tlb_hit_way
,
452 cache_valid_idx
, cache_tag_set
,
457 self
.virt_mode
= Signal()
458 self
.is_hit
= Signal()
459 self
.tlb_hit
= Signal()
460 self
.hit_way
= Signal(WAY_BITS
)
461 self
.rel_match
= Signal()
462 self
.req_index
= Signal(INDEX_BITS
)
463 self
.reload_tag
= Signal(TAG_BITS
)
465 self
.tlb_hit_way
= tlb_hit_way
466 self
.tlb_pte_way
= tlb_pte_way
467 self
.tlb_valid_way
= tlb_valid_way
468 self
.cache_valid_idx
= cache_valid_idx
469 self
.cache_tag_set
= cache_tag_set
470 self
.req_addr
= req_addr
471 self
.hit_set
= hit_set
473 def elaborate(self
, platform
):
479 virt_mode
= self
.virt_mode
481 tlb_pte_way
= self
.tlb_pte_way
482 tlb_valid_way
= self
.tlb_valid_way
483 cache_valid_idx
= self
.cache_valid_idx
484 cache_tag_set
= self
.cache_tag_set
485 req_addr
= self
.req_addr
486 tlb_hit_way
= self
.tlb_hit_way
487 tlb_hit
= self
.tlb_hit
488 hit_set
= self
.hit_set
489 hit_way
= self
.hit_way
490 rel_match
= self
.rel_match
491 req_index
= self
.req_index
492 reload_tag
= self
.reload_tag
494 rel_matches
= Array(Signal() for i
in range(TLB_NUM_WAYS
))
495 hit_way_set
= HitWaySet()
497 # Test if pending request is a hit on any way
498 # In order to make timing in virtual mode,
499 # when we are using the TLB, we compare each
500 # way with each of the real addresses from each way of
501 # the TLB, and then decide later which match to use.
503 with m
.If(virt_mode
):
504 for j
in range(TLB_NUM_WAYS
):
505 s_tag
= Signal(TAG_BITS
, name
="s_tag%d" % j
)
507 s_pte
= Signal(TLB_PTE_BITS
)
508 s_ra
= Signal(REAL_ADDR_BITS
)
509 comb
+= s_pte
.eq(read_tlb_pte(j
, tlb_pte_way
))
510 comb
+= s_ra
.eq(Cat(req_addr
[0:TLB_LG_PGSZ
],
511 s_pte
[TLB_LG_PGSZ
:REAL_ADDR_BITS
]))
512 comb
+= s_tag
.eq(get_tag(s_ra
))
514 for i
in range(NUM_WAYS
):
515 is_tag_hit
= Signal()
516 comb
+= is_tag_hit
.eq(go
& cache_valid_idx
[i
] &
517 (read_tag(i
, cache_tag_set
) == s_tag
)
519 with m
.If(is_tag_hit
):
520 comb
+= hit_way_set
[j
].eq(i
)
522 comb
+= hit_set
[j
].eq(s_hit
)
523 with m
.If(s_tag
== reload_tag
):
524 comb
+= rel_matches
[j
].eq(1)
526 comb
+= is_hit
.eq(hit_set
[tlb_hit_way
])
527 comb
+= hit_way
.eq(hit_way_set
[tlb_hit_way
])
528 comb
+= rel_match
.eq(rel_matches
[tlb_hit_way
])
530 s_tag
= Signal(TAG_BITS
)
531 comb
+= s_tag
.eq(get_tag(req_addr
))
532 for i
in range(NUM_WAYS
):
533 is_tag_hit
= Signal()
534 comb
+= is_tag_hit
.eq(go
& cache_valid_idx
[i
] &
535 read_tag(i
, cache_tag_set
) == s_tag
)
536 with m
.If(is_tag_hit
):
537 comb
+= hit_way
.eq(i
)
539 with m
.If(s_tag
== reload_tag
):
540 comb
+= rel_match
.eq(1)
545 class DCache(Elaboratable
):
546 """Set associative dcache write-through
547 TODO (in no specific order):
548 * See list in icache.vhdl
549 * Complete load misses on the cycle when WB data comes instead of
550 at the end of line (this requires dealing with requests coming in
554 self
.d_in
= LoadStore1ToDCacheType("d_in")
555 self
.d_out
= DCacheToLoadStore1Type("d_out")
557 self
.m_in
= MMUToDCacheType()
558 self
.m_out
= DCacheToMMUType()
560 self
.stall_out
= Signal()
562 self
.wb_out
= WBMasterOut()
563 self
.wb_in
= WBSlaveOut()
565 self
.log_out
= Signal(20)
567 def stage_0(self
, m
, r0
, r1
, r0_full
):
568 """Latch the request in r0.req as long as we're not stalling
572 d_in
, d_out
, m_in
= self
.d_in
, self
.d_out
, self
.m_in
576 # TODO, this goes in unit tests and formal proofs
577 with m
.If(~
(d_in
.valid
& m_in
.valid
)):
578 #sync += Display("request collision loadstore vs MMU")
581 with m
.If(m_in
.valid
):
582 sync
+= r
.req
.valid
.eq(1)
583 sync
+= r
.req
.load
.eq(~
(m_in
.tlbie | m_in
.tlbld
))
584 sync
+= r
.req
.dcbz
.eq(0)
585 sync
+= r
.req
.nc
.eq(0)
586 sync
+= r
.req
.reserve
.eq(0)
587 sync
+= r
.req
.virt_mode
.eq(1)
588 sync
+= r
.req
.priv_mode
.eq(1)
589 sync
+= r
.req
.addr
.eq(m_in
.addr
)
590 sync
+= r
.req
.data
.eq(m_in
.pte
)
591 sync
+= r
.req
.byte_sel
.eq(~
0) # Const -1 sets all to 0b111....
592 sync
+= r
.tlbie
.eq(m_in
.tlbie
)
593 sync
+= r
.doall
.eq(m_in
.doall
)
594 sync
+= r
.tlbld
.eq(m_in
.tlbld
)
595 sync
+= r
.mmu_req
.eq(1)
597 sync
+= r
.req
.eq(d_in
)
598 sync
+= r
.tlbie
.eq(0)
599 sync
+= r
.doall
.eq(0)
600 sync
+= r
.tlbld
.eq(0)
601 sync
+= r
.mmu_req
.eq(0)
602 with m
.If(~
(r1
.full
& r0_full
)):
604 sync
+= r0_full
.eq(r
.req
.valid
)
606 def tlb_read(self
, m
, r0_stall
, tlb_valid_way
,
607 tlb_tag_way
, tlb_pte_way
, dtlb_valid_bits
,
608 dtlb_tags
, dtlb_ptes
):
610 Operates in the second cycle on the request latched in r0.req.
611 TLB updates write the entry at the end of the second cycle.
615 m_in
, d_in
= self
.m_in
, self
.d_in
617 index
= Signal(TLB_SET_BITS
)
618 addrbits
= Signal(TLB_SET_BITS
)
621 amax
= TLB_LG_PGSZ
+ TLB_SET_BITS
623 with m
.If(m_in
.valid
):
624 comb
+= addrbits
.eq(m_in
.addr
[amin
: amax
])
626 comb
+= addrbits
.eq(d_in
.addr
[amin
: amax
])
627 comb
+= index
.eq(addrbits
)
629 # If we have any op and the previous op isn't finished,
630 # then keep the same output for next cycle.
631 with m
.If(~r0_stall
):
632 sync
+= tlb_valid_way
.eq(dtlb_valid_bits
[index
])
633 sync
+= tlb_tag_way
.eq(dtlb_tags
[index
])
634 sync
+= tlb_pte_way
.eq(dtlb_ptes
[index
])
636 def maybe_tlb_plrus(self
, m
, r1
, tlb_plru_victim
):
637 """Generate TLB PLRUs
642 if TLB_NUM_WAYS
== 0:
644 for i
in range(TLB_SET_SIZE
):
646 tlb_plru
= PLRU(WAY_BITS
)
647 setattr(m
.submodules
, "maybe_plru_%d" % i
, tlb_plru
)
648 tlb_plru_acc_en
= Signal()
650 comb
+= tlb_plru_acc_en
.eq(r1
.tlb_hit
& (r1
.tlb_hit_index
== i
))
651 comb
+= tlb_plru
.acc_en
.eq(tlb_plru_acc_en
)
652 comb
+= tlb_plru
.acc
.eq(r1
.tlb_hit_way
)
653 comb
+= tlb_plru_victim
[i
].eq(tlb_plru
.lru_o
)
655 def tlb_search(self
, m
, tlb_req_index
, r0
, r0_valid
,
656 tlb_valid_way
, tlb_tag_way
, tlb_hit_way
,
657 tlb_pte_way
, pte
, tlb_hit
, valid_ra
, perm_attr
, ra
):
662 hitway
= Signal(TLB_WAY_BITS
)
664 eatag
= Signal(TLB_EA_TAG_BITS
)
666 TLB_LG_END
= TLB_LG_PGSZ
+ TLB_SET_BITS
667 comb
+= tlb_req_index
.eq(r0
.req
.addr
[TLB_LG_PGSZ
: TLB_LG_END
])
668 comb
+= eatag
.eq(r0
.req
.addr
[TLB_LG_END
: 64 ])
670 for i
in range(TLB_NUM_WAYS
):
671 is_tag_hit
= Signal()
672 comb
+= is_tag_hit
.eq(tlb_valid_way
[i
]
673 & read_tlb_tag(i
, tlb_tag_way
) == eatag
)
674 with m
.If(is_tag_hit
):
678 comb
+= tlb_hit
.eq(hit
& r0_valid
)
679 comb
+= tlb_hit_way
.eq(hitway
)
682 comb
+= pte
.eq(read_tlb_pte(hitway
, tlb_pte_way
))
685 comb
+= valid_ra
.eq(tlb_hit | ~r0
.req
.virt_mode
)
686 with m
.If(r0
.req
.virt_mode
):
687 comb
+= ra
.eq(Cat(Const(0, ROW_OFF_BITS
),
688 r0
.req
.addr
[ROW_OFF_BITS
:TLB_LG_PGSZ
],
689 pte
[TLB_LG_PGSZ
:REAL_ADDR_BITS
]))
690 comb
+= perm_attr
.eq(extract_perm_attr(pte
))
692 comb
+= ra
.eq(Cat(Const(0, ROW_OFF_BITS
),
693 r0
.req
.addr
[ROW_OFF_BITS
:REAL_ADDR_BITS
]))
695 comb
+= perm_attr
.reference
.eq(1)
696 comb
+= perm_attr
.changed
.eq(1)
697 comb
+= perm_attr
.priv
.eq(1)
698 comb
+= perm_attr
.nocache
.eq(0)
699 comb
+= perm_attr
.rd_perm
.eq(1)
700 comb
+= perm_attr
.wr_perm
.eq(1)
702 def tlb_update(self
, m
, r0_valid
, r0
, dtlb_valid_bits
, tlb_req_index
,
703 tlb_hit_way
, tlb_hit
, tlb_plru_victim
, tlb_tag_way
,
704 dtlb_tags
, tlb_pte_way
, dtlb_ptes
):
712 comb
+= tlbie
.eq(r0_valid
& r0
.tlbie
)
713 comb
+= tlbwe
.eq(r0_valid
& r0
.tlbld
)
715 m
.submodules
.tlb_update
= d
= DTLBUpdate()
716 with m
.If(tlbie
& r0
.doall
):
717 # clear all valid bits at once
718 for i
in range(TLB_SET_SIZE
):
719 sync
+= dtlb_valid_bits
[i
].eq(0)
720 with m
.If(d
.updated
):
721 sync
+= dtlb_tags
[tlb_req_index
].eq(d
.tb_out
)
722 sync
+= dtlb_ptes
[tlb_req_index
].eq(d
.pb_out
)
723 with m
.If(d
.v_updated
):
724 sync
+= dtlb_valid_bits
[tlb_req_index
].eq(d
.db_out
)
726 comb
+= d
.dv
.eq(dtlb_valid_bits
[tlb_req_index
])
728 comb
+= d
.tlbie
.eq(tlbie
)
729 comb
+= d
.tlbwe
.eq(tlbwe
)
730 comb
+= d
.doall
.eq(r0
.doall
)
731 comb
+= d
.tlb_hit
.eq(tlb_hit
)
732 comb
+= d
.tlb_hit_way
.eq(tlb_hit_way
)
733 comb
+= d
.tlb_tag_way
.eq(tlb_tag_way
)
734 comb
+= d
.tlb_pte_way
.eq(tlb_pte_way
)
735 comb
+= d
.tlb_req_index
.eq(tlb_req_index
)
738 comb
+= d
.repl_way
.eq(tlb_hit_way
)
740 comb
+= d
.repl_way
.eq(tlb_plru_victim
[tlb_req_index
])
741 comb
+= d
.eatag
.eq(r0
.req
.addr
[TLB_LG_PGSZ
+ TLB_SET_BITS
:64])
742 comb
+= d
.pte_data
.eq(r0
.req
.data
)
744 def maybe_plrus(self
, m
, r1
, plru_victim
):
750 if TLB_NUM_WAYS
== 0:
753 for i
in range(NUM_LINES
):
755 plru
= PLRU(WAY_BITS
)
756 setattr(m
.submodules
, "plru%d" % i
, plru
)
757 plru_acc_en
= Signal()
759 comb
+= plru_acc_en
.eq(r1
.cache_hit
& (r1
.hit_index
== i
))
760 comb
+= plru
.acc_en
.eq(plru_acc_en
)
761 comb
+= plru
.acc
.eq(r1
.hit_way
)
762 comb
+= plru_victim
[i
].eq(plru
.lru_o
)
764 def cache_tag_read(self
, m
, r0_stall
, req_index
, cache_tag_set
, cache_tags
):
765 """Cache tag RAM read port
769 m_in
, d_in
= self
.m_in
, self
.d_in
771 index
= Signal(INDEX_BITS
)
774 comb
+= index
.eq(req_index
)
775 with m
.Elif(m_in
.valid
):
776 comb
+= index
.eq(get_index(m_in
.addr
))
778 comb
+= index
.eq(get_index(d_in
.addr
))
779 sync
+= cache_tag_set
.eq(cache_tags
[index
])
781 def dcache_request(self
, m
, r0
, ra
, req_index
, req_row
, req_tag
,
782 r0_valid
, r1
, cache_valid_bits
, replace_way
,
783 use_forward1_next
, use_forward2_next
,
784 req_hit_way
, plru_victim
, rc_ok
, perm_attr
,
785 valid_ra
, perm_ok
, access_ok
, req_op
, req_go
,
787 tlb_hit
, tlb_hit_way
, tlb_valid_way
, cache_tag_set
,
788 cancel_store
, req_same_tag
, r0_stall
, early_req_row
):
789 """Cache request parsing and hit detection
794 m_in
, d_in
= self
.m_in
, self
.d_in
797 hit_way
= Signal(WAY_BITS
)
802 hit_set
= Array(Signal() for i
in range(TLB_NUM_WAYS
))
803 cache_valid_idx
= Signal(INDEX_BITS
)
805 # Extract line, row and tag from request
806 comb
+= req_index
.eq(get_index(r0
.req
.addr
))
807 comb
+= req_row
.eq(get_row(r0
.req
.addr
))
808 comb
+= req_tag
.eq(get_tag(ra
))
810 comb
+= go
.eq(r0_valid
& ~
(r0
.tlbie | r0
.tlbld
) & ~r1
.ls_error
)
811 comb
+= cache_valid_idx
.eq(cache_valid_bits
[req_index
])
813 m
.submodules
.dcache_pend
= dc
= DCachePendingHit(tlb_pte_way
,
814 tlb_valid_way
, tlb_hit_way
,
815 cache_valid_idx
, cache_tag_set
,
819 comb
+= dc
.tlb_hit
.eq(tlb_hit
)
820 comb
+= dc
.reload_tag
.eq(r1
.reload_tag
)
821 comb
+= dc
.virt_mode
.eq(r0
.req
.virt_mode
)
823 comb
+= dc
.req_index
.eq(req_index
)
824 comb
+= is_hit
.eq(dc
.is_hit
)
825 comb
+= hit_way
.eq(dc
.hit_way
)
826 comb
+= req_same_tag
.eq(dc
.rel_match
)
828 # See if the request matches the line currently being reloaded
829 with m
.If((r1
.state
== State
.RELOAD_WAIT_ACK
) &
830 (req_index
== r1
.store_index
) & req_same_tag
):
831 # For a store, consider this a hit even if the row isn't
832 # valid since it will be by the time we perform the store.
833 # For a load, check the appropriate row valid bit.
834 valid
= r1
.rows_valid
[req_row
% ROW_PER_LINE
]
835 comb
+= is_hit
.eq(~r0
.req
.load | valid
)
836 comb
+= hit_way
.eq(replace_way
)
838 # Whether to use forwarded data for a load or not
839 comb
+= use_forward1_next
.eq(0)
840 with m
.If((get_row(r1
.req
.real_addr
) == req_row
) &
841 (r1
.req
.hit_way
== hit_way
)):
842 # Only need to consider r1.write_bram here, since if we
843 # are writing refill data here, then we don't have a
844 # cache hit this cycle on the line being refilled.
845 # (There is the possibility that the load following the
846 # load miss that started the refill could be to the old
847 # contents of the victim line, since it is a couple of
848 # cycles after the refill starts before we see the updated
849 # cache tag. In that case we don't use the bypass.)
850 comb
+= use_forward1_next
.eq(r1
.write_bram
)
851 comb
+= use_forward2_next
.eq(0)
852 with m
.If((r1
.forward_row1
== req_row
) & (r1
.forward_way1
== hit_way
)):
853 comb
+= use_forward2_next
.eq(r1
.forward_valid1
)
855 # The way that matched on a hit
856 comb
+= req_hit_way
.eq(hit_way
)
858 # The way to replace on a miss
859 with m
.If(r1
.write_tag
):
860 comb
+= replace_way
.eq(plru_victim
[r1
.store_index
])
862 comb
+= replace_way
.eq(r1
.store_way
)
864 # work out whether we have permission for this access
865 # NB we don't yet implement AMR, thus no KUAP
866 comb
+= rc_ok
.eq(perm_attr
.reference
867 & (r0
.req
.load | perm_attr
.changed
)
869 comb
+= perm_ok
.eq((r0
.req
.priv_mode | ~perm_attr
.priv
)
871 |
(r0
.req
.load
& perm_attr
.rd_perm
)
873 comb
+= access_ok
.eq(valid_ra
& perm_ok
& rc_ok
)
874 # Combine the request and cache hit status to decide what
875 # operation needs to be done
876 comb
+= nc
.eq(r0
.req
.nc | perm_attr
.nocache
)
877 comb
+= op
.eq(Op
.OP_NONE
)
879 with m
.If(~access_ok
):
880 comb
+= op
.eq(Op
.OP_BAD
)
881 with m
.Elif(cancel_store
):
882 comb
+= op
.eq(Op
.OP_STCX_FAIL
)
884 comb
+= opsel
.eq(Cat(is_hit
, nc
, r0
.req
.load
))
885 with m
.Switch(opsel
):
887 comb
+= op
.eq(Op
.OP_LOAD_HIT
)
889 comb
+= op
.eq(Op
.OP_LOAD_MISS
)
891 comb
+= op
.eq(Op
.OP_LOAD_NC
)
893 comb
+= op
.eq(Op
.OP_STORE_HIT
)
895 comb
+= op
.eq(Op
.OP_STORE_MISS
)
897 comb
+= op
.eq(Op
.OP_STORE_MISS
)
899 comb
+= op
.eq(Op
.OP_BAD
)
901 comb
+= op
.eq(Op
.OP_BAD
)
903 comb
+= op
.eq(Op
.OP_NONE
)
904 comb
+= req_op
.eq(op
)
905 comb
+= req_go
.eq(go
)
907 # Version of the row number that is valid one cycle earlier
908 # in the cases where we need to read the cache data BRAM.
909 # If we're stalling then we need to keep reading the last
911 with m
.If(~r0_stall
):
912 with m
.If(m_in
.valid
):
913 comb
+= early_req_row
.eq(get_row(m_in
.addr
))
915 comb
+= early_req_row
.eq(get_row(d_in
.addr
))
917 comb
+= early_req_row
.eq(req_row
)
919 def reservation_comb(self
, m
, cancel_store
, set_rsrv
, clear_rsrv
,
920 r0_valid
, r0
, reservation
):
921 """Handle load-with-reservation and store-conditional instructions
926 with m
.If(r0_valid
& r0
.req
.reserve
):
928 # XXX generate alignment interrupt if address
929 # is not aligned XXX or if r0.req.nc = '1'
930 with m
.If(r0
.req
.load
):
931 comb
+= set_rsrv
.eq(1) # load with reservation
933 comb
+= clear_rsrv
.eq(1) # store conditional
934 with m
.If(~reservation
.valid | r0
.req
.addr
[LINE_OFF_BITS
:64]):
935 comb
+= cancel_store
.eq(1)
937 def reservation_reg(self
, m
, r0_valid
, access_ok
, set_rsrv
, clear_rsrv
,
943 with m
.If(r0_valid
& access_ok
):
944 with m
.If(clear_rsrv
):
945 sync
+= reservation
.valid
.eq(0)
946 with m
.Elif(set_rsrv
):
947 sync
+= reservation
.valid
.eq(1)
948 sync
+= reservation
.addr
.eq(r0
.req
.addr
[LINE_OFF_BITS
:64])
950 def writeback_control(self
, m
, r1
, cache_out
):
951 """Return data for loads & completion control logic
955 d_out
, m_out
= self
.d_out
, self
.m_out
957 data_out
= Signal(64)
958 data_fwd
= Signal(64)
960 # Use the bypass if are reading the row that was
961 # written 1 or 2 cycles ago, including for the
962 # slow_valid = 1 case (i.e. completing a load
963 # miss or a non-cacheable load).
964 with m
.If(r1
.use_forward1
):
965 comb
+= data_fwd
.eq(r1
.forward_data1
)
967 comb
+= data_fwd
.eq(r1
.forward_data2
)
969 comb
+= data_out
.eq(cache_out
[r1
.hit_way
])
972 with m
.If(r1
.forward_sel
[i
]):
973 dsel
= data_fwd
.word_select(i
, 8)
974 comb
+= data_out
.word_select(i
, 8).eq(dsel
)
976 comb
+= d_out
.valid
.eq(r1
.ls_valid
)
977 comb
+= d_out
.data
.eq(data_out
)
978 comb
+= d_out
.store_done
.eq(~r1
.stcx_fail
)
979 comb
+= d_out
.error
.eq(r1
.ls_error
)
980 comb
+= d_out
.cache_paradox
.eq(r1
.cache_paradox
)
983 comb
+= m_out
.done
.eq(r1
.mmu_done
)
984 comb
+= m_out
.err
.eq(r1
.mmu_error
)
985 comb
+= m_out
.data
.eq(data_out
)
987 # We have a valid load or store hit or we just completed
988 # a slow op such as a load miss, a NC load or a store
990 # Note: the load hit is delayed by one cycle. However it
991 # can still not collide with r.slow_valid (well unless I
992 # miscalculated) because slow_valid can only be set on a
993 # subsequent request and not on its first cycle (the state
994 # machine must have advanced), which makes slow_valid
995 # at least 2 cycles from the previous hit_load_valid.
997 # Sanity: Only one of these must be set in any given cycle
999 if False: # TODO: need Display to get this to work
1000 assert (r1
.slow_valid
& r1
.stcx_fail
) != 1, \
1001 "unexpected slow_valid collision with stcx_fail"
1003 assert ((r1
.slow_valid | r1
.stcx_fail
) | r1
.hit_load_valid
) != 1, \
1004 "unexpected hit_load_delayed collision with slow_valid"
1006 with m
.If(~r1
.mmu_req
):
1007 # Request came from loadstore1...
1008 # Load hit case is the standard path
1009 with m
.If(r1
.hit_load_valid
):
1010 #Display(f"completing load hit data={data_out}")
1013 # error cases complete without stalling
1014 with m
.If(r1
.ls_error
):
1015 # Display("completing ld/st with error")
1018 # Slow ops (load miss, NC, stores)
1019 with m
.If(r1
.slow_valid
):
1020 #Display(f"completing store or load miss data={data_out}")
1024 # Request came from MMU
1025 with m
.If(r1
.hit_load_valid
):
1026 # Display(f"completing load hit to MMU, data={m_out.data}")
1028 # error cases complete without stalling
1029 with m
.If(r1
.mmu_error
):
1030 #Display("combpleting MMU ld with error")
1033 # Slow ops (i.e. load miss)
1034 with m
.If(r1
.slow_valid
):
1035 #Display("completing MMU load miss, data={m_out.data}")
1038 def rams(self
, m
, r1
, early_req_row
, cache_out
, replace_way
):
1040 Generate a cache RAM for each way. This handles the normal
1041 reads, writes from reloads and the special store-hit update
1044 Note: the BRAMs have an extra read buffer, meaning the output
1045 is pipelined an extra cycle. This differs from the
1046 icache. The writeback logic needs to take that into
1047 account by using 1-cycle delayed signals for load hits.
1052 for i
in range(NUM_WAYS
):
1054 rd_addr
= Signal(ROW_BITS
)
1056 wr_addr
= Signal(ROW_BITS
)
1057 wr_data
= Signal(WB_DATA_BITS
)
1058 wr_sel
= Signal(ROW_SIZE
)
1059 wr_sel_m
= Signal(ROW_SIZE
)
1060 _d_out
= Signal(WB_DATA_BITS
)
1062 way
= CacheRam(ROW_BITS
, WB_DATA_BITS
, True)
1063 setattr(m
.submodules
, "cacheram_%d" % i
, way
)
1065 comb
+= way
.rd_en
.eq(do_read
)
1066 comb
+= way
.rd_addr
.eq(rd_addr
)
1067 comb
+= _d_out
.eq(way
.rd_data_o
)
1068 comb
+= way
.wr_sel
.eq(wr_sel_m
)
1069 comb
+= way
.wr_addr
.eq(wr_addr
)
1070 comb
+= way
.wr_data
.eq(wr_data
)
1073 comb
+= do_read
.eq(1)
1074 comb
+= rd_addr
.eq(early_req_row
)
1075 comb
+= cache_out
[i
].eq(_d_out
)
1079 # Defaults to wishbone read responses (cache refill)
1081 # For timing, the mux on wr_data/sel/addr is not
1082 # dependent on anything other than the current state.
1084 with m
.If(r1
.write_bram
):
1085 # Write store data to BRAM. This happens one
1086 # cycle after the store is in r0.
1087 comb
+= wr_data
.eq(r1
.req
.data
)
1088 comb
+= wr_sel
.eq(r1
.req
.byte_sel
)
1089 comb
+= wr_addr
.eq(get_row(r1
.req
.real_addr
))
1091 with m
.If(i
== r1
.req
.hit_way
):
1092 comb
+= do_write
.eq(1)
1094 # Otherwise, we might be doing a reload or a DCBZ
1096 comb
+= wr_data
.eq(0)
1098 comb
+= wr_data
.eq(wb_in
.dat
)
1099 comb
+= wr_addr
.eq(r1
.store_row
)
1100 comb
+= wr_sel
.eq(~
0) # all 1s
1102 with m
.If((r1
.state
== State
.RELOAD_WAIT_ACK
)
1103 & wb_in
.ack
& (replace_way
== i
)):
1104 comb
+= do_write
.eq(1)
1106 # Mask write selects with do_write since BRAM
1107 # doesn't have a global write-enable
1108 with m
.If(do_write
):
1109 comb
+= wr_sel_m
.eq(wr_sel
)
1111 # Cache hit synchronous machine for the easy case.
1112 # This handles load hits.
1113 # It also handles error cases (TLB miss, cache paradox)
1114 def dcache_fast_hit(self
, m
, req_op
, r0_valid
, r0
, r1
,
1115 req_hit_way
, req_index
, access_ok
,
1116 tlb_hit
, tlb_hit_way
, tlb_req_index
):
1121 with m
.If(req_op
!= Op
.OP_NONE
):
1122 #Display(f"op:{req_op} addr:{r0.req.addr} nc: {r0.req.nc}" \
1123 # f"idx:{req_index} tag:{req_tag} way: {req_hit_way}"
1127 with m
.If(r0_valid
):
1128 sync
+= r1
.mmu_req
.eq(r0
.mmu_req
)
1130 # Fast path for load/store hits.
1131 # Set signals for the writeback controls.
1132 sync
+= r1
.hit_way
.eq(req_hit_way
)
1133 sync
+= r1
.hit_index
.eq(req_index
)
1135 with m
.If(req_op
== Op
.OP_LOAD_HIT
):
1136 sync
+= r1
.hit_load_valid
.eq(1)
1138 sync
+= r1
.hit_load_valid
.eq(0)
1140 with m
.If((req_op
== Op
.OP_LOAD_HIT
) |
(req_op
== Op
.OP_STORE_HIT
)):
1141 sync
+= r1
.cache_hit
.eq(1)
1143 sync
+= r1
.cache_hit
.eq(0)
1145 with m
.If(req_op
== Op
.OP_BAD
):
1146 # Display(f"Signalling ld/st error valid_ra={valid_ra}"
1147 # f"rc_ok={rc_ok} perm_ok={perm_ok}"
1148 sync
+= r1
.ls_error
.eq(~r0
.mmu_req
)
1149 sync
+= r1
.mmu_error
.eq(r0
.mmu_req
)
1150 sync
+= r1
.cache_paradox
.eq(access_ok
)
1153 sync
+= r1
.ls_error
.eq(0)
1154 sync
+= r1
.mmu_error
.eq(0)
1155 sync
+= r1
.cache_paradox
.eq(0)
1157 with m
.If(req_op
== Op
.OP_STCX_FAIL
):
1160 sync
+= r1
.stcx_fail
.eq(0)
1162 # Record TLB hit information for updating TLB PLRU
1163 sync
+= r1
.tlb_hit
.eq(tlb_hit
)
1164 sync
+= r1
.tlb_hit_way
.eq(tlb_hit_way
)
1165 sync
+= r1
.tlb_hit_index
.eq(tlb_req_index
)
1167 # Memory accesses are handled by this state machine:
1169 # * Cache load miss/reload (in conjunction with "rams")
1170 # * Load hits for non-cachable forms
1171 # * Stores (the collision case is handled in "rams")
1173 # All wishbone requests generation is done here.
1174 # This machine operates at stage 1.
1175 def dcache_slow(self
, m
, r1
, use_forward1_next
, use_forward2_next
,
1176 cache_valid_bits
, r0
, replace_way
,
1177 req_hit_way
, req_same_tag
,
1178 r0_valid
, req_op
, cache_tag
, req_go
, ra
):
1184 req
= MemAccessRequest()
1186 adjust_acks
= Signal(3)
1187 stbs_done
= Signal()
1189 sync
+= r1
.use_forward1
.eq(use_forward1_next
)
1190 sync
+= r1
.forward_sel
.eq(0)
1192 with m
.If(use_forward1_next
):
1193 sync
+= r1
.forward_sel
.eq(r1
.req
.byte_sel
)
1194 with m
.Elif(use_forward2_next
):
1195 sync
+= r1
.forward_sel
.eq(r1
.forward_sel1
)
1197 sync
+= r1
.forward_data2
.eq(r1
.forward_data1
)
1198 with m
.If(r1
.write_bram
):
1199 sync
+= r1
.forward_data1
.eq(r1
.req
.data
)
1200 sync
+= r1
.forward_sel1
.eq(r1
.req
.byte_sel
)
1201 sync
+= r1
.forward_way1
.eq(r1
.req
.hit_way
)
1202 sync
+= r1
.forward_row1
.eq(get_row(r1
.req
.real_addr
))
1203 sync
+= r1
.forward_valid1
.eq(1)
1206 sync
+= r1
.forward_data1
.eq(0)
1208 sync
+= r1
.forward_data1
.eq(wb_in
.dat
)
1209 sync
+= r1
.forward_sel1
.eq(~
0) # all 1s
1210 sync
+= r1
.forward_way1
.eq(replace_way
)
1211 sync
+= r1
.forward_row1
.eq(r1
.store_row
)
1212 sync
+= r1
.forward_valid1
.eq(0)
1214 # One cycle pulses reset
1215 sync
+= r1
.slow_valid
.eq(0)
1216 sync
+= r1
.write_bram
.eq(0)
1217 sync
+= r1
.inc_acks
.eq(0)
1218 sync
+= r1
.dec_acks
.eq(0)
1220 sync
+= r1
.ls_valid
.eq(0)
1221 # complete tlbies and TLB loads in the third cycle
1222 sync
+= r1
.mmu_done
.eq(r0_valid
& (r0
.tlbie | r0
.tlbld
))
1224 with m
.If((req_op
== Op
.OP_LOAD_HIT
)
1225 |
(req_op
== Op
.OP_STCX_FAIL
)):
1226 with m
.If(~r0
.mmu_req
):
1227 sync
+= r1
.ls_valid
.eq(1)
1229 sync
+= r1
.mmu_done
.eq(1)
1231 with m
.If(r1
.write_tag
):
1232 # Store new tag in selected way
1233 for i
in range(NUM_WAYS
):
1234 with m
.If(i
== replace_way
):
1235 ct
= Signal(TAG_RAM_WIDTH
)
1236 comb
+= ct
.eq(cache_tag
[r1
.store_index
])
1237 comb
+= ct
.word_select(i
, TAG_WIDTH
).eq(r1
.reload_tag
)
1238 sync
+= cache_tag
[r1
.store_index
].eq(ct
)
1239 sync
+= r1
.store_way
.eq(replace_way
)
1240 sync
+= r1
.write_tag
.eq(0)
1242 # Take request from r1.req if there is one there,
1243 # else from req_op, ra, etc.
1245 comb
+= req
.eq(r1
.req
)
1247 comb
+= req
.op
.eq(req_op
)
1248 comb
+= req
.valid
.eq(req_go
)
1249 comb
+= req
.mmu_req
.eq(r0
.mmu_req
)
1250 comb
+= req
.dcbz
.eq(r0
.req
.dcbz
)
1251 comb
+= req
.real_addr
.eq(ra
)
1253 with m
.If(~r0
.req
.dcbz
):
1254 comb
+= req
.data
.eq(r0
.req
.data
)
1256 comb
+= req
.data
.eq(0)
1258 # Select all bytes for dcbz
1259 # and for cacheable loads
1260 with m
.If(r0
.req
.dcbz |
(r0
.req
.load
& ~r0
.req
.nc
)):
1261 comb
+= req
.byte_sel
.eq(~
0) # all 1s
1263 comb
+= req
.byte_sel
.eq(r0
.req
.byte_sel
)
1264 comb
+= req
.hit_way
.eq(req_hit_way
)
1265 comb
+= req
.same_tag
.eq(req_same_tag
)
1267 # Store the incoming request from r0,
1268 # if it is a slow request
1269 # Note that r1.full = 1 implies req_op = OP_NONE
1270 with m
.If((req_op
== Op
.OP_LOAD_MISS
)
1271 |
(req_op
== Op
.OP_LOAD_NC
)
1272 |
(req_op
== Op
.OP_STORE_MISS
)
1273 |
(req_op
== Op
.OP_STORE_HIT
)):
1274 sync
+= r1
.req
.eq(req
)
1275 sync
+= r1
.full
.eq(1)
1277 # Main state machine
1278 with m
.Switch(r1
.state
):
1280 with m
.Case(State
.IDLE
):
1281 # XXX check 'left downto. probably means len(r1.wb.adr)
1282 # r1.wb.adr <= req.real_addr(
1283 # r1.wb.adr'left downto 0
1285 sync
+= r1
.wb
.adr
.eq(req
.real_addr
)
1286 sync
+= r1
.wb
.sel
.eq(req
.byte_sel
)
1287 sync
+= r1
.wb
.dat
.eq(req
.data
)
1288 sync
+= r1
.dcbz
.eq(req
.dcbz
)
1290 # Keep track of our index and way
1291 # for subsequent stores.
1292 sync
+= r1
.store_index
.eq(get_index(req
.real_addr
))
1293 sync
+= r1
.store_row
.eq(get_row(req
.real_addr
))
1294 sync
+= r1
.end_row_ix
.eq(
1295 get_row_of_line(get_row(req
.real_addr
))
1297 sync
+= r1
.reload_tag
.eq(get_tag(req
.real_addr
))
1298 sync
+= r1
.req
.same_tag
.eq(1)
1300 with m
.If(req
.op
== Op
.OP_STORE_HIT
):
1301 sync
+= r1
.store_way
.eq(req
.hit_way
)
1303 # Reset per-row valid bits,
1304 # ready for handling OP_LOAD_MISS
1305 for i
in range(ROW_PER_LINE
):
1306 sync
+= r1
.rows_valid
[i
].eq(0)
1308 with m
.Switch(req
.op
):
1309 with m
.Case(Op
.OP_LOAD_HIT
):
1310 # stay in IDLE state
1313 with m
.Case(Op
.OP_LOAD_MISS
):
1314 #Display(f"cache miss real addr:" \
1315 # f"{req_real_addr}" \
1316 # f" idx:{get_index(req_real_addr)}" \
1317 # f" tag:{get_tag(req.real_addr)}")
1320 # Start the wishbone cycle
1321 sync
+= r1
.wb
.we
.eq(0)
1322 sync
+= r1
.wb
.cyc
.eq(1)
1323 sync
+= r1
.wb
.stb
.eq(1)
1325 # Track that we had one request sent
1326 sync
+= r1
.state
.eq(State
.RELOAD_WAIT_ACK
)
1327 sync
+= r1
.write_tag
.eq(1)
1329 with m
.Case(Op
.OP_LOAD_NC
):
1330 sync
+= r1
.wb
.cyc
.eq(1)
1331 sync
+= r1
.wb
.stb
.eq(1)
1332 sync
+= r1
.wb
.we
.eq(0)
1333 sync
+= r1
.state
.eq(State
.NC_LOAD_WAIT_ACK
)
1335 with m
.Case(Op
.OP_STORE_HIT
, Op
.OP_STORE_MISS
):
1336 with m
.If(~req
.dcbz
):
1337 sync
+= r1
.state
.eq(State
.STORE_WAIT_ACK
)
1338 sync
+= r1
.acks_pending
.eq(1)
1339 sync
+= r1
.full
.eq(0)
1340 sync
+= r1
.slow_valid
.eq(1)
1342 with m
.If(~req
.mmu_req
):
1343 sync
+= r1
.ls_valid
.eq(1)
1345 sync
+= r1
.mmu_done
.eq(1)
1347 with m
.If(req
.op
== Op
.OP_STORE_HIT
):
1348 sync
+= r1
.write_bram
.eq(1)
1350 sync
+= r1
.state
.eq(State
.RELOAD_WAIT_ACK
)
1352 with m
.If(req
.op
== Op
.OP_STORE_MISS
):
1353 sync
+= r1
.write_tag
.eq(1)
1355 sync
+= r1
.wb
.we
.eq(1)
1356 sync
+= r1
.wb
.cyc
.eq(1)
1357 sync
+= r1
.wb
.stb
.eq(1)
1359 # OP_NONE and OP_BAD do nothing
1360 # OP_BAD & OP_STCX_FAIL were
1361 # handled above already
1362 with m
.Case(Op
.OP_NONE
):
1364 with m
.Case(Op
.OP_BAD
):
1366 with m
.Case(Op
.OP_STCX_FAIL
):
1369 with m
.Case(State
.RELOAD_WAIT_ACK
):
1370 # Requests are all sent if stb is 0
1371 comb
+= stbs_done
.eq(~r1
.wb
.stb
)
1373 with m
.If(~wb_in
.stall
& ~stbs_done
):
1374 # That was the last word?
1375 # We are done sending.
1376 # Clear stb and set stbs_done
1377 # so we can handle an eventual
1378 # last ack on the same cycle.
1379 with m
.If(is_last_row_addr(
1380 r1
.wb
.adr
, r1
.end_row_ix
)):
1381 sync
+= r1
.wb
.stb
.eq(0)
1382 comb
+= stbs_done
.eq(0)
1384 # Calculate the next row address in the current cache line
1385 rarange
= r1
.wb
.adr
[ROW_OFF_BITS
: LINE_OFF_BITS
]
1386 sync
+= rarange
.eq(rarange
+ 1)
1388 # Incoming acks processing
1389 sync
+= r1
.forward_valid1
.eq(wb_in
.ack
)
1390 with m
.If(wb_in
.ack
):
1391 # XXX needs an Array bit-accessor here
1392 sync
+= r1
.rows_valid
[r1
.store_row
% ROW_PER_LINE
].eq(1)
1394 # If this is the data we were looking for,
1395 # we can complete the request next cycle.
1396 # Compare the whole address in case the
1397 # request in r1.req is not the one that
1398 # started this refill.
1399 with m
.If(r1
.full
& r1
.req
.same_tag
&
1400 ((r1
.dcbz
& r1
.req
.dcbz
) |
1401 (~r1
.dcbz
& (r1
.req
.op
== Op
.OP_LOAD_MISS
))) &
1402 (r1
.store_row
== get_row(r1
.req
.real_addr
))):
1403 sync
+= r1
.full
.eq(0)
1404 sync
+= r1
.slow_valid
.eq(1)
1405 with m
.If(~r1
.mmu_req
):
1406 sync
+= r1
.ls_valid
.eq(1)
1408 sync
+= r1
.mmu_done
.eq(1)
1409 sync
+= r1
.forward_sel
.eq(~
0) # all 1s
1410 sync
+= r1
.use_forward1
.eq(1)
1412 # Check for completion
1413 with m
.If(stbs_done
& is_last_row(r1
.store_row
,
1415 # Complete wishbone cycle
1416 sync
+= r1
.wb
.cyc
.eq(0)
1418 # Cache line is now valid
1419 cv
= Signal(INDEX_BITS
)
1420 sync
+= cv
.eq(cache_valid_bits
[r1
.store_index
])
1421 sync
+= cv
.bit_select(r1
.store_way
, 1).eq(1)
1422 sync
+= r1
.state
.eq(State
.IDLE
)
1424 # Increment store row counter
1425 sync
+= r1
.store_row
.eq(next_row(r1
.store_row
))
1427 with m
.Case(State
.STORE_WAIT_ACK
):
1428 comb
+= stbs_done
.eq(~r1
.wb
.stb
)
1429 comb
+= acks
.eq(r1
.acks_pending
)
1431 with m
.If(r1
.inc_acks
!= r1
.dec_acks
):
1432 with m
.If(r1
.inc_acks
):
1433 comb
+= adjust_acks
.eq(acks
+ 1)
1435 comb
+= adjust_acks
.eq(acks
- 1)
1437 comb
+= adjust_acks
.eq(acks
)
1439 sync
+= r1
.acks_pending
.eq(adjust_acks
)
1441 # Clear stb when slave accepted request
1442 with m
.If(~wb_in
.stall
):
1443 # See if there is another store waiting
1444 # to be done which is in the same real page.
1445 with m
.If(req
.valid
):
1446 ra
= req
.real_addr
[0:SET_SIZE_BITS
]
1447 sync
+= r1
.wb
.adr
[0:SET_SIZE_BITS
].eq(ra
)
1448 sync
+= r1
.wb
.dat
.eq(req
.data
)
1449 sync
+= r1
.wb
.sel
.eq(req
.byte_sel
)
1451 with m
.Elif((adjust_acks
< 7) & req
.same_tag
&
1452 ((req
.op
== Op
.OP_STORE_MISS
)
1453 |
(req
.op
== Op
.OP_STORE_HIT
))):
1454 sync
+= r1
.wb
.stb
.eq(1)
1455 comb
+= stbs_done
.eq(0)
1457 with m
.If(req
.op
== Op
.OP_STORE_HIT
):
1458 sync
+= r1
.write_bram
.eq(1)
1459 sync
+= r1
.full
.eq(0)
1460 sync
+= r1
.slow_valid
.eq(1)
1462 # Store requests never come from the MMU
1463 sync
+= r1
.ls_valid
.eq(1)
1464 comb
+= stbs_done
.eq(0)
1465 sync
+= r1
.inc_acks
.eq(1)
1467 sync
+= r1
.wb
.stb
.eq(0)
1468 comb
+= stbs_done
.eq(1)
1470 # Got ack ? See if complete.
1471 with m
.If(wb_in
.ack
):
1472 with m
.If(stbs_done
& (adjust_acks
== 1)):
1473 sync
+= r1
.state
.eq(State
.IDLE
)
1474 sync
+= r1
.wb
.cyc
.eq(0)
1475 sync
+= r1
.wb
.stb
.eq(0)
1476 sync
+= r1
.dec_acks
.eq(1)
1478 with m
.Case(State
.NC_LOAD_WAIT_ACK
):
1479 # Clear stb when slave accepted request
1480 with m
.If(~wb_in
.stall
):
1481 sync
+= r1
.wb
.stb
.eq(0)
1483 # Got ack ? complete.
1484 with m
.If(wb_in
.ack
):
1485 sync
+= r1
.state
.eq(State
.IDLE
)
1486 sync
+= r1
.full
.eq(0)
1487 sync
+= r1
.slow_valid
.eq(1)
1489 with m
.If(~r1
.mmu_req
):
1490 sync
+= r1
.ls_valid
.eq(1)
1492 sync
+= r1
.mmu_done
.eq(1)
1494 sync
+= r1
.forward_sel
.eq(~
0) # all 1s
1495 sync
+= r1
.use_forward1
.eq(1)
1496 sync
+= r1
.wb
.cyc
.eq(0)
1497 sync
+= r1
.wb
.stb
.eq(0)
1499 def dcache_log(self
, m
, r1
, valid_ra
, tlb_hit_way
, stall_out
):
1502 d_out
, wb_in
, log_out
= self
.d_out
, self
.wb_in
, self
.log_out
1504 sync
+= log_out
.eq(Cat(r1
.state
[:3], valid_ra
, tlb_hit_way
[:3],
1505 stall_out
, req_op
[:3], d_out
.valid
, d_out
.error
,
1506 r1
.wb
.cyc
, r1
.wb
.stb
, wb_in
.ack
, wb_in
.stall
,
1509 def elaborate(self
, platform
):
1514 # Storage. Hopefully "cache_rows" is a BRAM, the rest is LUTs
1515 cache_tags
= CacheTagArray()
1516 cache_tag_set
= Signal(TAG_RAM_WIDTH
)
1517 cache_valid_bits
= CacheValidBitsArray()
1519 # TODO attribute ram_style : string;
1520 # TODO attribute ram_style of cache_tags : signal is "distributed";
1522 """note: these are passed to nmigen.hdl.Memory as "attributes".
1523 don't know how, just that they are.
1525 dtlb_valid_bits
= TLBValidBitsArray()
1526 dtlb_tags
= TLBTagsArray()
1527 dtlb_ptes
= TLBPtesArray()
1528 # TODO attribute ram_style of
1529 # dtlb_tags : signal is "distributed";
1530 # TODO attribute ram_style of
1531 # dtlb_ptes : signal is "distributed";
1538 reservation
= Reservation()
1540 # Async signals on incoming request
1541 req_index
= Signal(INDEX_BITS
)
1542 req_row
= Signal(ROW_BITS
)
1543 req_hit_way
= Signal(WAY_BITS
)
1544 req_tag
= Signal(TAG_BITS
)
1546 req_data
= Signal(64)
1547 req_same_tag
= Signal()
1550 early_req_row
= Signal(ROW_BITS
)
1552 cancel_store
= Signal()
1554 clear_rsrv
= Signal()
1559 use_forward1_next
= Signal()
1560 use_forward2_next
= Signal()
1562 cache_out
= CacheRamOut()
1564 plru_victim
= PLRUOut()
1565 replace_way
= Signal(WAY_BITS
)
1567 # Wishbone read/write/cache write formatting signals
1571 tlb_tag_way
= Signal(TLB_TAG_WAY_BITS
)
1572 tlb_pte_way
= Signal(TLB_PTE_WAY_BITS
)
1573 tlb_valid_way
= Signal(TLB_NUM_WAYS
)
1574 tlb_req_index
= Signal(TLB_SET_BITS
)
1576 tlb_hit_way
= Signal(TLB_WAY_BITS
)
1577 pte
= Signal(TLB_PTE_BITS
)
1578 ra
= Signal(REAL_ADDR_BITS
)
1580 perm_attr
= PermAttr()
1583 access_ok
= Signal()
1585 tlb_plru_victim
= TLBPLRUOut()
1587 # we don't yet handle collisions between loadstore1 requests
1589 comb
+= self
.m_out
.stall
.eq(0)
1591 # Hold off the request in r0 when r1 has an uncompleted request
1592 comb
+= r0_stall
.eq(r0_full
& r1
.full
)
1593 comb
+= r0_valid
.eq(r0_full
& ~r1
.full
)
1594 comb
+= self
.stall_out
.eq(r0_stall
)
1596 # Wire up wishbone request latch out of stage 1
1597 comb
+= self
.wb_out
.eq(r1
.wb
)
1599 # call sub-functions putting everything together, using shared
1600 # signals established above
1601 self
.stage_0(m
, r0
, r1
, r0_full
)
1602 self
.tlb_read(m
, r0_stall
, tlb_valid_way
,
1603 tlb_tag_way
, tlb_pte_way
, dtlb_valid_bits
,
1604 dtlb_tags
, dtlb_ptes
)
1605 self
.tlb_search(m
, tlb_req_index
, r0
, r0_valid
,
1606 tlb_valid_way
, tlb_tag_way
, tlb_hit_way
,
1607 tlb_pte_way
, pte
, tlb_hit
, valid_ra
, perm_attr
, ra
)
1608 self
.tlb_update(m
, r0_valid
, r0
, dtlb_valid_bits
, tlb_req_index
,
1609 tlb_hit_way
, tlb_hit
, tlb_plru_victim
, tlb_tag_way
,
1610 dtlb_tags
, tlb_pte_way
, dtlb_ptes
)
1611 self
.maybe_plrus(m
, r1
, plru_victim
)
1612 self
.maybe_tlb_plrus(m
, r1
, tlb_plru_victim
)
1613 self
.cache_tag_read(m
, r0_stall
, req_index
, cache_tag_set
, cache_tags
)
1614 self
.dcache_request(m
, r0
, ra
, req_index
, req_row
, req_tag
,
1615 r0_valid
, r1
, cache_valid_bits
, replace_way
,
1616 use_forward1_next
, use_forward2_next
,
1617 req_hit_way
, plru_victim
, rc_ok
, perm_attr
,
1618 valid_ra
, perm_ok
, access_ok
, req_op
, req_go
,
1620 tlb_hit
, tlb_hit_way
, tlb_valid_way
, cache_tag_set
,
1621 cancel_store
, req_same_tag
, r0_stall
, early_req_row
)
1622 self
.reservation_comb(m
, cancel_store
, set_rsrv
, clear_rsrv
,
1623 r0_valid
, r0
, reservation
)
1624 self
.reservation_reg(m
, r0_valid
, access_ok
, set_rsrv
, clear_rsrv
,
1626 self
.writeback_control(m
, r1
, cache_out
)
1627 self
.rams(m
, r1
, early_req_row
, cache_out
, replace_way
)
1628 self
.dcache_fast_hit(m
, req_op
, r0_valid
, r0
, r1
,
1629 req_hit_way
, req_index
, access_ok
,
1630 tlb_hit
, tlb_hit_way
, tlb_req_index
)
1631 self
.dcache_slow(m
, r1
, use_forward1_next
, use_forward2_next
,
1632 cache_valid_bits
, r0
, replace_way
,
1633 req_hit_way
, req_same_tag
,
1634 r0_valid
, req_op
, cache_tags
, req_go
, ra
)
1635 #self.dcache_log(m, r1, valid_ra, tlb_hit_way, stall_out)
1642 # entity dcache_tb is
1645 # architecture behave of dcache_tb is
1646 # signal clk : std_ulogic;
1647 # signal rst : std_ulogic;
1649 # signal d_in : Loadstore1ToDcacheType;
1650 # signal d_out : DcacheToLoadstore1Type;
1652 # signal m_in : MmuToDcacheType;
1653 # signal m_out : DcacheToMmuType;
1655 # signal wb_bram_in : wishbone_master_out;
1656 # signal wb_bram_out : wishbone_slave_out;
1658 # constant clk_period : time := 10 ns;
1660 # dcache0: entity work.dcache
1673 # wishbone_out => wb_bram_in,
1674 # wishbone_in => wb_bram_out
1677 # -- BRAM Memory slave
1678 # bram0: entity work.wishbone_bram_wrapper
1680 # MEMORY_SIZE => 1024,
1681 # RAM_INIT_FILE => "icache_test.bin"
1686 # wishbone_in => wb_bram_in,
1687 # wishbone_out => wb_bram_out
1690 # clk_process: process
1693 # wait for clk_period/2;
1695 # wait for clk_period/2;
1698 # rst_process: process
1701 # wait for 2*clk_period;
1709 # d_in.valid <= '0';
1712 # d_in.addr <= (others => '0');
1713 # d_in.data <= (others => '0');
1714 # m_in.valid <= '0';
1715 # m_in.addr <= (others => '0');
1716 # m_in.pte <= (others => '0');
1718 # wait for 4*clk_period;
1719 # wait until rising_edge(clk);
1721 # -- Cacheable read of address 4
1724 # d_in.addr <= x"0000000000000004";
1725 # d_in.valid <= '1';
1726 # wait until rising_edge(clk);
1727 # d_in.valid <= '0';
1729 # wait until rising_edge(clk) and d_out.valid = '1';
1730 # assert d_out.data = x"0000000100000000"
1731 # report "data @" & to_hstring(d_in.addr) &
1732 # "=" & to_hstring(d_out.data) &
1733 # " expected 0000000100000000"
1735 # -- wait for clk_period;
1737 # -- Cacheable read of address 30
1740 # d_in.addr <= x"0000000000000030";
1741 # d_in.valid <= '1';
1742 # wait until rising_edge(clk);
1743 # d_in.valid <= '0';
1745 # wait until rising_edge(clk) and d_out.valid = '1';
1746 # assert d_out.data = x"0000000D0000000C"
1747 # report "data @" & to_hstring(d_in.addr) &
1748 # "=" & to_hstring(d_out.data) &
1749 # " expected 0000000D0000000C"
1752 # -- Non-cacheable read of address 100
1755 # d_in.addr <= x"0000000000000100";
1756 # d_in.valid <= '1';
1757 # wait until rising_edge(clk);
1758 # d_in.valid <= '0';
1759 # wait until rising_edge(clk) and d_out.valid = '1';
1760 # assert d_out.data = x"0000004100000040"
1761 # report "data @" & to_hstring(d_in.addr) &
1762 # "=" & to_hstring(d_out.data) &
1763 # " expected 0000004100000040"
1766 # wait until rising_edge(clk);
1767 # wait until rising_edge(clk);
1768 # wait until rising_edge(clk);
1769 # wait until rising_edge(clk);
1774 def dcache_sim(dut
):
1776 yield dut
.d_in
.valid
.eq(0)
1777 yield dut
.d_in
.load
.eq(0)
1778 yield dut
.d_in
.nc
.eq(0)
1779 yield dut
.d_in
.addr
.eq(0)
1780 yield dut
.d_in
.data
.eq(0)
1781 yield dut
.m_in
.valid
.eq(0)
1782 yield dut
.m_in
.addr
.eq(0)
1783 yield dut
.m_in
.pte
.eq(0)
1784 # wait 4 * clk_period
1790 # Cacheable read of address 4
1791 yield dut
.d_in
.load
.eq(1)
1792 yield dut
.d_in
.nc
.eq(0)
1793 yield dut
.d_in
.addr
.eq(0x0000000000000004)
1794 yield dut
.d_in
.valid
.eq(1)
1796 yield dut
.d_in
.valid
.eq(0)
1798 while not (yield dut
.d_out
.valid
):
1800 data
= yield dut
.d_out
.data
1801 addr
= yield dut
.d_in
.addr
1802 assert data
== 0x0000000100000000, \
1803 f
"data @%x=%x expected 0x0000000100000000" % (data
, addr
)
1805 # Cacheable read of address 30
1806 yield dut
.d_in
.load
.eq(1)
1807 yield dut
.d_in
.nc
.eq(0)
1808 yield dut
.d_in
.addr
.eq(Const(0x0000000000000030, 64))
1809 yield dut
.d_in
.valid
.eq(1)
1811 yield dut
.d_in
.valid
.eq(0)
1813 while not (yield dut
.d_out
.valid
):
1815 data
= yield dut
.d_out
.data
1816 addr
= yield dut
.d_in
.addr
1817 assert data
== 0x0000000D0000000C, \
1818 f
"data @%x=%x expected 0000000D0000000C" % (data
, addr
)
1820 # Non-cacheable read of address 100
1821 yield dut
.d_in
.load
.eq(1)
1822 yield dut
.d_in
.nc
.eq(1)
1823 yield dut
.d_in
.addr
.eq(Const(0x0000000000000100, 64))
1824 yield dut
.d_in
.valid
.eq(1)
1826 yield dut
.d_in
.valid
.eq(0)
1828 while not (yield dut
.d_out
.valid
):
1830 data
= yield dut
.d_out
.data
1831 addr
= yield dut
.d_in
.addr
1832 assert data
== 0x0000004100000040, \
1833 f
"data @%x=%x expected 0000004100000040" % (data
, addr
)
1843 vl
= rtlil
.convert(dut
, ports
=[])
1844 with
open("test_dcache.il", "w") as f
:
1848 m
.submodules
.dcache
= dut
1854 sim
.add_sync_process(wrap(dcache_sim(dut
)))
1855 with sim
.write_vcd('test_dcache.vcd'):
1858 if __name__
== '__main__':