OpenCores
URL https://opencores.org/ocsvn/or1200_hp/or1200_hp/trunk

Subversion Repositories or1200_hp

[/] [or1200_hp/] [trunk/] [rtl/] [rtl_cm4/] [verilog/] [or1200_dc_fsm.v] - Blame information for rev 3

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 tobil
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  OR1200's DC FSM                                             ////
4
////                                                              ////
5
////  This file is part of the OpenRISC 1200 project              ////
6
////  http://www.opencores.org/cores/or1k/                        ////
7
////                                                              ////
8
////  Description                                                 ////
9
////  Data 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.8  2004/04/05 08:29:57  lampret
48
// Merged branch_qmem into main tree.
49
//
50
// Revision 1.7.4.1  2003/07/08 15:36:37  lampret
51
// Added embedded memory QMEM.
52
//
53
// Revision 1.7  2002/03/29 15:16:55  lampret
54
// Some of the warnings fixed.
55
//
56
// Revision 1.6  2002/03/28 19:10:40  lampret
57
// Optimized cache controller FSM.
58
//
59
// Revision 1.1.1.1  2002/03/21 16:55:45  lampret
60
// First import of the "new" XESS XSV environment.
61
//
62
//
63
// Revision 1.5  2002/02/11 04:33:17  lampret
64
// Speed optimizations (removed duplicate _cyc_ and _stb_). Fixed D/IMMU cache-inhibit attr.
65
//
66
// Revision 1.4  2002/02/01 19:56:54  lampret
67
// Fixed combinational loops.
68
//
69
// Revision 1.3  2002/01/28 01:15:59  lampret
70
// 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.
71
//
72
// Revision 1.2  2002/01/14 06:18:22  lampret
73
// Fixed mem2reg bug in FAST implementation. Updated debug unit to work with new genpc/if.
74
//
75
// Revision 1.1  2002/01/03 08:16:15  lampret
76
// New prefixes for RTL files, prefixed module names. Updated cache controllers and MMUs.
77
//
78
// Revision 1.9  2001/10/21 17:57:16  lampret
79
// Removed params from generic_XX.v. Added translate_off/on in sprs.v and id.v. Removed spr_addr from dc.v and ic.v. Fixed CR+LF.
80
//
81
// Revision 1.8  2001/10/19 23:28:46  lampret
82
// Fixed some synthesis warnings. Configured with caches and MMUs.
83
//
84
// Revision 1.7  2001/10/14 13:12:09  lampret
85
// MP3 version.
86
//
87
// Revision 1.1.1.1  2001/10/06 10:18:35  igorm
88
// no message
89
//
90
// Revision 1.2  2001/08/09 13:39:33  lampret
91
// Major clean-up.
92
//
93
// Revision 1.1  2001/07/20 00:46:03  lampret
94
// Development version of RTL. Libraries are missing.
95
//
96
//
97
 
98
// synopsys translate_off
99
`include "timescale.v"
100
// synopsys translate_on
101
`include "or1200_defines.v"
102
 
103
`define OR1200_DCFSM_IDLE       3'd0
104
`define OR1200_DCFSM_CLOAD      3'd1
105
`define OR1200_DCFSM_LREFILL3   3'd2
106
`define OR1200_DCFSM_CSTORE     3'd3
107
`define OR1200_DCFSM_SREFILL4   3'd4
108
 
109
//
110
// Data cache FSM for cache line of 16 bytes (4x singleword)
111
//
112
 
113
module or1200_dc_fsm_cm4(
114
                clk_i_cml_1,
115
                clk_i_cml_2,
116
                clk_i_cml_3,
117
 
118
        // Clock and reset
119
        clk, rst,
120
 
121
        // Internal i/f to top level DC
122
        dc_en, dcqmem_cycstb_i, dcqmem_ci_i, dcqmem_we_i, dcqmem_sel_i,
123
        tagcomp_miss, biudata_valid, biudata_error, start_addr, saved_addr,
124
        dcram_we, biu_read, biu_write, first_hit_ack, first_miss_ack, first_miss_err,
125
        burst, tag_we, dc_addr
126
);
127
 
128
 
129
input clk_i_cml_1;
130
input clk_i_cml_2;
131
input clk_i_cml_3;
132
reg  dc_en_cml_3;
133
reg  dc_en_cml_2;
134
reg  dc_en_cml_1;
135
reg  dcqmem_ci_i_cml_3;
136
reg  dcqmem_ci_i_cml_2;
137
reg  dcqmem_ci_i_cml_1;
138
reg  tagcomp_miss_cml_3;
139
reg  tagcomp_miss_cml_2;
140
reg  tagcomp_miss_cml_1;
141
reg  biudata_valid_cml_3;
142
reg  biudata_valid_cml_2;
143
reg  biudata_valid_cml_1;
144
reg  biudata_error_cml_3;
145
reg  biudata_error_cml_2;
146
reg [ 31 : 0 ] start_addr_cml_3;
147
reg [ 31 : 0 ] saved_addr_cml_2;
148
reg [ 31 : 0 ] saved_addr_cml_1;
149
reg  biu_read_cml_3;
150
reg [ 31 : 0 ] saved_addr_r_cml_3;
151
reg [ 31 : 0 ] saved_addr_r_cml_2;
152
reg [ 31 : 0 ] saved_addr_r_cml_1;
153
reg [ 2 : 0 ] state_cml_3;
154
reg [ 2 : 0 ] state_cml_2;
155
reg [ 2 : 0 ] state_cml_1;
156
reg [ 2 : 0 ] cnt_cml_3;
157
reg [ 2 : 0 ] cnt_cml_2;
158
reg [ 2 : 0 ] cnt_cml_1;
159
reg  hitmiss_eval_cml_3;
160
reg  hitmiss_eval_cml_2;
161
reg  hitmiss_eval_cml_1;
162
reg  store_cml_3;
163
reg  store_cml_2;
164
reg  store_cml_1;
165
reg  load_cml_3;
166
reg  load_cml_2;
167
reg  load_cml_1;
168
reg  cache_inhibit_cml_3;
169
reg  cache_inhibit_cml_2;
170
reg  cache_inhibit_cml_1;
171
reg  first_store_hit_ack_cml_3;
172
reg  first_store_hit_ack_cml_2;
173
reg  first_store_hit_ack_cml_1;
174
 
175
 
176
 
177
//
178
// I/O
179
//
180
input                           clk;
181
input                           rst;
182
input                           dc_en;
183
input                           dcqmem_cycstb_i;
184
input                           dcqmem_ci_i;
185
input                           dcqmem_we_i;
186
input   [3:0]                    dcqmem_sel_i;
187
input                           tagcomp_miss;
188
input                           biudata_valid;
189
input                           biudata_error;
190
input   [31:0]                   start_addr;
191
output  [31:0]                   saved_addr;
192
output  [3:0]                    dcram_we;
193
output                          biu_read;
194
output                          biu_write;
195
output                          first_hit_ack;
196
output                          first_miss_ack;
197
output                          first_miss_err;
198
output                          burst;
199
output                          tag_we;
200
output  [31:0]                   dc_addr;
201
 
202
//
203
// Internal wires and regs
204
//
205
reg     [31:0]                   saved_addr_r;
206
reg     [2:0]                    state;
207
reg     [2:0]                    cnt;
208
reg                             hitmiss_eval;
209
reg                             store;
210
reg                             load;
211
reg                             cache_inhibit;
212
wire                            first_store_hit_ack;
213
 
214
//
215
// Generate of DCRAM write enables
216
//
217
 
218
// SynEDA CoreMultiplier
219
// assignment(s): dcram_we
220
// replace(s): biudata_valid, load, cache_inhibit, first_store_hit_ack
221
assign dcram_we = {4{load_cml_3 & biudata_valid_cml_3 & !cache_inhibit_cml_3}} | {4{first_store_hit_ack_cml_3}} & dcqmem_sel_i;
222
 
223
// SynEDA CoreMultiplier
224
// assignment(s): tag_we
225
// replace(s): biudata_valid, biu_read, cache_inhibit
226
assign tag_we = biu_read_cml_3 & biudata_valid_cml_3 & !cache_inhibit_cml_3;
227
 
228
//
229
// BIU read and write
230
//
231
 
232
// SynEDA CoreMultiplier
233
// assignment(s): biu_read
234
// replace(s): tagcomp_miss, hitmiss_eval, load
235
assign biu_read = (hitmiss_eval_cml_2 & tagcomp_miss_cml_2) | (!hitmiss_eval_cml_2 & load_cml_2);
236
 
237
// SynEDA CoreMultiplier
238
// assignment(s): biu_write
239
// replace(s): store
240
assign biu_write = store_cml_2;
241
 
242
 
243
// SynEDA CoreMultiplier
244
// assignment(s): dc_addr
245
// replace(s): saved_addr, hitmiss_eval
246
assign dc_addr = (biu_read | biu_write) & !hitmiss_eval_cml_2 ? saved_addr_cml_2 : start_addr;
247
assign saved_addr = saved_addr_r;
248
 
249
//
250
// Assert for cache hit first word ready
251
// Assert for store cache hit first word ready
252
// Assert for cache miss first word stored/loaded OK
253
// Assert for cache miss first word stored/loaded with an error
254
//
255
assign first_hit_ack = (state == `OR1200_DCFSM_CLOAD) & !tagcomp_miss & !cache_inhibit & !dcqmem_ci_i | first_store_hit_ack;
256
assign first_store_hit_ack = (state == `OR1200_DCFSM_CSTORE) & !tagcomp_miss & biudata_valid & !cache_inhibit & !dcqmem_ci_i;
257
assign first_miss_ack = ((state == `OR1200_DCFSM_CLOAD) | (state == `OR1200_DCFSM_CSTORE)) & biudata_valid;
258
 
259
// SynEDA CoreMultiplier
260
// assignment(s): first_miss_err
261
// replace(s): state
262
assign first_miss_err = ((state_cml_1 == `OR1200_DCFSM_CLOAD) | (state_cml_1 == `OR1200_DCFSM_CSTORE)) & biudata_error;
263
 
264
//
265
// Assert burst when doing reload of complete cache line
266
//
267
 
268
// SynEDA CoreMultiplier
269
// assignment(s): burst
270
// replace(s): tagcomp_miss, state, cache_inhibit
271
assign burst = (state_cml_3 == `OR1200_DCFSM_CLOAD) & tagcomp_miss_cml_3 & !cache_inhibit_cml_3
272
                | (state_cml_3 == `OR1200_DCFSM_LREFILL3)
273
`ifdef OR1200_DC_STORE_REFILL
274
                | (state_cml_3 == `OR1200_DCFSM_SREFILL4)
275
`endif
276
                ;
277
 
278
//
279
// Main DC FSM
280
//
281
 
282
// SynEDA CoreMultiplier
283
// assignment(s): saved_addr_r, state, cnt, hitmiss_eval, store, load, cache_inhibit
284
// replace(s): dc_en, dcqmem_ci_i, tagcomp_miss, biudata_valid, biudata_error, start_addr, saved_addr_r, state, cnt, hitmiss_eval, cache_inhibit, store, load
285
always @(posedge clk or posedge rst) begin
286
        if (rst) begin
287
                state <= #1 `OR1200_DCFSM_IDLE;
288
                saved_addr_r <= #1 32'b0;
289
                hitmiss_eval <= #1 1'b0;
290
                store <= #1 1'b0;
291
                load <= #1 1'b0;
292
                cnt <= #1 3'b000;
293
                cache_inhibit <= #1 1'b0;
294
        end
295
        else begin  cache_inhibit <= cache_inhibit_cml_3; load <= load_cml_3; store <= store_cml_3; hitmiss_eval <= hitmiss_eval_cml_3; cnt <= cnt_cml_3; state <= state_cml_3; saved_addr_r <= saved_addr_r_cml_3;
296
        case (state_cml_3)      // synopsys parallel_case
297
                `OR1200_DCFSM_IDLE :
298
                        if (dc_en_cml_3 & dcqmem_cycstb_i & dcqmem_we_i) begin  // store
299
                                state <= #1 `OR1200_DCFSM_CSTORE;
300
                                saved_addr_r <= #1 start_addr_cml_3;
301
                                hitmiss_eval <= #1 1'b1;
302
                                store <= #1 1'b1;
303
                                load <= #1 1'b0;
304
                                cache_inhibit <= #1 1'b0;
305
                        end
306
                        else if (dc_en_cml_3 & dcqmem_cycstb_i) begin           // load
307
                                state <= #1 `OR1200_DCFSM_CLOAD;
308
                                saved_addr_r <= #1 start_addr_cml_3;
309
                                hitmiss_eval <= #1 1'b1;
310
                                store <= #1 1'b0;
311
                                load <= #1 1'b1;
312
                                cache_inhibit <= #1 1'b0;
313
                        end
314
                        else begin                                                      // idle
315
                                hitmiss_eval <= #1 1'b0;
316
                                store <= #1 1'b0;
317
                                load <= #1 1'b0;
318
                                cache_inhibit <= #1 1'b0;
319
                        end
320
                `OR1200_DCFSM_CLOAD: begin              // load
321
                        if (dcqmem_cycstb_i & dcqmem_ci_i_cml_3)
322
                                cache_inhibit <= #1 1'b1;
323
                        if (hitmiss_eval_cml_3)
324
                                saved_addr_r[31:13] <= #1 start_addr_cml_3[31:13];
325
                        if ((hitmiss_eval_cml_3 & !dcqmem_cycstb_i) ||                                  // load aborted (usually caused by DMMU)
326
                            (biudata_error_cml_3) ||                                                                            // load terminated with an error
327
                            ((cache_inhibit_cml_3 | dcqmem_ci_i_cml_3) & biudata_valid_cml_3)) begin    // load from cache-inhibited area
328
                                state <= #1 `OR1200_DCFSM_IDLE;
329
                                hitmiss_eval <= #1 1'b0;
330
                                load <= #1 1'b0;
331
                                cache_inhibit <= #1 1'b0;
332
                        end
333
                        else if (tagcomp_miss_cml_3 & biudata_valid_cml_3) begin        // load missed, finish current external load and refill
334
                                state <= #1 `OR1200_DCFSM_LREFILL3;
335
                                saved_addr_r[3:2] <= #1 saved_addr_r_cml_3[3:2] + 1'd1;
336
                                hitmiss_eval <= #1 1'b0;
337
                                cnt <= #1 `OR1200_DCLS-2;
338
                                cache_inhibit <= #1 1'b0;
339
                        end
340
                        else if (!tagcomp_miss_cml_3 & !dcqmem_ci_i_cml_3) begin        // load hit, finish immediately
341
                                state <= #1 `OR1200_DCFSM_IDLE;
342
                                hitmiss_eval <= #1 1'b0;
343
                                load <= #1 1'b0;
344
                                cache_inhibit <= #1 1'b0;
345
                        end
346
                        else                                            // load in-progress
347
                                hitmiss_eval <= #1 1'b0;
348
                end
349
                `OR1200_DCFSM_LREFILL3 : begin
350
                        if (biudata_valid_cml_3 && (|cnt_cml_3)) begin          // refill ack, more loads to come
351
                                cnt <= #1 cnt_cml_3 - 3'd1;
352
                                saved_addr_r[3:2] <= #1 saved_addr_r_cml_3[3:2] + 1'd1;
353
                        end
354
                        else if (biudata_valid_cml_3) begin                     // last load of line refill
355
                                state <= #1 `OR1200_DCFSM_IDLE;
356
                                load <= #1 1'b0;
357
                        end
358
                end
359
                `OR1200_DCFSM_CSTORE: begin             // store
360
                        if (dcqmem_cycstb_i & dcqmem_ci_i_cml_3)
361
                                cache_inhibit <= #1 1'b1;
362
                        if (hitmiss_eval_cml_3)
363
                                saved_addr_r[31:13] <= #1 start_addr_cml_3[31:13];
364
                        if ((hitmiss_eval_cml_3 & !dcqmem_cycstb_i) ||  // store aborted (usually caused by DMMU)
365
                            (biudata_error_cml_3) ||                                            // store terminated with an error
366
                            ((cache_inhibit_cml_3 | dcqmem_ci_i_cml_3) & biudata_valid_cml_3)) begin    // store to cache-inhibited area
367
                                state <= #1 `OR1200_DCFSM_IDLE;
368
                                hitmiss_eval <= #1 1'b0;
369
                                store <= #1 1'b0;
370
                                cache_inhibit <= #1 1'b0;
371
                        end
372
`ifdef OR1200_DC_STORE_REFILL
373
                        else if (tagcomp_miss_cml_3 & biudata_valid_cml_3) begin        // store missed, finish write-through and doq load refill
374
                                state <= #1 `OR1200_DCFSM_SREFILL4;
375
                                hitmiss_eval <= #1 1'b0;
376
                                store <= #1 1'b0;
377
                                load <= #1 1'b1;
378
                                cnt <= #1 `OR1200_DCLS-1;
379
                                cache_inhibit <= #1 1'b0;
380
                        end
381
`endif
382
                        else if (biudata_valid_cml_3) begin                     // store hit, finish write-through
383
                                state <= #1 `OR1200_DCFSM_IDLE;
384
                                hitmiss_eval <= #1 1'b0;
385
                                store <= #1 1'b0;
386
                                cache_inhibit <= #1 1'b0;
387
                        end
388
                        else                                            // store write-through in-progress
389
                                hitmiss_eval <= #1 1'b0;
390
                        end
391
`ifdef OR1200_DC_STORE_REFILL
392
                `OR1200_DCFSM_SREFILL4 : begin
393
                        if (biudata_valid_cml_3 && (|cnt_cml_3)) begin          // refill ack, more loads to come
394
                                cnt <= #1 cnt_cml_3 - 1'd1;
395
                                saved_addr_r[3:2] <= #1 saved_addr_r_cml_3[3:2] + 1'd1;
396
                        end
397
                        else if (biudata_valid_cml_3) begin                     // last load of line refill
398
                                state <= #1 `OR1200_DCFSM_IDLE;
399
                                load <= #1 1'b0;
400
                        end
401
                end
402
`endif
403
                default:
404
                        state <= #1 `OR1200_DCFSM_IDLE;
405
        endcase end
406
end
407
 
408
 
409
always @ (posedge clk_i_cml_1) begin
410
dc_en_cml_1 <= dc_en;
411
dcqmem_ci_i_cml_1 <= dcqmem_ci_i;
412
tagcomp_miss_cml_1 <= tagcomp_miss;
413
biudata_valid_cml_1 <= biudata_valid;
414
saved_addr_cml_1 <= saved_addr;
415
saved_addr_r_cml_1 <= saved_addr_r;
416
state_cml_1 <= state;
417
cnt_cml_1 <= cnt;
418
hitmiss_eval_cml_1 <= hitmiss_eval;
419
store_cml_1 <= store;
420
load_cml_1 <= load;
421
cache_inhibit_cml_1 <= cache_inhibit;
422
first_store_hit_ack_cml_1 <= first_store_hit_ack;
423
end
424
always @ (posedge clk_i_cml_2) begin
425
dc_en_cml_2 <= dc_en_cml_1;
426
dcqmem_ci_i_cml_2 <= dcqmem_ci_i_cml_1;
427
tagcomp_miss_cml_2 <= tagcomp_miss_cml_1;
428
biudata_valid_cml_2 <= biudata_valid_cml_1;
429
biudata_error_cml_2 <= biudata_error;
430
saved_addr_cml_2 <= saved_addr_cml_1;
431
saved_addr_r_cml_2 <= saved_addr_r_cml_1;
432
state_cml_2 <= state_cml_1;
433
cnt_cml_2 <= cnt_cml_1;
434
hitmiss_eval_cml_2 <= hitmiss_eval_cml_1;
435
store_cml_2 <= store_cml_1;
436
load_cml_2 <= load_cml_1;
437
cache_inhibit_cml_2 <= cache_inhibit_cml_1;
438
first_store_hit_ack_cml_2 <= first_store_hit_ack_cml_1;
439
end
440
always @ (posedge clk_i_cml_3) begin
441
dc_en_cml_3 <= dc_en_cml_2;
442
dcqmem_ci_i_cml_3 <= dcqmem_ci_i_cml_2;
443
tagcomp_miss_cml_3 <= tagcomp_miss_cml_2;
444
biudata_valid_cml_3 <= biudata_valid_cml_2;
445
biudata_error_cml_3 <= biudata_error_cml_2;
446
start_addr_cml_3 <= start_addr;
447
biu_read_cml_3 <= biu_read;
448
saved_addr_r_cml_3 <= saved_addr_r_cml_2;
449
state_cml_3 <= state_cml_2;
450
cnt_cml_3 <= cnt_cml_2;
451
hitmiss_eval_cml_3 <= hitmiss_eval_cml_2;
452
store_cml_3 <= store_cml_2;
453
load_cml_3 <= load_cml_2;
454
cache_inhibit_cml_3 <= cache_inhibit_cml_2;
455
first_store_hit_ack_cml_3 <= first_store_hit_ack_cml_2;
456
end
457
endmodule
458
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.