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

Subversion Repositories or1k

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

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

powered by: WebSVN 2.1.0

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