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

Subversion Repositories test_project

[/] [test_project/] [trunk/] [rtl/] [verilog/] [components/] [or1200r2/] [or1200_dc_fsm.v] - Blame information for rev 42

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

Line No. Rev Author Line
1 18 unneback
//////////////////////////////////////////////////////////////////////
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: or1200_dc_fsm.v,v $
47
// Revision 1.9  2004/06/08 18:17:36  lampret
48
// Non-functional changes. Coding style fixes.
49
//
50
// Revision 1.8  2004/04/05 08:29:57  lampret
51
// Merged branch_qmem into main tree.
52
//
53
// Revision 1.7.4.1  2003/07/08 15:36:37  lampret
54
// Added embedded memory QMEM.
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:15:59  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 dc.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_DCFSM_IDLE       3'd0
107
`define OR1200_DCFSM_CLOAD      3'd1
108
`define OR1200_DCFSM_LREFILL3   3'd2
109
`define OR1200_DCFSM_CSTORE     3'd3
110
`define OR1200_DCFSM_SREFILL4   3'd4
111
 
112
//
113
// Data cache FSM for cache line of 16 bytes (4x singleword)
114
//
115
 
116
module or1200_dc_fsm(
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
// I/O
129
//
130
input                           clk;
131
input                           rst;
132
input                           dc_en;
133
input                           dcqmem_cycstb_i;
134
input                           dcqmem_ci_i;
135
input                           dcqmem_we_i;
136
input   [3:0]                    dcqmem_sel_i;
137
input                           tagcomp_miss;
138
input                           biudata_valid;
139
input                           biudata_error;
140
input   [31:0]                   start_addr;
141
output  [31:0]                   saved_addr;
142
output  [3:0]                    dcram_we;
143
output                          biu_read;
144
output                          biu_write;
145
output                          first_hit_ack;
146
output                          first_miss_ack;
147
output                          first_miss_err;
148
output                          burst;
149
output                          tag_we;
150
output  [31:0]                   dc_addr;
151
 
152
//
153
// Internal wires and regs
154
//
155
reg     [31:0]                   saved_addr_r;
156
reg     [2:0]                    state;
157
reg     [2:0]                    cnt;
158
reg                             hitmiss_eval;
159
reg                             store;
160
reg                             load;
161
reg                             cache_inhibit;
162
wire                tagcomp_miss_wide;
163
wire                            first_store_hit_ack;
164
 
165
//
166
// Generate of DCRAM write enables
167
//
168
assign dcram_we = {4{load & biudata_valid & !cache_inhibit}} | {4{first_store_hit_ack}} & dcqmem_sel_i;
169
assign tag_we = biu_read & biudata_valid & !cache_inhibit;
170
 
171
//
172
// BIU read and write
173
//
174
assign biu_read = (hitmiss_eval & tagcomp_miss) | (!hitmiss_eval & load);
175
assign biu_write = store;
176
 
177
assign dc_addr = (biu_read | biu_write) & !hitmiss_eval ? saved_addr : start_addr;
178
assign saved_addr = saved_addr_r;
179
 
180
//
181
// Assert for cache hit first word ready
182
// Assert for store cache hit first word ready
183
// Assert for cache miss first word stored/loaded OK
184
// Assert for cache miss first word stored/loaded with an error
185
//
186
assign tagcomp_miss_wide = tagcomp_miss | (saved_addr != start_addr);
187
assign first_hit_ack = (state == `OR1200_DCFSM_CLOAD) & !tagcomp_miss_wide & !cache_inhibit | first_store_hit_ack;
188
assign first_store_hit_ack = (state == `OR1200_DCFSM_CSTORE) & !tagcomp_miss_wide & biudata_valid & !cache_inhibit;
189
assign first_miss_ack = ((state == `OR1200_DCFSM_CLOAD) | (state == `OR1200_DCFSM_CSTORE)) & biudata_valid;
190
assign first_miss_err = ((state == `OR1200_DCFSM_CLOAD) | (state == `OR1200_DCFSM_CSTORE)) & biudata_error;
191
 
192
//
193
// Assert burst when doing reload of complete cache line
194
//
195
assign burst = (state == `OR1200_DCFSM_CLOAD) & tagcomp_miss & !cache_inhibit
196
                | (state == `OR1200_DCFSM_LREFILL3)
197
`ifdef OR1200_DC_STORE_REFILL
198
                | (state == `OR1200_DCFSM_SREFILL4)
199
`endif
200
                ;
201
 
202
//
203
// Main DC FSM
204
//
205
always @(posedge clk or posedge rst) begin
206
        if (rst) begin
207
                state <= #1 `OR1200_DCFSM_IDLE;
208
                saved_addr_r <= #1 32'b0;
209
                hitmiss_eval <= #1 1'b0;
210
                store <= #1 1'b0;
211
                load <= #1 1'b0;
212
                cnt <= #1 3'b000;
213
                cache_inhibit <= #1 1'b0;
214
        end
215
        else
216
        case (state)    // synopsys parallel_case
217
                `OR1200_DCFSM_IDLE :
218
                        if (dc_en & dcqmem_cycstb_i & dcqmem_we_i) begin        // store
219
                                state <= #1 `OR1200_DCFSM_CSTORE;
220
                                saved_addr_r <= #1 start_addr;
221
                                hitmiss_eval <= #1 1'b1;
222
                                store <= #1 1'b1;
223
                                load <= #1 1'b0;
224
                cache_inhibit <= #1 dcqmem_ci_i;
225
                        end
226
                        else if (dc_en & dcqmem_cycstb_i) begin         // load
227
                                state <= #1 `OR1200_DCFSM_CLOAD;
228
                                saved_addr_r <= #1 start_addr;
229
                                hitmiss_eval <= #1 1'b1;
230
                                store <= #1 1'b0;
231
                                load <= #1 1'b1;
232
                cache_inhibit <= #1 dcqmem_ci_i;
233
                        end
234
                        else begin                                                      // idle
235
                                hitmiss_eval <= #1 1'b0;
236
                                store <= #1 1'b0;
237
                                load <= #1 1'b0;
238
                                cache_inhibit <= #1 1'b0;
239
                        end
240
                `OR1200_DCFSM_CLOAD: begin              // load
241
                        if (dcqmem_cycstb_i & dcqmem_ci_i)
242
                                cache_inhibit <= #1 1'b1;
243
                        if (hitmiss_eval)
244
                                saved_addr_r[31:13] <= #1 start_addr[31:13];
245
                        if ((hitmiss_eval & !dcqmem_cycstb_i) ||                                        // load aborted (usually caused by DMMU)
246
                            (biudata_error) ||                                                                          // load terminated with an error
247
                            ((cache_inhibit | dcqmem_ci_i) & biudata_valid)) begin      // load from cache-inhibited area
248
                                state <= #1 `OR1200_DCFSM_IDLE;
249
                                hitmiss_eval <= #1 1'b0;
250
                                load <= #1 1'b0;
251
                                cache_inhibit <= #1 1'b0;
252
                        end
253
                        else if (tagcomp_miss & biudata_valid) begin    // load missed, finish current external load and refill
254
                                state <= #1 `OR1200_DCFSM_LREFILL3;
255
                                saved_addr_r[3:2] <= #1 saved_addr_r[3:2] + 1'd1;
256
                                hitmiss_eval <= #1 1'b0;
257
                                cnt <= #1 `OR1200_DCLS-2;
258
                                cache_inhibit <= #1 1'b0;
259
                        end
260
                        else if (!tagcomp_miss_wide & !dcqmem_ci_i) begin       // load hit, finish immediately
261
                                state <= #1 `OR1200_DCFSM_IDLE;
262
                                hitmiss_eval <= #1 1'b0;
263
                                load <= #1 1'b0;
264
                                cache_inhibit <= #1 1'b0;
265
                        end
266
                        else                                            // load in-progress
267
                                hitmiss_eval <= #1 1'b0;
268
                end
269
                `OR1200_DCFSM_LREFILL3 : begin
270
                        if (biudata_valid && (|cnt)) begin              // refill ack, more loads to come
271
                                cnt <= #1 cnt - 3'd1;
272
                                saved_addr_r[3:2] <= #1 saved_addr_r[3:2] + 1'd1;
273
                        end
274
                        else if (biudata_valid) begin                   // last load of line refill
275
                                state <= #1 `OR1200_DCFSM_IDLE;
276
                                load <= #1 1'b0;
277
                        end
278
                end
279
                `OR1200_DCFSM_CSTORE: begin             // store
280
                        if (dcqmem_cycstb_i & dcqmem_ci_i)
281
                                cache_inhibit <= #1 1'b1;
282
                        if (hitmiss_eval)
283
                                saved_addr_r[31:13] <= #1 start_addr[31:13];
284
                        if ((hitmiss_eval & !dcqmem_cycstb_i) ||        // store aborted (usually caused by DMMU)
285
                            (biudata_error) ||                                          // store terminated with an error
286
                            ((cache_inhibit | dcqmem_ci_i) & biudata_valid)) begin      // store to cache-inhibited area
287
                                state <= #1 `OR1200_DCFSM_IDLE;
288
                                hitmiss_eval <= #1 1'b0;
289
                                store <= #1 1'b0;
290
                                cache_inhibit <= #1 1'b0;
291
                        end
292
`ifdef OR1200_DC_STORE_REFILL
293
                        else if (tagcomp_miss & biudata_valid) begin    // store missed, finish write-through and doq load refill
294
                                state <= #1 `OR1200_DCFSM_SREFILL4;
295
                                hitmiss_eval <= #1 1'b0;
296
                                store <= #1 1'b0;
297
                                load <= #1 1'b1;
298
                                cnt <= #1 `OR1200_DCLS-1;
299
                                cache_inhibit <= #1 1'b0;
300
                        end
301
`endif
302
                        else if (biudata_valid) begin                   // store hit, finish write-through
303
                                state <= #1 `OR1200_DCFSM_IDLE;
304
                                hitmiss_eval <= #1 1'b0;
305
                                store <= #1 1'b0;
306
                                cache_inhibit <= #1 1'b0;
307
                        end
308
                        else                                            // store write-through in-progress
309
                                hitmiss_eval <= #1 1'b0;
310
                        end
311
`ifdef OR1200_DC_STORE_REFILL
312
                `OR1200_DCFSM_SREFILL4 : begin
313
                        if (biudata_valid && (|cnt)) begin              // refill ack, more loads to come
314
                                cnt <= #1 cnt - 1'd1;
315
                                saved_addr_r[3:2] <= #1 saved_addr_r[3:2] + 1'd1;
316
                        end
317
                        else if (biudata_valid) begin                   // last load of line refill
318
                                state <= #1 `OR1200_DCFSM_IDLE;
319
                                load <= #1 1'b0;
320
                        end
321
                end
322
`endif
323
                default:
324
                        state <= #1 `OR1200_DCFSM_IDLE;
325
        endcase
326
end
327
 
328
endmodule

powered by: WebSVN 2.1.0

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