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

Subversion Repositories or1200_hp

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

powered by: WebSVN 2.1.0

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