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 522

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
   //
126
   // Assert for cache hit first word ready
127
   // Assert for cache miss first word stored/loaded OK
128
   // Assert for cache miss first word stored/loaded with an error
129
   //
130
   assign first_hit_ack = (state == `OR1200_ICFSM_CFETCH) & hitmiss_eval &
131
                          !tagcomp_miss & !cache_inhibit;
132
   assign first_miss_ack = (state == `OR1200_ICFSM_CFETCH) & biudata_valid;
133
   assign first_miss_err = (state == `OR1200_ICFSM_CFETCH) & biudata_error;
134
 
135
   //
136
   // Assert burst when doing reload of complete cache line
137
   //
138
   assign burst = (state == `OR1200_ICFSM_CFETCH) & tagcomp_miss &
139
                  !cache_inhibit | (state == `OR1200_ICFSM_LREFILL3);
140
 
141
   //
142
   // Main IC FSM
143
   //
144 358 julius
   always @(posedge clk or `OR1200_RST_EVENT rst) begin
145
      if (rst == `OR1200_RST_VALUE) begin
146 350 julius
         state <=  `OR1200_ICFSM_IDLE;
147
         saved_addr_r <=  32'b0;
148
         hitmiss_eval <=  1'b0;
149
         load <=  1'b0;
150 477 julius
         cnt <=  `OR1200_ICLS'd0;
151 350 julius
         cache_inhibit <=  1'b0;
152 415 julius
         last_eval_miss <= 0; // JPB
153 412 julius
 
154 350 julius
      end
155
      else
156
        case (state)    // synopsys parallel_case
157
          `OR1200_ICFSM_IDLE :
158
            if (ic_en & icqmem_cycstb_i) begin          // fetch
159
               state <=  `OR1200_ICFSM_CFETCH;
160
               saved_addr_r <=  start_addr;
161
               hitmiss_eval <=  1'b1;
162
               load <=  1'b1;
163
               cache_inhibit <=  icqmem_ci_i;
164 415 julius
               last_eval_miss <= 0; // JPB
165 350 julius
            end
166
            else begin                  // idle
167
               hitmiss_eval <=  1'b0;
168
               load <=  1'b0;
169
               cache_inhibit <=  1'b0;
170 412 julius
            end
171 350 julius
          `OR1200_ICFSM_CFETCH: begin   // fetch
172
 
173
             if (icqmem_cycstb_i & icqmem_ci_i)
174
               cache_inhibit <=  1'b1;
175
 
176
             if (hitmiss_eval)
177 477 julius
               saved_addr_r[31:`OR1200_ICTAGL] <= start_addr[31:`OR1200_ICTAGL];
178 350 julius
             if ((!ic_en) ||
179
                 // fetch aborted (usually caused by IMMU)
180
                 (hitmiss_eval & !icqmem_cycstb_i) ||
181
                 (biudata_error) ||  // fetch terminated with an error
182
                 // fetch from cache-inhibited page
183
                 (cache_inhibit & biudata_valid)) begin
184
                state <=  `OR1200_ICFSM_IDLE;
185
                hitmiss_eval <=  1'b0;
186
                load <=  1'b0;
187
                cache_inhibit <=  1'b0;
188
             end // if ((!ic_en) ||...       
189 415 julius
             // fetch missed, wait for first fetch and continue filling line
190 350 julius
             else if (tagcomp_miss & biudata_valid) begin
191
                state <=  `OR1200_ICFSM_LREFILL3;
192 477 julius
                saved_addr_r[`OR1200_ICLS-1:2]
193
                  <= saved_addr_r[`OR1200_ICLS-1:2] + 1;
194 350 julius
                hitmiss_eval <=  1'b0;
195 477 julius
                cnt <= ((1 << `OR1200_ICLS) - (2 * 4));
196 350 julius
                cache_inhibit <=  1'b0;
197
             end
198
             // fetch aborted (usually caused by exception)
199 415 julius
             else if (!icqmem_cycstb_i
200
                      & !last_eval_miss // JPB
201
                      ) begin
202 350 julius
                state <=  `OR1200_ICFSM_IDLE;
203
                hitmiss_eval <=  1'b0;
204
                load <=  1'b0;
205
                cache_inhibit <=  1'b0;
206
             end
207 415 julius
             // fetch hit, wait in this state for now
208
             else if (!tagcomp_miss & !icqmem_ci_i) begin
209 350 julius
                saved_addr_r <=  start_addr;
210
                cache_inhibit <=  1'b0;
211
             end
212
             else   // fetch in-progress
213
               hitmiss_eval <=  1'b0;
214 412 julius
 
215 415 julius
             if (hitmiss_eval & !tagcomp_miss) // JPB
216
               last_eval_miss <= 1; // JPB
217 412 julius
 
218 350 julius
          end
219
          `OR1200_ICFSM_LREFILL3 : begin
220
             // abort because IC has just been turned off
221
             if (!ic_en) begin
222
                // invalidate before IC can be turned on
223
                state <=  `OR1200_ICFSM_IDLE;
224
                saved_addr_r <=  start_addr;
225
                hitmiss_eval <=  1'b0;
226
                load <=  1'b0;
227
             end
228
             // refill ack, more fetchs to come
229
             else if (biudata_valid && (|cnt)) begin
230 477 julius
                cnt <=  cnt - `OR1200_ICLS'd4;
231
                saved_addr_r[`OR1200_ICLS-1:2]
232
                  <= saved_addr_r[`OR1200_ICLS-1:2] + 1;
233 350 julius
             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.