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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [or1200/] [rtl/] [verilog/] [or1200_ic_fsm.v] - Blame information for rev 249

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

Line No. Rev Author Line
1 10 unneback
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  OR1200's IC FSM                                             ////
4
////                                                              ////
5
////  This file is part of the OpenRISC 1200 project              ////
6
////  http://www.opencores.org/cores/or1k/                        ////
7
////                                                              ////
8
////  Description                                                 ////
9
////  Insn 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 141 marcus.erl
// $Log: or1200_ic_fsm.v,v $
47
// Revision 2.0  2010/06/30 11:00:00  ORSoC
48
// Minor update: 
49
// Bugs fixed. 
50
//
51
// Revision 1.10  2004/06/08 18:17:36  lampret
52
// Non-functional changes. Coding style fixes.
53
//
54 10 unneback
// Revision 1.9  2004/04/05 08:29:57  lampret
55
// Merged branch_qmem into main tree.
56
//
57
// Revision 1.8.4.1  2003/07/08 15:36:37  lampret
58
// Added embedded memory QMEM.
59
//
60
// Revision 1.8  2003/06/06 02:54:47  lampret
61
// When OR1200_NO_IMMU and OR1200_NO_IC are not both defined or undefined at the same time, results in a IC bug. Fixed.
62
//
63
// Revision 1.7  2002/03/29 15:16:55  lampret
64
// Some of the warnings fixed.
65
//
66
// Revision 1.6  2002/03/28 19:10:40  lampret
67
// Optimized cache controller FSM.
68
//
69
// Revision 1.1.1.1  2002/03/21 16:55:45  lampret
70
// First import of the "new" XESS XSV environment.
71
//
72
//
73
// Revision 1.5  2002/02/11 04:33:17  lampret
74
// Speed optimizations (removed duplicate _cyc_ and _stb_). Fixed D/IMMU cache-inhibit attr.
75
//
76
// Revision 1.4  2002/02/01 19:56:54  lampret
77
// Fixed combinational loops.
78
//
79
// Revision 1.3  2002/01/28 01:16:00  lampret
80
// 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.
81
//
82
// Revision 1.2  2002/01/14 06:18:22  lampret
83
// Fixed mem2reg bug in FAST implementation. Updated debug unit to work with new genpc/if.
84
//
85
// Revision 1.1  2002/01/03 08:16:15  lampret
86
// New prefixes for RTL files, prefixed module names. Updated cache controllers and MMUs.
87
//
88
// Revision 1.9  2001/10/21 17:57:16  lampret
89
// Removed params from generic_XX.v. Added translate_off/on in sprs.v and id.v. Removed spr_addr from ic.v and ic.v. Fixed CR+LF.
90
//
91
// Revision 1.8  2001/10/19 23:28:46  lampret
92
// Fixed some synthesis warnings. Configured with caches and MMUs.
93
//
94
// Revision 1.7  2001/10/14 13:12:09  lampret
95
// MP3 version.
96
//
97
// Revision 1.1.1.1  2001/10/06 10:18:35  igorm
98
// no message
99
//
100
// Revision 1.2  2001/08/09 13:39:33  lampret
101
// Major clean-up.
102
//
103
// Revision 1.1  2001/07/20 00:46:03  lampret
104
// Development version of RTL. Libraries are missing.
105
//
106
//
107
 
108
// synopsys translate_off
109
`include "timescale.v"
110
// synopsys translate_on
111
`include "or1200_defines.v"
112
 
113
`define OR1200_ICFSM_IDLE       2'd0
114
`define OR1200_ICFSM_CFETCH     2'd1
115
`define OR1200_ICFSM_LREFILL3   2'd2
116
`define OR1200_ICFSM_IFETCH     2'd3
117
 
118
//
119
// Data cache FSM for cache line of 16 bytes (4x singleword)
120
//
121
 
122
module or1200_ic_fsm(
123
        // Clock and reset
124
        clk, rst,
125
 
126
        // Internal i/f to top level IC
127
        ic_en, icqmem_cycstb_i, icqmem_ci_i,
128
        tagcomp_miss, biudata_valid, biudata_error, start_addr, saved_addr,
129
        icram_we, biu_read, first_hit_ack, first_miss_ack, first_miss_err,
130
        burst, tag_we
131
);
132
 
133
//
134
// I/O
135
//
136
input                           clk;
137
input                           rst;
138
input                           ic_en;
139
input                           icqmem_cycstb_i;
140
input                           icqmem_ci_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]                    icram_we;
147
output                          biu_read;
148
output                          first_hit_ack;
149
output                          first_miss_ack;
150
output                          first_miss_err;
151
output                          burst;
152
output                          tag_we;
153
 
154
//
155
// Internal wires and regs
156
//
157
reg     [31:0]                   saved_addr_r;
158
reg     [1:0]                    state;
159
reg     [2:0]                    cnt;
160
reg                             hitmiss_eval;
161
reg                             load;
162
reg                             cache_inhibit;
163
 
164
//
165
// Generate of ICRAM write enables
166
//
167
assign icram_we = {4{biu_read & biudata_valid & !cache_inhibit}};
168
assign tag_we = biu_read & biudata_valid & !cache_inhibit;
169
 
170
//
171
// BIU read and write
172
//
173
assign biu_read = (hitmiss_eval & tagcomp_miss) | (!hitmiss_eval & load);
174
 
175
//assign saved_addr = hitmiss_eval ? start_addr : saved_addr_r;
176
assign saved_addr = saved_addr_r;
177
 
178
//
179
// Assert for cache hit first word ready
180
// Assert for cache miss first word stored/loaded OK
181
// Assert for cache miss first word stored/loaded with an error
182
//
183 141 marcus.erl
assign first_hit_ack = (state == `OR1200_ICFSM_CFETCH) & hitmiss_eval & !tagcomp_miss & !cache_inhibit;
184 10 unneback
assign first_miss_ack = (state == `OR1200_ICFSM_CFETCH) & biudata_valid;
185
assign first_miss_err = (state == `OR1200_ICFSM_CFETCH) & biudata_error;
186
 
187
//
188
// Assert burst when doing reload of complete cache line
189
//
190
assign burst = (state == `OR1200_ICFSM_CFETCH) & tagcomp_miss & !cache_inhibit
191
                | (state == `OR1200_ICFSM_LREFILL3);
192
 
193
//
194
// Main IC FSM
195
//
196
always @(posedge clk or posedge rst) begin
197
        if (rst) begin
198
                state <= #1 `OR1200_ICFSM_IDLE;
199
                saved_addr_r <= #1 32'b0;
200
                hitmiss_eval <= #1 1'b0;
201
                load <= #1 1'b0;
202
                cnt <= #1 3'b000;
203
                cache_inhibit <= #1 1'b0;
204
        end
205
        else
206
        case (state)    // synopsys parallel_case
207
                `OR1200_ICFSM_IDLE :
208
                        if (ic_en & icqmem_cycstb_i) begin              // fetch
209
                                state <= #1 `OR1200_ICFSM_CFETCH;
210
                                saved_addr_r <= #1 start_addr;
211
                                hitmiss_eval <= #1 1'b1;
212
                                load <= #1 1'b1;
213 141 marcus.erl
                                cache_inhibit <= #1 icqmem_ci_i;
214 10 unneback
                        end
215
                        else begin                                                      // idle
216
                                hitmiss_eval <= #1 1'b0;
217
                                load <= #1 1'b0;
218
                                cache_inhibit <= #1 1'b0;
219
                        end
220
                `OR1200_ICFSM_CFETCH: begin     // fetch
221
                        if (icqmem_cycstb_i & icqmem_ci_i)
222
                                cache_inhibit <= #1 1'b1;
223
                        if (hitmiss_eval)
224
                                saved_addr_r[31:13] <= #1 start_addr[31:13];
225
                        if ((!ic_en) ||
226
                            (hitmiss_eval & !icqmem_cycstb_i) ||        // fetch aborted (usually caused by IMMU)
227
                            (biudata_error) ||                                          // fetch terminated with an error
228
                            (cache_inhibit & biudata_valid)) begin      // fetch from cache-inhibited page
229
                                state <= #1 `OR1200_ICFSM_IDLE;
230
                                hitmiss_eval <= #1 1'b0;
231
                                load <= #1 1'b0;
232
                                cache_inhibit <= #1 1'b0;
233
                        end
234
                        else if (tagcomp_miss & biudata_valid) begin    // fetch missed, finish current external fetch and refill
235
                                state <= #1 `OR1200_ICFSM_LREFILL3;
236
                                saved_addr_r[3:2] <= #1 saved_addr_r[3:2] + 1'd1;
237
                                hitmiss_eval <= #1 1'b0;
238
                                cnt <= #1 `OR1200_ICLS-2;
239
                                cache_inhibit <= #1 1'b0;
240
                        end
241
                        else if (!icqmem_cycstb_i) begin        // fetch aborted (usually caused by exception)
242
                                state <= #1 `OR1200_ICFSM_IDLE;
243
                                hitmiss_eval <= #1 1'b0;
244
                                load <= #1 1'b0;
245
                                cache_inhibit <= #1 1'b0;
246
                        end
247 141 marcus.erl
                        else if (!tagcomp_miss & !icqmem_ci_i) begin    // fetch hit, finish immediately
248
                                saved_addr_r <= #1 start_addr;
249
                                cache_inhibit <= #1 1'b0;
250
                        end
251 10 unneback
                        else                                            // fetch in-progress
252
                                hitmiss_eval <= #1 1'b0;
253
                end
254
                `OR1200_ICFSM_LREFILL3 : begin
255 141 marcus.erl
            if (!ic_en) begin                   // abort because IC has just been turned off
256
                                state <= #1 `OR1200_ICFSM_IDLE; // invalidate before IC can be turned on
257
                saved_addr_r <= #1 start_addr;
258
                hitmiss_eval <= #1 1'b0;
259
                load <= #1 1'b0;
260
            end
261
                        else if (biudata_valid && (|cnt)) begin         // refill ack, more fetchs to come
262 10 unneback
                                cnt <= #1 cnt - 3'd1;
263
                                saved_addr_r[3:2] <= #1 saved_addr_r[3:2] + 1'd1;
264
                        end
265
                        else if (biudata_valid) begin                   // last fetch of line refill
266
                                state <= #1 `OR1200_ICFSM_IDLE;
267
                                saved_addr_r <= #1 start_addr;
268
                                hitmiss_eval <= #1 1'b0;
269
                                load <= #1 1'b0;
270
                        end
271
                end
272
                default:
273
                        state <= #1 `OR1200_ICFSM_IDLE;
274
        endcase
275
end
276
 
277
endmodule

powered by: WebSVN 2.1.0

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