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

Subversion Repositories openrisc

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

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

Line No. Rev Author Line
1 10 unneback
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  OR1200's IC FSM                                             ////
4
////                                                              ////
5
////  This file is part of the OpenRISC 1200 project              ////
6 258 julius
////  http://opencores.org/project,or1k                           ////
7 10 unneback
////                                                              ////
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 141 marcus.erl
// $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 10 unneback
 
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
 
106 258 julius
   //
107
   // Generate of ICRAM write enables
108
   //
109
   assign icram_we = {4{biu_read & biudata_valid & !cache_inhibit}};
110
   assign tag_we = biu_read & biudata_valid & !cache_inhibit;
111 10 unneback
 
112 258 julius
   //
113
   // BIU read and write
114
   //
115
   assign biu_read = (hitmiss_eval & tagcomp_miss) | (!hitmiss_eval & load);
116 10 unneback
 
117 258 julius
   //assign saved_addr = hitmiss_eval ? start_addr : saved_addr_r;
118
   assign saved_addr = saved_addr_r;
119 10 unneback
 
120 258 julius
   //
121
   // Assert for cache hit first word ready
122
   // Assert for cache miss first word stored/loaded OK
123
   // Assert for cache miss first word stored/loaded with an error
124
   //
125
   assign first_hit_ack = (state == `OR1200_ICFSM_CFETCH) & hitmiss_eval &
126
                          !tagcomp_miss & !cache_inhibit;
127
   assign first_miss_ack = (state == `OR1200_ICFSM_CFETCH) & biudata_valid;
128
   assign first_miss_err = (state == `OR1200_ICFSM_CFETCH) & biudata_error;
129 10 unneback
 
130 258 julius
   //
131
   // Assert burst when doing reload of complete cache line
132
   //
133
   assign burst = (state == `OR1200_ICFSM_CFETCH) & tagcomp_miss &
134
                  !cache_inhibit | (state == `OR1200_ICFSM_LREFILL3);
135 10 unneback
 
136 258 julius
   //
137
   // Main IC FSM
138
   //
139
   always @(posedge clk or posedge rst) begin
140
      if (rst) begin
141
         state <=  `OR1200_ICFSM_IDLE;
142
         saved_addr_r <=  32'b0;
143
         hitmiss_eval <=  1'b0;
144
         load <=  1'b0;
145
         cnt <=  3'b000;
146
         cache_inhibit <=  1'b0;
147
      end
148
      else
149 10 unneback
        case (state)    // synopsys parallel_case
150 258 julius
          `OR1200_ICFSM_IDLE :
151
            if (ic_en & icqmem_cycstb_i) begin          // fetch
152
               state <=  `OR1200_ICFSM_CFETCH;
153
               saved_addr_r <=  start_addr;
154
               hitmiss_eval <=  1'b1;
155
               load <=  1'b1;
156
               cache_inhibit <=  icqmem_ci_i;
157
            end
158
            else begin                  // idle
159
               hitmiss_eval <=  1'b0;
160
               load <=  1'b0;
161
               cache_inhibit <=  1'b0;
162
            end
163
          `OR1200_ICFSM_CFETCH: begin   // fetch
164
 
165
             if (icqmem_cycstb_i & icqmem_ci_i)
166
               cache_inhibit <=  1'b1;
167
 
168
             if (hitmiss_eval)
169
               saved_addr_r[31:13] <=  start_addr[31:13];
170
 
171
             if ((!ic_en) ||
172
                 // fetch aborted (usually caused by IMMU)
173
                 (hitmiss_eval & !icqmem_cycstb_i) ||
174
                 (biudata_error) ||  // fetch terminated with an error
175
                 // fetch from cache-inhibited page
176
                 (cache_inhibit & biudata_valid)) begin
177
                state <=  `OR1200_ICFSM_IDLE;
178
                hitmiss_eval <=  1'b0;
179
                load <=  1'b0;
180
                cache_inhibit <=  1'b0;
181
             end // if ((!ic_en) ||...       
182
             // fetch missed, finish current external fetch and refill
183
             else if (tagcomp_miss & biudata_valid) begin
184
                state <=  `OR1200_ICFSM_LREFILL3;
185
                saved_addr_r[3:2] <=  saved_addr_r[3:2] + 1'd1;
186
                hitmiss_eval <=  1'b0;
187
                cnt <=  `OR1200_ICLS-2;
188
                cache_inhibit <=  1'b0;
189
             end
190
             // fetch aborted (usually caused by exception)
191
             else if (!icqmem_cycstb_i) begin
192
                state <=  `OR1200_ICFSM_IDLE;
193
                hitmiss_eval <=  1'b0;
194
                load <=  1'b0;
195
                cache_inhibit <=  1'b0;
196
             end
197
             // fetch hit, finish immediately
198
             else if (!tagcomp_miss & !icqmem_ci_i) begin
199
                saved_addr_r <=  start_addr;
200
                cache_inhibit <=  1'b0;
201
             end
202
             else   // fetch in-progress
203
               hitmiss_eval <=  1'b0;
204
          end
205
          `OR1200_ICFSM_LREFILL3 : begin
206
             // abort because IC has just been turned off
207
             if (!ic_en) begin
208
                // invalidate before IC can be turned on
209
                state <=  `OR1200_ICFSM_IDLE;
210
                saved_addr_r <=  start_addr;
211
                hitmiss_eval <=  1'b0;
212
                load <=  1'b0;
213
             end
214
             // refill ack, more fetchs to come
215
             else if (biudata_valid && (|cnt)) begin
216
                cnt <=  cnt - 3'd1;
217
                saved_addr_r[3:2] <=  saved_addr_r[3:2] + 1'd1;
218
             end
219
             // last fetch of line refill
220
             else if (biudata_valid) begin
221
                state <=  `OR1200_ICFSM_IDLE;
222
                saved_addr_r <=  start_addr;
223
                hitmiss_eval <=  1'b0;
224
                load <=  1'b0;
225
             end
226
          end
227
          default:
228
            state <=  `OR1200_ICFSM_IDLE;
229 10 unneback
        endcase
230 258 julius
   end
231 10 unneback
 
232
endmodule

powered by: WebSVN 2.1.0

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