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

Subversion Repositories or1k

[/] [or1k/] [tags/] [first/] [mp3/] [rtl/] [verilog/] [or1200.xcv/] [ic.v] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 266 lampret
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  OR1200's Instruction Cache Top Level                        ////
4
////                                                              ////
5
////  This file is part of the OpenRISC 1200 project              ////
6
////  http://www.opencores.org/cores/or1k/                        ////
7
////                                                              ////
8
////  Description                                                 ////
9
////  Instruction cache top level instantiating all IC blocks.    ////
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
// Revision 1.1.1.1  2001/10/06 10:18:36  igorm
48
// no message
49
//
50
// Revision 1.4  2001/08/17 08:01:19  lampret
51
// IC enable/disable.
52
//
53
// Revision 1.3  2001/08/13 03:36:20  lampret
54
// Added cfg regs. Moved all defines into one defines.v file. More cleanup.
55
//
56
// Revision 1.2  2001/08/09 13:39:33  lampret
57
// Major clean-up.
58
//
59
// Revision 1.1  2001/07/20 00:46:03  lampret
60
// Development version of RTL. Libraries are missing.
61
//
62
//
63
 
64
// synopsys translate_off
65
`include "timescale.v"
66
// synopsys translate_on
67
`include "defines.v"
68
 
69
module ic(
70
        clk, rst, clkdiv_by_2,
71
 
72
        // Internal i/f to fetcher
73
        ic_en, icfetch_dataout, icfetch_addr, icfetch_op, icfetch_stall,
74
 
75
        // SPRs
76
        spr_cs, spr_write, spr_addr, spr_dat_i,
77
 
78
        // External i/f to BIU
79
        icbiu_rdy,  icbiu_addr, icbiu_read,  icbiu_datain, icbiu_sel
80
);
81
 
82
parameter dw = `OPERAND_WIDTH;
83
 
84
//
85
// I/O
86
//
87
 
88
//
89
// Clock and reset
90
//
91
input                           clk;
92
input                           rst;
93
input                           clkdiv_by_2;
94
 
95
//
96
// External I/F
97
//
98
input                           icbiu_rdy;
99
output  [31:0]                   icbiu_addr;
100
output                          icbiu_read;
101
input   [dw-1:0]         icbiu_datain;
102
output  [3:0]                    icbiu_sel;
103
 
104
//
105
// Internal I/F
106
//
107
input                           ic_en;
108
output  [dw-1:0]         icfetch_dataout;
109
input   [31:0]                   icfetch_addr;
110
input   [`FETCHOP_WIDTH-1:0]     icfetch_op;
111
output                          icfetch_stall;
112
 
113
//
114
// SPR access
115
//
116
input                           spr_cs;
117
input                           spr_write;
118
input   [31:0]                   spr_addr;
119
input   [31:0]                   spr_dat_i;
120
 
121
//
122
// Internal wires and regs
123
//
124
wire                            tag_v;
125
wire    [18:0]                   tag;
126
wire    [dw-1:0]         to_icram;
127
wire    [dw-1:0]         from_icram;
128
wire    [31:0]                   saved_addr;
129
wire                            refill;
130
wire    [3:0]                    icram_we;
131
wire                            ictag_we;
132
wire    [31:0]                   ic_addr;
133
wire                            refill_first;
134
wire                            refill_prepare;
135
wire                            refill_start;
136
wire                            refill_rest;
137
reg     [1:0]                    valid_div;
138
reg                             hit;
139
wire                            queue;
140
wire                            cntrbusy;
141
wire                            icbiu_valid;
142
wire    [`FETCHOP_WIDTH-1:0]     icfsm_op;
143
wire                            icfsm_read;
144
reg     [1:0]                    bypass_wait;
145
wire    [`ICINDXH:4]            ictag_addr;
146
wire                            ictag_en;
147
wire                            ictag_v;
148
wire                            ic_inv;
149
 
150
//
151
// Simple assignments
152
//
153
assign ic_inv = spr_cs & spr_write;
154
assign icbiu_addr = ic_addr;
155
assign ictag_we = refill | ic_inv;
156
assign ictag_addr = ic_inv ? spr_dat_i[`ICINDXH:4] : ic_addr[`ICINDXH:4];
157
assign ictag_en = ic_inv | ic_en;
158
assign ictag_v = ~ic_inv;
159
 
160
//
161
// Bypass of IC when it is disabled
162
//
163
assign icfsm_op = (ic_en) ? icfetch_op : `FETCHOP_NOP;
164
assign icbiu_read = (ic_en) ? icfsm_read : (icfetch_op != `FETCHOP_NOP);
165
assign icbiu_sel = 4'b1111;
166
 
167
//               
168
// Wait for IC bypass access
169
//               
170
always @(posedge rst or posedge clk)
171
        if (rst)
172
                bypass_wait <= #1 2'b0;
173
//      else if (icbiu_valid)
174
        else if (icbiu_rdy)
175
                bypass_wait <= #1 2'b0;
176
        else if (icbiu_read)
177
                bypass_wait <= #1 {bypass_wait[0], 1'b1};
178
        else
179
                bypass_wait <= #1 2'b00;
180
 
181
//
182
// Queue
183
//
184
assign queue = (refill && icfsm_op && !refill_first & !refill_rest) ? 1'b1 : 1'b0;
185
 
186
//
187
// IC fetch stall
188
//
189
//assign icfetch_stall = (ic_en & (refill | ~hit)) | (~ic_en & bypass_wait[1] & ~icbiu_valid);
190
//assign icfetch_stall = (ic_en & (refill | ~hit)) | (~ic_en & bypass_wait[1] & ~icbiu_rdy);
191
assign icfetch_stall = (ic_en & (refill | ~hit)) | (~ic_en & icbiu_read & ~icbiu_rdy);
192
 
193
//
194
// Select between claddr generated by IC FSM and addr[3:2] generated by IFETCH
195
//
196
assign ic_addr = (refill == 1'b1) ? saved_addr : icfetch_addr;
197
 
198
//
199
// Input data generated by BIU
200
//
201
assign to_icram = icbiu_datain;
202
 
203
//
204
// Select between data generated by ICRAM or passed by BIU
205
//
206
assign icfetch_dataout = (refill_first == 1'b1) | (~ic_en) ? icbiu_datain : from_icram;
207
 
208
//
209
// Tag comparison
210
//
211
always @(tag or saved_addr or tag_v) begin
212
        if ((tag == saved_addr[31:`ICTAGL]) && tag_v)
213
                hit = 1'b1;
214
        else
215
                hit = 1'b0;
216
end
217
 
218
//
219
// Valid_div counts RISC clock cycles by modulo 4
220
//
221
always @(posedge clk or posedge rst)
222
        if (rst)
223
                valid_div <= #1 2'b0;
224
        else
225
                valid_div <= #1 valid_div + 'd1;
226
 
227
//
228
// icbiu_valid is one RISC clock cycle long icbiu_rdy.
229
// icbiu_rdy is two/four RISC clock cycles long because memory
230
// controller works at 1/2 or 1/4 of RISC clock freq (at 1/2 if
231
// clkdiv_by_2 is asserted).
232
//
233
assign icbiu_valid = icbiu_rdy & (valid_div[1] | clkdiv_by_2) & valid_div[0];
234
 
235
//
236
// Generate refill_start that signals to frz_logic a cache linefill is about to begin
237
//
238
assign refill_start = (refill_prepare & ~hit) ? 1'b1 : 1'b0;
239
 
240
//
241
// Instantiation of IC FSM
242
//
243
ic_fsm ic_fsm(
244
        .clk(clk),
245
        .rst(rst),
246
        .fetch_op(icfsm_op),
247
        .miss(~hit),
248
        .biudata_valid(icbiu_valid),
249
        .start_addr(icfetch_addr),
250
        .saved_addr(saved_addr),
251
        .refill(refill),
252
        .refill_first(refill_first),
253
        .refill_prepare(refill_prepare),
254
        .icram_we(icram_we),
255
        .biu_read(icfsm_read),
256
        .refill_rest(refill_rest),
257
        .cntrbusy(cntrbusy)
258
);
259
 
260
//
261
// Instantiation of IC main memory
262
//
263
ic_ram ic_ram(
264
        .clk(clk),
265
        .rst(rst),
266
        .addr(ic_addr[`ICINDXH:2]),
267
        .en(ic_en),
268
        .we(icram_we),
269
        .datain(to_icram),
270
        .dataout(from_icram)
271
);
272
 
273
//
274
// Instantiation of IC TAG memory
275
//
276
ic_tag ic_tag(
277
        .clk(clk),
278
        .rst(rst),
279
        .addr(ictag_addr[`ICINDXH:4]),
280
        .en(ictag_en),
281
        .we(ictag_we),
282
        .datain({ic_addr[31:`ICTAGL], ictag_v}),
283
        .tag_v(tag_v),
284
        .tag(tag)
285
);
286
 
287
endmodule

powered by: WebSVN 2.1.0

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