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

Subversion Repositories or1k

[/] [or1k/] [tags/] [rel_15/] [or1200/] [rtl/] [verilog/] [or1200_rf.v] - Blame information for rev 504

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

Line No. Rev Author Line
1 504 lampret
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  OR1200's register file inside CPU                           ////
4
////                                                              ////
5
////  This file is part of the OpenRISC 1200 project              ////
6
////  http://www.opencores.org/cores/or1k/                        ////
7
////                                                              ////
8
////  Description                                                 ////
9
////  Instantiation of register file memories                     ////
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.13  2001/11/20 18:46:15  simons
48
// Break point bug fixed
49
//
50
// Revision 1.12  2001/11/13 10:02:21  lampret
51
// Added 'setpc'. Renamed some signals (except_flushpipe into flushpipe etc)
52
//
53
// Revision 1.11  2001/11/12 01:45:40  lampret
54
// Moved flag bit into SR. Changed RF enable from constant enable to dynamic enable for read ports.
55
//
56
// Revision 1.10  2001/11/10 03:43:57  lampret
57
// Fixed exceptions.
58
//
59
// Revision 1.9  2001/10/21 17:57:16  lampret
60
// 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.
61
//
62
// Revision 1.8  2001/10/14 13:12:10  lampret
63
// MP3 version.
64
//
65
// Revision 1.1.1.1  2001/10/06 10:18:36  igorm
66
// no message
67
//
68
// Revision 1.3  2001/08/09 13:39:33  lampret
69
// Major clean-up.
70
//
71
// Revision 1.2  2001/07/22 03:31:54  lampret
72
// Fixed RAM's oen bug. Cache bypass under development.
73
//
74
// Revision 1.1  2001/07/20 00:46:21  lampret
75
// Development version of RTL. Libraries are missing.
76
//
77
//
78
 
79
// synopsys translate_off
80
`include "timescale.v"
81
// synopsys translate_on
82
`include "or1200_defines.v"
83
 
84
module or1200_rf(
85
        // Clock and reset
86
        clk, rst,
87
 
88
        // Write i/f
89
        supv, wb_freeze, addrw, dataw, we, flushpipe,
90
 
91
        // Read i/f
92
        id_freeze, addra, addrb, dataa, datab, rda, rdb,
93
 
94
        // Debug
95
        spr_cs, spr_write, spr_addr, spr_dat_i, spr_dat_o
96
);
97
 
98
parameter dw = `OR1200_OPERAND_WIDTH;
99
parameter aw = `OR1200_REGFILE_ADDR_WIDTH;
100
 
101
//
102
// I/O
103
//
104
 
105
//
106
// Clock and reset
107
//
108
input                           clk;
109
input                           rst;
110
 
111
//
112
// Write i/f
113
//
114
input                           supv;
115
input                           wb_freeze;
116
input   [aw-1:0]         addrw;
117
input   [dw-1:0]         dataw;
118
input                           we;
119
input                           flushpipe;
120
 
121
//
122
// Read i/f
123
//
124
input                           id_freeze;
125
input   [aw-1:0]         addra;
126
input   [aw-1:0]         addrb;
127
output  [dw-1:0]         dataa;
128
output  [dw-1:0]         datab;
129
input                           rda;
130
input                           rdb;
131
 
132
//
133
// SPR access for debugging purposes
134
//
135
input                           spr_cs;
136
input                           spr_write;
137
input   [31:0]                   spr_addr;
138
input   [31:0]                   spr_dat_i;
139
output  [31:0]                   spr_dat_o;
140
 
141
//
142
// Internal wires and regs
143
//
144
wire    [dw-1:0]         from_rfa;
145
wire    [dw-1:0]         from_rfb;
146
reg     [dw:0]                   dataa_saved;
147
reg     [dw:0]                   datab_saved;
148
wire    [aw-1:0]         rf_addra;
149
wire    [aw-1:0]         rf_addrw;
150
wire    [dw-1:0]         rf_dataw;
151
wire                            rf_we;
152
wire                            spr_valid;
153
wire                            rf_ena;
154
wire                            rf_enb;
155
reg                             rf_we_allow;
156
 
157
//
158
// SPR access is valid when spr_cs is asserted and
159
// SPR address matches GPR addresses
160
//
161
assign spr_valid = spr_cs & (spr_addr[10:5] == `OR1200_SPR_RF);
162
 
163
//
164
// SPR data output is always from RF A
165
//
166
assign spr_dat_o = from_rfa;
167
 
168
//
169
// Operand A comes from RF or from saved A register
170
//
171
assign dataa = (dataa_saved[32]) ? dataa_saved[31:0] : from_rfa;
172
 
173
//
174
// Operand B comes from RF or from saved B register
175
//
176
assign datab = (datab_saved[32]) ? datab_saved[31:0] : from_rfb;
177
 
178
//
179
// RF A read address is either from SPRS or normal from CPU control
180
//
181
assign rf_addra = (spr_valid & !spr_write) ? spr_addr[4:0] : addra;
182
 
183
//
184
// RF write address is either from SPRS or normal from CPU control
185
//
186
assign rf_addrw = (spr_valid & spr_write) ? spr_addr[4:0] : addrw;
187
 
188
//
189
// RF write data is either from SPRS or normal from CPU datapath
190
//
191
assign rf_dataw = (spr_valid & spr_write) ? spr_dat_i : dataw;
192
 
193
//
194
// RF write enable is either from SPRS or normal from CPU control
195
//
196
always @(posedge rst or posedge clk)
197
        if (rst)
198
                rf_we_allow <= #1 1'b1;
199
        else if (~wb_freeze)
200
                rf_we_allow <= #1 ~flushpipe;
201
 
202
assign rf_we = ((spr_valid & spr_write) | (we & ~wb_freeze)) & rf_we_allow & (supv | (|rf_addrw));
203
 
204
//
205
// CS RF A asserted when instruction reads operand A and ID stage
206
// is not stalled
207
//
208
assign rf_ena = rda & ~id_freeze | spr_valid;   // probably works with fixed binutils
209
// assign rf_ena = 1'b1;                        // does not work with single-stepping
210
//assign rf_ena = ~id_freeze | spr_valid;       // works with broken binutils 
211
 
212
//
213
// CS RF B asserted when instruction reads operand B and ID stage
214
// is not stalled
215
//
216
assign rf_enb = rdb & ~id_freeze | spr_valid;
217
// assign rf_enb = 1'b1;
218
//assign rf_enb = ~id_freeze | spr_valid;       // works with broken binutils 
219
 
220
//
221
// Stores operand from RF_A into temp reg when pipeline is frozen
222
//
223
always @(posedge clk or posedge rst)
224
        if (rst) begin
225
                dataa_saved <= #1 33'b0;
226
        end
227
        else if (id_freeze & !dataa_saved[32]) begin
228
                dataa_saved <= #1 {1'b1, from_rfa};
229
        end
230
        else if (!id_freeze)
231
                dataa_saved <= #1 33'b0;
232
 
233
//
234
// Stores operand from RF_B into temp reg when pipeline is frozen
235
//
236
always @(posedge clk or posedge rst)
237
        if (rst) begin
238
                datab_saved <= #1 33'b0;
239
        end
240
        else if (id_freeze & !datab_saved[32]) begin
241
                datab_saved <= #1 {1'b1, from_rfb};
242
        end
243
        else if (!id_freeze)
244
                datab_saved <= #1 33'b0;
245
 
246
`ifdef OR1200_RFRAM_TWOPORT
247
 
248
//
249
// Instantiation of register file two-port RAM A
250
//
251
or1200_tpram_32x32 rf_a(
252
        // Port A
253
        .clk_a(clk),
254
        .rst_a(rst),
255
        .ce_a(rf_ena),
256
        .we_a(1'b0),
257
        .oe_a(1'b1),
258
        .addr_a(rf_addra),
259
        .di_a(32'h0000_0000),
260
        .do_a(from_rfa),
261
 
262
        // Port B
263
        .clk_b(clk),
264
        .rst_b(rst),
265
        .ce_b(rf_we),
266
        .we_b(rf_we),
267
        .oe_b(1'b0),
268
        .addr_b(rf_addrw),
269
        .di_b(rf_dataw),
270
        .do_b()
271
);
272
 
273
//
274
// Instantiation of register file two-port RAM B
275
//
276
or1200_tpram_32x32 rf_b(
277
        // Port A
278
        .clk_a(clk),
279
        .rst_a(rst),
280
        .ce_a(rf_enb),
281
        .we_a(1'b0),
282
        .oe_a(1'b1),
283
        .addr_a(addrb),
284
        .di_a(32'h0000_0000),
285
        .do_a(from_rfb),
286
 
287
        // Port B
288
        .clk_b(clk),
289
        .rst_b(rst),
290
        .ce_b(rf_we),
291
        .we_b(rf_we),
292
        .oe_b(1'b0),
293
        .addr_b(rf_addrw),
294
        .di_b(rf_dataw),
295
        .do_b()
296
);
297
 
298
`else
299
 
300
//
301
// Instantiation of register file two-port RAM A
302
//
303
or1200_dpram_32x32 rf_a(
304
        // Port A
305
        .clk_a(clk),
306
        .rst_a(rst),
307
        .ce_a(rf_ena),
308
        .oe_a(1'b1),
309
        .addr_a(rf_addra),
310
        .do_a(from_rfa),
311
 
312
        // Port B
313
        .clk_b(clk),
314
        .rst_b(rst),
315
        .ce_b(rf_we),
316
        .we_b(rf_we),
317
        .addr_b(rf_addrw),
318
        .di_b(rf_dataw)
319
);
320
 
321
//
322
// Instantiation of register file two-port RAM B
323
//
324
or1200_dpram_32x32 rf_b(
325
        // Port A
326
        .clk_a(clk),
327
        .rst_a(rst),
328
        .ce_a(rf_enb),
329
        .oe_a(1'b1),
330
        .addr_a(addrb),
331
        .do_a(from_rfb),
332
 
333
        // Port B
334
        .clk_b(clk),
335
        .rst_b(rst),
336
        .ce_b(rf_we),
337
        .we_b(rf_we),
338
        .addr_b(rf_addrw),
339
        .di_b(rf_dataw)
340
);
341
 
342
`endif
343
 
344
endmodule

powered by: WebSVN 2.1.0

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