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

Subversion Repositories or1k

[/] [or1k/] [tags/] [rel_1/] [or1200/] [rtl/] [verilog/] [or1200_dc_fsm.v] - Blame information for rev 1780

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

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

powered by: WebSVN 2.1.0

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