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

Subversion Repositories aemb

[/] [aemb/] [trunk/] [rtl/] [verilog/] [aeMB2_intu.v] - Blame information for rev 134

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

Line No. Rev Author Line
1 134 sybreon
/* $Id: aeMB2_intu.v,v 1.5 2008-04-26 17:57:43 sybreon Exp $
2 118 sybreon
**
3
** AEMB2 EDK 6.2 COMPATIBLE CORE
4
** Copyright (C) 2004-2008 Shawn Tan <shawn.tan@aeste.net>
5
**
6
** This file is part of AEMB.
7
**
8
** AEMB is free software: you can redistribute it and/or modify it
9
** under the terms of the GNU Lesser General Public License as
10
** published by the Free Software Foundation, either version 3 of the
11
** License, or (at your option) any later version.
12
**
13
** AEMB is distributed in the hope that it will be useful, but WITHOUT
14
** ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15
** or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General
16
** Public License for more details.
17
**
18
** You should have received a copy of the GNU Lesser General Public
19
** License along with AEMB. If not, see <http:**www.gnu.org/licenses/>.
20
*/
21
/**
22
 * One Cycle Integer Unit
23
 * @file aeMB2_intu.v
24
 
25
 * This implements a single cycle integer unit. It performs all basic
26
   arithmetic, shift, and logic operations.
27
 
28
 */
29
 
30
module aeMB2_intu (/*AUTOARG*/
31
   // Outputs
32
   mem_ex, bpc_ex, alu_ex, alu_mx, msr_ex, sfr_mx,
33
   // Inputs
34
   opc_of, opa_of, opb_of, opd_of, imm_of, rd_of, ra_of, gclk, grst,
35
   dena, gpha
36
   );
37
   parameter AEMB_DWB = 32;
38
   parameter AEMB_IWB = 32;
39
   parameter AEMB_HTX = 1;
40
 
41
   output [31:2] mem_ex;
42
   output [31:2] bpc_ex;
43
 
44
   output [31:0] alu_ex,
45
                 alu_mx;
46
 
47
   input [5:0]    opc_of;
48
   input [31:0]  opa_of;
49
   input [31:0]  opb_of;
50
   input [31:0]  opd_of;
51
   input [15:0]  imm_of;
52
   input [4:0]    rd_of,
53
                 ra_of;
54
   output [7:0]  msr_ex;
55
   output [31:0] sfr_mx;
56
 
57
   // SYS signals
58
   input         gclk,
59
                 grst,
60
                 dena,
61
                 gpha;
62
 
63
   /*AUTOREG*/
64
   // Beginning of automatic regs (for this module's undeclared outputs)
65
   reg [31:0]            alu_ex;
66
   reg [31:0]            alu_mx;
67
   reg [31:2]           bpc_ex;
68
   reg [31:2]           mem_ex;
69
   reg [31:0]            sfr_mx;
70
   // End of automatics
71
 
72
   reg                  rMSR_C,
73
                        rMSR_CC,
74
                        rMSR_C0, rMSR_C1,
75
                        rMSR_MTX,
76
                        rMSR_DCE,
77
                        rMSR_ICE,
78
                        rMSR_BIP,
79
                        rMSR_IE,
80
                        rMSR_BE;
81 134 sybreon
 
82
   // ADDER   
83 125 sybreon
   /* Infer a ADD cell because ADD/SUB cannot be inferred cross
84 118 sybreon
    technologies. */
85
 
86
   // FIXME: Redesign this critical path
87 125 sybreon
 
88 118 sybreon
   reg [31:0]            add_ex;
89
   reg                  add_c;
90 131 sybreon
 
91 125 sybreon
   wire [31:0]           wADD;
92
   wire                 wADC;
93 118 sybreon
 
94
   wire                 fCCC = !opc_of[5] & !opc_of[4] & opc_of[1];
95
   wire                 fSUB = !opc_of[5] & !opc_of[4] & opc_of[0];
96 125 sybreon
   wire                 fCMP = !opc_of[3] & imm_of[1] & imm_of[0]; // unsigned
97
   wire                 wCMP = (fCMP) ? (opa_of > opb_of) : wADD[31];
98 118 sybreon
 
99 131 sybreon
   wire [31:0]           wOPA = (fSUB) ? ~opa_of : opa_of;
100 118 sybreon
   wire                 wOPC = (fCCC) ? rMSR_CC : fSUB;
101
 
102
   assign               {wADC, wADD} = (opb_of + wOPA) + wOPC;
103
 
104 125 sybreon
   always @(/*AUTOSENSE*/imm_of or opc_of or wADC or wADD or wCMP) begin
105
      {add_c, add_ex} <= #1
106
                         (!opc_of[3] & imm_of[0]) ?
107
                         {wADC, wCMP , wADD[30:0]} : // add with carry
108
                         {wADC, wADD[31:0]} ; // add with carry
109 118 sybreon
   end
110
 
111
   // SHIFT/LOGIC/MOVE
112
   reg [31:0]            slm_ex;
113
   reg                  slm_c;
114
 
115
   always @(/*AUTOSENSE*/imm_of or opa_of or opb_of or opc_of
116
            or rMSR_CC)
117
     case (opc_of[2:0])
118
       // LOGIC
119
       3'o0: slm_ex <= #1 opa_of | opb_of;
120
       3'o1: slm_ex <= #1 opa_of & opb_of;
121
       3'o2: slm_ex <= #1 opa_of ^ opb_of;
122
       3'o3: slm_ex <= #1 opa_of & ~opb_of;
123
       // SHIFT/SEXT
124
       3'o4: case ({imm_of[6:5],imm_of[0]})
125
               3'o1: slm_ex <= #1 {opa_of[31],opa_of[31:1]}; // SRA
126
               3'o3: slm_ex <= #1 {rMSR_CC,opa_of[31:1]}; // SRC
127
               3'o5: slm_ex <= #1 {1'b0,opa_of[31:1]}; // SRL
128
               3'o6: slm_ex <= #1 {{(24){opa_of[7]}}, opa_of[7:0]}; // SEXT8
129
               3'o7: slm_ex <= #1  {{(16){opa_of[15]}}, opa_of[15:0]}; // SEXT16
130 125 sybreon
               default: slm_ex <= #1 32'hX;
131 118 sybreon
             endcase // case ({imm_of[6:5],imm_of[0]})
132
       // MFS/MTS/MSET/MCLR
133
       //3'o5: slm_ex <= #1 sfr_of;       
134
       // BRL (PC from SFR)
135
       //3'o6: slm_ex <= #1 sfr_of;
136
       default: slm_ex <= #1 32'hX;
137
     endcase // case (opc_of[2:0])
138
 
139
   always @(/*AUTOSENSE*/imm_of or opa_of or rMSR_CC)
140
     slm_c <= #1 (&imm_of[6:5]) ? rMSR_CC : opa_of[0];
141
 
142
   // ALU RESULT
143
   always @(posedge gclk)
144
     if (grst) begin
145
        /*AUTORESET*/
146
        // Beginning of autoreset for uninitialized flops
147
        alu_ex <= 32'h0;
148
        alu_mx <= 32'h0;
149 131 sybreon
        bpc_ex <= 30'h0;
150 118 sybreon
        mem_ex <= 30'h0;
151
        // End of automatics
152
     end else if (dena) begin
153
        alu_mx <= #1 alu_ex;
154
        alu_ex <= #1 (opc_of[5]) ? slm_ex : add_ex;
155 134 sybreon
        mem_ex <= #1 wADD[AEMB_DWB-1:2]; // LXX/SXX     
156 131 sybreon
        bpc_ex <= #1
157
                  (!opc_of[0] & ra_of[3]) ? // check for BRA
158
                  opb_of[AEMB_IWB-1:2] : // BRA only
159 134 sybreon
                  wADD[AEMB_IWB-1:2]; // RTD/BCC/BR
160 118 sybreon
     end
161
 
162
   // MSR SECTION
163
 
164
   /*
165
    MSR REGISTER
166
 
167
    We should keep common configuration bits in the lower 16-bits of
168
    the MSR in order to avoid using the IMMI instruction.
169
 
170
    MSR bits
171
    31 - CC (carry copy)
172
    30 - HTE (hardware thread enabled)
173
    29 - PHA (current phase)
174
 
175 125 sybreon
    7  - DCE (data cache enable)
176
    5  - ICE (instruction cache enable)
177
    4  - MTX (hardware mutex bit)
178
    3  - BIP (break in progress)
179
    2  - C (carry flag)
180
    1  - IE (interrupt enable)
181
 
182 118 sybreon
    */
183
 
184
   assign msr_ex = {
185
                    rMSR_DCE,
186
                    1'b0,
187
                    rMSR_ICE,
188
                    rMSR_MTX,
189
                    rMSR_BIP,
190
                    rMSR_C,
191
                    rMSR_IE,
192
                    rMSR_BE
193
                    };
194
 
195
   // MSRSET/MSRCLR (small ALU)
196
   wire [7:0] wRES = (ra_of[0]) ?
197
               (msr_ex[7:0]) & ~imm_of[7:0] : // MSRCLR
198
               (msr_ex[7:0]) | imm_of[7:0]; // MSRSET      
199
 
200
   // 0 - Break
201
   // 1 - Interrupt
202
   // 2 - Exception
203
   // 3 - Reserved
204
   wire             fRTID = (opc_of == 6'o55) & rd_of[0];
205
   wire             fRTBD = (opc_of == 6'o55) & rd_of[1];
206 125 sybreon
 
207 118 sybreon
   wire             fBRKI = (opc_of == 6'o56) & (ra_of[4:0] == 5'hD);
208
   wire             fBRKB = ((opc_of == 6'o46) | (opc_of == 6'o56)) & (ra_of[4:0] == 5'hC);
209 125 sybreon
 
210 134 sybreon
   //wire           fMOV = (opc_of == 6'o45);
211
   wire             fMOV = opc_of[5] & !opc_of[4] & !opc_of[3] & opc_of[2] & !opc_of[1] & opc_of[0];
212 118 sybreon
   wire             fMTS = fMOV & &imm_of[15:14];
213
   wire             fMOP = fMOV & ~|imm_of[15:14];
214
 
215
   reg [31:0]        sfr_ex;
216
 
217
   always @(posedge gclk)
218
     if (grst) begin
219
        /*AUTORESET*/
220
        // Beginning of autoreset for uninitialized flops
221
        rMSR_BE <= 1'h0;
222
        rMSR_BIP <= 1'h0;
223
        rMSR_DCE <= 1'h0;
224
        rMSR_ICE <= 1'h0;
225
        rMSR_IE <= 1'h0;
226
        rMSR_MTX <= 1'h0;
227
        sfr_ex <= 32'h0;
228
        sfr_mx <= 32'h0;
229
        // End of automatics
230
     end else if (dena) begin // if (grst)
231
        sfr_mx <= #1 sfr_ex;
232
        sfr_ex <= #1
233
                  {rMSR_CC,
234
                   AEMB_HTX[0],
235 126 sybreon
                   gpha,
236 118 sybreon
                   21'd0,
237
                   rMSR_DCE,
238
                   1'b0,
239
                   rMSR_ICE,
240
                   rMSR_MTX,
241
                   rMSR_BIP,
242
                   rMSR_CC,
243
                   rMSR_IE,
244
                   rMSR_BE
245
                   };
246 134 sybreon
        /*
247 118 sybreon
        rMSR_DCE <= #1
248
                   (fMTS) ? opa_of[7] :
249
                   (fMOP) ? wRES[7] :
250
                   rMSR_DCE;
251 134 sybreon
 
252 118 sybreon
        rMSR_ICE <= #1
253
                   (fMTS) ? opa_of[5] :
254
                   (fMOP) ? wRES[5] :
255
                   rMSR_ICE;
256
 
257
        rMSR_MTX <= #1
258
                   (fMTS) ? opa_of[4] :
259
                   (fMOP) ? wRES[4] :
260
                   rMSR_MTX;
261
 
262
        rMSR_BE <= #1
263
                   (fMTS) ? opa_of[0] :
264
                   (fMOP) ? wRES[0] :
265
                   rMSR_BE;
266 134 sybreon
         */
267 118 sybreon
 
268 134 sybreon
        case ({fMTS, fMOP})
269
          2'o2: {rMSR_DCE,
270
                 rMSR_ICE,
271
                 rMSR_MTX,
272
                 rMSR_BE} <= #1 {opa_of[7],
273
                                 opa_of[5],
274
                                 opa_of[4],
275
                                 opa_of[0]};
276
          2'o1: {rMSR_DCE,
277
                 rMSR_ICE,
278
                 rMSR_MTX,
279
                 rMSR_BE} <= #1 {wRES[7],
280
                                 wRES[5],
281
                                 wRES[4],
282
                                 wRES[0]};
283
          default: {rMSR_DCE,
284
                    rMSR_ICE,
285
                    rMSR_MTX,
286
                    rMSR_BE} <= #1 {rMSR_DCE,
287
                                    rMSR_ICE,
288
                                    rMSR_MTX,
289
                                    rMSR_BE};
290
        endcase // case ({fMTS, fMOP})
291
 
292
        case ({fMTS, fMOP})
293
          2'o2: {rMSR_BIP,
294
                 rMSR_IE} <= #1 {opa_of[3],
295
                                 opa_of[1]};
296
          2'o1: {rMSR_BIP,
297
                 rMSR_IE} <= #1 {wRES[3],
298
                                 wRES[1]};
299
          default: begin
300
             rMSR_BIP <= #1 (fBRKB | fRTBD) ? !rMSR_BIP : rMSR_BIP;
301
             rMSR_IE <= #1 (fBRKI | fRTID) ? !rMSR_IE : rMSR_IE;
302
          end
303
        endcase // case ({fMTS, fMOP})
304
 
305
        /*
306 118 sybreon
        rMSR_IE <= #1
307
                   (fBRKI) ? 1'b0 :
308
                   (fRTID) ? 1'b1 :
309
                   (fMTS) ? opa_of[1] :
310
                   (fMOP) ? wRES[1] :
311
                   rMSR_IE;
312
 
313
        rMSR_BIP <= #1
314
                    (fBRKB) ? 1'b1 :
315
                    (fRTBD) ? 1'b0 :
316
                    (fMTS) ? opa_of[3] :
317
                    (fMOP) ? wRES[3] :
318
                    rMSR_BIP;
319 134 sybreon
        */
320 125 sybreon
     end // if (dena)
321 118 sybreon
 
322
   // BARREL C
323
   wire fADDSUB = (opc_of[5:2] == 4'h0) | (opc_of[5:2] == 4'h2);
324 131 sybreon
   wire fSHIFT  = (opc_of == 6'o44) & (imm_of[6:5] != 2'o3);
325 125 sybreon
 
326 118 sybreon
   always @(posedge gclk)
327
     if (grst) begin
328
        /*AUTORESET*/
329
     end else if (dena) begin
330
     end
331 125 sybreon
 
332 118 sybreon
   always @(posedge gclk)
333
     if (grst) begin
334
        /*AUTORESET*/
335
        // Beginning of autoreset for uninitialized flops
336
        rMSR_C <= 1'h0;
337 131 sybreon
        rMSR_CC <= 1'h0;
338 118 sybreon
        // End of automatics
339
     end else if (dena) begin
340 131 sybreon
        rMSR_CC <= #1 rMSR_C;
341 118 sybreon
        rMSR_C <= #1
342
                  (fMTS) ? opa_of[2] :
343
                  (fMOP) ? wRES[2] :
344
                  (fSHIFT) ? opa_of[0] : // SRA/SRL/SRC
345
                  (fADDSUB) ? add_c : // ADD/SUB/ADDC/SUBC
346
                  rMSR_CC;
347
     end
348
 
349
endmodule // aeMB2_intu
350
 
351 131 sybreon
/*
352
 $Log: not supported by cvs2svn $
353 134 sybreon
 Revision 1.4  2008/04/26 01:09:06  sybreon
354
 Passes basic tests. Minor documentation changes to make it compatible with iverilog pre-processor.
355
 
356 131 sybreon
 Revision 1.3  2008/04/23 14:18:30  sybreon
357
 Fixed CMP bug.
358
 
359
 Revision 1.2  2008/04/21 12:11:38  sybreon
360
 Passes arithmetic tests with single thread.
361
 
362
 Revision 1.1  2008/04/18 00:21:52  sybreon
363
 Initial import.
364
*/

powered by: WebSVN 2.1.0

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