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

Subversion Repositories aemb

[/] [aemb/] [trunk/] [rtl/] [verilog/] [aeMB2_ctrl.v] - Blame information for rev 203

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

Line No. Rev Author Line
1 160 sybreon
/* $Id: aeMB2_ctrl.v,v 1.7 2008-05-11 13:50:50 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
 * Instruction Decode & Control
23
 * @file aeMB2_ctrl.v
24
 
25
 * This is the data decoder that will control the command signals and
26
   operand fetch.
27
 
28
 */
29
 
30
module aeMB2_ctrl (/*AUTOARG*/
31
   // Outputs
32
   opa_of, opb_of, opd_of, opc_of, ra_of, rd_of, imm_of, rd_ex,
33
   mux_of, mux_ex, hzd_bpc, hzd_fwd,
34
   // Inputs
35 157 sybreon
   opa_if, opb_if, opd_if, brk_if, bra_ex, rpc_if, alu_ex, ich_dat,
36
   gclk, grst, dena, iena, gpha
37 118 sybreon
   );
38
   parameter AEMB_HTX = 1;
39
 
40
   // EX CONTROL
41
   output [31:0] opa_of;
42
   output [31:0] opb_of;
43
   output [31:0] opd_of;
44
   output [5:0]  opc_of;
45
   output [4:0]  ra_of,
46
                 //rb_of,
47
                 rd_of;
48
   output [15:0] imm_of;
49
   output [4:0]   rd_ex;
50
 
51
   // REGS
52
   input [31:0]  opa_if,
53
                 opb_if,
54
                 opd_if;
55
 
56
   // WB CONTROL
57
   output [2:0]  mux_of,
58
                 mux_ex;
59
 
60
   // INTERNAL
61 157 sybreon
   input [1:0]    brk_if;
62 118 sybreon
   input [1:0]    bra_ex;
63
   input [31:2]  rpc_if;
64
   input [31:0]  alu_ex;
65
   input [31:0]  ich_dat;
66
 
67
   output        hzd_bpc;
68
   output        hzd_fwd;
69
 
70
   // SYSTEM
71
   input         gclk,
72
                 grst,
73
                 dena,
74
                 iena,
75
                 gpha;
76 157 sybreon
 
77 118 sybreon
   /*AUTOREG*/
78
   // Beginning of automatic regs (for this module's undeclared outputs)
79
   reg [15:0]            imm_of;
80
   reg [2:0]             mux_ex;
81
   reg [2:0]             mux_of;
82
   reg [31:0]            opa_of;
83
   reg [31:0]            opb_of;
84
   reg [5:0]             opc_of;
85
   reg [31:0]            opd_of;
86
   reg [4:0]             ra_of;
87
   reg [4:0]             rd_ex;
88
   reg [4:0]             rd_of;
89
   // End of automatics
90
 
91 157 sybreon
   wire                 fINT;
92
   //wire [31:0]                wXCEOP = 32'hBA2D0020; // Vector 0x20
93
   wire [31:0]           wINTOP = 32'hB9CD0010; // Vector 0x10   
94
   //wire [31:0]                wNOPOP = 32'h88000000; // branch-no-delay/stall
95
 
96 118 sybreon
   wire [1:0]            mux_opa, mux_opb, mux_opd;
97
 
98
   // translate signals
99
   wire [4:0]            wRD, wRA, wRB;
100
   wire [5:0]            wOPC;
101
   wire [15:0]           wIMM;
102
   wire [31:0]           imm_if;
103
 
104 157 sybreon
   assign               {wOPC, wRD, wRA, wIMM} = (fINT) ? wINTOP : ich_dat;
105 118 sybreon
   assign               wRB = wIMM[15:11];
106
 
107
   // decode main opgroups
108
 
109 150 sybreon
   //wire               fSFT = (wOPC == 6'o44);
110
   //wire               fLOG = ({wOPC[5:4],wOPC[2]} == 3'o4);      
111 118 sybreon
   wire                 fMUL = (wOPC == 6'o20) | (wOPC == 6'o30);
112
   wire                 fBSF = (wOPC == 6'o21) | (wOPC == 6'o31);
113 150 sybreon
   //wire               fDIV = (wOPC == 6'o22);   
114 118 sybreon
   wire                 fRTD = (wOPC == 6'o55);
115
   wire                 fBCC = (wOPC == 6'o47) | (wOPC == 6'o57);
116
   wire                 fBRU = (wOPC == 6'o46) | (wOPC == 6'o56);
117 150 sybreon
   //wire               fBRA = fBRU & wRA[3];      
118 118 sybreon
   wire                 fIMM = (wOPC == 6'o54);
119
   wire                 fMOV = (wOPC == 6'o45);
120
   wire                 fLOD = ({wOPC[5:4],wOPC[2]} == 3'o6);
121
   wire                 fSTR = ({wOPC[5:4],wOPC[2]} == 3'o7);
122 150 sybreon
   //wire               fLDST = (wOPC[5:4] == 2'o3);   
123
   //wire               fPUT = (wOPC == 6'o33) & wRB[4];
124 118 sybreon
   wire                 fGET = (wOPC == 6'o33) & !wRB[4];
125
 
126
 
127
   // control signals
128 134 sybreon
   localparam [2:0]      MUX_SFR = 3'o7,
129
                        MUX_BSF = 3'o6,
130
                        MUX_MUL = 3'o5,
131
                        MUX_MEM = 3'o4,
132
 
133
                        MUX_RPC = 3'o2,
134
                        MUX_ALU = 3'o1,
135 150 sybreon
                        MUX_NOP = 3'o0;
136 118 sybreon
 
137
   always @(posedge gclk)
138
     if (grst) begin
139
        /*AUTORESET*/
140
        // Beginning of autoreset for uninitialized flops
141
        imm_of <= 16'h0;
142
        mux_of <= 3'h0;
143
        opc_of <= 6'h0;
144
        ra_of <= 5'h0;
145
        rd_of <= 5'h0;
146
        // End of automatics
147
     end else if (dena) begin
148
 
149 150 sybreon
        mux_of <= #1
150
                  (hzd_bpc | hzd_fwd | fSTR | fRTD | fBCC) ? MUX_NOP :
151
                  (fLOD | fGET) ? MUX_MEM :
152 118 sybreon
                  (fMOV) ? MUX_SFR :
153
                  (fMUL) ? MUX_MUL :
154
                  (fBSF) ? MUX_BSF :
155 150 sybreon
                  (fBRU) ? MUX_RPC :
156
                  MUX_ALU;
157 118 sybreon
 
158 157 sybreon
        opc_of <= #1
159 150 sybreon
                  (hzd_bpc | hzd_fwd) ? 6'o42 : // XOR (SKIP) 
160 118 sybreon
                  wOPC;
161
 
162
        rd_of <= #1 wRD;
163
        ra_of <= #1 wRA;
164
        imm_of <= #1 wIMM;
165
 
166 131 sybreon
     end // if (dena)
167 134 sybreon
 
168 118 sybreon
   // immediate implementation
169
   reg [15:0]            rIMM0, rIMM1;
170
   reg                  rFIM0, rFIM1;
171 134 sybreon
   //wire               wFIMH = (gpha & AEMB_HTX[0]) ? rFIM1 : rFIM0;   
172
   //wire [15:0]                wIMMH = (gpha & AEMB_HTX[0]) ? rIMM1 : rIMM0;
173 118 sybreon
 
174
   assign               imm_if[15:0] = wIMM;
175 134 sybreon
   assign               imm_if[31:16] = (rFIM1) ? rIMM1 :
176 118 sybreon
                                        {(16){wIMM[15]}};
177
 
178 134 sybreon
   // BARREL IMM
179 118 sybreon
   always @(posedge gclk)
180
     if (grst) begin
181
        /*AUTORESET*/
182
        // Beginning of autoreset for uninitialized flops
183
        rFIM0 <= 1'h0;
184
        rFIM1 <= 1'h0;
185
        rIMM0 <= 16'h0;
186
        rIMM1 <= 16'h0;
187
        // End of automatics
188
     end else if (dena) begin
189 134 sybreon
        rFIM1 <= #1 rFIM0;
190
        rFIM0 <= #1 fIMM & !hzd_bpc;
191
 
192
        rIMM1 <= #1 rIMM0;
193
        rIMM0 <= #1 wIMM;
194 131 sybreon
     end
195 157 sybreon
 
196 160 sybreon
   assign fINT = brk_if[0] & gpha & !rFIM1;
197 118 sybreon
 
198
   // operand latch   
199
   reg                  wrb_ex;
200
   reg                  fwd_ex;
201 134 sybreon
   reg [2:0]             mux_mx;
202
 
203 118 sybreon
   wire                 opb_fwd, opa_fwd, opd_fwd;
204
 
205
   assign               mux_opb = {wOPC[3], opb_fwd};
206 150 sybreon
   assign               opb_fwd = ((wRB ^ rd_ex) == 5'd0) & // RB forwarding needed
207 118 sybreon
                                  fwd_ex & wrb_ex;
208
 
209
   assign               mux_opa = {(fBRU|fBCC), opa_fwd};
210 150 sybreon
   assign               opa_fwd = ((wRA ^ rd_ex) == 5'd0) & // RA forwarding needed
211 118 sybreon
                                  fwd_ex & wrb_ex;
212
 
213
   assign               mux_opd = {fBCC, opd_fwd};
214 150 sybreon
   assign               opd_fwd = (( ((wRA ^ rd_ex) == 5'd0) & fBCC) | // RA forwarding
215
                                   ( ((wRD ^ rd_ex) == 5'd0) & fSTR)) & // RD forwarding
216 118 sybreon
                                  fwd_ex & wrb_ex;
217
 
218
   always @(posedge gclk)
219
     if (grst) begin
220
        /*AUTORESET*/
221
        // Beginning of autoreset for uninitialized flops
222
        fwd_ex <= 1'h0;
223
        mux_ex <= 3'h0;
224 120 sybreon
        mux_mx <= 3'h0;
225 118 sybreon
        rd_ex <= 5'h0;
226
        wrb_ex <= 1'h0;
227
        // End of automatics
228
     end else if (dena) begin
229
        wrb_ex <= #1 |rd_of & |mux_of; // FIXME: check mux      
230
        fwd_ex <= #1 |mux_of; // FIXME: check mux
231
 
232 120 sybreon
        mux_mx <= #1 mux_ex;
233 118 sybreon
        mux_ex <= #1 mux_of;
234
        rd_ex <= #1 rd_of;
235
     end
236 134 sybreon
 
237 118 sybreon
   always @(posedge gclk)
238
     if (grst) begin
239
        /*AUTORESET*/
240
        // Beginning of autoreset for uninitialized flops
241
        opa_of <= 32'h0;
242
        opb_of <= 32'h0;
243
        opd_of <= 32'h0;
244
        // End of automatics
245
 
246
     end else if (dena) begin
247
 
248
        case (mux_opd)
249
          2'o2: opd_of <= #1 opa_if; // BCC
250
          2'o1: opd_of <= #1 alu_ex; // FWD
251
          2'o0: opd_of <= #1 opd_if; // SXX
252
          2'o3: opd_of <= #1 alu_ex; // FWD               
253 131 sybreon
        endcase // case (mux_opd)
254 118 sybreon
 
255
        case (mux_opb)
256
          2'o0: opb_of <= #1 opb_if;
257
          2'o1: opb_of <= #1 alu_ex;
258
          2'o2: opb_of <= #1 imm_if;
259
          2'o3: opb_of <= #1 imm_if;
260 131 sybreon
        endcase // case (mux_opb)
261 118 sybreon
 
262
        case (mux_opa)
263
          2'o0: opa_of <= #1 opa_if;
264
          2'o1: opa_of <= #1 alu_ex;
265
          2'o2: opa_of <= #1 {rpc_if, 2'o0};
266
          2'o3: opa_of <= #1 {rpc_if, 2'o0};
267 131 sybreon
        endcase // case (mux_opa)
268 118 sybreon
 
269 131 sybreon
     end // if (dena)
270 118 sybreon
 
271
   // Hazard Detection
272 150 sybreon
   //wire               wFMUL = (mux_ex == MUX_MUL);
273
   //wire               wFBSF = (mux_ex == MUX_BSF);
274
   //wire               wFMEM = (mux_ex == MUX_MEM);
275
   //wire               wFMOV = (mux_ex == MUX_SFR);   
276 118 sybreon
 
277 134 sybreon
   assign               hzd_fwd = (opd_fwd | opa_fwd | opb_fwd) & mux_ex[2];
278
                                  //(wFMUL | wFBSF | wFMEM | wFMOV);
279 118 sybreon
   assign               hzd_bpc = (bra_ex[1] & !bra_ex[0]);
280
 
281
endmodule // aeMB2_ctrl
282
 
283 131 sybreon
/*
284
 $Log: not supported by cvs2svn $
285 160 sybreon
 Revision 1.6  2008/05/01 08:32:58  sybreon
286
 Added interrupt capability.
287
 
288 157 sybreon
 Revision 1.5  2008/04/28 08:15:25  sybreon
289
 Optimisations.
290
 
291 150 sybreon
 Revision 1.4  2008/04/26 17:57:43  sybreon
292
 Minor performance improvements.
293
 
294 134 sybreon
 Revision 1.3  2008/04/26 01:09:05  sybreon
295
 Passes basic tests. Minor documentation changes to make it compatible with iverilog pre-processor.
296
 
297 131 sybreon
 Revision 1.2  2008/04/20 16:34:32  sybreon
298
 Basic version with some features left out.
299
 
300
 Revision 1.1  2008/04/18 00:21:52  sybreon
301
 Initial import.
302
*/

powered by: WebSVN 2.1.0

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