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

Subversion Repositories or1k

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

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

powered by: WebSVN 2.1.0

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