1 |
2 |
tobil |
//////////////////////////////////////////////////////////////////////
|
2 |
|
|
//// ////
|
3 |
|
|
//// OR1200's IC FSM ////
|
4 |
|
|
//// ////
|
5 |
|
|
//// This file is part of the OpenRISC 1200 project ////
|
6 |
|
|
//// http://www.opencores.org/cores/or1k/ ////
|
7 |
|
|
//// ////
|
8 |
|
|
//// Description ////
|
9 |
|
|
//// Insn cache state machine ////
|
10 |
|
|
//// ////
|
11 |
|
|
//// To Do: ////
|
12 |
|
|
//// - make it smaller and faster ////
|
13 |
|
|
//// ////
|
14 |
|
|
//// Author(s): ////
|
15 |
|
|
//// - Damjan Lampret, lampret@opencores.org ////
|
16 |
|
|
//// ////
|
17 |
|
|
//////////////////////////////////////////////////////////////////////
|
18 |
|
|
//// ////
|
19 |
|
|
//// Copyright (C) 2000 Authors and OPENCORES.ORG ////
|
20 |
|
|
//// ////
|
21 |
|
|
//// This source file may be used and distributed without ////
|
22 |
|
|
//// restriction provided that this copyright statement is not ////
|
23 |
|
|
//// removed from the file and that any derivative work contains ////
|
24 |
|
|
//// the original copyright notice and the associated disclaimer. ////
|
25 |
|
|
//// ////
|
26 |
|
|
//// This source file is free software; you can redistribute it ////
|
27 |
|
|
//// and/or modify it under the terms of the GNU Lesser General ////
|
28 |
|
|
//// Public License as published by the Free Software Foundation; ////
|
29 |
|
|
//// either version 2.1 of the License, or (at your option) any ////
|
30 |
|
|
//// later version. ////
|
31 |
|
|
//// ////
|
32 |
|
|
//// This source is distributed in the hope that it will be ////
|
33 |
|
|
//// useful, but WITHOUT ANY WARRANTY; without even the implied ////
|
34 |
|
|
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ////
|
35 |
|
|
//// PURPOSE. See the GNU Lesser General Public License for more ////
|
36 |
|
|
//// details. ////
|
37 |
|
|
//// ////
|
38 |
|
|
//// You should have received a copy of the GNU Lesser General ////
|
39 |
|
|
//// Public License along with this source; if not, download it ////
|
40 |
|
|
//// from http://www.opencores.org/lgpl.shtml ////
|
41 |
|
|
//// ////
|
42 |
|
|
//////////////////////////////////////////////////////////////////////
|
43 |
|
|
//
|
44 |
|
|
// CVS Revision History
|
45 |
|
|
//
|
46 |
|
|
// $Log: not supported by cvs2svn $
|
47 |
|
|
// Revision 1.9 2004/04/05 08:29:57 lampret
|
48 |
|
|
// Merged branch_qmem into main tree.
|
49 |
|
|
//
|
50 |
|
|
// Revision 1.8.4.1 2003/07/08 15:36:37 lampret
|
51 |
|
|
// Added embedded memory QMEM.
|
52 |
|
|
//
|
53 |
|
|
// Revision 1.8 2003/06/06 02:54:47 lampret
|
54 |
|
|
// When OR1200_NO_IMMU and OR1200_NO_IC are not both defined or undefined at the same time, results in a IC bug. Fixed.
|
55 |
|
|
//
|
56 |
|
|
// Revision 1.7 2002/03/29 15:16:55 lampret
|
57 |
|
|
// Some of the warnings fixed.
|
58 |
|
|
//
|
59 |
|
|
// Revision 1.6 2002/03/28 19:10:40 lampret
|
60 |
|
|
// Optimized cache controller FSM.
|
61 |
|
|
//
|
62 |
|
|
// Revision 1.1.1.1 2002/03/21 16:55:45 lampret
|
63 |
|
|
// First import of the "new" XESS XSV environment.
|
64 |
|
|
//
|
65 |
|
|
//
|
66 |
|
|
// Revision 1.5 2002/02/11 04:33:17 lampret
|
67 |
|
|
// Speed optimizations (removed duplicate _cyc_ and _stb_). Fixed D/IMMU cache-inhibit attr.
|
68 |
|
|
//
|
69 |
|
|
// Revision 1.4 2002/02/01 19:56:54 lampret
|
70 |
|
|
// Fixed combinational loops.
|
71 |
|
|
//
|
72 |
|
|
// Revision 1.3 2002/01/28 01:16:00 lampret
|
73 |
|
|
// Changed 'void' nop-ops instead of insn[0] to use insn[16]. Debug unit stalls the tick timer. Prepared new flag generation for add and and insns. Blocked DC/IC while they are turned off. Fixed I/D MMU SPRs layout except WAYs. TODO: smart IC invalidate, l.j 2 and TLB ways.
|
74 |
|
|
//
|
75 |
|
|
// Revision 1.2 2002/01/14 06:18:22 lampret
|
76 |
|
|
// Fixed mem2reg bug in FAST implementation. Updated debug unit to work with new genpc/if.
|
77 |
|
|
//
|
78 |
|
|
// Revision 1.1 2002/01/03 08:16:15 lampret
|
79 |
|
|
// New prefixes for RTL files, prefixed module names. Updated cache controllers and MMUs.
|
80 |
|
|
//
|
81 |
|
|
// Revision 1.9 2001/10/21 17:57:16 lampret
|
82 |
|
|
// Removed params from generic_XX.v. Added translate_off/on in sprs.v and id.v. Removed spr_addr from ic.v and ic.v. Fixed CR+LF.
|
83 |
|
|
//
|
84 |
|
|
// Revision 1.8 2001/10/19 23:28:46 lampret
|
85 |
|
|
// Fixed some synthesis warnings. Configured with caches and MMUs.
|
86 |
|
|
//
|
87 |
|
|
// Revision 1.7 2001/10/14 13:12:09 lampret
|
88 |
|
|
// MP3 version.
|
89 |
|
|
//
|
90 |
|
|
// Revision 1.1.1.1 2001/10/06 10:18:35 igorm
|
91 |
|
|
// no message
|
92 |
|
|
//
|
93 |
|
|
// Revision 1.2 2001/08/09 13:39:33 lampret
|
94 |
|
|
// Major clean-up.
|
95 |
|
|
//
|
96 |
|
|
// Revision 1.1 2001/07/20 00:46:03 lampret
|
97 |
|
|
// Development version of RTL. Libraries are missing.
|
98 |
|
|
//
|
99 |
|
|
//
|
100 |
|
|
|
101 |
|
|
// synopsys translate_off
|
102 |
|
|
`include "timescale.v"
|
103 |
|
|
// synopsys translate_on
|
104 |
|
|
`include "or1200_defines.v"
|
105 |
|
|
|
106 |
|
|
`define OR1200_ICFSM_IDLE 2'd0
|
107 |
|
|
`define OR1200_ICFSM_CFETCH 2'd1
|
108 |
|
|
`define OR1200_ICFSM_LREFILL3 2'd2
|
109 |
|
|
`define OR1200_ICFSM_IFETCH 2'd3
|
110 |
|
|
|
111 |
|
|
//
|
112 |
|
|
// Data cache FSM for cache line of 16 bytes (4x singleword)
|
113 |
|
|
//
|
114 |
|
|
|
115 |
|
|
module or1200_ic_fsm_cm4(
|
116 |
|
|
clk_i_cml_1,
|
117 |
|
|
clk_i_cml_2,
|
118 |
|
|
clk_i_cml_3,
|
119 |
|
|
|
120 |
|
|
// Clock and reset
|
121 |
|
|
clk, rst,
|
122 |
|
|
|
123 |
|
|
// Internal i/f to top level IC
|
124 |
|
|
ic_en, icqmem_cycstb_i, icqmem_ci_i,
|
125 |
|
|
tagcomp_miss, biudata_valid, biudata_error, start_addr, saved_addr,
|
126 |
|
|
icram_we, biu_read, first_hit_ack, first_miss_ack, first_miss_err,
|
127 |
|
|
burst, tag_we
|
128 |
|
|
);
|
129 |
|
|
|
130 |
|
|
|
131 |
|
|
input clk_i_cml_1;
|
132 |
|
|
input clk_i_cml_2;
|
133 |
|
|
input clk_i_cml_3;
|
134 |
|
|
reg ic_en_cml_3;
|
135 |
|
|
reg ic_en_cml_2;
|
136 |
|
|
reg ic_en_cml_1;
|
137 |
|
|
reg icqmem_ci_i_cml_1;
|
138 |
|
|
reg tagcomp_miss_cml_3;
|
139 |
|
|
reg tagcomp_miss_cml_2;
|
140 |
|
|
reg biudata_valid_cml_3;
|
141 |
|
|
reg biudata_valid_cml_2;
|
142 |
|
|
reg biudata_valid_cml_1;
|
143 |
|
|
reg biudata_error_cml_3;
|
144 |
|
|
reg biudata_error_cml_2;
|
145 |
|
|
reg biudata_error_cml_1;
|
146 |
|
|
reg biu_read_cml_3;
|
147 |
|
|
reg [ 31 : 0 ] saved_addr_r_cml_3;
|
148 |
|
|
reg [ 31 : 0 ] saved_addr_r_cml_2;
|
149 |
|
|
reg [ 31 : 0 ] saved_addr_r_cml_1;
|
150 |
|
|
reg [ 1 : 0 ] state_cml_3;
|
151 |
|
|
reg [ 1 : 0 ] state_cml_2;
|
152 |
|
|
reg [ 1 : 0 ] state_cml_1;
|
153 |
|
|
reg [ 2 : 0 ] cnt_cml_3;
|
154 |
|
|
reg [ 2 : 0 ] cnt_cml_2;
|
155 |
|
|
reg [ 2 : 0 ] cnt_cml_1;
|
156 |
|
|
reg hitmiss_eval_cml_3;
|
157 |
|
|
reg hitmiss_eval_cml_2;
|
158 |
|
|
reg hitmiss_eval_cml_1;
|
159 |
|
|
reg load_cml_3;
|
160 |
|
|
reg load_cml_2;
|
161 |
|
|
reg load_cml_1;
|
162 |
|
|
reg cache_inhibit_cml_3;
|
163 |
|
|
reg cache_inhibit_cml_2;
|
164 |
|
|
reg cache_inhibit_cml_1;
|
165 |
|
|
|
166 |
|
|
|
167 |
|
|
|
168 |
|
|
//
|
169 |
|
|
// I/O
|
170 |
|
|
//
|
171 |
|
|
input clk;
|
172 |
|
|
input rst;
|
173 |
|
|
input ic_en;
|
174 |
|
|
input icqmem_cycstb_i;
|
175 |
|
|
input icqmem_ci_i;
|
176 |
|
|
input tagcomp_miss;
|
177 |
|
|
input biudata_valid;
|
178 |
|
|
input biudata_error;
|
179 |
|
|
input [31:0] start_addr;
|
180 |
|
|
output [31:0] saved_addr;
|
181 |
|
|
output [3:0] icram_we;
|
182 |
|
|
output biu_read;
|
183 |
|
|
output first_hit_ack;
|
184 |
|
|
output first_miss_ack;
|
185 |
|
|
output first_miss_err;
|
186 |
|
|
output burst;
|
187 |
|
|
output tag_we;
|
188 |
|
|
|
189 |
|
|
//
|
190 |
|
|
// Internal wires and regs
|
191 |
|
|
//
|
192 |
|
|
reg [31:0] saved_addr_r;
|
193 |
|
|
reg [1:0] state;
|
194 |
|
|
reg [2:0] cnt;
|
195 |
|
|
reg hitmiss_eval;
|
196 |
|
|
reg load;
|
197 |
|
|
reg cache_inhibit;
|
198 |
|
|
|
199 |
|
|
//
|
200 |
|
|
// Generate of ICRAM write enables
|
201 |
|
|
//
|
202 |
|
|
|
203 |
|
|
// SynEDA CoreMultiplier
|
204 |
|
|
// assignment(s): icram_we
|
205 |
|
|
// replace(s): biudata_valid, biu_read, cache_inhibit
|
206 |
|
|
assign icram_we = {4{biu_read_cml_3 & biudata_valid_cml_3 & !cache_inhibit_cml_3}};
|
207 |
|
|
|
208 |
|
|
|
209 |
|
|
// SynEDA CoreMultiplier
|
210 |
|
|
// assignment(s): tag_we
|
211 |
|
|
// replace(s): biudata_valid, biu_read, cache_inhibit
|
212 |
|
|
assign tag_we = biu_read_cml_3 & biudata_valid_cml_3 & !cache_inhibit_cml_3;
|
213 |
|
|
|
214 |
|
|
//
|
215 |
|
|
// BIU read and write
|
216 |
|
|
//
|
217 |
|
|
|
218 |
|
|
// SynEDA CoreMultiplier
|
219 |
|
|
// assignment(s): biu_read
|
220 |
|
|
// replace(s): tagcomp_miss, hitmiss_eval, load
|
221 |
|
|
assign biu_read = (hitmiss_eval_cml_2 & tagcomp_miss_cml_2) | (!hitmiss_eval_cml_2 & load_cml_2);
|
222 |
|
|
|
223 |
|
|
//assign saved_addr = hitmiss_eval ? start_addr : saved_addr_r;
|
224 |
|
|
assign saved_addr = saved_addr_r;
|
225 |
|
|
|
226 |
|
|
//
|
227 |
|
|
// Assert for cache hit first word ready
|
228 |
|
|
// Assert for cache miss first word stored/loaded OK
|
229 |
|
|
// Assert for cache miss first word stored/loaded with an error
|
230 |
|
|
//
|
231 |
|
|
|
232 |
|
|
// SynEDA CoreMultiplier
|
233 |
|
|
// assignment(s): first_hit_ack
|
234 |
|
|
// replace(s): icqmem_ci_i, state, hitmiss_eval, cache_inhibit
|
235 |
|
|
assign first_hit_ack = (state_cml_1 == `OR1200_ICFSM_CFETCH) & hitmiss_eval_cml_1 & !tagcomp_miss & !cache_inhibit_cml_1 & !icqmem_ci_i_cml_1;
|
236 |
|
|
assign first_miss_ack = (state == `OR1200_ICFSM_CFETCH) & biudata_valid;
|
237 |
|
|
assign first_miss_err = (state == `OR1200_ICFSM_CFETCH) & biudata_error;
|
238 |
|
|
|
239 |
|
|
//
|
240 |
|
|
// Assert burst when doing reload of complete cache line
|
241 |
|
|
//
|
242 |
|
|
|
243 |
|
|
// SynEDA CoreMultiplier
|
244 |
|
|
// assignment(s): burst
|
245 |
|
|
// replace(s): tagcomp_miss, state, cache_inhibit
|
246 |
|
|
assign burst = (state_cml_3 == `OR1200_ICFSM_CFETCH) & tagcomp_miss_cml_3 & !cache_inhibit_cml_3
|
247 |
|
|
| (state_cml_3 == `OR1200_ICFSM_LREFILL3);
|
248 |
|
|
|
249 |
|
|
//
|
250 |
|
|
// Main IC FSM
|
251 |
|
|
//
|
252 |
|
|
|
253 |
|
|
// SynEDA CoreMultiplier
|
254 |
|
|
// assignment(s): saved_addr_r, state, cnt, hitmiss_eval, load, cache_inhibit
|
255 |
|
|
// replace(s): ic_en, tagcomp_miss, biudata_valid, biudata_error, saved_addr_r, state, cnt, hitmiss_eval, cache_inhibit, load
|
256 |
|
|
always @(posedge clk or posedge rst) begin
|
257 |
|
|
if (rst) begin
|
258 |
|
|
state <= #1 `OR1200_ICFSM_IDLE;
|
259 |
|
|
saved_addr_r <= #1 32'b0;
|
260 |
|
|
hitmiss_eval <= #1 1'b0;
|
261 |
|
|
load <= #1 1'b0;
|
262 |
|
|
cnt <= #1 3'b000;
|
263 |
|
|
cache_inhibit <= #1 1'b0;
|
264 |
|
|
end
|
265 |
|
|
else begin cache_inhibit <= cache_inhibit_cml_3; load <= load_cml_3; hitmiss_eval <= hitmiss_eval_cml_3; cnt <= cnt_cml_3; state <= state_cml_3; saved_addr_r <= saved_addr_r_cml_3;
|
266 |
|
|
case (state_cml_3) // synopsys parallel_case
|
267 |
|
|
`OR1200_ICFSM_IDLE :
|
268 |
|
|
if (ic_en_cml_3 & icqmem_cycstb_i) begin // fetch
|
269 |
|
|
state <= #1 `OR1200_ICFSM_CFETCH;
|
270 |
|
|
saved_addr_r <= #1 start_addr;
|
271 |
|
|
hitmiss_eval <= #1 1'b1;
|
272 |
|
|
load <= #1 1'b1;
|
273 |
|
|
cache_inhibit <= #1 1'b0;
|
274 |
|
|
end
|
275 |
|
|
else begin // idle
|
276 |
|
|
hitmiss_eval <= #1 1'b0;
|
277 |
|
|
load <= #1 1'b0;
|
278 |
|
|
cache_inhibit <= #1 1'b0;
|
279 |
|
|
end
|
280 |
|
|
`OR1200_ICFSM_CFETCH: begin // fetch
|
281 |
|
|
if (icqmem_cycstb_i & icqmem_ci_i)
|
282 |
|
|
cache_inhibit <= #1 1'b1;
|
283 |
|
|
if (hitmiss_eval_cml_3)
|
284 |
|
|
saved_addr_r[31:13] <= #1 start_addr[31:13];
|
285 |
|
|
if ((!ic_en_cml_3) ||
|
286 |
|
|
(hitmiss_eval_cml_3 & !icqmem_cycstb_i) || // fetch aborted (usually caused by IMMU)
|
287 |
|
|
(biudata_error_cml_3) || // fetch terminated with an error
|
288 |
|
|
(cache_inhibit_cml_3 & biudata_valid_cml_3)) begin // fetch from cache-inhibited page
|
289 |
|
|
state <= #1 `OR1200_ICFSM_IDLE;
|
290 |
|
|
hitmiss_eval <= #1 1'b0;
|
291 |
|
|
load <= #1 1'b0;
|
292 |
|
|
cache_inhibit <= #1 1'b0;
|
293 |
|
|
end
|
294 |
|
|
else if (tagcomp_miss_cml_3 & biudata_valid_cml_3) begin // fetch missed, finish current external fetch and refill
|
295 |
|
|
state <= #1 `OR1200_ICFSM_LREFILL3;
|
296 |
|
|
saved_addr_r[3:2] <= #1 saved_addr_r_cml_3[3:2] + 1'd1;
|
297 |
|
|
hitmiss_eval <= #1 1'b0;
|
298 |
|
|
cnt <= #1 `OR1200_ICLS-2;
|
299 |
|
|
cache_inhibit <= #1 1'b0;
|
300 |
|
|
end
|
301 |
|
|
else if (!tagcomp_miss_cml_3 & !icqmem_ci_i) begin // fetch hit, finish immediately
|
302 |
|
|
saved_addr_r <= #1 start_addr;
|
303 |
|
|
cache_inhibit <= #1 1'b0;
|
304 |
|
|
end
|
305 |
|
|
else if (!icqmem_cycstb_i) begin // fetch aborted (usually caused by exception)
|
306 |
|
|
state <= #1 `OR1200_ICFSM_IDLE;
|
307 |
|
|
hitmiss_eval <= #1 1'b0;
|
308 |
|
|
load <= #1 1'b0;
|
309 |
|
|
cache_inhibit <= #1 1'b0;
|
310 |
|
|
end
|
311 |
|
|
else // fetch in-progress
|
312 |
|
|
hitmiss_eval <= #1 1'b0;
|
313 |
|
|
end
|
314 |
|
|
`OR1200_ICFSM_LREFILL3 : begin
|
315 |
|
|
if (biudata_valid_cml_3 && (|cnt_cml_3)) begin // refill ack, more fetchs to come
|
316 |
|
|
cnt <= #1 cnt_cml_3 - 3'd1;
|
317 |
|
|
saved_addr_r[3:2] <= #1 saved_addr_r_cml_3[3:2] + 1'd1;
|
318 |
|
|
end
|
319 |
|
|
else if (biudata_valid_cml_3) begin // last fetch of line refill
|
320 |
|
|
state <= #1 `OR1200_ICFSM_IDLE;
|
321 |
|
|
saved_addr_r <= #1 start_addr;
|
322 |
|
|
hitmiss_eval <= #1 1'b0;
|
323 |
|
|
load <= #1 1'b0;
|
324 |
|
|
end
|
325 |
|
|
end
|
326 |
|
|
default:
|
327 |
|
|
state <= #1 `OR1200_ICFSM_IDLE;
|
328 |
|
|
endcase end
|
329 |
|
|
end
|
330 |
|
|
|
331 |
|
|
|
332 |
|
|
always @ (posedge clk_i_cml_1) begin
|
333 |
|
|
ic_en_cml_1 <= ic_en;
|
334 |
|
|
icqmem_ci_i_cml_1 <= icqmem_ci_i;
|
335 |
|
|
biudata_valid_cml_1 <= biudata_valid;
|
336 |
|
|
biudata_error_cml_1 <= biudata_error;
|
337 |
|
|
saved_addr_r_cml_1 <= saved_addr_r;
|
338 |
|
|
state_cml_1 <= state;
|
339 |
|
|
cnt_cml_1 <= cnt;
|
340 |
|
|
hitmiss_eval_cml_1 <= hitmiss_eval;
|
341 |
|
|
load_cml_1 <= load;
|
342 |
|
|
cache_inhibit_cml_1 <= cache_inhibit;
|
343 |
|
|
end
|
344 |
|
|
always @ (posedge clk_i_cml_2) begin
|
345 |
|
|
ic_en_cml_2 <= ic_en_cml_1;
|
346 |
|
|
tagcomp_miss_cml_2 <= tagcomp_miss;
|
347 |
|
|
biudata_valid_cml_2 <= biudata_valid_cml_1;
|
348 |
|
|
biudata_error_cml_2 <= biudata_error_cml_1;
|
349 |
|
|
saved_addr_r_cml_2 <= saved_addr_r_cml_1;
|
350 |
|
|
state_cml_2 <= state_cml_1;
|
351 |
|
|
cnt_cml_2 <= cnt_cml_1;
|
352 |
|
|
hitmiss_eval_cml_2 <= hitmiss_eval_cml_1;
|
353 |
|
|
load_cml_2 <= load_cml_1;
|
354 |
|
|
cache_inhibit_cml_2 <= cache_inhibit_cml_1;
|
355 |
|
|
end
|
356 |
|
|
always @ (posedge clk_i_cml_3) begin
|
357 |
|
|
ic_en_cml_3 <= ic_en_cml_2;
|
358 |
|
|
tagcomp_miss_cml_3 <= tagcomp_miss_cml_2;
|
359 |
|
|
biudata_valid_cml_3 <= biudata_valid_cml_2;
|
360 |
|
|
biudata_error_cml_3 <= biudata_error_cml_2;
|
361 |
|
|
biu_read_cml_3 <= biu_read;
|
362 |
|
|
saved_addr_r_cml_3 <= saved_addr_r_cml_2;
|
363 |
|
|
state_cml_3 <= state_cml_2;
|
364 |
|
|
cnt_cml_3 <= cnt_cml_2;
|
365 |
|
|
hitmiss_eval_cml_3 <= hitmiss_eval_cml_2;
|
366 |
|
|
load_cml_3 <= load_cml_2;
|
367 |
|
|
cache_inhibit_cml_3 <= cache_inhibit_cml_2;
|
368 |
|
|
end
|
369 |
|
|
endmodule
|
370 |
|
|
|