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

Subversion Repositories or1k

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

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

powered by: WebSVN 2.1.0

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