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 864

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 415 julius
// Instruction cache FSM
62 350 julius
//
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 415 julius
        tagcomp_miss,
71
        biudata_valid, biudata_error,
72
        start_addr, saved_addr,
73
        icram_we, tag_we,
74
        biu_read,
75
        first_hit_ack, first_miss_ack, first_miss_err,
76
        burst
77 350 julius
);
78
 
79
//
80
// I/O
81
//
82
input                           clk;
83
input                           rst;
84
input                           ic_en;
85
input                           icqmem_cycstb_i;
86
input                           icqmem_ci_i;
87
input                           tagcomp_miss;
88
input                           biudata_valid;
89
input                           biudata_error;
90
input   [31:0]                   start_addr;
91
output  [31:0]                   saved_addr;
92
output  [3:0]                    icram_we;
93
output                          biu_read;
94
output                          first_hit_ack;
95
output                          first_miss_ack;
96
output                          first_miss_err;
97
output                          burst;
98
output                          tag_we;
99
 
100
//
101
// Internal wires and regs
102
//
103
reg     [31:0]                   saved_addr_r;
104
reg     [1:0]                    state;
105 477 julius
reg [`OR1200_ICLS-1:0]           cnt;
106 350 julius
reg                             hitmiss_eval;
107
reg                             load;
108
reg                             cache_inhibit;
109 415 julius
reg                             last_eval_miss; // JPB
110 412 julius
 
111 350 julius
   //
112
   // Generate of ICRAM write enables
113
   //
114
   assign icram_we = {4{biu_read & biudata_valid & !cache_inhibit}};
115
   assign tag_we = biu_read & biudata_valid & !cache_inhibit;
116
 
117
   //
118
   // BIU read and write
119
   //
120
   assign biu_read = (hitmiss_eval & tagcomp_miss) | (!hitmiss_eval & load);
121
 
122
   //assign saved_addr = hitmiss_eval ? start_addr : saved_addr_r;
123
   assign saved_addr = saved_addr_r;
124
 
125 849 stekern
   // Asserted when a cache hit occurs and the first word is ready/valid
126 350 julius
   assign first_hit_ack = (state == `OR1200_ICFSM_CFETCH) & hitmiss_eval &
127
                          !tagcomp_miss & !cache_inhibit;
128 849 stekern
 
129
   // Asserted when a cache miss occurs, but the first word of the new
130
   // cache line is ready (on the bus)
131
   // Cache hits overpower bus data
132
   assign first_miss_ack = (state == `OR1200_ICFSM_CFETCH) & biudata_valid &
133
                           ~first_hit_ack;
134
 
135
   // Asserted when a cache occurs, but there was a bus error with handling
136
   // the old line or fetching the new line
137 350 julius
   assign first_miss_err = (state == `OR1200_ICFSM_CFETCH) & biudata_error;
138
 
139
   //
140
   // Assert burst when doing reload of complete cache line
141
   //
142
   assign burst = (state == `OR1200_ICFSM_CFETCH) & tagcomp_miss &
143
                  !cache_inhibit | (state == `OR1200_ICFSM_LREFILL3);
144
 
145
   //
146
   // Main IC FSM
147
   //
148 358 julius
   always @(posedge clk or `OR1200_RST_EVENT rst) begin
149
      if (rst == `OR1200_RST_VALUE) begin
150 350 julius
         state <=  `OR1200_ICFSM_IDLE;
151
         saved_addr_r <=  32'b0;
152
         hitmiss_eval <=  1'b0;
153
         load <=  1'b0;
154 477 julius
         cnt <=  `OR1200_ICLS'd0;
155 350 julius
         cache_inhibit <=  1'b0;
156 415 julius
         last_eval_miss <= 0; // JPB
157 412 julius
 
158 350 julius
      end
159
      else
160
        case (state)    // synopsys parallel_case
161
          `OR1200_ICFSM_IDLE :
162
            if (ic_en & icqmem_cycstb_i) begin          // fetch
163
               state <=  `OR1200_ICFSM_CFETCH;
164
               saved_addr_r <=  start_addr;
165
               hitmiss_eval <=  1'b1;
166
               load <=  1'b1;
167
               cache_inhibit <=  icqmem_ci_i;
168 415 julius
               last_eval_miss <= 0; // JPB
169 350 julius
            end
170
            else begin                  // idle
171
               hitmiss_eval <=  1'b0;
172
               load <=  1'b0;
173
               cache_inhibit <=  1'b0;
174 412 julius
            end
175 350 julius
          `OR1200_ICFSM_CFETCH: begin   // fetch
176
 
177
             if (icqmem_cycstb_i & icqmem_ci_i)
178
               cache_inhibit <=  1'b1;
179
 
180
             if (hitmiss_eval)
181 477 julius
               saved_addr_r[31:`OR1200_ICTAGL] <= start_addr[31:`OR1200_ICTAGL];
182 849 stekern
 
183
             // Check for stopped cache loads
184
                 // instruction cache turned-off
185 350 julius
             if ((!ic_en) ||
186
                 // fetch aborted (usually caused by IMMU)
187
                 (hitmiss_eval & !icqmem_cycstb_i) ||
188
                 (biudata_error) ||  // fetch terminated with an error
189
                 // fetch from cache-inhibited page
190
                 (cache_inhibit & biudata_valid)) begin
191
                state <=  `OR1200_ICFSM_IDLE;
192
                hitmiss_eval <=  1'b0;
193
                load <=  1'b0;
194
                cache_inhibit <=  1'b0;
195
             end // if ((!ic_en) ||...       
196 415 julius
             // fetch missed, wait for first fetch and continue filling line
197 350 julius
             else if (tagcomp_miss & biudata_valid) begin
198
                state <=  `OR1200_ICFSM_LREFILL3;
199 477 julius
                saved_addr_r[`OR1200_ICLS-1:2]
200
                  <= saved_addr_r[`OR1200_ICLS-1:2] + 1;
201 350 julius
                hitmiss_eval <=  1'b0;
202 477 julius
                cnt <= ((1 << `OR1200_ICLS) - (2 * 4));
203 350 julius
                cache_inhibit <=  1'b0;
204
             end
205
             // fetch aborted (usually caused by exception)
206 415 julius
             else if (!icqmem_cycstb_i
207
                      & !last_eval_miss // JPB
208
                      ) begin
209 350 julius
                state <=  `OR1200_ICFSM_IDLE;
210
                hitmiss_eval <=  1'b0;
211
                load <=  1'b0;
212
                cache_inhibit <=  1'b0;
213
             end
214 415 julius
             // fetch hit, wait in this state for now
215
             else if (!tagcomp_miss & !icqmem_ci_i) begin
216 350 julius
                saved_addr_r <=  start_addr;
217
                cache_inhibit <=  1'b0;
218
             end
219
             else   // fetch in-progress
220
               hitmiss_eval <=  1'b0;
221 412 julius
 
222 415 julius
             if (hitmiss_eval & !tagcomp_miss) // JPB
223
               last_eval_miss <= 1; // JPB
224 412 julius
 
225 350 julius
          end
226
          `OR1200_ICFSM_LREFILL3 : begin
227
             // abort because IC has just been turned off
228
             if (!ic_en) begin
229
                // invalidate before IC can be turned on
230
                state <=  `OR1200_ICFSM_IDLE;
231
                saved_addr_r <=  start_addr;
232
                hitmiss_eval <=  1'b0;
233
                load <=  1'b0;
234
             end
235
             // refill ack, more fetchs to come
236
             else if (biudata_valid && (|cnt)) begin
237 477 julius
                cnt <=  cnt - `OR1200_ICLS'd4;
238
                saved_addr_r[`OR1200_ICLS-1:2]
239
                  <= saved_addr_r[`OR1200_ICLS-1:2] + 1;
240 350 julius
             end
241
             // last fetch of line refill
242
             else if (biudata_valid) begin
243
                state <=  `OR1200_ICFSM_IDLE;
244
                saved_addr_r <=  start_addr;
245
                hitmiss_eval <=  1'b0;
246
                load <=  1'b0;
247
             end
248
          end
249
          default:
250
            state <=  `OR1200_ICFSM_IDLE;
251
        endcase
252
   end
253
 
254
endmodule

powered by: WebSVN 2.1.0

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