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 25

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

Line No. Rev Author Line
1 3 sybreon
/*
2 25 sybreon
 * $Id: aeMB_regfile.v,v 1.12 2007-04-27 00:23:55 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 25 sybreon
 * Revision 1.11  2007/04/26 14:29:53  sybreon
31
 * Made minor performance optimisations.
32
 *
33 24 sybreon
 * Revision 1.10  2007/04/25 22:52:53  sybreon
34
 * Fixed minor simulation bug.
35
 *
36 23 sybreon
 * Revision 1.9  2007/04/25 22:15:04  sybreon
37
 * Added support for 8-bit and 16-bit data types.
38
 *
39 22 sybreon
 * Revision 1.8  2007/04/12 20:21:33  sybreon
40
 * Moved testbench into /sim/verilog.
41
 * Simulation cleanups.
42
 *
43 18 sybreon
 * Revision 1.7  2007/04/11 16:30:06  sybreon
44
 * Cosmetic changes
45
 *
46 17 sybreon
 * Revision 1.6  2007/04/11 04:30:43  sybreon
47
 * Added pipeline stalling from incomplete bus cycles.
48
 * Separated sync and async portions of code.
49
 *
50 16 sybreon
 * Revision 1.5  2007/04/04 14:08:34  sybreon
51
 * Added initial interrupt/exception support.
52
 *
53 14 sybreon
 * Revision 1.4  2007/04/04 06:11:47  sybreon
54
 * Fixed memory read-write data hazard
55
 *
56 8 sybreon
 * Revision 1.3  2007/04/03 14:46:26  sybreon
57
 * Fixed endian correction issues on data bus.
58
 *
59 5 sybreon
 * Revision 1.2  2007/03/26 12:21:31  sybreon
60
 * Fixed a minor bug where RD is trashed by a STORE instruction. Spotted by Joon Lee.
61
 *
62 4 sybreon
 * Revision 1.1  2007/03/09 17:52:17  sybreon
63
 * initial import
64 3 sybreon
 *
65
 */
66
 
67
module aeMB_regfile(/*AUTOARG*/
68
   // Outputs
69 22 sybreon
   dwb_dat_o, rREGA, rREGB, sDWBDAT,
70 3 sybreon
   // Inputs
71 25 sybreon
   dwb_dat_i, rDWBSTB, rDWBWE, rRA, rRB, rRD, rRESULT, rFSM, rPC,
72
   rOPC, rDWBSEL, rLNK, rRWE, nclk, nrst, drun, nrun
73 3 sybreon
   );
74 25 sybreon
   // Data WB address bus width
75 3 sybreon
   parameter DSIZ = 32;
76
 
77 25 sybreon
   // Data WB Signals
78 3 sybreon
   output [31:0] dwb_dat_o;
79
   input [31:0]  dwb_dat_i;
80
 
81 25 sybreon
   // Internal Signals
82 3 sybreon
   output [31:0] rREGA, rREGB;
83 25 sybreon
   output [31:0] sDWBDAT;
84 3 sybreon
   input         rDWBSTB, rDWBWE;
85 25 sybreon
   input [4:0]    rRA, rRB, rRD;
86 3 sybreon
   input [31:0]  rRESULT;
87
   input [1:0]    rFSM;
88 16 sybreon
   input [31:0]  rPC;
89 22 sybreon
   input [5:0]    rOPC;
90
   input [3:0]    rDWBSEL;
91 3 sybreon
   input         rLNK, rRWE;
92 16 sybreon
   input         nclk, nrst, drun, nrun;
93 3 sybreon
 
94 25 sybreon
   // ASYNCHRONOUS ////////////////////////////////////////////////////////////////////
95 4 sybreon
 
96 25 sybreon
   wire [31:0]    wRESULT;
97
   wire          fWE = rRWE & !rDWBWE;
98
   wire          fLNK = rLNK;
99
   wire          fLD = rDWBSTB ^ rDWBWE;
100
   wire          fDFWD = !(rRD ^ rRD_) & fWE;
101
   wire          fMFWD = rDWBSTB & !rDWBWE;
102 3 sybreon
 
103 25 sybreon
   /**
104
    Delay Latches
105
    ----------
106
    The PC and RD are latched internally as it will be needed for
107
    linking and interrupt handling.
108
 
109
    FIXME: May need to be blocked (drun).
110
    */
111
 
112
   reg [31:2]    rPC_, xPC_;
113
   reg [4:0]      rRD_, xRD_;
114
 
115
   always @(/*AUTOSENSE*/rPC or rRD) begin
116
      xPC_ <= rPC[31:2];
117
      xRD_ <= rRD;
118
   end
119
 
120
   /**
121
    Data WISHBONE Bus
122
    -----------------
123
    The data word that is read or written between the core and the
124
    external bus may need to be re-ordered.
125
 
126
    FIXME: Endian correction!
127
    */
128
 
129 22 sybreon
   wire [31:0]    wDWBDAT;
130
   reg [31:0]     sDWBDAT;
131
   reg [31:0]     rDWBDAT;
132 5 sybreon
   assign        dwb_dat_o = {rDWBDAT[7:0],rDWBDAT[15:8],rDWBDAT[23:16],rDWBDAT[31:24]};
133 22 sybreon
   assign        wDWBDAT = {dwb_dat_i[7:0],dwb_dat_i[15:8],dwb_dat_i[23:16],dwb_dat_i[31:24]};
134 8 sybreon
 
135 25 sybreon
   /**
136
    RAM Based Register File
137
    -----------------------
138
    This approach was chosen for implementing the register file as it
139
    was easier to implement and resulted in a higher speed than a pure
140
    register based implementation. A comparison was made using
141
    synthesis data obtained from Xilinx ISE:
142
    Reg : 1284 slices @ 78 MHz
143
    RAM : 227 slices @ 141 MHz
144
    */
145 22 sybreon
 
146 17 sybreon
   reg [31:0]  rMEMA[0:31], rMEMB[0:31], rMEMD[0:31];
147 16 sybreon
   wire [31:0] wDDAT, wREGA, wREGB, wREGD, wWBDAT;
148
   wire        wDWE = (fLD | fLNK | fWE) & |rRD_ & nrun;
149 22 sybreon
   assign      wDDAT = (fLD) ? sDWBDAT :
150 25 sybreon
                       (fLNK) ? {rPC_,2'd0} :
151
                       rRESULT;
152 16 sybreon
   assign      wWBDAT = (fDFWD) ? wRESULT : wREGD;
153 25 sybreon
   assign      wRESULT = (fMFWD) ? sDWBDAT : rRESULT;
154 16 sybreon
 
155 25 sybreon
   assign      rREGA = rMEMA[rRA];
156
   assign      rREGB = rMEMB[rRB];
157 17 sybreon
   assign      wREGD = rMEMD[rRD];
158 16 sybreon
 
159 17 sybreon
   always @(negedge nclk)
160 25 sybreon
     if (wDWE | !nrst) begin
161 17 sybreon
        rMEMA[rRD_] <= wDDAT;
162
        rMEMB[rRD_] <= wDDAT;
163
        rMEMD[rRD_] <= wDDAT;
164
     end
165 22 sybreon
 
166 25 sybreon
   /**
167
    Memory Resizer
168
    --------------
169
    This moves the appropriate bytes around depending on the size of
170
    the operation. There is no checking for invalid size selection.
171
    */
172
 
173 22 sybreon
   reg [31:0] sWBDAT;
174
   always @(/*AUTOSENSE*/rOPC or wWBDAT)
175
     case (rOPC[1:0])
176 25 sybreon
       // 8-bit
177
       2'o0: sWBDAT <= {(4){wWBDAT[7:0]}};
178
       // 16-bit
179 22 sybreon
       2'o1: sWBDAT <= {(2){wWBDAT[15:0]}};
180 25 sybreon
       // 32-bit
181 22 sybreon
       default: sWBDAT <= wWBDAT;
182
     endcase // case (rOPC[1:0])
183 25 sybreon
 
184
   always @(/*AUTOSENSE*/rDWBSEL or wDWBDAT)
185
     case (rDWBSEL)
186
       // 8-bit
187
       4'h8: sDWBDAT <= {24'd0,wDWBDAT[31:24]};
188
       4'h4: sDWBDAT <= {24'd0,wDWBDAT[23:16]};
189
       4'h2: sDWBDAT <= {24'd0,wDWBDAT[15:8]};
190
       4'h1: sDWBDAT <= {24'd0,wDWBDAT[7:0]};
191
       // 16-bit
192
       4'hC: sDWBDAT <= {16'd0,wDWBDAT[31:16]};
193
       4'h3: sDWBDAT <= {16'd0,wDWBDAT[15:0]};
194
       // 32-bit
195
       default: sDWBDAT <= wDWBDAT;
196
     endcase // case (rDWBSEL)
197
 
198 16 sybreon
   // PIPELINE REGISTERS //////////////////////////////////////////////////
199 17 sybreon
 
200 16 sybreon
   always @(negedge nclk or negedge nrst)
201
     if (!nrst) begin
202
        /*AUTORESET*/
203
        // Beginning of autoreset for uninitialized flops
204
        rDWBDAT <= 32'h0;
205 25 sybreon
        rPC_ <= 30'h0;
206
        rRD_ <= 5'h0;
207 16 sybreon
        // End of automatics
208
     end else if (nrun) begin
209 25 sybreon
        rDWBDAT <= #1 sWBDAT;
210
        rPC_ <= xPC_;
211
        rRD_ <= xRD_;
212 16 sybreon
     end
213
 
214 17 sybreon
   // SIMULATION ONLY ///////////////////////////////////////////////////
215 25 sybreon
   /**
216
    The register file is initialised with random values to reflect a
217
    realistic situation where the values are undefined at power-up.
218
    */
219 17 sybreon
   integer i;
220
   initial begin
221
      for (i=0;i<31;i=i+1) begin
222 25 sybreon
         rMEMA[i] <= $random;
223
         rMEMB[i] <= $random;
224
         rMEMD[i] <= $random;
225 17 sybreon
      end
226
   end
227 16 sybreon
 
228 3 sybreon
endmodule // aeMB_regfile
229
 
230
// Local Variables:
231
// verilog-library-directories:(".")
232
// verilog-library-files:("")
233
// End:

powered by: WebSVN 2.1.0

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