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

Subversion Repositories or1k

[/] [or1k/] [branches/] [mp3_stable/] [mp3/] [rtl/] [verilog/] [or1200.xcv/] [dc.v] - Blame information for rev 317

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

Line No. Rev Author Line
1 266 lampret
//////////////////////////////////////////////////////////////////////
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.1.1.1  2001/10/06 10:18:35  igorm
48
// no message
49
//
50
// Revision 1.4  2001/08/13 03:36:20  lampret
51
// Added cfg regs. Moved all defines into one defines.v file. More cleanup.
52
//
53
// Revision 1.3  2001/08/09 13:39:33  lampret
54
// Major clean-up.
55
//
56
// Revision 1.2  2001/07/22 03:31:53  lampret
57
// Fixed RAM's oen bug. Cache bypass under development.
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
//
70
// Data cache
71
//
72
 
73
module dc(
74
        // Rst, clk and clock control
75
        clk, rst, clkdiv_by_2,
76
 
77
        // External i/f
78
        dcbiu_rdy, dcbiu_datain, dcbiu_dataout, dcbiu_addr, dcbiu_read, dcbiu_write, dcbiu_sel,
79
 
80
        // Internal i/f
81
        dc_en, dclsu_addr, dclsu_lsuop, dclsu_datain, dclsu_dataout, dclsu_stall, dclsu_unstall,
82
 
83
        // SPRs
84
        spr_cs, spr_write, spr_addr, spr_dat_i
85
);
86
 
87
parameter dw = `OPERAND_WIDTH;
88
 
89
//
90
// I/O
91
//
92
 
93
//
94
// Clock and reset
95
//
96
input                           clk;
97
input                           rst;
98
input                           clkdiv_by_2;
99
 
100
//
101
// External I/F
102
//
103
input                           dcbiu_rdy;
104
input   [dw-1:0]         dcbiu_datain;
105
output  [31:0]                   dcbiu_addr;
106
output                          dcbiu_read;
107
output                          dcbiu_write;
108
output  [3:0]                    dcbiu_sel;
109
 
110
//
111
// Internal I/F
112
//
113
input                           dc_en;
114
input   [31:0]                   dclsu_addr;
115
input   [`LSUOP_WIDTH-1:0]       dclsu_lsuop;
116
input   [dw-1:0]         dclsu_datain;
117
output  [dw-1:0]         dclsu_dataout;
118
output  [dw-1:0]         dcbiu_dataout;
119
output                          dclsu_stall;
120
output                          dclsu_unstall;
121
 
122
//
123
// SPR access
124
//
125
input                           spr_cs;
126
input                           spr_write;
127
input   [31:0]                   spr_addr;
128
input   [31:0]                   spr_dat_i;
129
 
130
//
131
// Internal wires and regs
132
//
133
wire                            tag_v;
134
wire    [18:0]                   tag;
135
wire    [dw-1:0]         to_dcram;
136
wire    [dw-1:0]         from_dcram;
137
wire    [dw-1:0]         to_mem2reg;
138
wire    [31:0]                   saved_addr;
139
wire                            refill;
140
wire    [3:0]                    dcram_we;
141
wire                            dctag_we;
142
wire    [dw-1:0]         lsu_datain_memaligned;
143
wire    [31:0]                   dc_addr;
144
wire                            refill_first;
145
wire                            refill_prepare;
146
wire                            refill_start;
147
wire                            refill_rest;
148
wire    [`LSUOP_WIDTH-1:0]       dcfsm_lsuop;
149
wire                            dcfsm_read;
150
wire                            dcfsm_write;
151
wire    [1:0]                    mem2reg_addr;
152
reg                             hit;
153
reg     [1:0]                    valid_div;
154
reg     [3:0]                    dcbiu_sel;
155
reg     [1:0]                    bypass_wait;
156
wire                            queue;
157
wire                            cntrbusy;
158
wire                            dcbiu_valid;
159
wire    [12:4]                  dctag_addr;
160
wire                            dctag_en;
161
wire                            dctag_v;
162
wire                            dc_inv;
163
 
164
//
165
// Simple assignments
166
//
167
assign dcbiu_addr = dc_addr;
168
assign dclsu_unstall = dcbiu_rdy;
169
assign dc_inv = spr_cs & spr_write;
170
assign dctag_we = refill | dc_inv;
171
assign dctag_addr = dc_inv ? spr_dat_i[12:4] : dc_addr[12:4];
172
assign dctag_en = dc_inv | dc_en;
173
assign dctag_v = ~dc_inv;
174
 
175
//
176
// Data to BIU is from DCRAM when DC is enabled or from LSU when
177
// DC is disabled
178
//
179
assign dcbiu_dataout = (dc_en) ? from_dcram : lsu_datain_memaligned;
180
 
181
//
182
// Bypases of the DC when DC is disabled
183
//
184
assign dcfsm_lsuop = (dc_en) ? dclsu_lsuop : `LSUOP_NOP;
185
assign dcbiu_read = (dc_en) ? dcfsm_read : ((|dclsu_lsuop) && ~dclsu_lsuop[3]);
186
assign dcbiu_write = (dc_en) ? dcfsm_write : ((|dclsu_lsuop) && dclsu_lsuop[3]);
187
always @(dc_en or dclsu_lsuop or dclsu_addr)
188
        casex({dc_en, dclsu_lsuop, dclsu_addr[1:0]})
189
                {1'b0, `LSUOP_SB, 2'b00} : dcbiu_sel = 4'b1000;
190
                {1'b0, `LSUOP_SB, 2'b01} : dcbiu_sel = 4'b0100;
191
                {1'b0, `LSUOP_SB, 2'b10} : dcbiu_sel = 4'b0010;
192
                {1'b0, `LSUOP_SB, 2'b11} : dcbiu_sel = 4'b0001;
193
                {1'b0, `LSUOP_SH, 2'b00} : dcbiu_sel = 4'b1100;
194
                {1'b0, `LSUOP_SH, 2'b10} : dcbiu_sel = 4'b0011;
195
                {1'b0, `LSUOP_SW, 2'b00} : dcbiu_sel = 4'b1111;
196
                {1'b0, `LSUOP_LBZ, 2'b00}, {1'b0, `LSUOP_LBS, 2'b00} : dcbiu_sel = 4'b1000;
197
                {1'b0, `LSUOP_LBZ, 2'b01}, {1'b0, `LSUOP_LBS, 2'b01} : dcbiu_sel = 4'b0100;
198
                {1'b0, `LSUOP_LBZ, 2'b10}, {1'b0, `LSUOP_LBS, 2'b10} : dcbiu_sel = 4'b0010;
199
                {1'b0, `LSUOP_LBZ, 2'b11}, {1'b0, `LSUOP_LBS, 2'b11} : dcbiu_sel = 4'b0001;
200
                {1'b0, `LSUOP_LHZ, 2'b00}, {1'b0, `LSUOP_LHS, 2'b00} : dcbiu_sel = 4'b1100;
201
                {1'b0, `LSUOP_LHZ, 2'b10}, {1'b0, `LSUOP_LHS, 2'b10} : dcbiu_sel = 4'b0011;
202
                {1'b0, `LSUOP_LWZ, 2'b00}, {1'b0, `LSUOP_LWS, 2'b00} : dcbiu_sel = 4'b1111;
203
                7'b1xxxxxx : dcbiu_sel = 4'b1111;
204
                default : dcbiu_sel = 4'b0000;
205
        endcase
206
 
207
assign mem2reg_addr = (dc_en) ? saved_addr[1:0] : dclsu_addr[1:0];
208
 
209
//
210
// Wait for DC bypass access
211
//
212
always @(posedge rst or posedge clk)
213
        if (rst)
214
                bypass_wait <= #1 2'b00;
215
        else if (dcbiu_valid)
216
                bypass_wait <= #1 2'b00;
217
        else if (dcbiu_read | dcbiu_write)
218
                bypass_wait <= #1 {bypass_wait[0], 1'b1};
219
        else
220
                bypass_wait <= #1 2'b00;
221
 
222
//
223
// Queue
224
//
225
assign queue = (refill && (|dcfsm_lsuop) && !refill_first && !refill_rest) ? 1'b1 : 1'b0;
226
 
227
//
228
// DC/LSU stall
229
//
230
//assign dclsu_stall = refill_start | (refill_first & ~dcbiu_valid)| refill_rest | queue | cntrbusy | (~dc_en & bypass_wait[1] & ~dcbiu_valid);
231
assign dclsu_stall = refill_start | (refill_first & ~dcbiu_valid)| refill_rest | queue | cntrbusy | (~dc_en & (dcbiu_read | dcbiu_write) & ~dcbiu_rdy);
232
 
233
//
234
// Select between claddr generated by DC FSM and addr[3:2] generated by LSU
235
//
236
assign dc_addr = (refill == 1'b1) ? saved_addr : dclsu_addr;
237
 
238
//
239
// Select between input data generated by LSU or by BIU
240
//
241
assign to_dcram = (refill == 1'b1) ? dcbiu_datain : lsu_datain_memaligned;
242
 
243
//
244
// Select between data generated by DCRAM or passed by BIU
245
//
246
assign to_mem2reg = (refill_first == 1'b1) | (~dc_en) ? dcbiu_datain : from_dcram;
247
 
248
//
249
// Tag comparison
250
//
251
always @(tag or saved_addr or tag_v) begin
252
        if ((tag == saved_addr[31:13]) && tag_v)
253
                hit = 1'b1;
254
        else
255
                hit = 1'b0;
256
end
257
 
258
//
259
// Valid_div counts RISC clock cycles by modulo 4
260
//
261
always @(posedge clk or posedge rst)
262
        if (rst)
263
                valid_div <= #1 2'b0;
264
        else
265
                valid_div <= #1 valid_div + 'd1;
266
 
267
//
268
// dcbiu_valid is one RISC clock cycle long dcbiu_rdy.
269
// dcbiu_rdy is two or four RISC clock cycles long because memory
270
// controller works at 1/2 or 1/4 of RISC clock freq (at 1/2 if
271
// clkdiv_by_2 is asserted).
272
//
273
assign dcbiu_valid = dcbiu_rdy & (valid_div[1] | clkdiv_by_2) & valid_div[0];
274
 
275
//
276
// Generate refill_start that signals to frz_logic a cache linefill is about to begin
277
//
278
assign refill_start = (refill_prepare & ~hit) ? 1'b1 : 1'b0;
279
 
280
//
281
// Instantiation of DC Finite State Machine
282
//
283
dc_fsm dc_fsm(
284
        .clk(clk),
285
        .rst(rst),
286
        .lsu_op(dcfsm_lsuop),
287
        .miss(~hit),
288
        .biudata_valid(dcbiu_valid),
289
        .start_addr(dclsu_addr),
290
        .saved_addr(saved_addr),
291
        .refill(refill),
292
        .refill_first(refill_first),
293
        .refill_prepare(refill_prepare),
294
        .dcram_we(dcram_we),
295
        .biu_read(dcfsm_read),
296
        .biu_write(dcfsm_write),
297
        .refill_rest(refill_rest),
298
        .cntrbusy(cntrbusy)
299
);
300
 
301
//
302
// Instantiation of Regfile-to-memory aligner
303
//
304
reg2mem reg2mem(
305
        .addr(dc_addr[1:0]),
306
        .lsu_op(dclsu_lsuop),
307
        .regdata(dclsu_datain),
308
        .memdata(lsu_datain_memaligned)
309
);
310
 
311
//
312
// Instantiation of DC main memory
313
//
314
dc_ram dc_ram(
315
        .clk(clk),
316
        .rst(rst),
317
        .addr(dc_addr[12:2]),
318
        .en(dc_en),
319
        .we(dcram_we),
320
        .datain(to_dcram),
321
        .dataout(from_dcram)
322
);
323
 
324
//
325
// Instantiation of DC TAG memory
326
//
327
dc_tag dc_tag(
328
        .clk(clk),
329
        .rst(rst),
330
        .addr(dctag_addr),
331
        .en(dctag_en),
332
        .we(dctag_we),
333
        .datain({dc_addr[31:13], dctag_v}),
334
        .tag_v(tag_v),
335
        .tag(tag)
336
);
337
 
338
//
339
// Instatiation of Memory-to-regfile aligner
340
//
341
mem2reg mem2reg(
342
        .addr(mem2reg_addr[1:0]),
343
        .lsu_op(dclsu_lsuop),
344
        .memdata(to_mem2reg),
345
        .regdata(dclsu_dataout)
346
);
347
 
348
endmodule

powered by: WebSVN 2.1.0

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