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

Subversion Repositories or1k

[/] [or1k/] [branches/] [mp3_stable/] [or1200/] [rtl/] [verilog/] [rf.v] - Blame information for rev 209

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

Line No. Rev Author Line
1 161 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 203 lampret
// Revision 1.3  2001/08/09 13:39:33  lampret
48
// Major clean-up.
49
//
50 168 lampret
// Revision 1.2  2001/07/22 03:31:54  lampret
51
// Fixed RAM's oen bug. Cache bypass under development.
52
//
53 166 lampret
// Revision 1.1  2001/07/20 00:46:21  lampret
54
// Development version of RTL. Libraries are missing.
55 161 lampret
//
56 166 lampret
//
57 161 lampret
 
58 203 lampret
// synopsys translate_off
59 168 lampret
`include "timescale.v"
60 203 lampret
// synopsys translate_on
61 168 lampret
`include "defines.v"
62 161 lampret
 
63 168 lampret
module rf(
64
        // Clock and reset
65
        clk, rst,
66 161 lampret
 
67 168 lampret
        // Write i/f
68
        addrw, dataw, we,
69
 
70
        // Read i/f
71 205 lampret
        id_freeze, addra, addrb, dataa, datab,
72 168 lampret
 
73
        // Debug
74 209 lampret
        spr_cs, spr_write, spr_addr, spr_dat_i, spr_dat_o
75 161 lampret
);
76
 
77
parameter dw = `OPERAND_WIDTH;
78
parameter aw = `REGFILE_ADDR_WIDTH;
79
 
80 168 lampret
//
81
// I/O
82
//
83 161 lampret
 
84 168 lampret
//
85
// Clock and reset
86
//
87
input                           clk;
88
input                           rst;
89 161 lampret
 
90 168 lampret
//
91
// Write i/f
92
//
93
input   [aw-1:0]         addrw;
94
input   [dw-1:0]         dataw;
95
input                           we;
96 161 lampret
 
97 168 lampret
//
98
// Read i/f
99
//
100 205 lampret
input                           id_freeze;
101 168 lampret
input   [aw-1:0]         addra;
102
input   [aw-1:0]         addrb;
103
output  [dw-1:0]         dataa;
104
output  [dw-1:0]         datab;
105 161 lampret
 
106 168 lampret
//
107 209 lampret
// SPR access for debugging purposes
108 168 lampret
//
109 209 lampret
input                           spr_cs;
110
input                           spr_write;
111
input   [31:0]                   spr_addr;
112
input   [31:0]                   spr_dat_i;
113
output  [31:0]                   spr_dat_o;
114 161 lampret
 
115 168 lampret
//
116
// Internal wires and regs
117
//
118
wire    [dw-1:0]         from_rfa;
119
wire    [dw-1:0]         from_rfb;
120
reg     [dw:0]                   dataa_saved;
121
reg     [dw:0]                   datab_saved;
122 209 lampret
wire    [aw-1:0]         rf_addra;
123
wire    [aw-1:0]         rf_addrw;
124
wire    [dw-1:0]         rf_dataw;
125
wire                            rf_we;
126
wire                            spr_valid;
127 161 lampret
 
128 168 lampret
//
129 209 lampret
// SPR access is valid when spr_cs is asserted and
130
// SPR address matches GPR addresses
131 168 lampret
//
132 209 lampret
assign spr_valid = spr_cs & (spr_addr[10:5] == `SPR_RF);
133 161 lampret
 
134 168 lampret
//
135 209 lampret
// SPR data output is always from RF A
136
//
137
assign spr_dat_o = from_rfa;
138
 
139
//
140 168 lampret
// Operand A comes from RF or from saved A register
141
//
142 161 lampret
assign dataa = (dataa_saved[32]) ? dataa_saved[31:0] : from_rfa;
143 168 lampret
 
144
//
145
// Operand B comes from RF or from saved B register
146
//
147 161 lampret
assign datab = (datab_saved[32]) ? datab_saved[31:0] : from_rfb;
148
 
149 168 lampret
//
150 209 lampret
// RF A read address is either from SPRS or normal from CPU control
151
//
152
assign rf_addra = (spr_valid & !spr_write) ? spr_addr[4:0] : addra;
153
 
154
//
155
// RF write address is either from SPRS or normal from CPU control
156
//
157
assign rf_addrw = (spr_valid & spr_write) ? spr_addr[4:0] : addrw;
158
 
159
//
160
// RF write data is either from SPRS or normal from CPU datapath
161
//
162
assign rf_dataw = (spr_valid & spr_write) ? spr_dat_i : dataw;
163
 
164
//
165
// RF write enable is either from SPRS or normal from CPU control
166
//
167
assign rf_we = (spr_valid & spr_write) | we;
168
 
169
//
170 161 lampret
// Stores operand from RF_A into temp reg when pipeline is frozen
171 168 lampret
//
172 161 lampret
always @(posedge clk or posedge rst)
173
        if (rst) begin
174
                dataa_saved <= #1 33'b0;
175
        end
176 205 lampret
        else if (id_freeze & !dataa_saved[32]) begin
177 161 lampret
                dataa_saved <= #1 {1'b1, from_rfa};
178
        end
179 205 lampret
        else if (!id_freeze)
180
                dataa_saved <= #1 33'b0;
181 161 lampret
 
182 168 lampret
//
183 161 lampret
// Stores operand from RF_B into temp reg when pipeline is frozen
184 168 lampret
//
185 161 lampret
always @(posedge clk or posedge rst)
186
        if (rst) begin
187
                datab_saved <= #1 33'b0;
188
        end
189 205 lampret
        else if (id_freeze & !datab_saved[32]) begin
190 161 lampret
                datab_saved <= #1 {1'b1, from_rfb};
191
        end
192 205 lampret
        else if (!id_freeze)
193
                datab_saved <= #1 33'b0;
194 161 lampret
 
195 168 lampret
//
196 203 lampret
// Instantiation of register file two-port RAM A
197 168 lampret
//
198 203 lampret
generic_tpram_32x32 rf_a(
199 168 lampret
        // Port A
200
        .clk_a(clk),
201
        .rst_a(rst),
202
        .ce_a(1'b1),
203 203 lampret
        .we_a(1'b0),
204 168 lampret
        .oe_a(1'b1),
205 209 lampret
        .addr_a(rf_addra),
206 203 lampret
        .di_a(32'h0000_0000),
207 168 lampret
        .do_a(from_rfa),
208 161 lampret
 
209 168 lampret
        // Port B
210
        .clk_b(clk),
211
        .rst_b(rst),
212 209 lampret
        .ce_b(rf_we),
213
        .we_b(rf_we),
214 203 lampret
        .oe_b(1'b0),
215 209 lampret
        .addr_b(rf_addrw),
216
        .di_b(rf_dataw),
217 203 lampret
        .do_b()
218 161 lampret
);
219
 
220 168 lampret
//
221 203 lampret
// Instantiation of register file two-port RAM B
222 168 lampret
//
223 203 lampret
generic_tpram_32x32 rf_b(
224 168 lampret
        // Port A
225
        .clk_a(clk),
226
        .rst_a(rst),
227
        .ce_a(1'b1),
228 203 lampret
        .we_a(1'b0),
229 168 lampret
        .oe_a(1'b1),
230
        .addr_a(addrb),
231 203 lampret
        .di_a(32'h0000_0000),
232 168 lampret
        .do_a(from_rfb),
233 161 lampret
 
234 168 lampret
        // Port B
235
        .clk_b(clk),
236
        .rst_b(rst),
237 209 lampret
        .ce_b(rf_we),
238
        .we_b(rf_we),
239 203 lampret
        .oe_b(1'b0),
240 209 lampret
        .addr_b(rf_addrw),
241
        .di_b(rf_dataw),
242 203 lampret
        .do_b()
243 161 lampret
);
244
 
245
endmodule

powered by: WebSVN 2.1.0

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