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

Subversion Repositories openrisc

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

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

Line No. Rev Author Line
1 350 julius
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  OR1200's IC FSM                                             ////
4
////                                                              ////
5
////  This file is part of the OpenRISC 1200 project              ////
6
////  http://opencores.org/project,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
// $Log: or1200_ic_fsm.v,v $
45
// Revision 2.0  2010/06/30 11:00:00  ORSoC
46
// Minor update: 
47
// Bugs fixed. 
48
//
49
 
50
// synopsys translate_off
51
`include "timescale.v"
52
// synopsys translate_on
53
`include "or1200_defines.v"
54
 
55
`define OR1200_ICFSM_IDLE       2'd0
56
`define OR1200_ICFSM_CFETCH     2'd1
57
`define OR1200_ICFSM_LREFILL3   2'd2
58
`define OR1200_ICFSM_IFETCH     2'd3
59
 
60
//
61
// Data cache FSM for cache line of 16 bytes (4x singleword)
62
//
63
 
64
module or1200_ic_fsm(
65
        // Clock and reset
66
        clk, rst,
67
 
68
        // Internal i/f to top level IC
69
        ic_en, icqmem_cycstb_i, icqmem_ci_i,
70
        tagcomp_miss, biudata_valid, biudata_error, start_addr, saved_addr,
71
        icram_we, biu_read, first_hit_ack, first_miss_ack, first_miss_err,
72
        burst, tag_we
73
);
74
 
75
//
76
// I/O
77
//
78
input                           clk;
79
input                           rst;
80
input                           ic_en;
81
input                           icqmem_cycstb_i;
82
input                           icqmem_ci_i;
83
input                           tagcomp_miss;
84
input                           biudata_valid;
85
input                           biudata_error;
86
input   [31:0]                   start_addr;
87
output  [31:0]                   saved_addr;
88
output  [3:0]                    icram_we;
89
output                          biu_read;
90
output                          first_hit_ack;
91
output                          first_miss_ack;
92
output                          first_miss_err;
93
output                          burst;
94
output                          tag_we;
95
 
96
//
97
// Internal wires and regs
98
//
99
reg     [31:0]                   saved_addr_r;
100
reg     [1:0]                    state;
101
reg     [2:0]                    cnt;
102
reg                             hitmiss_eval;
103
reg                             load;
104
reg                             cache_inhibit;
105 412 julius
reg                             waiting_for_first_fill_ack; // JPB
106
 
107 350 julius
   //
108
   // Generate of ICRAM write enables
109
   //
110
   assign icram_we = {4{biu_read & biudata_valid & !cache_inhibit}};
111
   assign tag_we = biu_read & biudata_valid & !cache_inhibit;
112
 
113
   //
114
   // BIU read and write
115
   //
116
   assign biu_read = (hitmiss_eval & tagcomp_miss) | (!hitmiss_eval & load);
117
 
118
   //assign saved_addr = hitmiss_eval ? start_addr : saved_addr_r;
119
   assign saved_addr = saved_addr_r;
120
 
121
   //
122
   // Assert for cache hit first word ready
123
   // Assert for cache miss first word stored/loaded OK
124
   // Assert for cache miss first word stored/loaded with an error
125
   //
126
   assign first_hit_ack = (state == `OR1200_ICFSM_CFETCH) & hitmiss_eval &
127
                          !tagcomp_miss & !cache_inhibit;
128
   assign first_miss_ack = (state == `OR1200_ICFSM_CFETCH) & biudata_valid;
129
   assign first_miss_err = (state == `OR1200_ICFSM_CFETCH) & biudata_error;
130
 
131
   //
132
   // Assert burst when doing reload of complete cache line
133
   //
134
   assign burst = (state == `OR1200_ICFSM_CFETCH) & tagcomp_miss &
135
                  !cache_inhibit | (state == `OR1200_ICFSM_LREFILL3);
136
 
137
   //
138
   // Main IC FSM
139
   //
140 358 julius
   always @(posedge clk or `OR1200_RST_EVENT rst) begin
141
      if (rst == `OR1200_RST_VALUE) begin
142 350 julius
         state <=  `OR1200_ICFSM_IDLE;
143
         saved_addr_r <=  32'b0;
144
         hitmiss_eval <=  1'b0;
145
         load <=  1'b0;
146
         cnt <=  3'b000;
147
         cache_inhibit <=  1'b0;
148 412 julius
         waiting_for_first_fill_ack <= 0; // JPB
149
 
150 350 julius
      end
151
      else
152
        case (state)    // synopsys parallel_case
153
          `OR1200_ICFSM_IDLE :
154
            if (ic_en & icqmem_cycstb_i) begin          // fetch
155
               state <=  `OR1200_ICFSM_CFETCH;
156
               saved_addr_r <=  start_addr;
157
               hitmiss_eval <=  1'b1;
158
               load <=  1'b1;
159
               cache_inhibit <=  icqmem_ci_i;
160 412 julius
               waiting_for_first_fill_ack <= 0; // JPB
161 350 julius
            end
162
            else begin                  // idle
163
               hitmiss_eval <=  1'b0;
164
               load <=  1'b0;
165
               cache_inhibit <=  1'b0;
166 412 julius
            end
167 350 julius
          `OR1200_ICFSM_CFETCH: begin   // fetch
168
 
169
             if (icqmem_cycstb_i & icqmem_ci_i)
170
               cache_inhibit <=  1'b1;
171
 
172
             if (hitmiss_eval)
173
               saved_addr_r[31:13] <=  start_addr[31:13];
174
 
175
             if ((!ic_en) ||
176
                 // fetch aborted (usually caused by IMMU)
177
                 (hitmiss_eval & !icqmem_cycstb_i) ||
178
                 (biudata_error) ||  // fetch terminated with an error
179
                 // fetch from cache-inhibited page
180
                 (cache_inhibit & biudata_valid)) begin
181
                state <=  `OR1200_ICFSM_IDLE;
182
                hitmiss_eval <=  1'b0;
183
                load <=  1'b0;
184
                cache_inhibit <=  1'b0;
185 412 julius
                waiting_for_first_fill_ack <= 0;
186 350 julius
             end // if ((!ic_en) ||...       
187
             // fetch missed, finish current external fetch and refill
188
             else if (tagcomp_miss & biudata_valid) begin
189
                state <=  `OR1200_ICFSM_LREFILL3;
190
                saved_addr_r[3:2] <=  saved_addr_r[3:2] + 1'd1;
191
                hitmiss_eval <=  1'b0;
192
                cnt <=  `OR1200_ICLS-2;
193
                cache_inhibit <=  1'b0;
194 412 julius
                waiting_for_first_fill_ack <= 0; // JPB
195 350 julius
             end
196
             // fetch aborted (usually caused by exception)
197
             else if (!icqmem_cycstb_i) begin
198
                state <=  `OR1200_ICFSM_IDLE;
199
                hitmiss_eval <=  1'b0;
200
                load <=  1'b0;
201
                cache_inhibit <=  1'b0;
202 412 julius
                waiting_for_first_fill_ack <= 0; // JPB
203 350 julius
             end
204
             // fetch hit, finish immediately
205 412 julius
             else if (!tagcomp_miss & !icqmem_ci_i &
206
                      !waiting_for_first_fill_ack) begin
207
                state <=  `OR1200_ICFSM_IDLE; // JPB
208
                load <= 1'b0; // JPB    
209
                hitmiss_eval <=  1'b0; // JPB
210 350 julius
                saved_addr_r <=  start_addr;
211
                cache_inhibit <=  1'b0;
212
             end
213
             else   // fetch in-progress
214
               hitmiss_eval <=  1'b0;
215 412 julius
 
216
             if (hitmiss_eval & tagcomp_miss) // JPB
217
               waiting_for_first_fill_ack <= 1;
218
 
219 350 julius
          end
220
          `OR1200_ICFSM_LREFILL3 : begin
221
             // abort because IC has just been turned off
222
             if (!ic_en) begin
223
                // invalidate before IC can be turned on
224
                state <=  `OR1200_ICFSM_IDLE;
225
                saved_addr_r <=  start_addr;
226
                hitmiss_eval <=  1'b0;
227
                load <=  1'b0;
228
             end
229
             // refill ack, more fetchs to come
230
             else if (biudata_valid && (|cnt)) begin
231
                cnt <=  cnt - 3'd1;
232
                saved_addr_r[3:2] <=  saved_addr_r[3:2] + 1'd1;
233
             end
234
             // last fetch of line refill
235
             else if (biudata_valid) begin
236
                state <=  `OR1200_ICFSM_IDLE;
237
                saved_addr_r <=  start_addr;
238
                hitmiss_eval <=  1'b0;
239
                load <=  1'b0;
240
             end
241
          end
242
          default:
243
            state <=  `OR1200_ICFSM_IDLE;
244
        endcase
245
   end
246
 
247
endmodule

powered by: WebSVN 2.1.0

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