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

Subversion Repositories openriscdevboard

[/] [openriscdevboard/] [trunk/] [cyc2-openrisc/] [rtl/] [or1200/] [or1200_dc_fsm.v] - Blame information for rev 3

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 sfielding
//////////////////////////////////////////////////////////////////////
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.1  2006/12/21 16:46:58  vak
48
// Initial revision imported from
49
// http://www.opencores.org/cvsget.cgi/or1k/orp/orp_soc/rtl/verilog.
50
//
51
// Revision 1.9  2004/06/08 18:17:36  lampret
52
// Non-functional changes. Coding style fixes.
53
//
54
// Revision 1.8  2004/04/05 08:29:57  lampret
55
// Merged branch_qmem into main tree.
56
//
57
// Revision 1.7.4.1  2003/07/08 15:36:37  lampret
58
// Added embedded memory QMEM.
59
//
60
// Revision 1.7  2002/03/29 15:16:55  lampret
61
// Some of the warnings fixed.
62
//
63
// Revision 1.6  2002/03/28 19:10:40  lampret
64
// Optimized cache controller FSM.
65
//
66
// Revision 1.1.1.1  2002/03/21 16:55:45  lampret
67
// First import of the "new" XESS XSV environment.
68
//
69
//
70
// Revision 1.5  2002/02/11 04:33:17  lampret
71
// Speed optimizations (removed duplicate _cyc_ and _stb_). Fixed D/IMMU cache-inhibit attr.
72
//
73
// Revision 1.4  2002/02/01 19:56:54  lampret
74
// Fixed combinational loops.
75
//
76
// Revision 1.3  2002/01/28 01:15:59  lampret
77
// 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.
78
//
79
// Revision 1.2  2002/01/14 06:18:22  lampret
80
// Fixed mem2reg bug in FAST implementation. Updated debug unit to work with new genpc/if.
81
//
82
// Revision 1.1  2002/01/03 08:16:15  lampret
83
// New prefixes for RTL files, prefixed module names. Updated cache controllers and MMUs.
84
//
85
// Revision 1.9  2001/10/21 17:57:16  lampret
86
// 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.
87
//
88
// Revision 1.8  2001/10/19 23:28:46  lampret
89
// Fixed some synthesis warnings. Configured with caches and MMUs.
90
//
91
// Revision 1.7  2001/10/14 13:12:09  lampret
92
// MP3 version.
93
//
94
// Revision 1.1.1.1  2001/10/06 10:18:35  igorm
95
// no message
96
//
97
// Revision 1.2  2001/08/09 13:39:33  lampret
98
// Major clean-up.
99
//
100
// Revision 1.1  2001/07/20 00:46:03  lampret
101
// Development version of RTL. Libraries are missing.
102
//
103
//
104
 
105
// synopsys translate_off
106
`include "timescale.v"
107
// synopsys translate_on
108
`include "or1200_defines.v"
109
 
110
`define OR1200_DCFSM_IDLE       3'd0
111
`define OR1200_DCFSM_CLOAD      3'd1
112
`define OR1200_DCFSM_LREFILL3   3'd2
113
`define OR1200_DCFSM_CSTORE     3'd3
114
`define OR1200_DCFSM_SREFILL4   3'd4
115
 
116
//
117
// Data cache FSM for cache line of 16 bytes (4x singleword)
118
//
119
 
120
module or1200_dc_fsm(
121
        // Clock and reset
122
        clk, rst,
123
 
124
        // Internal i/f to top level DC
125
        dc_en, dcqmem_cycstb_i, dcqmem_ci_i, dcqmem_we_i, dcqmem_sel_i,
126
        tagcomp_miss, biudata_valid, biudata_error, start_addr, saved_addr,
127
        dcram_we, biu_read, biu_write, first_hit_ack, first_miss_ack, first_miss_err,
128
        burst, tag_we, dc_addr
129
);
130
 
131
//
132
// I/O
133
//
134
input                           clk;
135
input                           rst;
136
input                           dc_en;
137
input                           dcqmem_cycstb_i;
138
input                           dcqmem_ci_i;
139
input                           dcqmem_we_i;
140
input   [3:0]                    dcqmem_sel_i;
141
input                           tagcomp_miss;
142
input                           biudata_valid;
143
input                           biudata_error;
144
input   [31:0]                   start_addr;
145
output  [31:0]                   saved_addr;
146
output  [3:0]                    dcram_we;
147
output                          biu_read;
148
output                          biu_write;
149
output                          first_hit_ack;
150
output                          first_miss_ack;
151
output                          first_miss_err;
152
output                          burst;
153
output                          tag_we;
154
output  [31:0]                   dc_addr;
155
 
156
//
157
// Internal wires and regs
158
//
159
reg     [31:0]                   saved_addr_r;
160
reg     [2:0]                    state;
161
reg     [2:0]                    cnt;
162
reg                             hitmiss_eval;
163
reg                             store;
164
reg                             load;
165
reg                             cache_inhibit;
166
wire                            first_store_hit_ack;
167
 
168
//
169
// Generate of DCRAM write enables
170
//
171
assign dcram_we = {4{load & biudata_valid & !cache_inhibit}} | {4{first_store_hit_ack}} & dcqmem_sel_i;
172
assign tag_we = biu_read & biudata_valid & !cache_inhibit;
173
 
174
//
175
// BIU read and write
176
//
177
assign biu_read = (hitmiss_eval & tagcomp_miss) | (!hitmiss_eval & load);
178
assign biu_write = store;
179
 
180
assign dc_addr = (biu_read | biu_write) & !hitmiss_eval ? saved_addr : start_addr;
181
assign saved_addr = saved_addr_r;
182
 
183
//
184
// Assert for cache hit first word ready
185
// Assert for store cache hit first word ready
186
// Assert for cache miss first word stored/loaded OK
187
// Assert for cache miss first word stored/loaded with an error
188
//
189
assign first_hit_ack = (state == `OR1200_DCFSM_CLOAD) & !tagcomp_miss & !cache_inhibit & !dcqmem_ci_i | first_store_hit_ack;
190
assign first_store_hit_ack = (state == `OR1200_DCFSM_CSTORE) & !tagcomp_miss & biudata_valid & !cache_inhibit & !dcqmem_ci_i;
191
assign first_miss_ack = ((state == `OR1200_DCFSM_CLOAD) | (state == `OR1200_DCFSM_CSTORE)) & biudata_valid;
192
assign first_miss_err = ((state == `OR1200_DCFSM_CLOAD) | (state == `OR1200_DCFSM_CSTORE)) & biudata_error;
193
 
194
//
195
// Assert burst when doing reload of complete cache line
196
//
197
assign burst = (state == `OR1200_DCFSM_CLOAD) & tagcomp_miss & !cache_inhibit
198
                | (state == `OR1200_DCFSM_LREFILL3)
199
`ifdef OR1200_DC_STORE_REFILL
200
                | (state == `OR1200_DCFSM_SREFILL4)
201
`endif
202
                ;
203
 
204
//
205
// Main DC FSM
206
//
207
always @(posedge clk or posedge rst) begin
208
        if (rst) begin
209
                state <= #1 `OR1200_DCFSM_IDLE;
210
                saved_addr_r <= #1 32'b0;
211
                hitmiss_eval <= #1 1'b0;
212
                store <= #1 1'b0;
213
                load <= #1 1'b0;
214
                cnt <= #1 3'b000;
215
                cache_inhibit <= #1 1'b0;
216
        end
217
        else
218
        case (state)    // synopsys parallel_case
219
                `OR1200_DCFSM_IDLE :
220
                        if (dc_en & dcqmem_cycstb_i & dcqmem_we_i) begin        // store
221
                                state <= #1 `OR1200_DCFSM_CSTORE;
222
                                saved_addr_r <= #1 start_addr;
223
                                hitmiss_eval <= #1 1'b1;
224
                                store <= #1 1'b1;
225
                                load <= #1 1'b0;
226
                                cache_inhibit <= #1 1'b0;
227
                        end
228
                        else if (dc_en & dcqmem_cycstb_i) begin         // load
229
                                state <= #1 `OR1200_DCFSM_CLOAD;
230
                                saved_addr_r <= #1 start_addr;
231
                                hitmiss_eval <= #1 1'b1;
232
                                store <= #1 1'b0;
233
                                load <= #1 1'b1;
234
                                cache_inhibit <= #1 1'b0;
235
                        end
236
                        else begin                                                      // idle
237
                                hitmiss_eval <= #1 1'b0;
238
                                store <= #1 1'b0;
239
                                load <= #1 1'b0;
240
                                cache_inhibit <= #1 1'b0;
241
                        end
242
                `OR1200_DCFSM_CLOAD: begin              // load
243
                        if (dcqmem_cycstb_i & dcqmem_ci_i)
244
                                cache_inhibit <= #1 1'b1;
245
                        if (hitmiss_eval)
246
                                saved_addr_r[31:13] <= #1 start_addr[31:13];
247
                        if ((hitmiss_eval & !dcqmem_cycstb_i) ||                                        // load aborted (usually caused by DMMU)
248
                            (biudata_error) ||                                                                          // load terminated with an error
249
                            ((cache_inhibit | dcqmem_ci_i) & biudata_valid)) begin      // load from cache-inhibited area
250
                                state <= #1 `OR1200_DCFSM_IDLE;
251
                                hitmiss_eval <= #1 1'b0;
252
                                load <= #1 1'b0;
253
                                cache_inhibit <= #1 1'b0;
254
                        end
255
                        else if (tagcomp_miss & biudata_valid) begin    // load missed, finish current external load and refill
256
                                state <= #1 `OR1200_DCFSM_LREFILL3;
257
                                saved_addr_r[3:2] <= #1 saved_addr_r[3:2] + 1'd1;
258
                                hitmiss_eval <= #1 1'b0;
259
                                cnt <= #1 `OR1200_DCLS-2;
260
                                cache_inhibit <= #1 1'b0;
261
                        end
262
                        else if (!tagcomp_miss & !dcqmem_ci_i) begin    // load hit, finish immediately
263
                                state <= #1 `OR1200_DCFSM_IDLE;
264
                                hitmiss_eval <= #1 1'b0;
265
                                load <= #1 1'b0;
266
                                cache_inhibit <= #1 1'b0;
267
                        end
268
                        else                                            // load in-progress
269
                                hitmiss_eval <= #1 1'b0;
270
                end
271
                `OR1200_DCFSM_LREFILL3 : begin
272
                        if (biudata_valid && (|cnt)) begin              // refill ack, more loads to come
273
                                cnt <= #1 cnt - 3'd1;
274
                                saved_addr_r[3:2] <= #1 saved_addr_r[3:2] + 1'd1;
275
                        end
276
                        else if (biudata_valid) begin                   // last load of line refill
277
                                state <= #1 `OR1200_DCFSM_IDLE;
278
                                load <= #1 1'b0;
279
                        end
280
                end
281
                `OR1200_DCFSM_CSTORE: begin             // store
282
                        if (dcqmem_cycstb_i & dcqmem_ci_i)
283
                                cache_inhibit <= #1 1'b1;
284
                        if (hitmiss_eval)
285
                                saved_addr_r[31:13] <= #1 start_addr[31:13];
286
                        if ((hitmiss_eval & !dcqmem_cycstb_i) ||        // store aborted (usually caused by DMMU)
287
                            (biudata_error) ||                                          // store terminated with an error
288
                            ((cache_inhibit | dcqmem_ci_i) & biudata_valid)) begin      // store to cache-inhibited area
289
                                state <= #1 `OR1200_DCFSM_IDLE;
290
                                hitmiss_eval <= #1 1'b0;
291
                                store <= #1 1'b0;
292
                                cache_inhibit <= #1 1'b0;
293
                        end
294
`ifdef OR1200_DC_STORE_REFILL
295
                        else if (tagcomp_miss & biudata_valid) begin    // store missed, finish write-through and doq load refill
296
                                state <= #1 `OR1200_DCFSM_SREFILL4;
297
                                hitmiss_eval <= #1 1'b0;
298
                                store <= #1 1'b0;
299
                                load <= #1 1'b1;
300
                                cnt <= #1 `OR1200_DCLS-1;
301
                                cache_inhibit <= #1 1'b0;
302
                        end
303
`endif
304
                        else if (biudata_valid) begin                   // store hit, finish write-through
305
                                state <= #1 `OR1200_DCFSM_IDLE;
306
                                hitmiss_eval <= #1 1'b0;
307
                                store <= #1 1'b0;
308
                                cache_inhibit <= #1 1'b0;
309
                        end
310
                        else                                            // store write-through in-progress
311
                                hitmiss_eval <= #1 1'b0;
312
                        end
313
`ifdef OR1200_DC_STORE_REFILL
314
                `OR1200_DCFSM_SREFILL4 : begin
315
                        if (biudata_valid && (|cnt)) begin              // refill ack, more loads to come
316
                                cnt <= #1 cnt - 1'd1;
317
                                saved_addr_r[3:2] <= #1 saved_addr_r[3:2] + 1'd1;
318
                        end
319
                        else if (biudata_valid) begin                   // last load of line refill
320
                                state <= #1 `OR1200_DCFSM_IDLE;
321
                                load <= #1 1'b0;
322
                        end
323
                end
324
`endif
325
                default:
326
                        state <= #1 `OR1200_DCFSM_IDLE;
327
        endcase
328
end
329
 
330
endmodule

powered by: WebSVN 2.1.0

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