1 |
2 |
conte |
//////////////////////////////////////////////////////////////////////
|
2 |
|
|
//// ////
|
3 |
|
|
//// OR1200's Data 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 |
|
|
//// Instantiation of all DC 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.8 2004/04/05 08:29:57 lampret
|
48 |
|
|
// Merged branch_qmem into main tree.
|
49 |
|
|
//
|
50 |
|
|
// Revision 1.6.4.2 2003/12/09 11:46:48 simons
|
51 |
|
|
// Mbist nameing changed, Artisan ram instance signal names fixed, some synthesis waning fixed.
|
52 |
|
|
//
|
53 |
|
|
// Revision 1.6.4.1 2003/07/08 15:36:37 lampret
|
54 |
|
|
// Added embedded memory QMEM.
|
55 |
|
|
//
|
56 |
|
|
// Revision 1.6 2002/10/17 20:04:40 lampret
|
57 |
|
|
// Added BIST scan. Special VS RAMs need to be used to implement BIST.
|
58 |
|
|
//
|
59 |
|
|
// Revision 1.5 2002/08/18 19:54:47 lampret
|
60 |
|
|
// Added store buffer.
|
61 |
|
|
//
|
62 |
|
|
// Revision 1.4 2002/02/11 04:33:17 lampret
|
63 |
|
|
// Speed optimizations (removed duplicate _cyc_ and _stb_). Fixed D/IMMU cache-inhibit attr.
|
64 |
|
|
//
|
65 |
|
|
// Revision 1.3 2002/01/28 01:16:00 lampret
|
66 |
|
|
// Changed 'void' nop-ops instead of insn[0] to use insn[16]. Debug unit stalls the tick timer. Prepared new flag generation for add and and insns. Blocked DC/IC while they are turned off. Fixed I/D MMU SPRs layout except WAYs. TODO: smart IC invalidate, l.j 2 and TLB ways.
|
67 |
|
|
//
|
68 |
|
|
// Revision 1.2 2002/01/14 06:18:22 lampret
|
69 |
|
|
// Fixed mem2reg bug in FAST implementation. Updated debug unit to work with new genpc/if.
|
70 |
|
|
//
|
71 |
|
|
// Revision 1.1 2002/01/03 08:16:15 lampret
|
72 |
|
|
// New prefixes for RTL files, prefixed module names. Updated cache controllers and MMUs.
|
73 |
|
|
//
|
74 |
|
|
// Revision 1.10 2001/10/21 17:57:16 lampret
|
75 |
|
|
// Removed params from generic_XX.v. Added translate_off/on in sprs.v and id.v. Removed spr_addr from dc.v and ic.v. Fixed CR+LF.
|
76 |
|
|
//
|
77 |
|
|
// Revision 1.9 2001/10/14 13:12:09 lampret
|
78 |
|
|
// MP3 version.
|
79 |
|
|
//
|
80 |
|
|
// Revision 1.1.1.1 2001/10/06 10:18:35 igorm
|
81 |
|
|
// no message
|
82 |
|
|
//
|
83 |
|
|
// Revision 1.4 2001/08/13 03:36:20 lampret
|
84 |
|
|
// Added cfg regs. Moved all defines into one defines.v file. More cleanup.
|
85 |
|
|
//
|
86 |
|
|
// Revision 1.3 2001/08/09 13:39:33 lampret
|
87 |
|
|
// Major clean-up.
|
88 |
|
|
//
|
89 |
|
|
// Revision 1.2 2001/07/22 03:31:53 lampret
|
90 |
|
|
// Fixed RAM's oen bug. Cache bypass under development.
|
91 |
|
|
//
|
92 |
|
|
// Revision 1.1 2001/07/20 00:46:03 lampret
|
93 |
|
|
// Development version of RTL. Libraries are missing.
|
94 |
|
|
//
|
95 |
|
|
//
|
96 |
|
|
|
97 |
|
|
// synopsys translate_off
|
98 |
|
|
`include "timescale.v"
|
99 |
|
|
// synopsys translate_on
|
100 |
|
|
`include "or1200_defines.v"
|
101 |
|
|
|
102 |
|
|
//
|
103 |
|
|
// Data cache
|
104 |
|
|
//
|
105 |
|
|
module or1200_dc_top(
|
106 |
|
|
// Rst, clk and clock control
|
107 |
|
|
clk, rst,
|
108 |
|
|
|
109 |
|
|
// External i/f
|
110 |
|
|
dcsb_dat_o, dcsb_adr_o, dcsb_cyc_o, dcsb_stb_o, dcsb_we_o, dcsb_sel_o, dcsb_cab_o,
|
111 |
|
|
dcsb_dat_i, dcsb_ack_i, dcsb_err_i,
|
112 |
|
|
|
113 |
|
|
// Internal i/f
|
114 |
|
|
dc_en,
|
115 |
|
|
dcqmem_adr_i, dcqmem_cycstb_i, dcqmem_ci_i,
|
116 |
|
|
dcqmem_we_i, dcqmem_sel_i, dcqmem_tag_i, dcqmem_dat_i,
|
117 |
|
|
dcqmem_dat_o, dcqmem_ack_o, dcqmem_rty_o, dcqmem_err_o, dcqmem_tag_o,
|
118 |
|
|
|
119 |
|
|
`ifdef OR1200_BIST
|
120 |
|
|
// RAM BIST
|
121 |
|
|
mbist_si_i, mbist_so_o, mbist_ctrl_i,
|
122 |
|
|
`endif
|
123 |
|
|
|
124 |
|
|
// SPRs
|
125 |
|
|
spr_cs, spr_write, spr_dat_i
|
126 |
|
|
);
|
127 |
|
|
|
128 |
|
|
parameter dw = 32; // `OR1200_OPERAND_WIDTH;
|
129 |
|
|
|
130 |
|
|
//
|
131 |
|
|
// I/O
|
132 |
|
|
//
|
133 |
|
|
|
134 |
|
|
//
|
135 |
|
|
// Clock and reset
|
136 |
|
|
//
|
137 |
|
|
input clk;
|
138 |
|
|
input rst;
|
139 |
|
|
|
140 |
|
|
//
|
141 |
|
|
// External I/F
|
142 |
|
|
//
|
143 |
|
|
output [dw-1:0] dcsb_dat_o;
|
144 |
|
|
output [31:0] dcsb_adr_o;
|
145 |
|
|
output dcsb_cyc_o;
|
146 |
|
|
output dcsb_stb_o;
|
147 |
|
|
output dcsb_we_o;
|
148 |
|
|
output [3:0] dcsb_sel_o;
|
149 |
|
|
output dcsb_cab_o;
|
150 |
|
|
input [dw-1:0] dcsb_dat_i;
|
151 |
|
|
input dcsb_ack_i;
|
152 |
|
|
input dcsb_err_i;
|
153 |
|
|
|
154 |
|
|
//
|
155 |
|
|
// Internal I/F
|
156 |
|
|
//
|
157 |
|
|
input dc_en;
|
158 |
|
|
input [31:0] dcqmem_adr_i;
|
159 |
|
|
input dcqmem_cycstb_i;
|
160 |
|
|
input dcqmem_ci_i;
|
161 |
|
|
input dcqmem_we_i;
|
162 |
|
|
input [3:0] dcqmem_sel_i;
|
163 |
|
|
input [3:0] dcqmem_tag_i;
|
164 |
|
|
input [dw-1:0] dcqmem_dat_i;
|
165 |
|
|
output [dw-1:0] dcqmem_dat_o;
|
166 |
|
|
output dcqmem_ack_o;
|
167 |
|
|
output dcqmem_rty_o;
|
168 |
|
|
output dcqmem_err_o;
|
169 |
|
|
output [3:0] dcqmem_tag_o;
|
170 |
|
|
|
171 |
|
|
`ifdef OR1200_BIST
|
172 |
|
|
//
|
173 |
|
|
// RAM BIST
|
174 |
|
|
//
|
175 |
|
|
input mbist_si_i;
|
176 |
|
|
input [`OR1200_MBIST_CTRL_WIDTH - 1:0] mbist_ctrl_i;
|
177 |
|
|
output mbist_so_o;
|
178 |
|
|
`endif
|
179 |
|
|
|
180 |
|
|
//
|
181 |
|
|
// SPR access
|
182 |
|
|
//
|
183 |
|
|
input spr_cs;
|
184 |
|
|
input spr_write;
|
185 |
|
|
input [31:0] spr_dat_i;
|
186 |
|
|
|
187 |
|
|
//
|
188 |
|
|
// Internal wires and regs
|
189 |
|
|
//
|
190 |
|
|
wire tag_v;
|
191 |
|
|
wire [`OR1200_DCTAG_W-2:0] tag;
|
192 |
|
|
wire [dw-1:0] to_dcram;
|
193 |
|
|
wire [dw-1:0] from_dcram;
|
194 |
|
|
wire [31:0] saved_addr;
|
195 |
|
|
wire [3:0] dcram_we;
|
196 |
|
|
wire dctag_we;
|
197 |
|
|
wire [31:0] dc_addr;
|
198 |
|
|
wire dcfsm_biu_read;
|
199 |
|
|
wire dcfsm_biu_write;
|
200 |
|
|
reg tagcomp_miss;
|
201 |
|
|
wire [`OR1200_DCINDXH:`OR1200_DCLS] dctag_addr;
|
202 |
|
|
wire dctag_en;
|
203 |
|
|
wire dctag_v;
|
204 |
|
|
wire dc_inv;
|
205 |
|
|
wire dcfsm_first_hit_ack;
|
206 |
|
|
wire dcfsm_first_miss_ack;
|
207 |
|
|
wire dcfsm_first_miss_err;
|
208 |
|
|
wire dcfsm_burst;
|
209 |
|
|
wire dcfsm_tag_we;
|
210 |
|
|
`ifdef OR1200_BIST
|
211 |
|
|
//
|
212 |
|
|
// RAM BIST
|
213 |
|
|
//
|
214 |
|
|
wire mbist_ram_so;
|
215 |
|
|
wire mbist_tag_so;
|
216 |
|
|
wire mbist_ram_si = mbist_si_i;
|
217 |
|
|
wire mbist_tag_si = mbist_ram_so;
|
218 |
|
|
assign mbist_so_o = mbist_tag_so;
|
219 |
|
|
`endif
|
220 |
|
|
|
221 |
|
|
//
|
222 |
|
|
// Simple assignments
|
223 |
|
|
//
|
224 |
|
|
assign dcsb_adr_o = dc_addr;
|
225 |
|
|
assign dc_inv = spr_cs & spr_write;
|
226 |
|
|
assign dctag_we = dcfsm_tag_we | dc_inv;
|
227 |
|
|
assign dctag_addr = dc_inv ? spr_dat_i[`OR1200_DCINDXH:`OR1200_DCLS] : dc_addr[`OR1200_DCINDXH:`OR1200_DCLS];
|
228 |
|
|
assign dctag_en = dc_inv | dc_en;
|
229 |
|
|
assign dctag_v = ~dc_inv;
|
230 |
|
|
|
231 |
|
|
//
|
232 |
|
|
// Data to BIU is from DCRAM when DC is enabled or from LSU when
|
233 |
|
|
// DC is disabled
|
234 |
|
|
//
|
235 |
|
|
assign dcsb_dat_o = dcqmem_dat_i;
|
236 |
|
|
|
237 |
|
|
//
|
238 |
|
|
// Bypases of the DC when DC is disabled
|
239 |
|
|
//
|
240 |
|
|
assign dcsb_cyc_o = (dc_en) ? dcfsm_biu_read | dcfsm_biu_write : dcqmem_cycstb_i;
|
241 |
|
|
assign dcsb_stb_o = (dc_en) ? dcfsm_biu_read | dcfsm_biu_write : dcqmem_cycstb_i;
|
242 |
|
|
assign dcsb_we_o = (dc_en) ? dcfsm_biu_write : dcqmem_we_i;
|
243 |
|
|
assign dcsb_sel_o = (dc_en & dcfsm_biu_read & !dcfsm_biu_write & !dcqmem_ci_i) ? 4'b1111 : dcqmem_sel_i;
|
244 |
|
|
assign dcsb_cab_o = (dc_en) ? dcfsm_burst : 1'b0;
|
245 |
|
|
assign dcqmem_rty_o = ~dcqmem_ack_o;
|
246 |
|
|
assign dcqmem_tag_o = dcqmem_err_o ? `OR1200_DTAG_BE : dcqmem_tag_i;
|
247 |
|
|
|
248 |
|
|
//
|
249 |
|
|
// DC/LSU normal and error termination
|
250 |
|
|
//
|
251 |
|
|
assign dcqmem_ack_o = dc_en ? dcfsm_first_hit_ack | dcfsm_first_miss_ack : dcsb_ack_i;
|
252 |
|
|
assign dcqmem_err_o = dc_en ? dcfsm_first_miss_err : dcsb_err_i;
|
253 |
|
|
|
254 |
|
|
//
|
255 |
|
|
// Select between claddr generated by DC FSM and addr[3:2] generated by LSU
|
256 |
|
|
//
|
257 |
|
|
//assign dc_addr = (dcfsm_biu_read | dcfsm_biu_write) ? saved_addr : dcqmem_adr_i;
|
258 |
|
|
|
259 |
|
|
//
|
260 |
|
|
// Select between input data generated by LSU or by BIU
|
261 |
|
|
//
|
262 |
|
|
assign to_dcram = (dcfsm_biu_read) ? dcsb_dat_i : dcqmem_dat_i;
|
263 |
|
|
|
264 |
|
|
//
|
265 |
|
|
// Select between data generated by DCRAM or passed by BIU
|
266 |
|
|
//
|
267 |
|
|
assign dcqmem_dat_o = dcfsm_first_miss_ack | !dc_en ? dcsb_dat_i : from_dcram;
|
268 |
|
|
|
269 |
|
|
//
|
270 |
|
|
// Tag comparison
|
271 |
|
|
//
|
272 |
|
|
always @(tag or saved_addr or tag_v) begin
|
273 |
|
|
if ((tag != saved_addr[31:`OR1200_DCTAGL]) || !tag_v)
|
274 |
|
|
tagcomp_miss = 1'b1;
|
275 |
|
|
else
|
276 |
|
|
tagcomp_miss = 1'b0;
|
277 |
|
|
end
|
278 |
|
|
|
279 |
|
|
//
|
280 |
|
|
// Instantiation of DC Finite State Machine
|
281 |
|
|
//
|
282 |
|
|
or1200_dc_fsm or1200_dc_fsm(
|
283 |
|
|
.clk(clk),
|
284 |
|
|
.rst(rst),
|
285 |
|
|
.dc_en(dc_en),
|
286 |
|
|
.dcqmem_cycstb_i(dcqmem_cycstb_i),
|
287 |
|
|
.dcqmem_ci_i(dcqmem_ci_i),
|
288 |
|
|
.dcqmem_we_i(dcqmem_we_i),
|
289 |
|
|
.dcqmem_sel_i(dcqmem_sel_i),
|
290 |
|
|
.tagcomp_miss(tagcomp_miss),
|
291 |
|
|
.biudata_valid(dcsb_ack_i),
|
292 |
|
|
.biudata_error(dcsb_err_i),
|
293 |
|
|
.start_addr(dcqmem_adr_i),
|
294 |
|
|
.saved_addr(saved_addr),
|
295 |
|
|
.dcram_we(dcram_we),
|
296 |
|
|
.biu_read(dcfsm_biu_read),
|
297 |
|
|
.biu_write(dcfsm_biu_write),
|
298 |
|
|
.first_hit_ack(dcfsm_first_hit_ack),
|
299 |
|
|
.first_miss_ack(dcfsm_first_miss_ack),
|
300 |
|
|
.first_miss_err(dcfsm_first_miss_err),
|
301 |
|
|
.burst(dcfsm_burst),
|
302 |
|
|
.tag_we(dcfsm_tag_we),
|
303 |
|
|
.dc_addr(dc_addr)
|
304 |
|
|
);
|
305 |
|
|
|
306 |
|
|
//
|
307 |
|
|
// Instantiation of DC main memory
|
308 |
|
|
//
|
309 |
|
|
or1200_dc_ram or1200_dc_ram(
|
310 |
|
|
.clk(clk),
|
311 |
|
|
.rst(rst),
|
312 |
|
|
`ifdef OR1200_BIST
|
313 |
|
|
// RAM BIST
|
314 |
|
|
.mbist_si_i(mbist_ram_si),
|
315 |
|
|
.mbist_so_o(mbist_ram_so),
|
316 |
|
|
.mbist_ctrl_i(mbist_ctrl_i),
|
317 |
|
|
`endif
|
318 |
|
|
.addr(dc_addr[`OR1200_DCINDXH:2]),
|
319 |
|
|
.en(dc_en),
|
320 |
|
|
.we(dcram_we),
|
321 |
|
|
.datain(to_dcram),
|
322 |
|
|
.dataout(from_dcram)
|
323 |
|
|
);
|
324 |
|
|
|
325 |
|
|
//
|
326 |
|
|
// Instantiation of DC TAG memory
|
327 |
|
|
//
|
328 |
|
|
or1200_dc_tag or1200_dc_tag(
|
329 |
|
|
.clk(clk),
|
330 |
|
|
.rst(rst),
|
331 |
|
|
`ifdef OR1200_BIST
|
332 |
|
|
// RAM BIST
|
333 |
|
|
.mbist_si_i(mbist_tag_si),
|
334 |
|
|
.mbist_so_o(mbist_tag_so),
|
335 |
|
|
.mbist_ctrl_i(mbist_ctrl_i),
|
336 |
|
|
`endif
|
337 |
|
|
.addr(dctag_addr),
|
338 |
|
|
.en(dctag_en),
|
339 |
|
|
.we(dctag_we),
|
340 |
|
|
.datain({dc_addr[31:`OR1200_DCTAGL], dctag_v}),
|
341 |
|
|
.tag_v(tag_v),
|
342 |
|
|
.tag(tag)
|
343 |
|
|
);
|
344 |
|
|
|
345 |
|
|
endmodule
|