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

Subversion Repositories or1k

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

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 1171 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 1171 lampret
// Revision 1.8  2003/06/06 02:54:47  lampret
48
// When OR1200_NO_IMMU and OR1200_NO_IC are not both defined or undefined at the same time, results in a IC bug. Fixed.
49
//
50 1161 lampret
// Revision 1.7  2002/03/29 15:16:55  lampret
51
// Some of the warnings fixed.
52
//
53 788 lampret
// Revision 1.6  2002/03/28 19:10:40  lampret
54
// Optimized cache controller FSM.
55
//
56 775 lampret
// Revision 1.1.1.1  2002/03/21 16:55:45  lampret
57
// First import of the "new" XESS XSV environment.
58
//
59
//
60
// Revision 1.5  2002/02/11 04:33:17  lampret
61
// Speed optimizations (removed duplicate _cyc_ and _stb_). Fixed D/IMMU cache-inhibit attr.
62
//
63 660 lampret
// Revision 1.4  2002/02/01 19:56:54  lampret
64
// Fixed combinational loops.
65
//
66 636 lampret
// Revision 1.3  2002/01/28 01:16:00  lampret
67
// 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.
68
//
69 617 lampret
// Revision 1.2  2002/01/14 06:18:22  lampret
70
// Fixed mem2reg bug in FAST implementation. Updated debug unit to work with new genpc/if.
71
//
72 562 lampret
// Revision 1.1  2002/01/03 08:16:15  lampret
73
// New prefixes for RTL files, prefixed module names. Updated cache controllers and MMUs.
74
//
75 504 lampret
// Revision 1.9  2001/10/21 17:57:16  lampret
76
// 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.
77
//
78
// Revision 1.8  2001/10/19 23:28:46  lampret
79
// Fixed some synthesis warnings. Configured with caches and MMUs.
80
//
81
// Revision 1.7  2001/10/14 13:12:09  lampret
82
// MP3 version.
83
//
84
// Revision 1.1.1.1  2001/10/06 10:18:35  igorm
85
// no message
86
//
87
// Revision 1.2  2001/08/09 13:39:33  lampret
88
// Major clean-up.
89
//
90
// Revision 1.1  2001/07/20 00:46:03  lampret
91
// Development version of RTL. Libraries are missing.
92
//
93
//
94
 
95
// synopsys translate_off
96
`include "timescale.v"
97
// synopsys translate_on
98
`include "or1200_defines.v"
99
 
100 788 lampret
`define OR1200_ICFSM_IDLE       2'd0
101
`define OR1200_ICFSM_CFETCH     2'd1
102
`define OR1200_ICFSM_LREFILL3   2'd2
103
`define OR1200_ICFSM_IFETCH     2'd3
104 504 lampret
 
105
//
106
// Data cache FSM for cache line of 16 bytes (4x singleword)
107
//
108
 
109
module or1200_ic_fsm(
110
        // Clock and reset
111
        clk, rst,
112
 
113
        // Internal i/f to top level IC
114 1171 lampret
        ic_en, icqmem_cycstb_i, icqmem_ci_i,
115 504 lampret
        tagcomp_miss, biudata_valid, biudata_error, start_addr, saved_addr,
116
        icram_we, biu_read, first_hit_ack, first_miss_ack, first_miss_err,
117 660 lampret
        burst, tag_we
118 504 lampret
);
119
 
120
//
121
// I/O
122
//
123
input                           clk;
124
input                           rst;
125
input                           ic_en;
126 1171 lampret
input                           icqmem_cycstb_i;
127
input                           icqmem_ci_i;
128 504 lampret
input                           tagcomp_miss;
129
input                           biudata_valid;
130
input                           biudata_error;
131
input   [31:0]                   start_addr;
132
output  [31:0]                   saved_addr;
133
output  [3:0]                    icram_we;
134
output                          biu_read;
135
output                          first_hit_ack;
136
output                          first_miss_ack;
137
output                          first_miss_err;
138
output                          burst;
139 660 lampret
output                          tag_we;
140 504 lampret
 
141
//
142
// Internal wires and regs
143
//
144 660 lampret
reg     [31:0]                   saved_addr_r;
145 788 lampret
reg     [1:0]                    state;
146 504 lampret
reg     [2:0]                    cnt;
147
reg                             hitmiss_eval;
148
reg                             load;
149 660 lampret
reg                             cache_inhibit;
150 504 lampret
 
151
//
152
// Generate of ICRAM write enables
153
//
154 1161 lampret
assign icram_we = {4{biu_read & biudata_valid & !cache_inhibit}};
155 660 lampret
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
 
162 660 lampret
//assign saved_addr = hitmiss_eval ? start_addr : saved_addr_r;
163
assign saved_addr = saved_addr_r;
164
 
165 504 lampret
//
166
// Assert for cache hit first word ready
167
// Assert for cache miss first word stored/loaded OK
168
// Assert for cache miss first word stored/loaded with an error
169
//
170 1171 lampret
assign first_hit_ack = (state == `OR1200_ICFSM_CFETCH) & hitmiss_eval & !tagcomp_miss & !cache_inhibit & !icqmem_ci_i;
171 660 lampret
assign first_miss_ack = (state == `OR1200_ICFSM_CFETCH) & biudata_valid;
172
assign first_miss_err = (state == `OR1200_ICFSM_CFETCH) & biudata_error;
173 504 lampret
 
174
//
175
// Assert burst when doing reload of complete cache line
176
//
177 660 lampret
assign burst = (state == `OR1200_ICFSM_CFETCH) & tagcomp_miss & !cache_inhibit
178 504 lampret
                | (state == `OR1200_ICFSM_LREFILL3);
179
 
180
//
181
// Main IC FSM
182
//
183
always @(posedge clk or posedge rst) begin
184
        if (rst) begin
185
                state <= #1 `OR1200_ICFSM_IDLE;
186 660 lampret
                saved_addr_r <= #1 32'b0;
187 504 lampret
                hitmiss_eval <= #1 1'b0;
188
                load <= #1 1'b0;
189
                cnt <= #1 3'b000;
190 660 lampret
                cache_inhibit <= #1 1'b0;
191 504 lampret
        end
192
        else
193
        case (state)    // synopsys parallel_case
194
                `OR1200_ICFSM_IDLE :
195 1171 lampret
                        if (ic_en & icqmem_cycstb_i) begin              // fetch
196 636 lampret
                                state <= #1 `OR1200_ICFSM_CFETCH;
197 660 lampret
                                saved_addr_r <= #1 start_addr;
198 504 lampret
                                hitmiss_eval <= #1 1'b1;
199
                                load <= #1 1'b1;
200 660 lampret
                                cache_inhibit <= #1 1'b0;
201 504 lampret
                        end
202
                        else begin                                                      // idle
203
                                hitmiss_eval <= #1 1'b0;
204
                                load <= #1 1'b0;
205 660 lampret
                                cache_inhibit <= #1 1'b0;
206 504 lampret
                        end
207 660 lampret
                `OR1200_ICFSM_CFETCH: begin     // fetch
208 1171 lampret
                        if (icqmem_cycstb_i & icqmem_ci_i)
209 660 lampret
                                cache_inhibit <= #1 1'b1;
210
                        if (hitmiss_eval)
211
                                saved_addr_r[31:13] <= #1 start_addr[31:13];
212 775 lampret
                        if ((!ic_en) ||
213 1171 lampret
                            (hitmiss_eval & !icqmem_cycstb_i) ||        // fetch aborted (usually caused by IMMU)
214 775 lampret
                            (biudata_error) ||                                          // fetch terminated with an error
215
                            (cache_inhibit & biudata_valid)) begin      // fetch from cache-inhibited page
216 504 lampret
                                state <= #1 `OR1200_ICFSM_IDLE;
217
                                hitmiss_eval <= #1 1'b0;
218
                                load <= #1 1'b0;
219 660 lampret
                                cache_inhibit <= #1 1'b0;
220 504 lampret
                        end
221 636 lampret
                        else if (tagcomp_miss & biudata_valid) begin    // fetch missed, finish current external fetch and refill
222 504 lampret
                                state <= #1 `OR1200_ICFSM_LREFILL3;
223 1171 lampret
                                saved_addr_r[3:2] <= #1 saved_addr_r[3:2] + 1'd1;
224 504 lampret
                                hitmiss_eval <= #1 1'b0;
225
                                cnt <= #1 `OR1200_ICLS-2;
226 660 lampret
                                cache_inhibit <= #1 1'b0;
227 504 lampret
                        end
228 1171 lampret
                        else if (!tagcomp_miss & !icqmem_ci_i) begin    // fetch hit, finish immediately
229 660 lampret
                                saved_addr_r <= #1 start_addr;
230
                                cache_inhibit <= #1 1'b0;
231 504 lampret
                        end
232 1171 lampret
                        else if (!icqmem_cycstb_i) begin        // fetch aborted (usually caused by exception)
233 562 lampret
                                state <= #1 `OR1200_ICFSM_IDLE;
234
                                hitmiss_eval <= #1 1'b0;
235
                                load <= #1 1'b0;
236 660 lampret
                                cache_inhibit <= #1 1'b0;
237 562 lampret
                        end
238 636 lampret
                        else                                            // fetch in-progress
239 504 lampret
                                hitmiss_eval <= #1 1'b0;
240 660 lampret
                end
241 504 lampret
                `OR1200_ICFSM_LREFILL3 : begin
242 775 lampret
                        if (biudata_valid && (|cnt)) begin              // refill ack, more fetchs to come
243 1171 lampret
                                cnt <= #1 cnt - 1'd1;
244
                                saved_addr_r[3:2] <= #1 saved_addr_r[3:2] + 1'd1;
245 504 lampret
                        end
246 636 lampret
                        else if (biudata_valid) begin                   // last fetch of line refill
247 504 lampret
                                state <= #1 `OR1200_ICFSM_IDLE;
248 660 lampret
                                saved_addr_r <= #1 start_addr;
249 504 lampret
                                hitmiss_eval <= #1 1'b0;
250
                                load <= #1 1'b0;
251
                        end
252
                end
253
                default:
254
                        state <= #1 `OR1200_ICFSM_IDLE;
255
        endcase
256
end
257
 
258
endmodule

powered by: WebSVN 2.1.0

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