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

Subversion Repositories aemb

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

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

Line No. Rev Author Line
1 158 sybreon
/* $Id: aeMB2_intu.v,v 1.7 2008-05-01 12:00:18 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 150 sybreon
   //input [2:0]         mux_of;   
48 118 sybreon
   input [5:0]    opc_of;
49
   input [31:0]  opa_of;
50
   input [31:0]  opb_of;
51
   input [31:0]  opd_of;
52
   input [15:0]  imm_of;
53
   input [4:0]    rd_of,
54
                 ra_of;
55
   output [7:0]  msr_ex;
56
   output [31:0] sfr_mx;
57
 
58
   // SYS signals
59
   input         gclk,
60
                 grst,
61
                 dena,
62
                 gpha;
63
 
64
   /*AUTOREG*/
65
   // Beginning of automatic regs (for this module's undeclared outputs)
66
   reg [31:0]            alu_ex;
67
   reg [31:0]            alu_mx;
68
   reg [31:2]           bpc_ex;
69
   reg [31:2]           mem_ex;
70
   reg [31:0]            sfr_mx;
71
   // End of automatics
72
 
73 150 sybreon
   localparam [2:0]      MUX_SFR = 3'o7,
74
                        MUX_BSF = 3'o6,
75
                        MUX_MUL = 3'o5,
76
                        MUX_MEM = 3'o4,
77
 
78
                        MUX_RPC = 3'o2,
79
                        MUX_ALU = 3'o1,
80
                        MUX_NOP = 3'o0;
81
 
82 118 sybreon
   reg                  rMSR_C,
83
                        rMSR_CC,
84
                        rMSR_MTX,
85 150 sybreon
                        rMSR_DTE,
86
                        rMSR_ITE,
87 118 sybreon
                        rMSR_BIP,
88
                        rMSR_IE,
89
                        rMSR_BE;
90 134 sybreon
 
91 150 sybreon
   // Infer a ADD with carry cell because ADDSUB cannot be inferred
92
   // across technologies.
93 118 sybreon
 
94
   reg [31:0]            add_ex;
95
   reg                  add_c;
96 131 sybreon
 
97 125 sybreon
   wire [31:0]           wADD;
98
   wire                 wADC;
99 118 sybreon
 
100 150 sybreon
   wire                 fCCC = !opc_of[5] & opc_of[1]; // & !opc_of[4]
101
   wire                 fSUB = !opc_of[5] & opc_of[0]; // & !opc_of[4]
102 158 sybreon
   wire                 fCMP = !opc_of[3] & imm_of[1]; // unsigned only
103
   wire                 wCMP = (fCMP) ? !wADC : wADD[31]; // cmpu adjust
104 118 sybreon
 
105 131 sybreon
   wire [31:0]           wOPA = (fSUB) ? ~opa_of : opa_of;
106 118 sybreon
   wire                 wOPC = (fCCC) ? rMSR_CC : fSUB;
107
 
108 150 sybreon
   assign               {wADC, wADD} = (opb_of + wOPA) + wOPC; // add carry
109 118 sybreon
 
110 150 sybreon
   always @(/*AUTOSENSE*/wADC or wADD or wCMP) begin
111
      {add_c, add_ex} <= #1 {wADC, wCMP, wADD[30:0]}; // add with carry
112 118 sybreon
   end
113
 
114
   // SHIFT/LOGIC/MOVE
115
   reg [31:0]            slm_ex;
116
 
117
   always @(/*AUTOSENSE*/imm_of or opa_of or opb_of or opc_of
118
            or rMSR_CC)
119
     case (opc_of[2:0])
120
       // LOGIC
121
       3'o0: slm_ex <= #1 opa_of | opb_of;
122
       3'o1: slm_ex <= #1 opa_of & opb_of;
123
       3'o2: slm_ex <= #1 opa_of ^ opb_of;
124
       3'o3: slm_ex <= #1 opa_of & ~opb_of;
125
       // SHIFT/SEXT
126
       3'o4: case ({imm_of[6:5],imm_of[0]})
127
               3'o1: slm_ex <= #1 {opa_of[31],opa_of[31:1]}; // SRA
128
               3'o3: slm_ex <= #1 {rMSR_CC,opa_of[31:1]}; // SRC
129
               3'o5: slm_ex <= #1 {1'b0,opa_of[31:1]}; // SRL
130
               3'o6: slm_ex <= #1 {{(24){opa_of[7]}}, opa_of[7:0]}; // SEXT8
131
               3'o7: slm_ex <= #1  {{(16){opa_of[15]}}, opa_of[15:0]}; // SEXT16
132 125 sybreon
               default: slm_ex <= #1 32'hX;
133 118 sybreon
             endcase // case ({imm_of[6:5],imm_of[0]})
134
       // MFS/MTS/MSET/MCLR
135
       //3'o5: slm_ex <= #1 sfr_of;       
136
       // BRL (PC from SFR)
137
       //3'o6: slm_ex <= #1 sfr_of;
138
       default: slm_ex <= #1 32'hX;
139
     endcase // case (opc_of[2:0])
140
 
141
   // ALU RESULT
142
   always @(posedge gclk)
143
     if (grst) begin
144
        /*AUTORESET*/
145
        // Beginning of autoreset for uninitialized flops
146
        alu_ex <= 32'h0;
147
        alu_mx <= 32'h0;
148 131 sybreon
        bpc_ex <= 30'h0;
149 118 sybreon
        mem_ex <= 30'h0;
150
        // End of automatics
151
     end else if (dena) begin
152
        alu_mx <= #1 alu_ex;
153
        alu_ex <= #1 (opc_of[5]) ? slm_ex : add_ex;
154 134 sybreon
        mem_ex <= #1 wADD[AEMB_DWB-1:2]; // LXX/SXX     
155 131 sybreon
        bpc_ex <= #1
156
                  (!opc_of[0] & ra_of[3]) ? // check for BRA
157
                  opb_of[AEMB_IWB-1:2] : // BRA only
158 134 sybreon
                  wADD[AEMB_IWB-1:2]; // RTD/BCC/BR
159 118 sybreon
     end
160
 
161
   // MSR SECTION
162
 
163
   /*
164
    MSR REGISTER
165
 
166
    We should keep common configuration bits in the lower 16-bits of
167
    the MSR in order to avoid using the IMMI instruction.
168
 
169
    MSR bits
170
    31 - CC (carry copy)
171
    30 - HTE (hardware thread enabled)
172
    29 - PHA (current phase)
173
 
174 150 sybreon
    7  - DTE (data cache enable)
175
    5  - ITE (instruction cache enable)
176 125 sybreon
    4  - MTX (hardware mutex bit)
177
    3  - BIP (break in progress)
178
    2  - C (carry flag)
179
    1  - IE (interrupt enable)
180
 
181 118 sybreon
    */
182
 
183
   assign msr_ex = {
184 150 sybreon
                    rMSR_DTE,
185 118 sybreon
                    1'b0,
186 150 sybreon
                    rMSR_ITE,
187 118 sybreon
                    rMSR_MTX,
188
                    rMSR_BIP,
189
                    rMSR_C,
190
                    rMSR_IE,
191
                    rMSR_BE
192
                    };
193
 
194
   // MSRSET/MSRCLR (small ALU)
195
   wire [7:0] wRES = (ra_of[0]) ?
196 150 sybreon
              (msr_ex[7:0]) & ~imm_of[7:0] : // MSRCLR
197
              (msr_ex[7:0]) | imm_of[7:0]; // MSRSET      
198 118 sybreon
 
199
   // 0 - Break
200
   // 1 - Interrupt
201
   // 2 - Exception
202
   // 3 - Reserved
203 150 sybreon
   wire       fRTID = (opc_of == 6'o55) & rd_of[0];
204
   wire       fRTBD = (opc_of == 6'o55) & rd_of[1];
205 125 sybreon
 
206 150 sybreon
   wire       fBRKI = (opc_of == 6'o56) & (ra_of[4:0] == 5'hD);
207
   wire       fBRKB = ((opc_of == 6'o46) | (opc_of == 6'o56)) & (ra_of[4:0] == 5'hC);
208 125 sybreon
 
209 150 sybreon
   wire       fMOV = (opc_of == 6'o45);
210
   wire       fMTS = fMOV & &imm_of[15:14];
211
   wire       fMOP = fMOV & ~|imm_of[15:14];
212 118 sybreon
 
213 150 sybreon
   reg [31:0] sfr_ex;
214
 
215 118 sybreon
   always @(posedge gclk)
216
     if (grst) begin
217
        /*AUTORESET*/
218
        // Beginning of autoreset for uninitialized flops
219
        rMSR_BE <= 1'h0;
220
        rMSR_BIP <= 1'h0;
221 150 sybreon
        rMSR_DTE <= 1'h0;
222 118 sybreon
        rMSR_IE <= 1'h0;
223 150 sybreon
        rMSR_ITE <= 1'h0;
224 118 sybreon
        rMSR_MTX <= 1'h0;
225
        sfr_ex <= 32'h0;
226
        sfr_mx <= 32'h0;
227
        // End of automatics
228
     end else if (dena) begin // if (grst)
229
        sfr_mx <= #1 sfr_ex;
230
        sfr_ex <= #1
231
                  {rMSR_CC,
232
                   AEMB_HTX[0],
233 126 sybreon
                   gpha,
234 118 sybreon
                   21'd0,
235 150 sybreon
                   rMSR_DTE,
236 118 sybreon
                   1'b0,
237 150 sybreon
                   rMSR_ITE,
238 118 sybreon
                   rMSR_MTX,
239
                   rMSR_BIP,
240
                   rMSR_CC,
241
                   rMSR_IE,
242
                   rMSR_BE
243
                   };
244 158 sybreon
 
245 150 sybreon
        rMSR_DTE <= #1
246 118 sybreon
                   (fMTS) ? opa_of[7] :
247
                   (fMOP) ? wRES[7] :
248 150 sybreon
                   rMSR_DTE;
249 134 sybreon
 
250 150 sybreon
        rMSR_ITE <= #1
251 118 sybreon
                   (fMTS) ? opa_of[5] :
252
                   (fMOP) ? wRES[5] :
253 150 sybreon
                   rMSR_ITE;
254 118 sybreon
 
255
        rMSR_MTX <= #1
256
                   (fMTS) ? opa_of[4] :
257
                   (fMOP) ? wRES[4] :
258
                   rMSR_MTX;
259
 
260
        rMSR_BE <= #1
261
                   (fMTS) ? opa_of[0] :
262
                   (fMOP) ? wRES[0] :
263
                   rMSR_BE;
264
 
265 158 sybreon
        rMSR_IE <= #1
266
                   (fBRKI) ? 1'b0 :
267
                   (fRTID) ? 1'b1 :
268
                   (fMTS) ? opa_of[1] :
269
                   (fMOP) ? wRES[1] :
270
                   rMSR_IE;
271
 
272
        rMSR_BIP <= #1
273
                    (fBRKB) ? 1'b1 :
274
                    (fRTBD) ? 1'b0 :
275
                    (fMTS) ? opa_of[3] :
276
                    (fMOP) ? wRES[3] :
277
                    rMSR_BIP;
278
        /*
279
 
280 134 sybreon
        case ({fMTS, fMOP})
281 150 sybreon
          2'o2: {rMSR_DTE,
282
                 rMSR_ITE,
283 134 sybreon
                 rMSR_MTX,
284
                 rMSR_BE} <= #1 {opa_of[7],
285
                                 opa_of[5],
286
                                 opa_of[4],
287
                                 opa_of[0]};
288 150 sybreon
          2'o1: {rMSR_DTE,
289
                 rMSR_ITE,
290 134 sybreon
                 rMSR_MTX,
291
                 rMSR_BE} <= #1 {wRES[7],
292
                                 wRES[5],
293
                                 wRES[4],
294
                                 wRES[0]};
295 150 sybreon
          default: {rMSR_DTE,
296
                    rMSR_ITE,
297 134 sybreon
                    rMSR_MTX,
298 150 sybreon
                    rMSR_BE} <= #1 {rMSR_DTE,
299
                                    rMSR_ITE,
300 134 sybreon
                                    rMSR_MTX,
301
                                    rMSR_BE};
302
        endcase // case ({fMTS, fMOP})
303
 
304
        case ({fMTS, fMOP})
305
          2'o2: {rMSR_BIP,
306
                 rMSR_IE} <= #1 {opa_of[3],
307
                                 opa_of[1]};
308
          2'o1: {rMSR_BIP,
309
                 rMSR_IE} <= #1 {wRES[3],
310
                                 wRES[1]};
311
          default: begin
312
             rMSR_BIP <= #1 (fBRKB | fRTBD) ? !rMSR_BIP : rMSR_BIP;
313
             rMSR_IE <= #1 (fBRKI | fRTID) ? !rMSR_IE : rMSR_IE;
314
          end
315
        endcase // case ({fMTS, fMOP})
316 158 sybreon
         */
317 125 sybreon
     end // if (dena)
318 118 sybreon
 
319
   // BARREL C
320 158 sybreon
   wire fADDSUB = !opc_of[5] & !opc_of[4] & !opc_of[2];
321
   // (opc_of[5:2] == 4'h0) | (opc_of[5:2] == 4'h2);
322
   wire fSHIFT  = (opc_of == 6'o44) & &imm_of[6:5];
323 125 sybreon
 
324 118 sybreon
   always @(posedge gclk)
325
     if (grst) begin
326
        /*AUTORESET*/
327
     end else if (dena) begin
328
     end
329 125 sybreon
 
330 118 sybreon
   always @(posedge gclk)
331
     if (grst) begin
332
        /*AUTORESET*/
333
        // Beginning of autoreset for uninitialized flops
334
        rMSR_C <= 1'h0;
335 131 sybreon
        rMSR_CC <= 1'h0;
336 118 sybreon
        // End of automatics
337
     end else if (dena) begin
338 131 sybreon
        rMSR_CC <= #1 rMSR_C;
339 158 sybreon
 
340 118 sybreon
        rMSR_C <= #1
341
                  (fMTS) ? opa_of[2] :
342
                  (fMOP) ? wRES[2] :
343
                  (fSHIFT) ? opa_of[0] : // SRA/SRL/SRC
344
                  (fADDSUB) ? add_c : // ADD/SUB/ADDC/SUBC
345
                  rMSR_CC;
346 158 sybreon
 
347
        /*
348
        case ({fMTS,fMOP,fSHIFT,fADDSUB})
349
          4'h8: rMSR_C <= #1 opa_of[2];
350
          4'h4: rMSR_C <= #1 wRES[2];
351
          4'h2: rMSR_C <= #1 opa_of[0];
352
          4'h1: rMSR_C <= #1 add_c;
353
          default: rMSR_C <= #1 rMSR_CC;
354
        endcase // case ({fMTS,fMOP,fSHIFT,fADDSUB})
355
        */
356 118 sybreon
     end
357
 
358
endmodule // aeMB2_intu
359
 
360 131 sybreon
/*
361
 $Log: not supported by cvs2svn $
362 158 sybreon
 Revision 1.6  2008/04/28 08:15:25  sybreon
363
 Optimisations.
364
 
365 150 sybreon
 Revision 1.5  2008/04/26 17:57:43  sybreon
366
 Minor performance improvements.
367
 
368 134 sybreon
 Revision 1.4  2008/04/26 01:09:06  sybreon
369
 Passes basic tests. Minor documentation changes to make it compatible with iverilog pre-processor.
370
 
371 131 sybreon
 Revision 1.3  2008/04/23 14:18:30  sybreon
372
 Fixed CMP bug.
373
 
374
 Revision 1.2  2008/04/21 12:11:38  sybreon
375
 Passes arithmetic tests with single thread.
376
 
377
 Revision 1.1  2008/04/18 00:21:52  sybreon
378
 Initial import.
379
*/

powered by: WebSVN 2.1.0

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