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

Subversion Repositories or1200_hp

[/] [or1200_hp/] [trunk/] [rtl/] [rtl_cm3/] [verilog/] [or1200_dc_fsm.v] - Blame information for rev 2

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_cm3(
114
                clk_i_cml_1,
115
                clk_i_cml_2,
116
 
117
        // Clock and reset
118
        clk, rst,
119
 
120
        // Internal i/f to top level DC
121
        dc_en, dcqmem_cycstb_i, dcqmem_ci_i, dcqmem_we_i, dcqmem_sel_i,
122
        tagcomp_miss, biudata_valid, biudata_error, start_addr, saved_addr,
123
        dcram_we, biu_read, biu_write, first_hit_ack, first_miss_ack, first_miss_err,
124
        burst, tag_we, dc_addr
125
);
126
 
127
 
128
input clk_i_cml_1;
129
input clk_i_cml_2;
130
reg  dc_en_cml_2;
131
reg  dcqmem_ci_i_cml_2;
132
reg  tagcomp_miss_cml_2;
133
reg  tagcomp_miss_cml_1;
134
reg  biudata_valid_cml_2;
135
reg  biudata_valid_cml_1;
136
reg  biudata_error_cml_2;
137
reg [ 31 : 0 ] start_addr_cml_2;
138
reg [ 31 : 0 ] saved_addr_cml_1;
139
reg  biu_read_cml_2;
140
reg [ 31 : 0 ] saved_addr_r_cml_2;
141
reg [ 31 : 0 ] saved_addr_r_cml_1;
142
reg [ 2 : 0 ] state_cml_2;
143
reg [ 2 : 0 ] state_cml_1;
144
reg [ 2 : 0 ] cnt_cml_2;
145
reg [ 2 : 0 ] cnt_cml_1;
146
reg  hitmiss_eval_cml_2;
147
reg  hitmiss_eval_cml_1;
148
reg  store_cml_2;
149
reg  store_cml_1;
150
reg  load_cml_2;
151
reg  load_cml_1;
152
reg  cache_inhibit_cml_2;
153
reg  cache_inhibit_cml_1;
154
reg  first_store_hit_ack_cml_2;
155
 
156
 
157
 
158
//
159
// I/O
160
//
161
input                           clk;
162
input                           rst;
163
input                           dc_en;
164
input                           dcqmem_cycstb_i;
165
input                           dcqmem_ci_i;
166
input                           dcqmem_we_i;
167
input   [3:0]                    dcqmem_sel_i;
168
input                           tagcomp_miss;
169
input                           biudata_valid;
170
input                           biudata_error;
171
input   [31:0]                   start_addr;
172
output  [31:0]                   saved_addr;
173
output  [3:0]                    dcram_we;
174
output                          biu_read;
175
output                          biu_write;
176
output                          first_hit_ack;
177
output                          first_miss_ack;
178
output                          first_miss_err;
179
output                          burst;
180
output                          tag_we;
181
output  [31:0]                   dc_addr;
182
 
183
//
184
// Internal wires and regs
185
//
186
reg     [31:0]                   saved_addr_r;
187
reg     [2:0]                    state;
188
reg     [2:0]                    cnt;
189
reg                             hitmiss_eval;
190
reg                             store;
191
reg                             load;
192
reg                             cache_inhibit;
193
wire                            first_store_hit_ack;
194
 
195
//
196
// Generate of DCRAM write enables
197
//
198
 
199
// SynEDA CoreMultiplier
200
// assignment(s): dcram_we
201
// replace(s): biudata_valid, load, cache_inhibit, first_store_hit_ack
202
assign dcram_we = {4{load_cml_2 & biudata_valid_cml_2 & !cache_inhibit_cml_2}} | {4{first_store_hit_ack_cml_2}} & dcqmem_sel_i;
203
 
204
// SynEDA CoreMultiplier
205
// assignment(s): tag_we
206
// replace(s): biudata_valid, biu_read, cache_inhibit
207
assign tag_we = biu_read_cml_2 & biudata_valid_cml_2 & !cache_inhibit_cml_2;
208
 
209
//
210
// BIU read and write
211
//
212
 
213
// SynEDA CoreMultiplier
214
// assignment(s): biu_read
215
// replace(s): tagcomp_miss, hitmiss_eval, load
216
assign biu_read = (hitmiss_eval_cml_1 & tagcomp_miss_cml_1) | (!hitmiss_eval_cml_1 & load_cml_1);
217
 
218
// SynEDA CoreMultiplier
219
// assignment(s): biu_write
220
// replace(s): store
221
assign biu_write = store_cml_1;
222
 
223
 
224
// SynEDA CoreMultiplier
225
// assignment(s): dc_addr
226
// replace(s): saved_addr, hitmiss_eval
227
assign dc_addr = (biu_read | biu_write) & !hitmiss_eval_cml_1 ? saved_addr_cml_1 : start_addr;
228
assign saved_addr = saved_addr_r;
229
 
230
//
231
// Assert for cache hit first word ready
232
// Assert for store cache hit first word ready
233
// Assert for cache miss first word stored/loaded OK
234
// Assert for cache miss first word stored/loaded with an error
235
//
236
 
237
// SynEDA CoreMultiplier
238
// assignment(s): first_hit_ack
239
// replace(s): tagcomp_miss, state, cache_inhibit
240
assign first_hit_ack = (state_cml_1 == `OR1200_DCFSM_CLOAD) & !tagcomp_miss_cml_1 & !cache_inhibit_cml_1 & !dcqmem_ci_i | first_store_hit_ack;
241
 
242
// SynEDA CoreMultiplier
243
// assignment(s): first_store_hit_ack
244
// replace(s): tagcomp_miss, biudata_valid, state, cache_inhibit
245
assign first_store_hit_ack = (state_cml_1 == `OR1200_DCFSM_CSTORE) & !tagcomp_miss_cml_1 & biudata_valid_cml_1 & !cache_inhibit_cml_1 & !dcqmem_ci_i;
246
assign first_miss_ack = ((state == `OR1200_DCFSM_CLOAD) | (state == `OR1200_DCFSM_CSTORE)) & biudata_valid;
247
 
248
// SynEDA CoreMultiplier
249
// assignment(s): first_miss_err
250
// replace(s): state
251
assign first_miss_err = ((state_cml_1 == `OR1200_DCFSM_CLOAD) | (state_cml_1 == `OR1200_DCFSM_CSTORE)) & biudata_error;
252
 
253
//
254
// Assert burst when doing reload of complete cache line
255
//
256
 
257
// SynEDA CoreMultiplier
258
// assignment(s): burst
259
// replace(s): tagcomp_miss, state, cache_inhibit
260
assign burst = (state_cml_2 == `OR1200_DCFSM_CLOAD) & tagcomp_miss_cml_2 & !cache_inhibit_cml_2
261
                | (state_cml_2 == `OR1200_DCFSM_LREFILL3)
262
`ifdef OR1200_DC_STORE_REFILL
263
                | (state_cml_2 == `OR1200_DCFSM_SREFILL4)
264
`endif
265
                ;
266
 
267
//
268
// Main DC FSM
269
//
270
 
271
// SynEDA CoreMultiplier
272
// assignment(s): saved_addr_r, state, cnt, hitmiss_eval, store, load, cache_inhibit
273
// 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
274
always @(posedge clk or posedge rst) begin
275
        if (rst) begin
276
                state <= #1 `OR1200_DCFSM_IDLE;
277
                saved_addr_r <= #1 32'b0;
278
                hitmiss_eval <= #1 1'b0;
279
                store <= #1 1'b0;
280
                load <= #1 1'b0;
281
                cnt <= #1 3'b000;
282
                cache_inhibit <= #1 1'b0;
283
        end
284
        else begin  cache_inhibit <= cache_inhibit_cml_2; load <= load_cml_2; store <= store_cml_2; hitmiss_eval <= hitmiss_eval_cml_2; cnt <= cnt_cml_2; state <= state_cml_2; saved_addr_r <= saved_addr_r_cml_2;
285
        case (state_cml_2)      // synopsys parallel_case
286
                `OR1200_DCFSM_IDLE :
287
                        if (dc_en_cml_2 & dcqmem_cycstb_i & dcqmem_we_i) begin  // store
288
                                state <= #1 `OR1200_DCFSM_CSTORE;
289
                                saved_addr_r <= #1 start_addr_cml_2;
290
                                hitmiss_eval <= #1 1'b1;
291
                                store <= #1 1'b1;
292
                                load <= #1 1'b0;
293
                                cache_inhibit <= #1 1'b0;
294
                        end
295
                        else if (dc_en_cml_2 & dcqmem_cycstb_i) begin           // load
296
                                state <= #1 `OR1200_DCFSM_CLOAD;
297
                                saved_addr_r <= #1 start_addr_cml_2;
298
                                hitmiss_eval <= #1 1'b1;
299
                                store <= #1 1'b0;
300
                                load <= #1 1'b1;
301
                                cache_inhibit <= #1 1'b0;
302
                        end
303
                        else begin                                                      // idle
304
                                hitmiss_eval <= #1 1'b0;
305
                                store <= #1 1'b0;
306
                                load <= #1 1'b0;
307
                                cache_inhibit <= #1 1'b0;
308
                        end
309
                `OR1200_DCFSM_CLOAD: begin              // load
310
                        if (dcqmem_cycstb_i & dcqmem_ci_i_cml_2)
311
                                cache_inhibit <= #1 1'b1;
312
                        if (hitmiss_eval_cml_2)
313
                                saved_addr_r[31:13] <= #1 start_addr_cml_2[31:13];
314
                        if ((hitmiss_eval_cml_2 & !dcqmem_cycstb_i) ||                                  // load aborted (usually caused by DMMU)
315
                            (biudata_error_cml_2) ||                                                                            // load terminated with an error
316
                            ((cache_inhibit_cml_2 | dcqmem_ci_i_cml_2) & biudata_valid_cml_2)) begin    // load from cache-inhibited area
317
                                state <= #1 `OR1200_DCFSM_IDLE;
318
                                hitmiss_eval <= #1 1'b0;
319
                                load <= #1 1'b0;
320
                                cache_inhibit <= #1 1'b0;
321
                        end
322
                        else if (tagcomp_miss_cml_2 & biudata_valid_cml_2) begin        // load missed, finish current external load and refill
323
                                state <= #1 `OR1200_DCFSM_LREFILL3;
324
                                saved_addr_r[3:2] <= #1 saved_addr_r_cml_2[3:2] + 1'd1;
325
                                hitmiss_eval <= #1 1'b0;
326
                                cnt <= #1 `OR1200_DCLS-2;
327
                                cache_inhibit <= #1 1'b0;
328
                        end
329
                        else if (!tagcomp_miss_cml_2 & !dcqmem_ci_i_cml_2) begin        // load hit, finish immediately
330
                                state <= #1 `OR1200_DCFSM_IDLE;
331
                                hitmiss_eval <= #1 1'b0;
332
                                load <= #1 1'b0;
333
                                cache_inhibit <= #1 1'b0;
334
                        end
335
                        else                                            // load in-progress
336
                                hitmiss_eval <= #1 1'b0;
337
                end
338
                `OR1200_DCFSM_LREFILL3 : begin
339
                        if (biudata_valid_cml_2 && (|cnt_cml_2)) begin          // refill ack, more loads to come
340
                                cnt <= #1 cnt_cml_2 - 3'd1;
341
                                saved_addr_r[3:2] <= #1 saved_addr_r_cml_2[3:2] + 1'd1;
342
                        end
343
                        else if (biudata_valid_cml_2) begin                     // last load of line refill
344
                                state <= #1 `OR1200_DCFSM_IDLE;
345
                                load <= #1 1'b0;
346
                        end
347
                end
348
                `OR1200_DCFSM_CSTORE: begin             // store
349
                        if (dcqmem_cycstb_i & dcqmem_ci_i_cml_2)
350
                                cache_inhibit <= #1 1'b1;
351
                        if (hitmiss_eval_cml_2)
352
                                saved_addr_r[31:13] <= #1 start_addr_cml_2[31:13];
353
                        if ((hitmiss_eval_cml_2 & !dcqmem_cycstb_i) ||  // store aborted (usually caused by DMMU)
354
                            (biudata_error_cml_2) ||                                            // store terminated with an error
355
                            ((cache_inhibit_cml_2 | dcqmem_ci_i_cml_2) & biudata_valid_cml_2)) begin    // store to cache-inhibited area
356
                                state <= #1 `OR1200_DCFSM_IDLE;
357
                                hitmiss_eval <= #1 1'b0;
358
                                store <= #1 1'b0;
359
                                cache_inhibit <= #1 1'b0;
360
                        end
361
`ifdef OR1200_DC_STORE_REFILL
362
                        else if (tagcomp_miss_cml_2 & biudata_valid_cml_2) begin        // store missed, finish write-through and doq load refill
363
                                state <= #1 `OR1200_DCFSM_SREFILL4;
364
                                hitmiss_eval <= #1 1'b0;
365
                                store <= #1 1'b0;
366
                                load <= #1 1'b1;
367
                                cnt <= #1 `OR1200_DCLS-1;
368
                                cache_inhibit <= #1 1'b0;
369
                        end
370
`endif
371
                        else if (biudata_valid_cml_2) begin                     // store hit, finish write-through
372
                                state <= #1 `OR1200_DCFSM_IDLE;
373
                                hitmiss_eval <= #1 1'b0;
374
                                store <= #1 1'b0;
375
                                cache_inhibit <= #1 1'b0;
376
                        end
377
                        else                                            // store write-through in-progress
378
                                hitmiss_eval <= #1 1'b0;
379
                        end
380
`ifdef OR1200_DC_STORE_REFILL
381
                `OR1200_DCFSM_SREFILL4 : begin
382
                        if (biudata_valid_cml_2 && (|cnt_cml_2)) begin          // refill ack, more loads to come
383
                                cnt <= #1 cnt_cml_2 - 1'd1;
384
                                saved_addr_r[3:2] <= #1 saved_addr_r_cml_2[3:2] + 1'd1;
385
                        end
386
                        else if (biudata_valid_cml_2) begin                     // last load of line refill
387
                                state <= #1 `OR1200_DCFSM_IDLE;
388
                                load <= #1 1'b0;
389
                        end
390
                end
391
`endif
392
                default:
393
                        state <= #1 `OR1200_DCFSM_IDLE;
394
        endcase end
395
end
396
 
397
 
398
always @ (posedge clk_i_cml_1) begin
399
tagcomp_miss_cml_1 <= tagcomp_miss;
400
biudata_valid_cml_1 <= biudata_valid;
401
saved_addr_cml_1 <= saved_addr;
402
saved_addr_r_cml_1 <= saved_addr_r;
403
state_cml_1 <= state;
404
cnt_cml_1 <= cnt;
405
hitmiss_eval_cml_1 <= hitmiss_eval;
406
store_cml_1 <= store;
407
load_cml_1 <= load;
408
cache_inhibit_cml_1 <= cache_inhibit;
409
end
410
always @ (posedge clk_i_cml_2) begin
411
dc_en_cml_2 <= dc_en;
412
dcqmem_ci_i_cml_2 <= dcqmem_ci_i;
413
tagcomp_miss_cml_2 <= tagcomp_miss_cml_1;
414
biudata_valid_cml_2 <= biudata_valid_cml_1;
415
biudata_error_cml_2 <= biudata_error;
416
start_addr_cml_2 <= start_addr;
417
biu_read_cml_2 <= biu_read;
418
saved_addr_r_cml_2 <= saved_addr_r_cml_1;
419
state_cml_2 <= state_cml_1;
420
cnt_cml_2 <= cnt_cml_1;
421
hitmiss_eval_cml_2 <= hitmiss_eval_cml_1;
422
store_cml_2 <= store_cml_1;
423
load_cml_2 <= load_cml_1;
424
cache_inhibit_cml_2 <= cache_inhibit_cml_1;
425
first_store_hit_ack_cml_2 <= first_store_hit_ack;
426
end
427
endmodule
428
 

powered by: WebSVN 2.1.0

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