2 -- Set associative dcache write-through
4 -- TODO (in no specific order):
6 -- * See list in icache.vhdl
7 -- * Complete load misses on the cycle when WB data comes instead of
8 -- at the end of line (this requires dealing with requests coming in
10 -- * Load with update could use one less non-pipelined cycle by moving
11 -- the register update to the pipeline bubble that exists when going
12 -- back to the IDLE state.
15 use ieee.std_logic_1164.all;
16 use ieee.numeric_std.all;
22 use work.wishbone_types.all;
27 LINE_SIZE : positive := 64;
28 -- Number of lines in a set
29 NUM_LINES : positive := 32;
31 NUM_WAYS : positive := 4
37 d_in : in Loadstore1ToDcacheType;
38 d_out : out DcacheToWritebackType;
40 stall_out : out std_ulogic;
42 wishbone_out : out wishbone_master_out;
43 wishbone_in : in wishbone_slave_out
47 architecture rtl of dcache is
48 -- BRAM organisation: We never access more than wishbone_data_bits at
49 -- a time so to save resources we make the array only that wide, and
50 -- use consecutive indices for to make a cache "line"
52 -- ROW_SIZE is the width in bytes of the BRAM (based on WB, so 64-bits)
53 constant ROW_SIZE : natural := wishbone_data_bits / 8;
54 -- ROW_PER_LINE is the number of row (wishbone transactions) in a line
55 constant ROW_PER_LINE : natural := LINE_SIZE / ROW_SIZE;
56 -- BRAM_ROWS is the number of rows in BRAM needed to represent the full
58 constant BRAM_ROWS : natural := NUM_LINES * ROW_PER_LINE;
60 -- Bit fields counts in the address
62 -- ROW_BITS is the number of bits to select a row
63 constant ROW_BITS : natural := log2(BRAM_ROWS);
64 -- ROW_LINEBITS is the number of bits to select a row within a line
65 constant ROW_LINEBITS : natural := log2(ROW_PER_LINE);
66 -- LINE_OFF_BITS is the number of bits for the offset in a cache line
67 constant LINE_OFF_BITS : natural := log2(LINE_SIZE);
68 -- ROW_OFF_BITS is the number of bits for the offset in a row
69 constant ROW_OFF_BITS : natural := log2(ROW_SIZE);
70 -- INDEX_BITS is the number if bits to select a cache line
71 constant INDEX_BITS : natural := log2(NUM_LINES);
72 -- TAG_BITS is the number of bits of the tag part of the address
73 constant TAG_BITS : natural := 64 - LINE_OFF_BITS - INDEX_BITS;
74 -- WAY_BITS is the number of bits to select a way
75 constant WAY_BITS : natural := log2(NUM_WAYS);
77 -- Example of layout for 32 lines of 64 bytes:
79 -- .. tag |index| line |
81 -- .. | |---| | ROW_LINEBITS (3)
82 -- .. | |--- - --| LINE_OFF_BITS (6)
83 -- .. | |- --| ROW_OFF_BITS (3)
84 -- .. |----- ---| | ROW_BITS (8)
85 -- .. |-----| | INDEX_BITS (5)
86 -- .. --------| | TAG_BITS (53)
88 subtype row_t is integer range 0 to BRAM_ROWS-1;
89 subtype index_t is integer range 0 to NUM_LINES-1;
90 subtype way_t is integer range 0 to NUM_WAYS-1;
92 -- The cache data BRAM organized as described above for each way
93 subtype cache_row_t is std_ulogic_vector(wishbone_data_bits-1 downto 0);
95 -- The cache tags LUTRAM has a row per set. Vivado is a pain and will
96 -- not handle a clean (commented) definition of the cache tags as a 3d
97 -- memory. For now, work around it by putting all the tags
98 subtype cache_tag_t is std_logic_vector(TAG_BITS-1 downto 0);
99 -- type cache_tags_set_t is array(way_t) of cache_tag_t;
100 -- type cache_tags_array_t is array(index_t) of cache_tags_set_t;
101 constant TAG_RAM_WIDTH : natural := TAG_BITS * NUM_WAYS;
102 subtype cache_tags_set_t is std_logic_vector(TAG_RAM_WIDTH-1 downto 0);
103 type cache_tags_array_t is array(index_t) of cache_tags_set_t;
105 -- The cache valid bits
106 subtype cache_way_valids_t is std_ulogic_vector(NUM_WAYS-1 downto 0);
107 type cache_valids_t is array(index_t) of cache_way_valids_t;
109 -- Storage. Hopefully "cache_rows" is a BRAM, the rest is LUTs
110 signal cache_tags : cache_tags_array_t;
111 signal cache_valids : cache_valids_t;
113 attribute ram_style : string;
114 attribute ram_style of cache_tags : signal is "distributed";
116 -- Type of operation on a "valid" input
117 type op_t is (OP_NONE,
118 OP_LOAD_HIT, -- Cache hit on load
119 OP_LOAD_MISS, -- Load missing cache
120 OP_LOAD_NC, -- Non-cachable load
121 OP_BAD, -- BAD: Cache hit on NC load/store
122 OP_STORE_HIT, -- Store hitting cache
123 OP_STORE_MISS); -- Store missing cache
125 -- Cache state machine
126 type state_t is (IDLE, -- Normal load hit processing
127 LOAD_UPDATE, -- Load with update extra cycle
128 LOAD_UPDATE2, -- Load with update extra cycle
129 RELOAD_WAIT_ACK, -- Cache reload wait ack
130 STORE_WAIT_ACK, -- Store wait ack
131 NC_LOAD_WAIT_ACK);-- Non-cachable load wait ack
135 -- Dcache operations:
137 -- In order to make timing, we use the BRAMs with an output buffer,
138 -- which means that the BRAM output is delayed by an extra cycle.
140 -- Thus, the dcache has a 2-stage internal pipeline for cache hits
143 -- All other operations are handled via stalling in the first stage.
145 -- The second stage can thus complete a hit at the same time as the
146 -- first stage emits a stall for a complex op.
149 -- First stage register, contains state for stage 1 of load hits
150 -- and for the state machine used by all other operations
152 type reg_stage_1_t is record
153 -- Latch the complete request from ls1
154 req : Loadstore1ToDcacheType;
158 hit_load_valid : std_ulogic;
160 -- Register update (load/store with update)
161 update_valid : std_ulogic;
163 -- Data buffer for "slow" read ops (load miss and NC loads).
164 slow_data : std_ulogic_vector(63 downto 0);
165 slow_valid : std_ulogic;
167 -- Cache miss state (reload state machine)
169 wb : wishbone_master_out;
172 store_index : index_t;
175 signal r1 : reg_stage_1_t;
177 -- Second stage register, only used for load hits
179 type reg_stage_2_t is record
181 hit_load_valid : std_ulogic;
182 load_is_update : std_ulogic;
183 load_reg : std_ulogic_vector(4 downto 0);
184 data_shift : std_ulogic_vector(2 downto 0);
185 length : std_ulogic_vector(3 downto 0);
186 sign_extend : std_ulogic;
187 byte_reverse : std_ulogic;
190 signal r2 : reg_stage_2_t;
192 -- Async signals on incoming request
193 signal req_index : index_t;
194 signal req_row : row_t;
195 signal req_hit_way : way_t;
196 signal req_tag : cache_tag_t;
197 signal req_op : op_t;
198 signal req_laddr : std_ulogic_vector(63 downto 0);
200 -- Cache RAM interface
201 type cache_ram_out_t is array(way_t) of cache_row_t;
202 signal cache_out : cache_ram_out_t;
204 -- PLRU output interface
205 type plru_out_t is array(index_t) of std_ulogic_vector(WAY_BITS-1 downto 0);
206 signal plru_victim : plru_out_t;
207 signal replace_way : way_t;
209 -- Wishbone read/write/cache write formatting signals
210 signal bus_sel : wishbone_sel_type;
211 signal store_data : wishbone_data_type;
214 -- Helper functions to decode incoming requests
217 -- Return the cache line index (tag index) for an address
218 function get_index(addr: std_ulogic_vector(63 downto 0)) return index_t is
220 return to_integer(unsigned(addr(63-TAG_BITS downto LINE_OFF_BITS)));
223 -- Return the cache row index (data memory) for an address
224 function get_row(addr: std_ulogic_vector(63 downto 0)) return row_t is
226 return to_integer(unsigned(addr(63-TAG_BITS downto ROW_OFF_BITS)));
229 -- Returns whether this is the last row of a line
230 function is_last_row_addr(addr: wishbone_addr_type) return boolean is
231 constant ones : std_ulogic_vector(ROW_LINEBITS-1 downto 0) := (others => '1');
233 return addr(LINE_OFF_BITS-1 downto ROW_OFF_BITS) = ones;
236 -- Returns whether this is the last row of a line
237 function is_last_row(row: row_t) return boolean is
238 variable row_v : std_ulogic_vector(ROW_BITS-1 downto 0);
239 constant ones : std_ulogic_vector(ROW_LINEBITS-1 downto 0) := (others => '1');
241 row_v := std_ulogic_vector(to_unsigned(row, ROW_BITS));
242 return row_v(ROW_LINEBITS-1 downto 0) = ones;
245 -- Return the address of the next row in the current cache line
246 function next_row_addr(addr: wishbone_addr_type) return std_ulogic_vector is
247 variable row_idx : std_ulogic_vector(ROW_LINEBITS-1 downto 0);
248 variable result : wishbone_addr_type;
250 -- Is there no simpler way in VHDL to generate that 3 bits adder ?
251 row_idx := addr(LINE_OFF_BITS-1 downto ROW_OFF_BITS);
252 row_idx := std_ulogic_vector(unsigned(row_idx) + 1);
254 result(LINE_OFF_BITS-1 downto ROW_OFF_BITS) := row_idx;
258 -- Return the next row in the current cache line. We use a dedicated
259 -- function in order to limit the size of the generated adder to be
260 -- only the bits within a cache line (3 bits with default settings)
262 function next_row(row: row_t) return row_t is
263 variable row_v : std_ulogic_vector(ROW_BITS-1 downto 0);
264 variable row_idx : std_ulogic_vector(ROW_LINEBITS-1 downto 0);
265 variable result : std_ulogic_vector(ROW_BITS-1 downto 0);
267 row_v := std_ulogic_vector(to_unsigned(row, ROW_BITS));
268 row_idx := row_v(ROW_LINEBITS-1 downto 0);
269 row_v(ROW_LINEBITS-1 downto 0) := std_ulogic_vector(unsigned(row_idx) + 1);
270 return to_integer(unsigned(row_v));
273 -- Get the tag value from the address
274 function get_tag(addr: std_ulogic_vector(63 downto 0)) return cache_tag_t is
276 return addr(63 downto 64-TAG_BITS);
279 -- Read a tag from a tag memory row
280 function read_tag(way: way_t; tagset: cache_tags_set_t) return cache_tag_t is
282 return tagset((way+1) * TAG_BITS - 1 downto way * TAG_BITS);
285 -- Write a tag to tag memory row
286 procedure write_tag(way: in way_t; tagset: inout cache_tags_set_t;
289 tagset((way+1) * TAG_BITS - 1 downto way * TAG_BITS) := tag;
292 -- Generate byte enables from sizes
293 function length_to_sel(length : in std_logic_vector(3 downto 0)) return std_ulogic_vector is
307 end function length_to_sel;
309 -- Calculate shift and byte enables for wishbone
310 function wishbone_data_shift(address : in std_ulogic_vector(63 downto 0)) return natural is
312 return to_integer(unsigned(address(2 downto 0))) * 8;
313 end function wishbone_data_shift;
315 function wishbone_data_sel(size : in std_logic_vector(3 downto 0);
316 address : in std_logic_vector(63 downto 0))
317 return std_ulogic_vector is
319 return std_ulogic_vector(shift_left(unsigned(length_to_sel(size)),
320 to_integer(unsigned(address(2 downto 0)))));
321 end function wishbone_data_sel;
325 assert LINE_SIZE mod ROW_SIZE = 0 report "LINE_SIZE not multiple of ROW_SIZE" severity FAILURE;
326 assert ispow2(LINE_SIZE) report "LINE_SIZE not power of 2" severity FAILURE;
327 assert ispow2(NUM_LINES) report "NUM_LINES not power of 2" severity FAILURE;
328 assert ispow2(ROW_PER_LINE) report "ROW_PER_LINE not power of 2" severity FAILURE;
329 assert (ROW_BITS = INDEX_BITS + ROW_LINEBITS)
330 report "geometry bits don't add up" severity FAILURE;
331 assert (LINE_OFF_BITS = ROW_OFF_BITS + ROW_LINEBITS)
332 report "geometry bits don't add up" severity FAILURE;
333 assert (64 = TAG_BITS + INDEX_BITS + LINE_OFF_BITS)
334 report "geometry bits don't add up" severity FAILURE;
335 assert (64 = TAG_BITS + ROW_BITS + ROW_OFF_BITS)
336 report "geometry bits don't add up" severity FAILURE;
337 assert (64 = wishbone_data_bits)
338 report "Can't yet handle a wishbone width that isn't 64-bits" severity FAILURE;
341 maybe_plrus: if NUM_WAYS > 1 generate
343 plrus: for i in 0 to NUM_LINES-1 generate
345 signal plru_acc : std_ulogic_vector(WAY_BITS-1 downto 0);
346 signal plru_acc_en : std_ulogic;
347 signal plru_out : std_ulogic_vector(WAY_BITS-1 downto 0);
350 plru : entity work.plru
358 acc_en => plru_acc_en,
362 process(req_index, req_op, req_hit_way, plru_out)
365 if (req_op = OP_LOAD_HIT or
366 req_op = OP_STORE_HIT) and req_index = i then
371 plru_acc <= std_ulogic_vector(to_unsigned(req_hit_way, WAY_BITS));
372 plru_victim(i) <= plru_out;
377 -- Cache request parsing and hit detection
378 dcache_request : process(all)
379 variable is_hit : std_ulogic;
380 variable hit_way : way_t;
382 variable tmp : std_ulogic_vector(63 downto 0);
383 variable data : std_ulogic_vector(63 downto 0);
384 variable opsel : std_ulogic_vector(3 downto 0);
386 -- Extract line, row and tag from request
387 req_index <= get_index(d_in.addr);
388 req_row <= get_row(d_in.addr);
389 req_tag <= get_tag(d_in.addr);
391 -- Calculate address of beginning of cache line, will be
392 -- used for cache miss processing if needed
394 req_laddr <= d_in.addr(63 downto LINE_OFF_BITS) &
395 (LINE_OFF_BITS-1 downto 0 => '0');
397 -- Test if pending request is a hit on any way
401 if d_in.valid = '1' and cache_valids(req_index)(i) = '1' then
402 if read_tag(i, cache_tags(req_index)) = req_tag then
409 -- The way that matched on a hit
410 req_hit_way <= hit_way;
412 -- The way to replace on a miss
413 replace_way <= to_integer(unsigned(plru_victim(req_index)));
415 -- Combine the request and cache his status to decide what
416 -- operation needs to be done
418 opsel := d_in.valid & d_in.load & d_in.nc & is_hit;
420 when "1101" => op := OP_LOAD_HIT;
421 when "1100" => op := OP_LOAD_MISS;
422 when "1110" => op := OP_LOAD_NC;
423 when "1001" => op := OP_STORE_HIT;
424 when "1000" => op := OP_STORE_MISS;
425 when "1010" => op := OP_STORE_MISS;
426 when "1011" => op := OP_BAD;
427 when "1111" => op := OP_BAD;
428 when others => op := OP_NONE;
436 -- Misc signal assignments
439 -- Wire up wishbone request latch out of stage 1
440 wishbone_out <= r1.wb;
442 -- Wishbone & BRAM write data formatting for stores (most of it already
443 -- happens in loadstore1, this is the remaining data shifting)
445 store_data <= std_logic_vector(shift_left(unsigned(d_in.data),
446 wishbone_data_shift(d_in.addr)));
448 -- Wishbone read and write and BRAM write sel bits generation
449 bus_sel <= wishbone_data_sel(d_in.length, d_in.addr);
451 -- TODO: Generate errors
452 -- err_nc_collision <= '1' when req_op = OP_BAD else '0';
454 -- Generate stalls from stage 1 state machine
455 stall_out <= '1' when r1.state /= IDLE else '0';
457 -- Writeback (loads and reg updates) & completion control logic
459 writeback_control: process(all)
462 -- The mux on d_out.write reg defaults to the normal load hit case.
463 d_out.write_enable <= '0';
465 d_out.write_reg <= r2.load_reg;
466 d_out.write_data <= cache_out(r2.hit_way);
467 d_out.write_len <= r2.length;
468 d_out.write_shift <= r2.data_shift;
469 d_out.sign_extend <= r2.sign_extend;
470 d_out.byte_reverse <= r2.byte_reverse;
471 d_out.second_word <= '0';
473 -- We have a valid load or store hit or we just completed a slow
474 -- op such as a load miss, a NC load or a store
476 -- Note: the load hit is delayed by one cycle. However it can still
477 -- not collide with r.slow_valid (well unless I miscalculated) because
478 -- slow_valid can only be set on a subsequent request and not on its
479 -- first cycle (the state machine must have advanced), which makes
480 -- slow_valid at least 2 cycles from the previous hit_load_valid.
483 -- Sanity: Only one of these must be set in any given cycle
484 assert (r1.update_valid and r2.hit_load_valid) /= '1' report
485 "unexpected hit_load_delayed collision with update_valid"
487 assert (r1.slow_valid and r2.hit_load_valid) /= '1' report
488 "unexpected hit_load_delayed collision with slow_valid"
490 assert (r1.slow_valid and r1.update_valid) /= '1' report
491 "unexpected update_valid collision with slow_valid"
494 -- Delayed load hit case is the standard path
495 if r2.hit_load_valid = '1' then
496 d_out.write_enable <= '1';
498 -- If it's not a load with update, complete it now
499 if r2.load_is_update = '0' then
504 -- Slow ops (load miss, NC, stores)
505 if r1.slow_valid = '1' then
506 -- If it's a load, enable register writeback and switch
510 d_out.write_reg <= r1.req.write_reg;
511 d_out.write_enable <= '1';
513 -- Read data comes from the slow data latch, formatter
514 -- from the latched request.
516 d_out.write_data <= r1.slow_data;
517 d_out.write_shift <= r1.req.addr(2 downto 0);
518 d_out.sign_extend <= r1.req.sign_extend;
519 d_out.byte_reverse <= r1.req.byte_reverse;
520 d_out.write_len <= r1.req.length;
523 -- If it's a store or a non-update load form, complete now
524 if r1.req.load = '0' or r1.req.update = '0' then
529 -- We have a register update to do.
530 if r1.update_valid = '1' then
531 d_out.write_enable <= '1';
532 d_out.write_reg <= r1.req.update_reg;
534 -- Change the read data mux to the address that's going into
535 -- the register and the formatter does nothing.
537 d_out.write_data <= r1.req.addr;
538 d_out.write_shift <= "000";
539 d_out.write_len <= "1000";
540 d_out.sign_extend <= '0';
541 d_out.byte_reverse <= '0';
543 -- If it was a load, this completes the operation (load with
546 if r1.req.load = '1' then
554 -- Generate a cache RAM for each way. This handles the normal
555 -- reads, writes from reloads and the special store-hit update
558 -- Note: the BRAMs have an extra read buffer, meaning the output
559 -- is pipelined an extra cycle. This differs from the
560 -- icache. The writeback logic needs to take that into
561 -- account by using 1-cycle delayed signals for load hits.
563 rams: for i in 0 to NUM_WAYS-1 generate
564 signal do_read : std_ulogic;
565 signal rd_addr : std_ulogic_vector(ROW_BITS-1 downto 0);
566 signal do_write : std_ulogic;
567 signal wr_addr : std_ulogic_vector(ROW_BITS-1 downto 0);
568 signal wr_data : std_ulogic_vector(wishbone_data_bits-1 downto 0);
569 signal wr_sel : std_ulogic_vector(ROW_SIZE-1 downto 0);
570 signal dout : cache_row_t;
572 way: entity work.cache_ram
574 ROW_BITS => ROW_BITS,
575 WIDTH => wishbone_data_bits,
589 variable tmp_adr : std_ulogic_vector(63 downto 0);
590 variable reloading : boolean;
594 rd_addr <= std_ulogic_vector(to_unsigned(req_row, ROW_BITS));
595 cache_out(i) <= dout;
599 -- Defaults to wishbone read responses (cache refill),
601 -- For timing, the mux on wr_data/sel/addr is not dependent on anything
602 -- other than the current state. Only the do_write signal is.
604 if r1.state = IDLE then
605 -- When IDLE, the only write path is the store-hit update case
606 wr_addr <= std_ulogic_vector(to_unsigned(req_row, ROW_BITS));
607 wr_data <= store_data;
610 -- Otherwise, we might be doing a reload
611 wr_data <= wishbone_in.dat;
612 wr_sel <= (others => '1');
613 wr_addr <= std_ulogic_vector(to_unsigned(r1.store_row, ROW_BITS));
616 -- The two actual write cases here
618 reloading := r1.state = RELOAD_WAIT_ACK;
619 if reloading and wishbone_in.ack = '1' and r1.store_way = i then
622 if req_op = OP_STORE_HIT and req_hit_way = i then
623 assert not reloading report "Store hit while in state:" &
624 state_t'image(r1.state)
632 -- Cache hit synchronous machine for the easy case. This handles
633 -- non-update form load hits and stage 1 to stage 2 transfers
635 dcache_fast_hit : process(clk)
637 if rising_edge(clk) then
638 -- stage 1 -> stage 2
639 r2.hit_load_valid <= r1.hit_load_valid;
640 r2.hit_way <= r1.hit_way;
641 r2.load_is_update <= r1.req.update;
642 r2.load_reg <= r1.req.write_reg;
643 r2.data_shift <= r1.req.addr(2 downto 0);
644 r2.length <= r1.req.length;
645 r2.sign_extend <= r1.req.sign_extend;
646 r2.byte_reverse <= r1.req.byte_reverse;
648 -- If we have a request incoming, we have to latch it as d_in.valid
649 -- is only set for a single cycle. It's up to the control logic to
650 -- ensure we don't override an uncompleted request (for now we are
651 -- single issue on load/stores so we are fine, later, we can generate
652 -- a stall output if necessary).
654 if req_op /= OP_NONE then
657 report "op:" & op_t'image(req_op) &
658 " addr:" & to_hstring(d_in.addr) &
659 " upd:" & std_ulogic'image(d_in.update) &
660 " nc:" & std_ulogic'image(d_in.nc) &
661 " reg:" & to_hstring(d_in.write_reg) &
662 " idx:" & integer'image(req_index) &
663 " tag:" & to_hstring(req_tag) &
664 " way: " & integer'image(req_hit_way);
667 -- Fast path for load/store hits. Set signals for the writeback controls.
668 if req_op = OP_LOAD_HIT then
669 r1.hit_way <= req_hit_way;
670 r1.hit_load_valid <= '1';
672 r1.hit_load_valid <= '0';
678 -- Every other case is handled by this stage machine:
680 -- * Cache load miss/reload (in conjunction with "rams")
681 -- * Load hits for update forms
682 -- * Load hits for non-cachable forms
683 -- * Stores (the collision case is handled in "rams")
685 -- All wishbone requests generation is done here. This machine
686 -- operates at stage 1.
688 dcache_slow : process(clk)
689 variable tagset : cache_tags_set_t;
690 variable stbs_done : boolean;
692 if rising_edge(clk) then
693 -- On reset, clear all valid bits to force misses
695 for i in index_t loop
696 cache_valids(i) <= (others => '0');
699 r1.slow_valid <= '0';
700 r1.update_valid <= '0';
704 -- Not useful normally but helps avoiding tons of sim warnings
705 r1.wb.adr <= (others => '0');
707 -- One cycle pulses reset
708 r1.slow_valid <= '0';
709 r1.update_valid <= '0';
711 -- We cannot currently process a new request when not idle
712 assert req_op = OP_NONE or r1.state = IDLE report "request " &
713 op_t'image(req_op) & " while in state " & state_t'image(r1.state)
716 -- Main state machine
721 -- We have a load with update hit, we need the delayed update cycle
722 if d_in.update = '1' then
723 r1.state <= LOAD_UPDATE;
727 -- Normal load cache miss, start the reload machine
729 report "cache miss addr:" & to_hstring(d_in.addr) &
730 " idx:" & integer'image(req_index) &
731 " way:" & integer'image(replace_way) &
732 " tag:" & to_hstring(req_tag);
734 -- Force misses on that way while reloading that line
735 cache_valids(req_index)(replace_way) <= '0';
737 -- Store new tag in selected way
738 for i in 0 to NUM_WAYS-1 loop
739 if i = replace_way then
740 tagset := cache_tags(req_index);
741 write_tag(i, tagset, req_tag);
742 cache_tags(req_index) <= tagset;
746 -- Keep track of our index and way for subsequent stores.
747 r1.store_index <= req_index;
748 r1.store_way <= replace_way;
749 r1.store_row <= get_row(req_laddr);
751 -- Prep for first wishbone read. We calculate the address of
752 -- the start of the cache line and start the WB cycle
754 r1.wb.adr <= req_laddr(r1.wb.adr'left downto 0);
755 r1.wb.sel <= (others => '1');
760 -- Track that we had one request sent
761 r1.state <= RELOAD_WAIT_ACK;
764 r1.wb.sel <= bus_sel;
765 r1.wb.adr <= d_in.addr(r1.wb.adr'left downto 3) & "000";
769 r1.state <= NC_LOAD_WAIT_ACK;
771 when OP_STORE_HIT | OP_STORE_MISS =>
772 -- For store-with-update do the register update
773 if d_in.update = '1' then
774 r1.update_valid <= '1';
776 r1.wb.sel <= bus_sel;
777 r1.wb.adr <= d_in.addr(r1.wb.adr'left downto 3) & "000";
778 r1.wb.dat <= store_data;
782 r1.state <= STORE_WAIT_ACK;
784 -- OP_NONE and OP_BAD do nothing
789 when RELOAD_WAIT_ACK =>
790 -- Requests are all sent if stb is 0
791 stbs_done := r1.wb.stb = '0';
793 -- If we are still sending requests, was one accepted ?
794 if wishbone_in.stall = '0' and not stbs_done then
795 -- That was the last word ? We are done sending. Clear
796 -- stb and set stbs_done so we can handle an eventual last
797 -- ack on the same cycle.
799 if is_last_row_addr(r1.wb.adr) then
804 -- Calculate the next row address
805 r1.wb.adr <= next_row_addr(r1.wb.adr);
808 -- Incoming acks processing
809 if wishbone_in.ack = '1' then
810 -- Is this the data we were looking for ? Latch it so
811 -- we can respond later. We don't currently complete the
812 -- pending miss request immediately, we wait for the
813 -- whole line to be loaded. The reason is that if we
814 -- did, we would potentially get new requests in while
815 -- not idle, which we don't currently know how to deal
818 if r1.store_row = get_row(r1.req.addr) then
819 r1.slow_data <= wishbone_in.dat;
822 -- Check for completion
823 if stbs_done and is_last_row(r1.store_row) then
824 -- Complete wishbone cycle
827 -- Cache line is now valid
828 cache_valids(r1.store_index)(r1.store_way) <= '1';
830 -- Complete the load that missed. For load with update
831 -- we also need to do the deferred update cycle.
833 r1.slow_valid <= '1';
834 if r1.req.load = '1' and r1.req.update = '1' then
835 r1.state <= LOAD_UPDATE;
836 report "completing miss with load-update !";
839 report "completing miss !";
843 -- Increment store row counter
844 r1.store_row <= next_row(r1.store_row);
848 -- We need the extra cycle to complete a load with update
849 r1.state <= LOAD_UPDATE2;
851 -- We need the extra cycle to complete a load with update
852 r1.update_valid <= '1';
855 when STORE_WAIT_ACK | NC_LOAD_WAIT_ACK =>
856 -- Clear stb when slave accepted request
857 if wishbone_in.stall = '0' then
861 -- Got ack ? complete.
862 if wishbone_in.ack = '1' then
863 if r1.state = NC_LOAD_WAIT_ACK then
864 r1.slow_data <= wishbone_in.dat;
866 r1.slow_valid <= '1';