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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [or1200/] [rtl/] [verilog/] [or1200_ic_fsm.v] - Blame information for rev 1774

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

Line No. Rev Author Line
1 504 lampret
//////////////////////////////////////////////////////////////////////
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 1267 lampret
////  Insn cache state machine                                    ////
10 504 lampret
////                                                              ////
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 1293 lampret
// Revision 1.9  2004/04/05 08:29:57  lampret
48
// Merged branch_qmem into main tree.
49
//
50 1267 lampret
// Revision 1.8.4.1  2003/07/08 15:36:37  lampret
51
// Added embedded memory QMEM.
52
//
53
// Revision 1.8  2003/06/06 02:54:47  lampret
54
// When OR1200_NO_IMMU and OR1200_NO_IC are not both defined or undefined at the same time, results in a IC bug. Fixed.
55
//
56 1161 lampret
// Revision 1.7  2002/03/29 15:16:55  lampret
57
// Some of the warnings fixed.
58
//
59 788 lampret
// Revision 1.6  2002/03/28 19:10:40  lampret
60
// Optimized cache controller FSM.
61
//
62 775 lampret
// 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 660 lampret
// Revision 1.4  2002/02/01 19:56:54  lampret
70
// Fixed combinational loops.
71
//
72 636 lampret
// Revision 1.3  2002/01/28 01:16:00  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 617 lampret
// 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 562 lampret
// 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 504 lampret
// 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 ic.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 788 lampret
`define OR1200_ICFSM_IDLE       2'd0
107
`define OR1200_ICFSM_CFETCH     2'd1
108
`define OR1200_ICFSM_LREFILL3   2'd2
109
`define OR1200_ICFSM_IFETCH     2'd3
110 504 lampret
 
111
//
112
// Data cache FSM for cache line of 16 bytes (4x singleword)
113
//
114
 
115
module or1200_ic_fsm(
116
        // Clock and reset
117
        clk, rst,
118
 
119
        // Internal i/f to top level IC
120 1267 lampret
        ic_en, icqmem_cycstb_i, icqmem_ci_i,
121 504 lampret
        tagcomp_miss, biudata_valid, biudata_error, start_addr, saved_addr,
122
        icram_we, biu_read, first_hit_ack, first_miss_ack, first_miss_err,
123 660 lampret
        burst, tag_we
124 504 lampret
);
125
 
126
//
127
// I/O
128
//
129
input                           clk;
130
input                           rst;
131
input                           ic_en;
132 1267 lampret
input                           icqmem_cycstb_i;
133
input                           icqmem_ci_i;
134 504 lampret
input                           tagcomp_miss;
135
input                           biudata_valid;
136
input                           biudata_error;
137
input   [31:0]                   start_addr;
138
output  [31:0]                   saved_addr;
139
output  [3:0]                    icram_we;
140
output                          biu_read;
141
output                          first_hit_ack;
142
output                          first_miss_ack;
143
output                          first_miss_err;
144
output                          burst;
145 660 lampret
output                          tag_we;
146 504 lampret
 
147
//
148
// Internal wires and regs
149
//
150 660 lampret
reg     [31:0]                   saved_addr_r;
151 788 lampret
reg     [1:0]                    state;
152 504 lampret
reg     [2:0]                    cnt;
153
reg                             hitmiss_eval;
154
reg                             load;
155 660 lampret
reg                             cache_inhibit;
156 504 lampret
 
157
//
158
// Generate of ICRAM write enables
159
//
160 1161 lampret
assign icram_we = {4{biu_read & biudata_valid & !cache_inhibit}};
161 660 lampret
assign tag_we = biu_read & biudata_valid & !cache_inhibit;
162 504 lampret
 
163
//
164
// BIU read and write
165
//
166
assign biu_read = (hitmiss_eval & tagcomp_miss) | (!hitmiss_eval & load);
167
 
168 660 lampret
//assign saved_addr = hitmiss_eval ? start_addr : saved_addr_r;
169
assign saved_addr = saved_addr_r;
170
 
171 504 lampret
//
172
// Assert for cache hit first word ready
173
// Assert for cache miss first word stored/loaded OK
174
// Assert for cache miss first word stored/loaded with an error
175
//
176 1267 lampret
assign first_hit_ack = (state == `OR1200_ICFSM_CFETCH) & hitmiss_eval & !tagcomp_miss & !cache_inhibit & !icqmem_ci_i;
177 660 lampret
assign first_miss_ack = (state == `OR1200_ICFSM_CFETCH) & biudata_valid;
178
assign first_miss_err = (state == `OR1200_ICFSM_CFETCH) & biudata_error;
179 504 lampret
 
180
//
181
// Assert burst when doing reload of complete cache line
182
//
183 660 lampret
assign burst = (state == `OR1200_ICFSM_CFETCH) & tagcomp_miss & !cache_inhibit
184 504 lampret
                | (state == `OR1200_ICFSM_LREFILL3);
185
 
186
//
187
// Main IC FSM
188
//
189
always @(posedge clk or posedge rst) begin
190
        if (rst) begin
191
                state <= #1 `OR1200_ICFSM_IDLE;
192 660 lampret
                saved_addr_r <= #1 32'b0;
193 504 lampret
                hitmiss_eval <= #1 1'b0;
194
                load <= #1 1'b0;
195
                cnt <= #1 3'b000;
196 660 lampret
                cache_inhibit <= #1 1'b0;
197 504 lampret
        end
198
        else
199
        case (state)    // synopsys parallel_case
200
                `OR1200_ICFSM_IDLE :
201 1267 lampret
                        if (ic_en & icqmem_cycstb_i) begin              // fetch
202 636 lampret
                                state <= #1 `OR1200_ICFSM_CFETCH;
203 660 lampret
                                saved_addr_r <= #1 start_addr;
204 504 lampret
                                hitmiss_eval <= #1 1'b1;
205
                                load <= #1 1'b1;
206 660 lampret
                                cache_inhibit <= #1 1'b0;
207 504 lampret
                        end
208
                        else begin                                                      // idle
209
                                hitmiss_eval <= #1 1'b0;
210
                                load <= #1 1'b0;
211 660 lampret
                                cache_inhibit <= #1 1'b0;
212 504 lampret
                        end
213 660 lampret
                `OR1200_ICFSM_CFETCH: begin     // fetch
214 1267 lampret
                        if (icqmem_cycstb_i & icqmem_ci_i)
215 660 lampret
                                cache_inhibit <= #1 1'b1;
216
                        if (hitmiss_eval)
217
                                saved_addr_r[31:13] <= #1 start_addr[31:13];
218 775 lampret
                        if ((!ic_en) ||
219 1267 lampret
                            (hitmiss_eval & !icqmem_cycstb_i) ||        // fetch aborted (usually caused by IMMU)
220 775 lampret
                            (biudata_error) ||                                          // fetch terminated with an error
221
                            (cache_inhibit & biudata_valid)) begin      // fetch from cache-inhibited page
222 504 lampret
                                state <= #1 `OR1200_ICFSM_IDLE;
223
                                hitmiss_eval <= #1 1'b0;
224
                                load <= #1 1'b0;
225 660 lampret
                                cache_inhibit <= #1 1'b0;
226 504 lampret
                        end
227 636 lampret
                        else if (tagcomp_miss & biudata_valid) begin    // fetch missed, finish current external fetch and refill
228 504 lampret
                                state <= #1 `OR1200_ICFSM_LREFILL3;
229 1267 lampret
                                saved_addr_r[3:2] <= #1 saved_addr_r[3:2] + 1'd1;
230 504 lampret
                                hitmiss_eval <= #1 1'b0;
231
                                cnt <= #1 `OR1200_ICLS-2;
232 660 lampret
                                cache_inhibit <= #1 1'b0;
233 504 lampret
                        end
234 1267 lampret
                        else if (!tagcomp_miss & !icqmem_ci_i) begin    // fetch hit, finish immediately
235 660 lampret
                                saved_addr_r <= #1 start_addr;
236
                                cache_inhibit <= #1 1'b0;
237 504 lampret
                        end
238 1267 lampret
                        else if (!icqmem_cycstb_i) begin        // fetch aborted (usually caused by exception)
239 562 lampret
                                state <= #1 `OR1200_ICFSM_IDLE;
240
                                hitmiss_eval <= #1 1'b0;
241
                                load <= #1 1'b0;
242 660 lampret
                                cache_inhibit <= #1 1'b0;
243 562 lampret
                        end
244 636 lampret
                        else                                            // fetch in-progress
245 504 lampret
                                hitmiss_eval <= #1 1'b0;
246 660 lampret
                end
247 504 lampret
                `OR1200_ICFSM_LREFILL3 : begin
248 775 lampret
                        if (biudata_valid && (|cnt)) begin              // refill ack, more fetchs to come
249 1293 lampret
                                cnt <= #1 cnt - 3'd1;
250 1267 lampret
                                saved_addr_r[3:2] <= #1 saved_addr_r[3:2] + 1'd1;
251 504 lampret
                        end
252 636 lampret
                        else if (biudata_valid) begin                   // last fetch of line refill
253 504 lampret
                                state <= #1 `OR1200_ICFSM_IDLE;
254 660 lampret
                                saved_addr_r <= #1 start_addr;
255 504 lampret
                                hitmiss_eval <= #1 1'b0;
256
                                load <= #1 1'b0;
257
                        end
258
                end
259
                default:
260
                        state <= #1 `OR1200_ICFSM_IDLE;
261
        endcase
262
end
263
 
264
endmodule

powered by: WebSVN 2.1.0

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