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 636

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

powered by: WebSVN 2.1.0

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