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

Subversion Repositories aemb

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

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

Line No. Rev Author Line
1 118 sybreon
/* $Id: aeMB2_intu.v,v 1.1 2008-04-18 00:21:52 sybreon Exp $
2
**
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
/**
23
 * One Cycle Integer Unit
24
 * @file aeMB2_intu.v
25
 
26
 * This implements a single cycle integer unit. It performs all basic
27
   arithmetic, shift, and logic operations.
28
 
29
 */
30
 
31
module aeMB2_intu (/*AUTOARG*/
32
   // Outputs
33
   mem_ex, bpc_ex, alu_ex, alu_mx, msr_ex, sfr_mx,
34
   // Inputs
35
   opc_of, opa_of, opb_of, opd_of, imm_of, rd_of, ra_of, gclk, grst,
36
   dena, gpha
37
   );
38
   parameter AEMB_DWB = 32;
39
   parameter AEMB_IWB = 32;
40
   parameter AEMB_HTX = 1;
41
 
42
   output [31:2] mem_ex;
43
   output [31:2] bpc_ex;
44
 
45
   output [31:0] alu_ex,
46
                 alu_mx;
47
 
48
   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
   reg                  rMSR_C,
74
                        rMSR_CC,
75
                        rMSR_C0, rMSR_C1,
76
                        rMSR_MTX,
77
                        rMSR_DCE,
78
                        rMSR_ICE,
79
                        rMSR_BIP,
80
                        rMSR_IE,
81
                        rMSR_BE;
82
 
83
 
84
   // ADDER
85
 
86
   /* Infer a ADDER cell because ADD/SUB cannot be inferred cross
87
    technologies. */
88
 
89
   // FIXME: Redesign this critical path
90
 
91
   reg [31:0]            add_ex;
92
   reg                  add_c;
93
 
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
   wire                 fCMP = !opc_of[3] & !imm_of[1] & imm_of[0];
97
 
98
   wire [31:0]           wOPA = (fSUB) ? ~opa_of : opa_of;
99
   wire                 wOPC = (fCCC) ? rMSR_CC : fSUB;
100
   wire [31:0]           wADD;
101
   wire                 wADC;
102
 
103
   assign               {wADC, wADD} = (opb_of + wOPA) + wOPC;
104
 
105
   always @(/*AUTOSENSE*/fCMP or wADC or wADD) begin
106
      {add_c, add_ex} <= #1 {wADC, (wADD[31] ^ fCMP) , wADD[30:0]}; // add with carry
107
   end
108
 
109
   // SHIFT/LOGIC/MOVE
110
   reg [31:0]            slm_ex;
111
   reg                  slm_c;
112
 
113
   always @(/*AUTOSENSE*/imm_of or opa_of or opb_of or opc_of
114
            or rMSR_CC)
115
     case (opc_of[2:0])
116
       // LOGIC
117
       3'o0: slm_ex <= #1 opa_of | opb_of;
118
       3'o1: slm_ex <= #1 opa_of & opb_of;
119
       3'o2: slm_ex <= #1 opa_of ^ opb_of;
120
       3'o3: slm_ex <= #1 opa_of & ~opb_of;
121
       // SHIFT/SEXT
122
       3'o4: case ({imm_of[6:5],imm_of[0]})
123
               3'o1: slm_ex <= #1 {opa_of[31],opa_of[31:1]}; // SRA
124
               3'o3: slm_ex <= #1 {rMSR_CC,opa_of[31:1]}; // SRC
125
               3'o5: slm_ex <= #1 {1'b0,opa_of[31:1]}; // SRL
126
               3'o6: slm_ex <= #1 {{(24){opa_of[7]}}, opa_of[7:0]}; // SEXT8
127
               3'o7: slm_ex <= #1  {{(16){opa_of[15]}}, opa_of[15:0]}; // SEXT16
128
               default: slm_ex <= #1 32'hX;
129
             endcase // case ({imm_of[6:5],imm_of[0]})
130
       // MFS/MTS/MSET/MCLR
131
       //3'o5: slm_ex <= #1 sfr_of;       
132
       // BRL (PC from SFR)
133
       //3'o6: slm_ex <= #1 sfr_of;
134
       default: slm_ex <= #1 32'hX;
135
     endcase // case (opc_of[2:0])
136
 
137
   always @(/*AUTOSENSE*/imm_of or opa_of or rMSR_CC)
138
     slm_c <= #1 (&imm_of[6:5]) ? rMSR_CC : opa_of[0];
139
 
140
 
141
   // BRANCH CALC
142
   always @(posedge gclk)
143
     if (grst) begin
144
        /*AUTORESET*/
145
        // Beginning of autoreset for uninitialized flops
146
        bpc_ex <= 30'h0;
147
        // End of automatics
148
     end else if (dena) begin
149
        bpc_ex <= #1
150
                  (!opc_of[0] & ra_of[3]) ? // check for BRA
151
                  opb_of[AEMB_IWB-1:2] : // BRA only
152
                  add_ex[AEMB_IWB-1:2]; // RTD/BCC/BR
153
     end
154
 
155
   // ALU RESULT
156
   always @(posedge gclk)
157
     if (grst) begin
158
        /*AUTORESET*/
159
        // Beginning of autoreset for uninitialized flops
160
        alu_ex <= 32'h0;
161
        alu_mx <= 32'h0;
162
        mem_ex <= 30'h0;
163
        // End of automatics
164
     end else if (dena) begin
165
        alu_mx <= #1 alu_ex;
166
        alu_ex <= #1 (opc_of[5]) ? slm_ex : add_ex;
167
        mem_ex <= #1 add_ex[AEMB_DWB-1:2]; // LXX/SXX   
168
     end
169
 
170
 
171
   // MSR SECTION
172
 
173
   /*
174
    MSR REGISTER
175
 
176
    We should keep common configuration bits in the lower 16-bits of
177
    the MSR in order to avoid using the IMMI instruction.
178
 
179
    MSR bits
180
    31 - CC (carry copy)
181
    30 - HTE (hardware thread enabled)
182
    29 - PHA (current phase)
183
 
184
     7 - DCE (data cache enable)
185
     5 - ICE (instruction cache enable)
186
     4 - MTX (hardware mutex bit)
187
     3 - BIP (break in progress)
188
     2 - C (carry flag)
189
     1 - IE (interrupt enable)
190
 
191
    */
192
 
193
   assign msr_ex = {
194
                    rMSR_DCE,
195
                    1'b0,
196
                    rMSR_ICE,
197
                    rMSR_MTX,
198
                    rMSR_BIP,
199
                    rMSR_C,
200
                    rMSR_IE,
201
                    rMSR_BE
202
                    };
203
 
204
   // MSRSET/MSRCLR (small ALU)
205
   wire [7:0] wRES = (ra_of[0]) ?
206
               (msr_ex[7:0]) & ~imm_of[7:0] : // MSRCLR
207
               (msr_ex[7:0]) | imm_of[7:0]; // MSRSET      
208
 
209
   // 0 - Break
210
   // 1 - Interrupt
211
   // 2 - Exception
212
   // 3 - Reserved
213
   wire             fRTID = (opc_of == 6'o55) & rd_of[0];
214
   wire             fRTBD = (opc_of == 6'o55) & rd_of[1];
215
   wire             fBRKI = (opc_of == 6'o56) & (ra_of[4:0] == 5'hD);
216
   wire             fBRKB = ((opc_of == 6'o46) | (opc_of == 6'o56)) & (ra_of[4:0] == 5'hC);
217
   wire             fMOV = (opc_of == 6'o45);
218
   wire             fMTS = fMOV & &imm_of[15:14];
219
   wire             fMOP = fMOV & ~|imm_of[15:14];
220
 
221
   reg [31:0]        sfr_ex;
222
 
223
   always @(posedge gclk)
224
     if (grst) begin
225
        /*AUTORESET*/
226
        // Beginning of autoreset for uninitialized flops
227
        rMSR_BE <= 1'h0;
228
        rMSR_BIP <= 1'h0;
229
        rMSR_DCE <= 1'h0;
230
        rMSR_ICE <= 1'h0;
231
        rMSR_IE <= 1'h0;
232
        rMSR_MTX <= 1'h0;
233
        sfr_ex <= 32'h0;
234
        sfr_mx <= 32'h0;
235
        // End of automatics
236
     end else if (dena) begin // if (grst)
237
        sfr_mx <= #1 sfr_ex;
238
        sfr_ex <= #1
239
                  {rMSR_CC,
240
                   AEMB_HTX[0],
241
                   !gpha,
242
                   21'd0,
243
                   rMSR_DCE,
244
                   1'b0,
245
                   rMSR_ICE,
246
                   rMSR_MTX,
247
                   rMSR_BIP,
248
                   rMSR_CC,
249
                   rMSR_IE,
250
                   rMSR_BE
251
                   };
252
 
253
        rMSR_DCE <= #1
254
                   (fMTS) ? opa_of[7] :
255
                   (fMOP) ? wRES[7] :
256
                   rMSR_DCE;
257
 
258
        rMSR_ICE <= #1
259
                   (fMTS) ? opa_of[5] :
260
                   (fMOP) ? wRES[5] :
261
                   rMSR_ICE;
262
 
263
        rMSR_MTX <= #1
264
                   (fMTS) ? opa_of[4] :
265
                   (fMOP) ? wRES[4] :
266
                   rMSR_MTX;
267
 
268
        rMSR_BE <= #1
269
                   (fMTS) ? opa_of[0] :
270
                   (fMOP) ? wRES[0] :
271
                   rMSR_BE;
272
 
273
        rMSR_IE <= #1
274
                   (fBRKI) ? 1'b0 :
275
                   (fRTID) ? 1'b1 :
276
                   (fMTS) ? opa_of[1] :
277
                   (fMOP) ? wRES[1] :
278
                   rMSR_IE;
279
 
280
        rMSR_BIP <= #1
281
                    (fBRKB) ? 1'b1 :
282
                    (fRTBD) ? 1'b0 :
283
                    (fMTS) ? opa_of[3] :
284
                    (fMOP) ? wRES[3] :
285
                    rMSR_BIP;
286
 
287
     end
288
 
289
   // BARREL C
290
   wire fADDSUB = (opc_of[5:2] == 4'h0) | (opc_of[5:2] == 4'h2);
291
   wire fSHIFT  = (opc_of[5:2] == 4'h9) & (imm_of[6:5] != 2'o3);
292
 
293
   always @(posedge gclk)
294
     if (grst) begin
295
        /*AUTORESET*/
296
        // Beginning of autoreset for uninitialized flops
297
        rMSR_CC <= 1'h0;
298
        // End of automatics
299
     end else if (dena) begin
300
        rMSR_CC <= #1 rMSR_C;
301
     end
302
 
303
   always @(posedge gclk)
304
     if (grst) begin
305
        /*AUTORESET*/
306
        // Beginning of autoreset for uninitialized flops
307
        rMSR_C <= 1'h0;
308
        // End of automatics
309
     end else if (dena) begin
310
        rMSR_C <= #1
311
                  (fMTS) ? opa_of[2] :
312
                  (fMOP) ? wRES[2] :
313
                  (fSHIFT) ? opa_of[0] : // SRA/SRL/SRC
314
                  (fADDSUB) ? add_c : // ADD/SUB/ADDC/SUBC
315
                  rMSR_CC;
316
     end
317
 
318
endmodule // aeMB2_intu
319
 
320
// $Log: not supported by cvs2svn $

powered by: WebSVN 2.1.0

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