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

Subversion Repositories aemb

[/] [aemb/] [tags/] [AEMB_7_05/] [rtl/] [verilog/] [aeMB_regfile.v] - Blame information for rev 206

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

Line No. Rev Author Line
1 3 sybreon
/*
2 36 sybreon
 * $Id: aeMB_regfile.v,v 1.17 2007-05-17 09:08:21 sybreon Exp $
3 3 sybreon
 *
4 8 sybreon
 * AEMB Register File
5 25 sybreon
 * Copyright (C) 2004-2007 Shawn Tan Ser Ngiap <shawn.tan@aeste.net>
6 3 sybreon
 *
7 25 sybreon
 * This library is free software; you can redistribute it and/or
8
 * modify it under the terms of the GNU Lesser General Public License
9
 * as published by the Free Software Foundation; either version 2.1 of
10
 * the License, or (at your option) any later version.
11 3 sybreon
 *
12 25 sybreon
 * This library is distributed in the hope that it will be useful, but
13
 * WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
 * Lesser General Public License for more details.
16 3 sybreon
 *
17 25 sybreon
 * You should have received a copy of the GNU Lesser General Public
18
 * License along with this library; if not, write to the Free Software
19
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20
 * USA
21 3 sybreon
 *
22
 * DESCRIPTION
23 25 sybreon
 * Implements the 32 registers as memory. Some registers require
24
 * special actions during hardware exception/interrupts. Data
25
 * forwarding is also taken care of inside here to simplify decode
26
 * logic.
27 3 sybreon
 *
28
 * HISTORY
29
 * $Log: not supported by cvs2svn $
30 36 sybreon
 * Revision 1.16  2007/05/15 22:44:57  sybreon
31
 * Corrected speed issues after rev 1.9 update.
32
 *
33 34 sybreon
 * Revision 1.15  2007/04/30 15:56:50  sybreon
34
 * Removed byte acrobatics.
35
 *
36 31 sybreon
 * Revision 1.14  2007/04/27 15:15:49  sybreon
37
 * Fixed simulation bug.
38
 *
39 28 sybreon
 * Revision 1.13  2007/04/27 04:22:40  sybreon
40
 * Fixed minor synthesis bug.
41
 *
42 26 sybreon
 * Revision 1.12  2007/04/27 00:23:55  sybreon
43
 * Added code documentation.
44
 * Improved size & speed of rtl/verilog/aeMB_aslu.v
45
 *
46 25 sybreon
 * Revision 1.11  2007/04/26 14:29:53  sybreon
47
 * Made minor performance optimisations.
48
 *
49 24 sybreon
 * Revision 1.10  2007/04/25 22:52:53  sybreon
50
 * Fixed minor simulation bug.
51
 *
52 23 sybreon
 * Revision 1.9  2007/04/25 22:15:04  sybreon
53
 * Added support for 8-bit and 16-bit data types.
54
 *
55 22 sybreon
 * Revision 1.8  2007/04/12 20:21:33  sybreon
56
 * Moved testbench into /sim/verilog.
57
 * Simulation cleanups.
58
 *
59 18 sybreon
 * Revision 1.7  2007/04/11 16:30:06  sybreon
60
 * Cosmetic changes
61
 *
62 17 sybreon
 * Revision 1.6  2007/04/11 04:30:43  sybreon
63
 * Added pipeline stalling from incomplete bus cycles.
64
 * Separated sync and async portions of code.
65
 *
66 16 sybreon
 * Revision 1.5  2007/04/04 14:08:34  sybreon
67
 * Added initial interrupt/exception support.
68
 *
69 14 sybreon
 * Revision 1.4  2007/04/04 06:11:47  sybreon
70
 * Fixed memory read-write data hazard
71
 *
72 8 sybreon
 * Revision 1.3  2007/04/03 14:46:26  sybreon
73
 * Fixed endian correction issues on data bus.
74
 *
75 5 sybreon
 * Revision 1.2  2007/03/26 12:21:31  sybreon
76
 * Fixed a minor bug where RD is trashed by a STORE instruction. Spotted by Joon Lee.
77
 *
78 4 sybreon
 * Revision 1.1  2007/03/09 17:52:17  sybreon
79
 * initial import
80 3 sybreon
 *
81
 */
82
 
83
module aeMB_regfile(/*AUTOARG*/
84
   // Outputs
85 22 sybreon
   dwb_dat_o, rREGA, rREGB, sDWBDAT,
86 3 sybreon
   // Inputs
87 25 sybreon
   dwb_dat_i, rDWBSTB, rDWBWE, rRA, rRB, rRD, rRESULT, rFSM, rPC,
88 36 sybreon
   rOPC, rDWBSEL, rLNK, rRWE, nclk, prst, drun, prun
89 3 sybreon
   );
90 26 sybreon
   // FIXME: This parameter is not used here.
91 3 sybreon
   parameter DSIZ = 32;
92 26 sybreon
 
93 25 sybreon
   // Data WB Signals
94 3 sybreon
   output [31:0] dwb_dat_o;
95
   input [31:0]  dwb_dat_i;
96
 
97 25 sybreon
   // Internal Signals
98 3 sybreon
   output [31:0] rREGA, rREGB;
99 25 sybreon
   output [31:0] sDWBDAT;
100 3 sybreon
   input         rDWBSTB, rDWBWE;
101 25 sybreon
   input [4:0]    rRA, rRB, rRD;
102 3 sybreon
   input [31:0]  rRESULT;
103
   input [1:0]    rFSM;
104 16 sybreon
   input [31:0]  rPC;
105 22 sybreon
   input [5:0]    rOPC;
106
   input [3:0]    rDWBSEL;
107 3 sybreon
   input         rLNK, rRWE;
108 36 sybreon
   input         nclk, prst, drun, prun;
109 3 sybreon
 
110 25 sybreon
   /**
111
    Delay Latches
112
    ----------
113
    The PC and RD are latched internally as it will be needed for
114
    linking and interrupt handling.
115
 
116
    FIXME: May need to be blocked (drun).
117
    */
118
 
119
   reg [31:2]    rPC_, xPC_;
120
   reg [4:0]      rRD_, xRD_;
121
 
122
   always @(/*AUTOSENSE*/rPC or rRD) begin
123
      xPC_ <= rPC[31:2];
124
      xRD_ <= rRD;
125
   end
126 26 sybreon
 
127
   /**
128
    Control Flags
129
    -------------
130
    Various internal flags.
131
    */
132 25 sybreon
 
133 26 sybreon
   wire [31:0]    wRESULT;
134
   wire          fWE = rRWE & !rDWBWE;
135
   wire          fLNK = rLNK;
136
   wire          fLD = rDWBSTB ^ rDWBWE;
137
   wire          fDFWD = !(rRD ^ rRD_) & fWE;
138
   wire          fMFWD = rDWBSTB & !rDWBWE;
139
 
140 25 sybreon
   /**
141
    Data WISHBONE Bus
142
    -----------------
143
    The data word that is read or written between the core and the
144
    external bus may need to be re-ordered.
145
 
146
    FIXME: Endian correction!
147
    */
148
 
149 22 sybreon
   wire [31:0]    wDWBDAT;
150
   reg [31:0]     sDWBDAT;
151
   reg [31:0]     rDWBDAT;
152 31 sybreon
   assign        dwb_dat_o = rDWBDAT;
153
   assign        wDWBDAT = dwb_dat_i;
154 8 sybreon
 
155 25 sybreon
   /**
156
    RAM Based Register File
157
    -----------------------
158
    This approach was chosen for implementing the register file as it
159
    was easier to implement and resulted in a higher speed than a pure
160
    register based implementation. A comparison was made using
161
    synthesis data obtained from Xilinx ISE:
162
    Reg : 1284 slices @ 78 MHz
163
    RAM : 227 slices @ 141 MHz
164
    */
165 22 sybreon
 
166 17 sybreon
   reg [31:0]  rMEMA[0:31], rMEMB[0:31], rMEMD[0:31];
167 16 sybreon
   wire [31:0] wDDAT, wREGA, wREGB, wREGD, wWBDAT;
168 36 sybreon
   wire        wDWE = (fLD | fLNK | fWE) & |rRD_ & prun;
169 22 sybreon
   assign      wDDAT = (fLD) ? sDWBDAT :
170 25 sybreon
                       (fLNK) ? {rPC_,2'd0} :
171
                       rRESULT;
172 16 sybreon
 
173 25 sybreon
   assign      rREGA = rMEMA[rRA];
174
   assign      rREGB = rMEMB[rRB];
175 17 sybreon
   assign      wREGD = rMEMD[rRD];
176 16 sybreon
 
177 17 sybreon
   always @(negedge nclk)
178 36 sybreon
     if (wDWE | prst) begin
179 17 sybreon
        rMEMA[rRD_] <= wDDAT;
180
        rMEMB[rRD_] <= wDDAT;
181
        rMEMD[rRD_] <= wDDAT;
182
     end
183 22 sybreon
 
184 25 sybreon
   /**
185
    Memory Resizer
186
    --------------
187
    This moves the appropriate bytes around depending on the size of
188 34 sybreon
    the operation. There is no checking for invalid size selection. It
189
    also handles forwarding.
190 25 sybreon
    */
191
 
192 34 sybreon
   reg [31:0] xDWBDAT;
193
   always @(/*AUTOSENSE*/fDFWD or rOPC or rRESULT or wREGD)
194
     case ({fDFWD,rOPC[1:0]})
195 25 sybreon
       // 8-bit
196 34 sybreon
       3'o0: xDWBDAT <= {(4){wREGD[7:0]}};
197
       3'o4: xDWBDAT <= {(4){rRESULT[7:0]}};
198 25 sybreon
       // 16-bit
199 34 sybreon
       3'o1: xDWBDAT <= {(2){wREGD[15:0]}};
200
       3'o5: xDWBDAT <= {(2){rRESULT[15:0]}};
201 25 sybreon
       // 32-bit
202 34 sybreon
       3'o2, 3'o3: xDWBDAT <= wREGD;
203
       3'o6, 3'o7: xDWBDAT <= rRESULT;
204 36 sybreon
     endcase // case ({fDFWD,rOPC[1:0]})
205 25 sybreon
 
206
   always @(/*AUTOSENSE*/rDWBSEL or wDWBDAT)
207
     case (rDWBSEL)
208
       // 8-bit
209
       4'h8: sDWBDAT <= {24'd0,wDWBDAT[31:24]};
210
       4'h4: sDWBDAT <= {24'd0,wDWBDAT[23:16]};
211
       4'h2: sDWBDAT <= {24'd0,wDWBDAT[15:8]};
212
       4'h1: sDWBDAT <= {24'd0,wDWBDAT[7:0]};
213
       // 16-bit
214
       4'hC: sDWBDAT <= {16'd0,wDWBDAT[31:16]};
215
       4'h3: sDWBDAT <= {16'd0,wDWBDAT[15:0]};
216
       // 32-bit
217
       default: sDWBDAT <= wDWBDAT;
218
     endcase // case (rDWBSEL)
219
 
220 16 sybreon
   // PIPELINE REGISTERS //////////////////////////////////////////////////
221 17 sybreon
 
222 36 sybreon
   always @(negedge nclk)
223
     if (prst) begin
224 16 sybreon
        /*AUTORESET*/
225
        // Beginning of autoreset for uninitialized flops
226
        rDWBDAT <= 32'h0;
227 25 sybreon
        rPC_ <= 30'h0;
228
        rRD_ <= 5'h0;
229 16 sybreon
        // End of automatics
230 36 sybreon
     end else if (prun) begin
231 34 sybreon
        rDWBDAT <= #1 xDWBDAT;
232 25 sybreon
        rPC_ <= xPC_;
233
        rRD_ <= xRD_;
234 16 sybreon
     end
235
 
236 17 sybreon
   // SIMULATION ONLY ///////////////////////////////////////////////////
237 25 sybreon
   /**
238
    The register file is initialised with random values to reflect a
239
    realistic situation where the values are undefined at power-up.
240
    */
241 26 sybreon
   // synopsys translate_off
242 17 sybreon
   integer i;
243
   initial begin
244 28 sybreon
      for (i=0;i<32;i=i+1) begin
245 25 sybreon
         rMEMA[i] <= $random;
246
         rMEMB[i] <= $random;
247
         rMEMD[i] <= $random;
248 17 sybreon
      end
249
   end
250 26 sybreon
   // synopsys translate_on
251 16 sybreon
 
252 3 sybreon
endmodule // aeMB_regfile
253
 
254
// Local Variables:
255
// verilog-library-directories:(".")
256
// verilog-library-files:("")
257
// End:

powered by: WebSVN 2.1.0

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