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

Subversion Repositories aemb

[/] [aemb/] [branches/] [DEV_SYBREON/] [rtl/] [verilog/] [aeMB_bpcu.v] - Blame information for rev 194

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

Line No. Rev Author Line
1 61 sybreon
// $Id: aeMB_bpcu.v,v 1.4 2007-11-14 22:14:34 sybreon Exp $
2 41 sybreon
//
3
// AEMB BRANCH PROGRAMME COUNTER UNIT
4
// 
5
// Copyright (C) 2004-2007 Shawn Tan Ser Ngiap <shawn.tan@aeste.net>
6
//  
7 55 sybreon
// This file is part of AEMB.
8 41 sybreon
//
9 55 sybreon
// AEMB is free software: you can redistribute it and/or modify it
10
// under the terms of the GNU Lesser General Public License as
11
// published by the Free Software Foundation, either version 3 of the
12
// License, or (at your option) any later version.
13
//
14
// AEMB is distributed in the hope that it will be useful, but WITHOUT
15
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16
// or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General
17
// Public License for more details.
18
//
19 41 sybreon
// You should have received a copy of the GNU Lesser General Public
20 55 sybreon
// License along with AEMB. If not, see <http://www.gnu.org/licenses/>.
21 41 sybreon
//
22
// $Log: not supported by cvs2svn $
23 61 sybreon
// Revision 1.3  2007/11/10 16:39:38  sybreon
24
// Upgraded license to LGPLv3.
25
// Significant performance optimisations.
26
//
27 55 sybreon
// Revision 1.2  2007/11/02 19:20:58  sybreon
28
// Added better (beta) interrupt support.
29
// Changed MSR_IE to disabled at reset as per MB docs.
30
//
31 44 sybreon
// Revision 1.1  2007/11/02 03:25:39  sybreon
32
// New EDK 3.2 compatible design with optional barrel-shifter and multiplier.
33
// Fixed various minor data hazard bugs.
34
// Code compatible with -O0/1/2/3/s generated code.
35
//
36 41 sybreon
 
37
module aeMB_bpcu (/*AUTOARG*/
38
   // Outputs
39 61 sybreon
   iwb_adr_o, rPC, rPCLNK, rBRA, rDLY,
40 41 sybreon
   // Inputs
41 61 sybreon
   rMXALT, rOPC, rRD, rRA, rRESULT, rDWBDI, rREGA, gclk, grst, gena
42 41 sybreon
   );
43
   parameter IW = 24;
44
 
45
   // INST WISHBONE
46
   output [IW-1:2] iwb_adr_o;
47
 
48
   // INTERNAL
49
   output [31:2]   rPC, rPCLNK;
50
   output          rBRA;
51
   output          rDLY;
52 61 sybreon
   //output [1:0]    rATOM;
53
   //output [1:0]    xATOM;
54
 
55 41 sybreon
   input [1:0]      rMXALT;
56
   input [5:0]      rOPC;
57
   input [4:0]      rRD, rRA;
58
   input [31:0]    rRESULT; // ALU
59
   input [31:0]    rDWBDI; // RAM
60 44 sybreon
   input [31:0]    rREGA;
61 61 sybreon
   //input [1:0]           rXCE;   
62 41 sybreon
 
63
   // SYSTEM
64
   input           gclk, grst, gena;
65
 
66 44 sybreon
   // --- BRANCH CONTROL --------------------------------------------
67
   // Controls the branch and delay flags
68
 
69 41 sybreon
   wire            fRTD = (rOPC == 6'o55);
70
   wire            fBCC = (rOPC == 6'o47) | (rOPC == 6'o57);
71
   wire            fBRU = (rOPC == 6'o46) | (rOPC == 6'o56);
72
 
73
   wire [31:0]      wREGA;
74
   assign          wREGA = (rMXALT == 2'o2) ? rDWBDI :
75
                           (rMXALT == 2'o1) ? rRESULT :
76
                           rREGA;
77
 
78
   wire            wBEQ = (wREGA == 32'd0);
79
   wire            wBNE = ~wBEQ;
80
   wire            wBLT = wREGA[31];
81
   wire            wBLE = wBLT | wBEQ;
82
   wire            wBGE = ~wBLT;
83
   wire            wBGT = ~wBLE;
84
 
85
   reg             xXCC;
86
   always @(/*AUTOSENSE*/rRD or wBEQ or wBGE or wBGT or wBLE or wBLT
87
            or wBNE)
88
     case (rRD[2:0])
89
       3'o0: xXCC <= wBEQ;
90
       3'o1: xXCC <= wBNE;
91
       3'o2: xXCC <= wBLT;
92
       3'o3: xXCC <= wBLE;
93
       3'o4: xXCC <= wBGT;
94
       3'o5: xXCC <= wBGE;
95
       default: xXCC <= 1'bX;
96
     endcase // case (rRD[2:0])
97
 
98
   reg             rBRA, xBRA;
99
   reg             rDLY, xDLY;
100
   wire            fSKIP = rBRA & !rDLY;
101
 
102
   always @(/*AUTOSENSE*/fBCC or fBRU or fRTD or rBRA or rRA or rRD
103 61 sybreon
            or xXCC)
104
     //if (rBRA | |rXCE) begin
105
     if (rBRA) begin
106 41 sybreon
        /*AUTORESET*/
107
        // Beginning of autoreset for uninitialized flops
108
        xBRA <= 1'h0;
109
        xDLY <= 1'h0;
110
        // End of automatics
111
     end else begin
112
        xDLY <= (fBRU & rRA[4]) | (fBCC & rRD[4]) | fRTD;
113
        xBRA <= (fRTD | fBRU) ? 1'b1 :
114
                (fBCC) ? xXCC :
115
                1'b0;
116
     end
117
 
118 44 sybreon
   // --- PC PIPELINE ------------------------------------------------
119
   // PC and related changes
120 41 sybreon
 
121
   reg [31:2]      rIPC, xIPC;
122
   reg [31:2]      rPC, xPC;
123 44 sybreon
   reg [31:2]      rPCLNK, xPCLNK;
124 41 sybreon
 
125
   assign          iwb_adr_o = rIPC[IW-1:2];
126
 
127 61 sybreon
   always @(/*AUTOSENSE*/rBRA or rIPC or rPC or rRESULT) begin
128
      //xPCLNK <= (^rATOM) ? rPC : rPC;
129
      xPCLNK <= rPC;
130 44 sybreon
      //xPC <= (^rATOM) ? rIPC : rRESULT[31:2]; 
131
      xPC <= rIPC;
132
      //xIPC <= (rBRA) ? rRESULT[31:2] : (rIPC + 1);
133 61 sybreon
      /*
134 44 sybreon
     case (rXCE)
135
       2'o1: xIPC <= 30'h2;
136
       2'o2: xIPC <= 30'h4;
137
       2'o3: xIPC <= 30'h6;
138
       default: xIPC <= (rBRA) ? rRESULT[31:2] : (rIPC + 1);
139
     endcase // case (rXCE)
140 61 sybreon
       */
141
      xIPC <= (rBRA) ? rRESULT[31:2] : (rIPC + 1);
142 44 sybreon
   end
143 41 sybreon
 
144 44 sybreon
   // --- ATOMIC CONTROL ---------------------------------------------
145
   // This is used to indicate 'safe' instruction borders.
146
 
147
   wire         wIMM = (rOPC == 6'o54) & !fSKIP;
148
   wire         wRTD = (rOPC == 6'o55) & !fSKIP;
149
   wire         wBCC = xXCC & ((rOPC == 6'o47) | (rOPC == 6'o57)) & !fSKIP;
150
   wire         wBRU = ((rOPC == 6'o46) | (rOPC == 6'o56)) & !fSKIP;
151
 
152
   wire         fATOM = ~(wIMM | wRTD | wBCC | wBRU | rBRA);
153
   reg [1:0]     rATOM, xATOM;
154
 
155
   always @(/*AUTOSENSE*/fATOM or rATOM)
156
     xATOM <= {rATOM[0], (rATOM[0] ^ fATOM)};
157
 
158
 
159
   // --- SYNC PIPELINE ----------------------------------------------
160
 
161 41 sybreon
   always @(posedge gclk)
162
     if (grst) begin
163
        /*AUTORESET*/
164
        // Beginning of autoreset for uninitialized flops
165 44 sybreon
        rATOM <= 2'h0;
166 41 sybreon
        rBRA <= 1'h0;
167
        rDLY <= 1'h0;
168
        rIPC <= 30'h0;
169
        rPC <= 30'h0;
170
        rPCLNK <= 30'h0;
171
        // End of automatics
172
     end else if (gena) begin
173
        rIPC <= #1 xIPC;
174
        rBRA <= #1 xBRA;
175
        rPC <= #1 xPC;
176
        rPCLNK <= #1 xPCLNK;
177 44 sybreon
        rDLY <= #1 xDLY;
178
        rATOM <= #1 xATOM;
179 41 sybreon
     end
180 44 sybreon
 
181 41 sybreon
endmodule // aeMB_bpcu

powered by: WebSVN 2.1.0

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