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