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

Subversion Repositories aemb

[/] [aemb/] [branches/] [AEMB2_712/] [rtl/] [verilog/] [aeMB_xecu.v] - Blame information for rev 53

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

Line No. Rev Author Line
1 53 sybreon
// $Id: aeMB_xecu.v,v 1.5 2007-11-09 20:51:52 sybreon Exp $
2 41 sybreon
//
3
// AEMB MAIN EXECUTION ALU
4
//
5
// Copyright (C) 2004-2007 Shawn Tan Ser Ngiap <shawn.tan@aeste.net>
6
//  
7
// 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
//
12
// 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
//  
17
// 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
//
22
// $Log: not supported by cvs2svn $
23 53 sybreon
// Revision 1.4  2007/11/08 14:17:47  sybreon
24
// Parameterised optional components.
25
//
26 50 sybreon
// Revision 1.3  2007/11/03 08:34:55  sybreon
27
// Minor code cleanup.
28
//
29 45 sybreon
// Revision 1.2  2007/11/02 19:20:58  sybreon
30
// Added better (beta) interrupt support.
31
// Changed MSR_IE to disabled at reset as per MB docs.
32
//
33 44 sybreon
// Revision 1.1  2007/11/02 03:25:41  sybreon
34
// New EDK 3.2 compatible design with optional barrel-shifter and multiplier.
35
// Fixed various minor data hazard bugs.
36
// Code compatible with -O0/1/2/3/s generated code.
37
//
38 41 sybreon
 
39
module aeMB_xecu (/*AUTOARG*/
40
   // Outputs
41 53 sybreon
   dwb_adr_o, dwb_sel_o, fsl_adr_o, rRESULT, rDWBSEL, rMSR_IE,
42
   rMSR_BIP,
43 41 sybreon
   // Inputs
44 53 sybreon
   rXCE, rREGA, rREGB, rMXSRC, rMXTGT, rRA, rRB, rMXALU, rBRA, rDLY,
45
   rALT, rSIMM, rIMM, rOPC, rRD, rDWBDI, rPC, gclk, grst, gena
46 41 sybreon
   );
47
   parameter DW=32;
48 50 sybreon
 
49
   parameter MUL=0;
50
   parameter BSF=0;
51 41 sybreon
 
52
   // DATA WISHBONE
53
   output [DW-1:2] dwb_adr_o;
54
   output [3:0]    dwb_sel_o;
55 53 sybreon
 
56
   // FSL WISHBONE
57
   output [14:2]   fsl_adr_o;
58 41 sybreon
 
59
   // INTERNAL
60
   output [31:0]   rRESULT;
61
   output [3:0]    rDWBSEL;
62 44 sybreon
   output          rMSR_IE;
63
   output          rMSR_BIP;
64
   input [1:0]      rXCE;
65 41 sybreon
   input [31:0]    rREGA, rREGB;
66
   input [1:0]      rMXSRC, rMXTGT;
67 53 sybreon
   input [4:0]      rRA, rRB;
68 41 sybreon
   input [2:0]      rMXALU;
69
   input           rBRA, rDLY;
70 50 sybreon
   input [10:0]    rALT;
71 45 sybreon
 
72 41 sybreon
   input [31:0]    rSIMM;
73
   input [15:0]    rIMM;
74
   input [5:0]      rOPC;
75
   input [4:0]      rRD;
76
   input [31:0]    rDWBDI;
77
   input [31:2]    rPC;
78 50 sybreon
   //input [31:0]    rRES_MUL; // External Multiplier
79
   //input [31:0]    rRES_BSF; // External Barrel Shifter
80 41 sybreon
 
81
   // SYSTEM
82
   input           gclk, grst, gena;
83
 
84
   reg             rMSR_C, xMSR_C;
85
   reg             rMSR_IE, xMSR_IE;
86 44 sybreon
   reg             rMSR_BE, xMSR_BE;
87
   reg             rMSR_BIP, xMSR_BIP;
88 41 sybreon
 
89 44 sybreon
   wire            fSKIP = rBRA & !rDLY;
90
 
91 41 sybreon
   // --- OPERAND SELECT
92
 
93
   reg [31:0]       rOPA, rOPB;
94
   always @(/*AUTOSENSE*/rDWBDI or rMXSRC or rPC or rREGA or rRESULT)
95
     case (rMXSRC)
96
       2'o0: rOPA <= rREGA;
97
       2'o1: rOPA <= rRESULT;
98
       2'o2: rOPA <= rDWBDI;
99
       2'o3: rOPA <= {rPC, 2'o0};
100
     endcase // case (rMXSRC)
101
 
102
   always @(/*AUTOSENSE*/rDWBDI or rMXTGT or rREGB or rRESULT or rSIMM)
103
     case (rMXTGT)
104
       2'o0: rOPB <= rREGB;
105
       2'o1: rOPB <= rRESULT;
106
       2'o2: rOPB <= rDWBDI;
107
       2'o3: rOPB <= rSIMM;
108
     endcase // case (rMXTGT)
109
 
110 44 sybreon
   // --- ADD/SUB SELECTOR ----
111 50 sybreon
   // FIXME: Redesign
112 44 sybreon
   // TODO: Refactor
113
   // TODO: Verify signed compare
114
 
115
   wire             wADDC, wSUBC, wRES_AC, wCMPC, wOPC;
116
   wire [31:0]       wADD, wSUB, wRES_A, wCMP, wOPX;
117
 
118
   wire             wCMPU = (rOPA > rOPB);
119
   wire             wCMPF = (rIMM[1]) ? wCMPU :
120
                            ((wCMPU & ~(rOPB[31] ^ rOPA[31])) | (rOPB[31] & ~rOPA[31]));
121
 
122
   assign           {wCMPC,wCMP} = {wSUBC,wCMPF,wSUB[30:0]};
123
   assign           wOPX = (rOPC[0] & !rOPC[5]) ? ~rOPA : rOPA ;
124
   assign           wOPC = ((rMSR_C & rOPC[1]) | (rOPC[0] & !rOPC[1])) & (!rOPC[5] & ~&rOPC[5:4]);
125
 
126
   assign           {wSUBC,wSUB} = {wADDC,wADD};
127
   assign           {wADDC,wADD} = (rOPB + wOPX) + wOPC;
128
 
129
   reg              rRES_ADDC;
130
   reg [31:0]        rRES_ADD;
131
   always @(rIMM or rOPC or wADD or wADDC or wCMP
132
            or wCMPC or wSUB or wSUBC)
133
     case ({rOPC[3],rOPC[0],rIMM[0]})
134
       4'h2, 4'h6, 4'h7: {rRES_ADDC,rRES_ADD} <= #1 {~wSUBC,wSUB}; // SUB
135
       4'h3: {rRES_ADDC,rRES_ADD} <= #1 {~wCMPC,wCMP}; // CMP
136
       default: {rRES_ADDC,rRES_ADD} <= #1 {wADDC,wADD};
137
     endcase // case ({rOPC[3],rOPC[0],rIMM[0]})
138
 
139 50 sybreon
   // --- LOGIC SELECTOR --------------------------------------
140 41 sybreon
 
141
   reg [31:0]        rRES_LOG;
142
   always @(/*AUTOSENSE*/rOPA or rOPB or rOPC)
143
     case (rOPC[1:0])
144
       2'o0: rRES_LOG <= #1 rOPA | rOPB;
145
       2'o1: rRES_LOG <= #1 rOPA & rOPB;
146
       2'o2: rRES_LOG <= #1 rOPA ^ rOPB;
147
       2'o3: rRES_LOG <= #1 rOPA & ~rOPB;
148
     endcase // case (rOPC[1:0])
149
 
150 50 sybreon
   // --- SHIFTER SELECTOR ------------------------------------
151 41 sybreon
 
152
   reg [31:0]        rRES_SFT;
153
   reg              rRES_SFTC;
154
 
155
   always @(/*AUTOSENSE*/rIMM or rMSR_C or rOPA)
156
     case (rIMM[6:5])
157
       2'o0: {rRES_SFT, rRES_SFTC} <= #1 {rOPA[31],rOPA[31:0]};
158
       2'o1: {rRES_SFT, rRES_SFTC} <= #1 {rMSR_C,rOPA[31:0]};
159
       2'o2: {rRES_SFT, rRES_SFTC} <= #1 {1'b0,rOPA[31:0]};
160
       2'o3: {rRES_SFT, rRES_SFTC} <= #1 (rIMM[0]) ? { {(16){rOPA[15]}}, rOPA[15:0], rMSR_C} :
161
                                      { {(24){rOPA[7]}}, rOPA[7:0], rMSR_C};
162
     endcase // case (rIMM[6:5])
163
 
164 50 sybreon
   // --- MOVE SELECTOR ---------------------------------------
165 41 sybreon
 
166 44 sybreon
   wire [31:0]       wMSR = {rMSR_C, 3'o0,
167
                            20'h0ED32,
168
                            4'h0, rMSR_BIP, rMSR_C, rMSR_IE, rMSR_BE};
169 41 sybreon
   wire             fMFSR = (rOPC == 6'o45) & !rIMM[14] & rIMM[0];
170
   wire             fMFPC = (rOPC == 6'o45) & !rIMM[14] & !rIMM[0];
171
   reg [31:0]        rRES_MOV;
172
   always @(/*AUTOSENSE*/fMFPC or fMFSR or rOPA or rOPB or rPC or rRA
173
            or wMSR)
174
     rRES_MOV <= (fMFSR) ? wMSR :
175
                 (fMFPC) ? rPC :
176
                 (rRA[3]) ? rOPB :
177
                 rOPA;
178
 
179 50 sybreon
   // --- MULTIPLIER ------------------------------------------
180
 
181
   reg [31:0]        rRES_MUL;
182
   always @(/*AUTOSENSE*/rOPA or rOPB) begin
183
      rRES_MUL <= (rOPA * rOPB);
184
   end
185
 
186
   // --- BARREL SHIFTER --------------------------------------
187
 
188
   reg [31:0]     rRES_BSF;
189
   reg [31:0]     xBSRL, xBSRA, xBSLL;
190 41 sybreon
 
191 50 sybreon
   // Infer a logical left barrel shifter.   
192
   always @(/*AUTOSENSE*/rOPA or rOPB)
193
     xBSLL <= rOPA << rOPB[4:0];
194
 
195
   // Infer a logical right barrel shifter.
196
   always @(/*AUTOSENSE*/rOPA or rOPB)
197
     xBSRL <= rOPA >> rOPB[4:0];
198
 
199
   // Infer a arithmetic right barrel shifter.
200
   always @(/*AUTOSENSE*/rOPA or rOPB)
201
     case (rOPB[4:0])
202
       5'd00: xBSRA <= rOPA;
203
       5'd01: xBSRA <= {{(1){rOPA[31]}}, rOPA[31:1]};
204
       5'd02: xBSRA <= {{(2){rOPA[31]}}, rOPA[31:2]};
205
       5'd03: xBSRA <= {{(3){rOPA[31]}}, rOPA[31:3]};
206
       5'd04: xBSRA <= {{(4){rOPA[31]}}, rOPA[31:4]};
207
       5'd05: xBSRA <= {{(5){rOPA[31]}}, rOPA[31:5]};
208
       5'd06: xBSRA <= {{(6){rOPA[31]}}, rOPA[31:6]};
209
       5'd07: xBSRA <= {{(7){rOPA[31]}}, rOPA[31:7]};
210
       5'd08: xBSRA <= {{(8){rOPA[31]}}, rOPA[31:8]};
211
       5'd09: xBSRA <= {{(9){rOPA[31]}}, rOPA[31:9]};
212
       5'd10: xBSRA <= {{(10){rOPA[31]}}, rOPA[31:10]};
213
       5'd11: xBSRA <= {{(11){rOPA[31]}}, rOPA[31:11]};
214
       5'd12: xBSRA <= {{(12){rOPA[31]}}, rOPA[31:12]};
215
       5'd13: xBSRA <= {{(13){rOPA[31]}}, rOPA[31:13]};
216
       5'd14: xBSRA <= {{(14){rOPA[31]}}, rOPA[31:14]};
217
       5'd15: xBSRA <= {{(15){rOPA[31]}}, rOPA[31:15]};
218
       5'd16: xBSRA <= {{(16){rOPA[31]}}, rOPA[31:16]};
219
       5'd17: xBSRA <= {{(17){rOPA[31]}}, rOPA[31:17]};
220
       5'd18: xBSRA <= {{(18){rOPA[31]}}, rOPA[31:18]};
221
       5'd19: xBSRA <= {{(19){rOPA[31]}}, rOPA[31:19]};
222
       5'd20: xBSRA <= {{(20){rOPA[31]}}, rOPA[31:20]};
223
       5'd21: xBSRA <= {{(21){rOPA[31]}}, rOPA[31:21]};
224
       5'd22: xBSRA <= {{(22){rOPA[31]}}, rOPA[31:22]};
225
       5'd23: xBSRA <= {{(23){rOPA[31]}}, rOPA[31:23]};
226
       5'd24: xBSRA <= {{(24){rOPA[31]}}, rOPA[31:24]};
227
       5'd25: xBSRA <= {{(25){rOPA[31]}}, rOPA[31:25]};
228
       5'd26: xBSRA <= {{(26){rOPA[31]}}, rOPA[31:26]};
229
       5'd27: xBSRA <= {{(27){rOPA[31]}}, rOPA[31:27]};
230
       5'd28: xBSRA <= {{(28){rOPA[31]}}, rOPA[31:28]};
231
       5'd29: xBSRA <= {{(29){rOPA[31]}}, rOPA[31:29]};
232
       5'd30: xBSRA <= {{(30){rOPA[31]}}, rOPA[31:30]};
233
       5'd31: xBSRA <= {{(31){rOPA[31]}}, rOPA[31]};
234
     endcase // case (rOPB[4:0])
235
 
236
   always @(/*AUTOSENSE*/rALT or xBSLL or xBSRA or xBSRL)
237
     case (rALT[10:9])
238
       2'd0: rRES_BSF <= xBSRL;
239
       2'd1: rRES_BSF <= xBSRA;
240
       2'd2: rRES_BSF <= xBSLL;
241
       default: rRES_BSF <= 32'hX;
242
     endcase // case (rALT[10:9])
243
 
244
 
245 44 sybreon
   // --- MSR REGISTER -----------------
246 41 sybreon
 
247 44 sybreon
   // C
248
   wire            fMTS = (rOPC == 6'o45) & rIMM[14];
249
   wire            fADDC = ({rOPC[5:4], rOPC[2]} == 3'o0);
250 41 sybreon
 
251 44 sybreon
   always @(/*AUTOSENSE*/fADDC or fMTS or fSKIP or rMSR_C or rMXALU
252
            or rOPA or rRES_ADDC or rRES_SFTC or rXCE)
253
     if (fSKIP | |rXCE) begin
254
        xMSR_C <= rMSR_C;
255
     end else
256
       case (rMXALU)
257
         3'o0: xMSR_C <= (fADDC) ? rRES_ADDC : rMSR_C;
258
         3'o1: xMSR_C <= rMSR_C; // LOGIC       
259
         3'o2: xMSR_C <= rRES_SFTC; // SHIFT
260
         3'o3: xMSR_C <= (fMTS) ? rOPA[2] : rMSR_C;
261
         3'o4: xMSR_C <= rMSR_C;
262
         3'o5: xMSR_C <= rMSR_C;
263
         default: xMSR_C <= 1'hX;
264
       endcase
265
 
266
   // IE/BIP/BE
267
   wire             fRTID = (rOPC == 6'o55) & rRD[0];
268
   wire             fRTBD = (rOPC == 6'o55) & rRD[1];
269
   wire             fBRK = ((rOPC == 6'o56) | (rOPC == 6'o66)) & (rRA[4:2] == 3'o3);
270 41 sybreon
 
271 44 sybreon
   always @(/*AUTOSENSE*/fMTS or fRTID or rMSR_IE or rOPA or rXCE)
272
     xMSR_IE <= (rXCE == 2'o2) ? 1'b0 :
273
                (fRTID) ? 1'b1 :
274
                (fMTS) ? rOPA[1] :
275
                rMSR_IE;
276 41 sybreon
 
277 44 sybreon
   always @(/*AUTOSENSE*/fBRK or fMTS or fRTBD or rMSR_BIP or rOPA)
278
     xMSR_BIP <= (fBRK) ? 1'b1 :
279
                 (fRTBD) ? 1'b0 :
280
                 (fMTS) ? rOPA[3] :
281
                 rMSR_BIP;
282
 
283
   always @(/*AUTOSENSE*/fMTS or rMSR_BE or rOPA)
284
     xMSR_BE <= (fMTS) ? rOPA[0] : rMSR_BE;
285
 
286 50 sybreon
   // --- RESULT SELECTOR -------------------------------------------
287
   // Selects results from functional units. 
288 41 sybreon
   reg [31:0]       rRESULT, xRESULT;
289
 
290
   // RESULT
291
   always @(/*AUTOSENSE*/fSKIP or rMXALU or rRES_ADD or rRES_BSF
292
            or rRES_LOG or rRES_MOV or rRES_MUL or rRES_SFT)
293
     if (fSKIP)
294
       /*AUTORESET*/
295
       // Beginning of autoreset for uninitialized flops
296
       xRESULT <= 32'h0;
297
       // End of automatics
298
     else
299
       case (rMXALU)
300
         3'o0: xRESULT <= rRES_ADD;
301
         3'o1: xRESULT <= rRES_LOG;
302
         3'o2: xRESULT <= rRES_SFT;
303
         3'o3: xRESULT <= rRES_MOV;
304 50 sybreon
         3'o4: xRESULT <= (MUL) ? rRES_MUL : 32'hX;
305
         3'o5: xRESULT <= (BSF) ? rRES_BSF : 32'hX;
306 41 sybreon
         default: xRESULT <= 32'hX;
307
       endcase // case (rMXALU)
308
 
309
   // --- DATA WISHBONE -----
310
 
311
   reg [3:0]         rDWBSEL, xDWBSEL;
312
   assign           dwb_adr_o = rRESULT[DW-1:2];
313
   assign           dwb_sel_o = rDWBSEL;
314
 
315
   always @(/*AUTOSENSE*/rOPC or wADD)
316
     case (rOPC[1:0])
317 53 sybreon
       2'o0: case (wADD[1:0]) // 8'bit
318 41 sybreon
               2'o0: xDWBSEL <= 4'h8;
319
               2'o1: xDWBSEL <= 4'h4;
320
               2'o2: xDWBSEL <= 4'h2;
321
               2'o3: xDWBSEL <= 4'h1;
322
             endcase // case (wADD[1:0])
323 53 sybreon
       2'o1: xDWBSEL <= (wADD[1]) ? 4'h3 : 4'hC; // 16'bit
324
       2'o2: xDWBSEL <= 4'hF; // 32'bit
325
       2'o3: xDWBSEL <= 4'h0; // FSL
326 41 sybreon
     endcase // case (rOPC[1:0])
327 53 sybreon
 
328
   // --- FSL WISHBONE --------------------
329
 
330
   reg [14:2]       rFSLADR, xFSLADR;
331 41 sybreon
 
332 53 sybreon
   assign           fsl_adr_o = rFSLADR[14:2];
333
 
334
   always @(/*AUTOSENSE*/rALT or rRB) begin
335
      xFSLADR <= {rALT, rRB[3:2]};
336
   end
337
 
338 41 sybreon
   // --- SYNC ---
339
 
340
   always @(posedge gclk)
341
     if (grst) begin
342
        /*AUTORESET*/
343
        // Beginning of autoreset for uninitialized flops
344
        rDWBSEL <= 4'h0;
345 53 sybreon
        rFSLADR <= 13'h0;
346 44 sybreon
        rMSR_BE <= 1'h0;
347
        rMSR_BIP <= 1'h0;
348 41 sybreon
        rMSR_C <= 1'h0;
349 44 sybreon
        rMSR_IE <= 1'h0;
350 41 sybreon
        rRESULT <= 32'h0;
351
        // End of automatics
352
     end else if (gena) begin
353
        rRESULT <= #1 xRESULT;
354
        rDWBSEL <= #1 xDWBSEL;
355
        rMSR_C <= #1 xMSR_C;
356
        rMSR_IE <= #1 xMSR_IE;
357 44 sybreon
        rMSR_BE <= #1 xMSR_BE;
358 53 sybreon
        rMSR_BIP <= #1 xMSR_BIP;
359
        rFSLADR <= #1 xFSLADR;
360 41 sybreon
     end
361
 
362
endmodule // aeMB_xecu

powered by: WebSVN 2.1.0

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