1 |
10 |
unneback |
//////////////////////////////////////////////////////////////////////
|
2 |
|
|
//// ////
|
3 |
|
|
//// OR1200's DC FSM ////
|
4 |
|
|
//// ////
|
5 |
|
|
//// This file is part of the OpenRISC 1200 project ////
|
6 |
258 |
julius |
//// http://opencores.org/project,or1k ////
|
7 |
10 |
unneback |
//// ////
|
8 |
|
|
//// Description ////
|
9 |
|
|
//// Data cache state machine ////
|
10 |
|
|
//// ////
|
11 |
|
|
//// To Do: ////
|
12 |
258 |
julius |
//// - Test error during line read or write ////
|
13 |
10 |
unneback |
//// ////
|
14 |
|
|
//// Author(s): ////
|
15 |
|
|
//// - Damjan Lampret, lampret@opencores.org ////
|
16 |
258 |
julius |
//// - Julius Baxter, julius@opencores.org ////
|
17 |
10 |
unneback |
//// ////
|
18 |
|
|
//////////////////////////////////////////////////////////////////////
|
19 |
|
|
//// ////
|
20 |
258 |
julius |
//// Copyright (C) 2000, 2010 Authors and OPENCORES.ORG ////
|
21 |
10 |
unneback |
//// ////
|
22 |
|
|
//// This source file may be used and distributed without ////
|
23 |
|
|
//// restriction provided that this copyright statement is not ////
|
24 |
|
|
//// removed from the file and that any derivative work contains ////
|
25 |
|
|
//// the original copyright notice and the associated disclaimer. ////
|
26 |
|
|
//// ////
|
27 |
|
|
//// This source file is free software; you can redistribute it ////
|
28 |
|
|
//// and/or modify it under the terms of the GNU Lesser General ////
|
29 |
|
|
//// Public License as published by the Free Software Foundation; ////
|
30 |
|
|
//// either version 2.1 of the License, or (at your option) any ////
|
31 |
|
|
//// later version. ////
|
32 |
|
|
//// ////
|
33 |
|
|
//// This source is distributed in the hope that it will be ////
|
34 |
|
|
//// useful, but WITHOUT ANY WARRANTY; without even the implied ////
|
35 |
|
|
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ////
|
36 |
|
|
//// PURPOSE. See the GNU Lesser General Public License for more ////
|
37 |
|
|
//// details. ////
|
38 |
|
|
//// ////
|
39 |
|
|
//// You should have received a copy of the GNU Lesser General ////
|
40 |
|
|
//// Public License along with this source; if not, download it ////
|
41 |
|
|
//// from http://www.opencores.org/lgpl.shtml ////
|
42 |
|
|
//// ////
|
43 |
|
|
//////////////////////////////////////////////////////////////////////
|
44 |
|
|
//
|
45 |
141 |
marcus.erl |
// $Log: or1200_dc_fsm.v,v $
|
46 |
|
|
// Revision 2.0 2010/06/30 11:00:00 ORSoC
|
47 |
|
|
// Minor update:
|
48 |
|
|
// Bugs fixed.
|
49 |
|
|
//
|
50 |
10 |
unneback |
|
51 |
|
|
// synopsys translate_off
|
52 |
|
|
`include "timescale.v"
|
53 |
|
|
// synopsys translate_on
|
54 |
|
|
`include "or1200_defines.v"
|
55 |
|
|
|
56 |
|
|
`define OR1200_DCFSM_IDLE 3'd0
|
57 |
258 |
julius |
`define OR1200_DCFSM_CLOADSTORE 3'd1
|
58 |
|
|
`define OR1200_DCFSM_LOOP2 3'd2
|
59 |
|
|
`define OR1200_DCFSM_LOOP3 3'd3
|
60 |
|
|
`define OR1200_DCFSM_LOOP4 3'd4
|
61 |
|
|
`define OR1200_DCFSM_FLUSH5 3'd5
|
62 |
|
|
`define OR1200_DCFSM_INV6 3'd6
|
63 |
|
|
`define OR1200_DCFSM_WAITSPRCS7 3'd7
|
64 |
10 |
unneback |
|
65 |
258 |
julius |
|
66 |
|
|
|
67 |
10 |
unneback |
//
|
68 |
|
|
// Data cache FSM for cache line of 16 bytes (4x singleword)
|
69 |
|
|
//
|
70 |
|
|
|
71 |
258 |
julius |
module or1200_dc_fsm
|
72 |
|
|
(
|
73 |
|
|
// Clock and reset
|
74 |
|
|
clk, rst,
|
75 |
|
|
|
76 |
|
|
// Internal i/f to top level DC
|
77 |
|
|
dc_en, dcqmem_cycstb_i, dcqmem_ci_i, dcqmem_we_i, dcqmem_sel_i,
|
78 |
|
|
tagcomp_miss, biudata_valid, biudata_error, lsu_addr,
|
79 |
|
|
dcram_we, biu_read, biu_write, biu_do_sel, dcram_di_sel, first_hit_ack,
|
80 |
|
|
first_miss_ack, first_miss_err, burst, tag_we, tag_valid, dc_addr,
|
81 |
|
|
dc_no_writethrough, tag_dirty, dirty, tag, tag_v, dc_block_flush,
|
82 |
|
|
dc_block_writeback, spr_dat_i, mtspr_dc_done, spr_cswe
|
83 |
|
|
);
|
84 |
10 |
unneback |
|
85 |
258 |
julius |
//
|
86 |
|
|
// I/O
|
87 |
|
|
//
|
88 |
|
|
input clk;
|
89 |
|
|
input rst;
|
90 |
|
|
input dc_en;
|
91 |
|
|
input dcqmem_cycstb_i;
|
92 |
|
|
input dcqmem_ci_i;
|
93 |
|
|
input dcqmem_we_i;
|
94 |
|
|
input [3:0] dcqmem_sel_i;
|
95 |
|
|
input tagcomp_miss;
|
96 |
|
|
input biudata_valid;
|
97 |
|
|
input biudata_error;
|
98 |
|
|
input [31:0] lsu_addr;
|
99 |
|
|
output [3:0] dcram_we;
|
100 |
|
|
output biu_read;
|
101 |
|
|
output biu_write;
|
102 |
|
|
output dcram_di_sel;
|
103 |
|
|
output biu_do_sel;
|
104 |
|
|
output first_hit_ack;
|
105 |
|
|
output first_miss_ack;
|
106 |
|
|
output first_miss_err;
|
107 |
|
|
output burst;
|
108 |
|
|
output tag_we;
|
109 |
|
|
output tag_valid;
|
110 |
|
|
output [31:0] dc_addr;
|
111 |
|
|
input dc_no_writethrough;
|
112 |
|
|
output tag_dirty;
|
113 |
|
|
input dirty;
|
114 |
|
|
input [`OR1200_DCTAG_W-2:0] tag;
|
115 |
|
|
input tag_v;
|
116 |
|
|
input dc_block_flush;
|
117 |
|
|
input dc_block_writeback;
|
118 |
|
|
input [31:0] spr_dat_i;
|
119 |
|
|
output mtspr_dc_done;
|
120 |
|
|
input spr_cswe;
|
121 |
|
|
|
122 |
|
|
|
123 |
|
|
//
|
124 |
|
|
// Internal wires and regs
|
125 |
|
|
//
|
126 |
|
|
reg [31:0] addr_r;
|
127 |
|
|
reg [2:0] state;
|
128 |
|
|
reg [2:0] cnt;
|
129 |
|
|
reg hitmiss_eval;
|
130 |
|
|
reg store;
|
131 |
|
|
reg load;
|
132 |
|
|
reg cache_inhibit;
|
133 |
|
|
reg cache_miss;
|
134 |
|
|
reg cache_dirty_needs_writeback;
|
135 |
|
|
reg did_early_load_ack;
|
136 |
|
|
reg cache_spr_block_flush;
|
137 |
|
|
reg cache_spr_block_writeback;
|
138 |
|
|
reg cache_wb;
|
139 |
|
|
wire load_hit_ack;
|
140 |
|
|
wire load_miss_ack;
|
141 |
|
|
wire load_inhibit_ack;
|
142 |
|
|
wire store_hit_ack;
|
143 |
|
|
wire store_hit_writethrough_ack;
|
144 |
|
|
wire store_miss_writethrough_ack;
|
145 |
|
|
wire store_inhibit_ack;
|
146 |
|
|
wire store_miss_ack;
|
147 |
|
|
wire dcram_we_after_line_load;
|
148 |
|
|
wire dcram_we_during_line_load;
|
149 |
|
|
wire tagram_we_end_of_loadstore_loop;
|
150 |
|
|
wire tagram_dirty_bit_set;
|
151 |
|
|
wire writethrough;
|
152 |
|
|
wire cache_inhibit_with_eval;
|
153 |
|
|
wire [1:0] next_addr_word;
|
154 |
10 |
unneback |
|
155 |
258 |
julius |
//
|
156 |
|
|
// Cache inhibit
|
157 |
|
|
//
|
158 |
|
|
|
159 |
|
|
// Indicates whether cache is inhibited, during hitmiss_eval and after
|
160 |
|
|
assign cache_inhibit_with_eval = (hitmiss_eval & dcqmem_ci_i) |
|
161 |
|
|
(!hitmiss_eval & cache_inhibit);
|
162 |
|
|
|
163 |
|
|
//
|
164 |
|
|
// Generate of DCRAM write enables
|
165 |
|
|
//
|
166 |
10 |
unneback |
|
167 |
258 |
julius |
// WE when non-writethrough, and had to wait for a line to load.
|
168 |
|
|
assign dcram_we_after_line_load = (state == `OR1200_DCFSM_LOOP3) &
|
169 |
|
|
dcqmem_we_i & !cache_dirty_needs_writeback &
|
170 |
|
|
!did_early_load_ack;
|
171 |
10 |
unneback |
|
172 |
258 |
julius |
// WE when receiving the data cache line
|
173 |
|
|
assign dcram_we_during_line_load = (state == `OR1200_DCFSM_LOOP2) & load &
|
174 |
|
|
biudata_valid;
|
175 |
|
|
|
176 |
|
|
assign dcram_we =(// Write when hit - make sure it is only when hit - could
|
177 |
|
|
// maybe be doing write through and don't want to corrupt
|
178 |
|
|
// cache lines corresponding to the writethrough addr_r.
|
179 |
|
|
({4{store_hit_ack | store_hit_writethrough_ack}} |
|
180 |
|
|
// Write after load of line
|
181 |
|
|
{4{dcram_we_after_line_load}}) &
|
182 |
|
|
dcqmem_sel_i ) |
|
183 |
|
|
// Write during load
|
184 |
|
|
{4{dcram_we_during_line_load}};
|
185 |
10 |
unneback |
|
186 |
258 |
julius |
//
|
187 |
|
|
// Tag RAM signals
|
188 |
|
|
//
|
189 |
|
|
|
190 |
|
|
// WE to tag RAM when we finish loading a line.
|
191 |
|
|
assign tagram_we_end_of_loadstore_loop = ((state==`OR1200_DCFSM_LOOP2) &
|
192 |
|
|
biudata_valid & !(|cnt));
|
193 |
|
|
|
194 |
|
|
`ifndef OR1200_DC_WRITETHROUGH
|
195 |
|
|
// No writethrough, so mark a line dirty whenever we write to it
|
196 |
|
|
assign tagram_dirty_bit_set = store_hit_ack | store_miss_ack;
|
197 |
10 |
unneback |
|
198 |
258 |
julius |
// Generate done signal for MTSPR instructions that may block execution
|
199 |
|
|
assign mtspr_dc_done = // Either DC disabled or we're not selected, or
|
200 |
|
|
!dc_en | !spr_cswe |
|
201 |
|
|
// Requested address not valid or writeback and !dirty
|
202 |
|
|
((state==`OR1200_DCFSM_FLUSH5) &
|
203 |
|
|
(!tag_v | (cache_spr_block_writeback & !dirty))) |
|
204 |
|
|
// Writeback or flush is finished
|
205 |
|
|
((state==`OR1200_DCFSM_LOOP3) &
|
206 |
|
|
(cache_spr_block_flush | cache_spr_block_writeback))|
|
207 |
|
|
// Invalidate of clean line finished
|
208 |
|
|
((state==`OR1200_DCFSM_INV6) & cache_spr_block_flush);
|
209 |
|
|
|
210 |
|
|
|
211 |
|
|
`else
|
212 |
|
|
`ifdef OR1200_DC_NOSTACKWRITETHROUGH
|
213 |
|
|
// For dirty bit setting when having writethrough but not for stack
|
214 |
|
|
assign tagram_dirty_bit_set = store_hit_ack | store_miss_ack;
|
215 |
|
|
`else
|
216 |
|
|
// Lines will never be dirty if always writethrough
|
217 |
|
|
assign tagram_dirty_bit_set = 0;
|
218 |
|
|
`endif
|
219 |
|
|
|
220 |
|
|
assign mtspr_dc_done = 1'b1;
|
221 |
|
|
|
222 |
|
|
`endif
|
223 |
10 |
unneback |
|
224 |
258 |
julius |
assign tag_dirty = tagram_dirty_bit_set;
|
225 |
|
|
|
226 |
|
|
// WE to tag RAM
|
227 |
|
|
assign tag_we = tagram_we_end_of_loadstore_loop |
|
228 |
|
|
tagram_dirty_bit_set | (state == `OR1200_DCFSM_INV6);
|
229 |
|
|
|
230 |
10 |
unneback |
|
231 |
258 |
julius |
// Valid bit
|
232 |
|
|
// Set valid when end of line load, or marking dirty (is still valid)
|
233 |
|
|
assign tag_valid = ( tagram_we_end_of_loadstore_loop &
|
234 |
|
|
(load | (store & cache_spr_block_writeback)) ) |
|
235 |
|
|
tagram_dirty_bit_set;
|
236 |
10 |
unneback |
|
237 |
258 |
julius |
|
238 |
|
|
|
239 |
|
|
//
|
240 |
|
|
// BIU read and write
|
241 |
|
|
//
|
242 |
|
|
|
243 |
|
|
assign biu_read = // Bus read request when:
|
244 |
|
|
// 1) Have a miss and not dirty or a load with inhibit
|
245 |
|
|
((state == `OR1200_DCFSM_CLOADSTORE) &
|
246 |
|
|
(((hitmiss_eval & tagcomp_miss & !dirty &
|
247 |
|
|
!(store & writethrough)) |
|
248 |
|
|
(load & cache_inhibit_with_eval)) & dcqmem_cycstb_i)) |
|
249 |
|
|
// 2) In the loop and loading
|
250 |
|
|
((state == `OR1200_DCFSM_LOOP2) & load);
|
251 |
|
|
|
252 |
|
|
|
253 |
|
|
assign biu_write = // Bus write request when:
|
254 |
|
|
// 1) Have a miss and dirty or store with inhibit
|
255 |
|
|
((state == `OR1200_DCFSM_CLOADSTORE) &
|
256 |
|
|
(((hitmiss_eval & tagcomp_miss & dirty) |
|
257 |
|
|
(store & writethrough)) |
|
258 |
|
|
(store & cache_inhibit_with_eval)) & dcqmem_cycstb_i) |
|
259 |
|
|
// 2) In the loop and storing
|
260 |
|
|
((state == `OR1200_DCFSM_LOOP2) & store);
|
261 |
|
|
|
262 |
|
|
//
|
263 |
|
|
// Select for data to actual cache RAM (from LSU or BIU)
|
264 |
|
|
//
|
265 |
|
|
// Data to DCRAM - from external bus when loading (from IU when store)
|
266 |
|
|
assign dcram_di_sel = load;
|
267 |
|
|
// Data to external bus - always from IU except in case of bursting back
|
268 |
|
|
// the line to memory. (1 selects DCRAM)
|
269 |
|
|
assign biu_do_sel = (state == `OR1200_DCFSM_LOOP2) & store;
|
270 |
|
|
|
271 |
|
|
// 2-bit wire for calculating next word of burst write
|
272 |
|
|
assign next_addr_word = addr_r[3:2] + 1;
|
273 |
|
|
|
274 |
|
|
// Address to cache RAM (tag address also derived from this)
|
275 |
|
|
assign dc_addr =
|
276 |
|
|
// First check if we've got a block flush or WB op
|
277 |
|
|
((dc_block_flush & !cache_spr_block_flush) |
|
278 |
|
|
(dc_block_writeback & !cache_spr_block_writeback)) ?
|
279 |
|
|
spr_dat_i :
|
280 |
|
|
(state==`OR1200_DCFSM_FLUSH5) ? addr_r:
|
281 |
|
|
// If no SPR action, then always put out address from LSU
|
282 |
|
|
(state==`OR1200_DCFSM_IDLE | hitmiss_eval) ? lsu_addr :
|
283 |
|
|
// Next, if in writeback loop, when ACKed must immediately
|
284 |
|
|
// output next word address (the RAM address takes a cycle
|
285 |
|
|
// to increment, but it's needed immediately for burst)
|
286 |
|
|
// otherwise, output our registered address.
|
287 |
|
|
(state==`OR1200_DCFSM_LOOP2 & biudata_valid & store ) ?
|
288 |
|
|
{addr_r[31:4], next_addr_word, 2'b00} : addr_r;
|
289 |
|
|
|
290 |
|
|
`ifdef OR1200_DC_WRITETHROUGH
|
291 |
|
|
`ifdef OR1200_DC_NOSTACKWRITETHROUGH
|
292 |
|
|
assign writethrough = !dc_no_writethrough;
|
293 |
|
|
`else
|
294 |
|
|
assign writethrough = 1;
|
295 |
|
|
`endif
|
296 |
|
|
`else
|
297 |
|
|
assign writethrough = 0;
|
298 |
|
|
`endif
|
299 |
|
|
|
300 |
|
|
//
|
301 |
|
|
// ACK generation for LSU
|
302 |
|
|
//
|
303 |
|
|
|
304 |
|
|
// ACK for when it's a cache hit
|
305 |
|
|
assign first_hit_ack = load_hit_ack | store_hit_ack |
|
306 |
|
|
store_hit_writethrough_ack |
|
307 |
|
|
store_miss_writethrough_ack |
|
308 |
|
|
store_inhibit_ack | store_miss_ack ;
|
309 |
|
|
|
310 |
|
|
// ACK for when it's a cache miss - load only, is used in MUX for data back
|
311 |
|
|
// LSU straight off external data bus. In
|
312 |
|
|
// this was is also used for cache inhibit
|
313 |
|
|
// loads.
|
314 |
|
|
assign first_miss_ack = load_miss_ack | load_inhibit_ack;
|
315 |
|
|
|
316 |
|
|
// ACK cache hit on load
|
317 |
|
|
assign load_hit_ack = (state == `OR1200_DCFSM_CLOADSTORE) &
|
318 |
|
|
hitmiss_eval & !tagcomp_miss & !dcqmem_ci_i & load;
|
319 |
|
|
|
320 |
|
|
// ACK cache hit on store, no writethrough
|
321 |
|
|
assign store_hit_ack = (state == `OR1200_DCFSM_CLOADSTORE) &
|
322 |
|
|
hitmiss_eval & !tagcomp_miss & !dcqmem_ci_i &
|
323 |
|
|
store & !writethrough;
|
324 |
|
|
|
325 |
|
|
// ACK cache hit on store with writethrough
|
326 |
|
|
assign store_hit_writethrough_ack = (state == `OR1200_DCFSM_CLOADSTORE) &
|
327 |
|
|
!cache_miss & !cache_inhibit &
|
328 |
|
|
store & writethrough & biudata_valid;
|
329 |
|
|
|
330 |
|
|
// ACK cache miss on store with writethrough
|
331 |
|
|
assign store_miss_writethrough_ack = (state == `OR1200_DCFSM_CLOADSTORE) &
|
332 |
|
|
cache_miss & !cache_inhibit &
|
333 |
|
|
store & writethrough & biudata_valid;
|
334 |
|
|
|
335 |
|
|
// ACK store when cacheinhibit
|
336 |
|
|
assign store_inhibit_ack = (state == `OR1200_DCFSM_CLOADSTORE) &
|
337 |
|
|
store & cache_inhibit & biudata_valid;
|
338 |
|
|
|
339 |
|
|
|
340 |
|
|
// Get the _early_ ack on first ACK back from wishbone during load only
|
341 |
|
|
// Condition is that we're in the loop - that it's the first ack we get (can
|
342 |
|
|
// tell from value of cnt), and we're loading a line to read from it (not
|
343 |
|
|
// loading to write to it, in the case of a write without writethrough.)
|
344 |
|
|
assign load_miss_ack = ((state== `OR1200_DCFSM_LOOP2) & load &
|
345 |
|
|
(cnt==`OR1200_DCLS-1) & biudata_valid &
|
346 |
|
|
!(dcqmem_we_i & !writethrough));
|
347 |
|
|
|
348 |
|
|
assign load_inhibit_ack = (state == `OR1200_DCFSM_CLOADSTORE) &
|
349 |
|
|
load & cache_inhibit & biudata_valid;
|
350 |
|
|
|
351 |
|
|
// This will be case of write through disabled, and had to load a line.
|
352 |
|
|
assign store_miss_ack = dcram_we_after_line_load;
|
353 |
|
|
|
354 |
|
|
assign first_miss_err = biudata_error & dcqmem_cycstb_i;
|
355 |
|
|
|
356 |
|
|
// Signal burst when in the load/store loop. We will always try to burst.
|
357 |
|
|
assign burst = (state == `OR1200_DCFSM_LOOP2);
|
358 |
|
|
|
359 |
|
|
//
|
360 |
|
|
// Main DC FSM
|
361 |
|
|
//
|
362 |
358 |
julius |
always @(posedge clk or `OR1200_RST_EVENT rst) begin
|
363 |
|
|
if (rst == `OR1200_RST_VALUE) begin
|
364 |
258 |
julius |
state <= `OR1200_DCFSM_IDLE;
|
365 |
|
|
addr_r <= 32'b0;
|
366 |
|
|
hitmiss_eval <= 1'b0;
|
367 |
|
|
store <= 1'b0;
|
368 |
|
|
load <= 1'b0;
|
369 |
364 |
julius |
cnt <= 3'd0;
|
370 |
258 |
julius |
cache_miss <= 1'b0;
|
371 |
|
|
cache_dirty_needs_writeback <= 1'b0;
|
372 |
|
|
cache_inhibit <= 1'b0;
|
373 |
|
|
did_early_load_ack <= 1'b0;
|
374 |
|
|
cache_spr_block_flush <= 1'b0;
|
375 |
|
|
cache_spr_block_writeback <= 1'b0;
|
376 |
|
|
end
|
377 |
|
|
else
|
378 |
10 |
unneback |
case (state) // synopsys parallel_case
|
379 |
258 |
julius |
|
380 |
|
|
`OR1200_DCFSM_IDLE : begin
|
381 |
|
|
if (dc_en & (dc_block_flush | dc_block_writeback))
|
382 |
|
|
begin
|
383 |
|
|
cache_spr_block_flush <= dc_block_flush;
|
384 |
|
|
cache_spr_block_writeback <= dc_block_writeback;
|
385 |
|
|
hitmiss_eval <= 1'b1;
|
386 |
|
|
state <= `OR1200_DCFSM_FLUSH5;
|
387 |
|
|
addr_r <= spr_dat_i;
|
388 |
|
|
end
|
389 |
|
|
else if (dc_en & dcqmem_cycstb_i)
|
390 |
|
|
begin
|
391 |
|
|
state <= `OR1200_DCFSM_CLOADSTORE;
|
392 |
|
|
hitmiss_eval <= 1'b1;
|
393 |
|
|
store <= dcqmem_we_i;
|
394 |
|
|
load <= !dcqmem_we_i;
|
395 |
|
|
end
|
396 |
|
|
|
397 |
|
|
|
398 |
|
|
end // case: `OR1200_DCFSM_IDLE
|
399 |
|
|
|
400 |
|
|
`OR1200_DCFSM_CLOADSTORE: begin
|
401 |
|
|
hitmiss_eval <= 1'b0;
|
402 |
|
|
if (hitmiss_eval) begin
|
403 |
|
|
cache_inhibit <= dcqmem_ci_i; // Check for cache inhibit here
|
404 |
|
|
cache_miss <= tagcomp_miss;
|
405 |
|
|
cache_dirty_needs_writeback <= dirty;
|
406 |
|
|
addr_r <= lsu_addr;
|
407 |
|
|
end
|
408 |
|
|
|
409 |
|
|
// Evaluate any cache line load/stores in first cycle:
|
410 |
|
|
//
|
411 |
|
|
if (hitmiss_eval & tagcomp_miss & !(store & writethrough) &
|
412 |
|
|
!dcqmem_ci_i)
|
413 |
|
|
begin
|
414 |
|
|
// Miss - first either:
|
415 |
|
|
// 1) write back dirty line
|
416 |
|
|
if (dirty) begin
|
417 |
|
|
// Address for writeback
|
418 |
|
|
addr_r <= {tag, lsu_addr[`OR1200_DCINDXH:2],2'd0};
|
419 |
|
|
load <= 1'b0;
|
420 |
|
|
store <= 1'b1;
|
421 |
|
|
`ifdef OR1200_VERBOSE
|
422 |
|
|
$display("%t: dcache miss and dirty", $time);
|
423 |
10 |
unneback |
`endif
|
424 |
258 |
julius |
end
|
425 |
|
|
// 2) load requested line
|
426 |
|
|
else begin
|
427 |
|
|
addr_r <= lsu_addr;
|
428 |
|
|
load <= 1'b1;
|
429 |
|
|
store <= 1'b0;
|
430 |
|
|
end // else: !if(dirty)
|
431 |
|
|
state <= `OR1200_DCFSM_LOOP2;
|
432 |
|
|
// Set the counter for the burst accesses
|
433 |
|
|
cnt <= `OR1200_DCLS-1;
|
434 |
|
|
end
|
435 |
|
|
else if (// Strobe goes low
|
436 |
|
|
!dcqmem_cycstb_i |
|
437 |
|
|
// Cycle finishes
|
438 |
|
|
(!hitmiss_eval & (biudata_valid | biudata_error)) |
|
439 |
|
|
// Cache hit in first cycle....
|
440 |
|
|
(hitmiss_eval & !tagcomp_miss & !dcqmem_ci_i &
|
441 |
|
|
// .. and you're not doing a writethrough store..
|
442 |
|
|
!(store & writethrough))) begin
|
443 |
|
|
state <= `OR1200_DCFSM_IDLE;
|
444 |
|
|
load <= 1'b0;
|
445 |
|
|
store <= 1'b0;
|
446 |
|
|
cache_inhibit <= 1'b0;
|
447 |
|
|
cache_dirty_needs_writeback <= 1'b0;
|
448 |
|
|
end
|
449 |
|
|
end // case: `OR1200_DCFSM_CLOADSTORE
|
450 |
|
|
|
451 |
|
|
`OR1200_DCFSM_LOOP2 : begin // loop/abort
|
452 |
|
|
if (!dc_en| biudata_error) begin
|
453 |
|
|
state <= `OR1200_DCFSM_IDLE;
|
454 |
|
|
load <= 1'b0;
|
455 |
|
|
store <= 1'b0;
|
456 |
364 |
julius |
cnt <= 3'd0;
|
457 |
258 |
julius |
end
|
458 |
|
|
if (biudata_valid & (|cnt)) begin
|
459 |
364 |
julius |
cnt <= cnt - 3'd1;
|
460 |
258 |
julius |
addr_r[3:2] <= addr_r[3:2] + 1'b1;
|
461 |
|
|
end
|
462 |
|
|
else if (biudata_valid & !(|cnt)) begin
|
463 |
|
|
state <= `OR1200_DCFSM_LOOP3;
|
464 |
|
|
addr_r <= lsu_addr;
|
465 |
|
|
load <= 1'b0;
|
466 |
|
|
store <= 1'b0;
|
467 |
|
|
end
|
468 |
|
|
|
469 |
|
|
// Track if we did an early ack during a load
|
470 |
|
|
if (load_miss_ack)
|
471 |
|
|
did_early_load_ack <= 1'b1;
|
472 |
|
|
|
473 |
|
|
|
474 |
|
|
end // case: `OR1200_DCFSM_LOOP2
|
475 |
|
|
|
476 |
|
|
`OR1200_DCFSM_LOOP3: begin // figure out next step
|
477 |
|
|
if (cache_dirty_needs_writeback) begin
|
478 |
|
|
// Just did store of the dirty line so now load new one
|
479 |
|
|
load <= 1'b1;
|
480 |
|
|
// Set the counter for the burst accesses
|
481 |
|
|
cnt <= `OR1200_DCLS-1;
|
482 |
|
|
// Address of line to be loaded
|
483 |
|
|
addr_r <= lsu_addr;
|
484 |
|
|
cache_dirty_needs_writeback <= 1'b0;
|
485 |
|
|
state <= `OR1200_DCFSM_LOOP2;
|
486 |
|
|
end // if (cache_dirty_needs_writeback)
|
487 |
|
|
else if (cache_spr_block_flush | cache_spr_block_writeback) begin
|
488 |
|
|
// Just wrote back the line to memory, we're finished.
|
489 |
|
|
cache_spr_block_flush <= 1'b0;
|
490 |
|
|
cache_spr_block_writeback <= 1'b0;
|
491 |
|
|
state <= `OR1200_DCFSM_WAITSPRCS7;
|
492 |
|
|
end
|
493 |
|
|
else begin
|
494 |
|
|
// Just loaded a new line, finish up
|
495 |
|
|
did_early_load_ack <= 1'b0;
|
496 |
|
|
state <= `OR1200_DCFSM_LOOP4;
|
497 |
|
|
end
|
498 |
|
|
end // case: `OR1200_DCFSM_LOOP3
|
499 |
|
|
|
500 |
|
|
`OR1200_DCFSM_LOOP4: begin
|
501 |
|
|
state <= `OR1200_DCFSM_IDLE;
|
502 |
|
|
end
|
503 |
|
|
|
504 |
|
|
`OR1200_DCFSM_FLUSH5: begin
|
505 |
|
|
hitmiss_eval <= 1'b0;
|
506 |
|
|
if (hitmiss_eval & !tag_v)
|
507 |
|
|
begin
|
508 |
|
|
// Not even cached, just ignore
|
509 |
|
|
cache_spr_block_flush <= 1'b0;
|
510 |
|
|
cache_spr_block_writeback <= 1'b0;
|
511 |
|
|
state <= `OR1200_DCFSM_WAITSPRCS7;
|
512 |
|
|
end
|
513 |
|
|
else if (hitmiss_eval & tag_v)
|
514 |
|
|
begin
|
515 |
|
|
// Tag is valid - what do we do?
|
516 |
|
|
if ((cache_spr_block_flush | cache_spr_block_writeback) &
|
517 |
|
|
dirty) begin
|
518 |
|
|
// Need to writeback
|
519 |
|
|
// Address for writeback (spr_dat_i has already changed so
|
520 |
|
|
// use line number from addr_r)
|
521 |
|
|
addr_r <= {tag, addr_r[`OR1200_DCINDXH:2],2'd0};
|
522 |
|
|
load <= 1'b0;
|
523 |
|
|
store <= 1'b1;
|
524 |
|
|
`ifdef OR1200_VERBOSE
|
525 |
|
|
$display("%t: block flush: dirty block", $time);
|
526 |
10 |
unneback |
`endif
|
527 |
258 |
julius |
state <= `OR1200_DCFSM_LOOP2;
|
528 |
|
|
// Set the counter for the burst accesses
|
529 |
|
|
cnt <= `OR1200_DCLS-1;
|
530 |
|
|
end
|
531 |
|
|
else if (cache_spr_block_flush & !dirty)
|
532 |
|
|
begin
|
533 |
|
|
// Line not dirty, just need to invalidate
|
534 |
|
|
state <= `OR1200_DCFSM_INV6;
|
535 |
|
|
end // else: !if(dirty)
|
536 |
|
|
else if (cache_spr_block_writeback & !dirty)
|
537 |
|
|
begin
|
538 |
|
|
// Nothing to do - line is valid but not dirty
|
539 |
|
|
cache_spr_block_writeback <= 1'b0;
|
540 |
|
|
state <= `OR1200_DCFSM_WAITSPRCS7;
|
541 |
|
|
end
|
542 |
|
|
end // if (hitmiss_eval & tag_v)
|
543 |
|
|
end
|
544 |
|
|
`OR1200_DCFSM_INV6: begin
|
545 |
|
|
cache_spr_block_flush <= 1'b0;
|
546 |
|
|
// Wait until SPR CS goes low before going back to idle
|
547 |
|
|
if (!spr_cswe)
|
548 |
|
|
state <= `OR1200_DCFSM_IDLE;
|
549 |
|
|
end
|
550 |
|
|
`OR1200_DCFSM_WAITSPRCS7: begin
|
551 |
|
|
// Wait until SPR CS goes low before going back to idle
|
552 |
|
|
if (!spr_cswe)
|
553 |
|
|
state <= `OR1200_DCFSM_IDLE;
|
554 |
|
|
end
|
555 |
141 |
marcus.erl |
|
556 |
258 |
julius |
endcase // case (state)
|
557 |
|
|
|
558 |
358 |
julius |
end // always @ (posedge clk or `OR1200_RST_EVENT rst)
|
559 |
258 |
julius |
|
560 |
10 |
unneback |
|
561 |
|
|
endmodule
|