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

Subversion Repositories aemb

[/] [aemb/] [branches/] [AEMB2_712/] [rtl/] [verilog/] [aeMB_bpcu.v] - Blame information for rev 55

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

Line No. Rev Author Line
1 55 sybreon
// $Id: aeMB_bpcu.v,v 1.3 2007-11-10 16:39:38 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 55 sybreon
// Revision 1.2  2007/11/02 19:20:58  sybreon
24
// Added better (beta) interrupt support.
25
// Changed MSR_IE to disabled at reset as per MB docs.
26
//
27 44 sybreon
// Revision 1.1  2007/11/02 03:25:39  sybreon
28
// New EDK 3.2 compatible design with optional barrel-shifter and multiplier.
29
// Fixed various minor data hazard bugs.
30
// Code compatible with -O0/1/2/3/s generated code.
31
//
32 41 sybreon
 
33
module aeMB_bpcu (/*AUTOARG*/
34
   // Outputs
35 44 sybreon
   iwb_adr_o, rPC, rPCLNK, rBRA, rDLY, rATOM,
36 41 sybreon
   // Inputs
37
   rMXALT, rOPC, rRD, rRA, rRESULT, rDWBDI, rREGA, rXCE, gclk, grst,
38
   gena
39
   );
40
   parameter IW = 24;
41
 
42
   // INST WISHBONE
43
   output [IW-1:2] iwb_adr_o;
44
 
45
   // INTERNAL
46
   output [31:2]   rPC, rPCLNK;
47
   output          rBRA;
48
   output          rDLY;
49 44 sybreon
   output [1:0]    rATOM;
50 41 sybreon
   input [1:0]      rMXALT;
51
   input [5:0]      rOPC;
52
   input [4:0]      rRD, rRA;
53
   input [31:0]    rRESULT; // ALU
54
   input [31:0]    rDWBDI; // RAM
55 44 sybreon
   input [31:0]    rREGA;
56 41 sybreon
   input [1:0]      rXCE;
57
 
58
   // SYSTEM
59
   input           gclk, grst, gena;
60
 
61 44 sybreon
   // --- BRANCH CONTROL --------------------------------------------
62
   // Controls the branch and delay flags
63
 
64 41 sybreon
   wire            fRTD = (rOPC == 6'o55);
65
   wire            fBCC = (rOPC == 6'o47) | (rOPC == 6'o57);
66
   wire            fBRU = (rOPC == 6'o46) | (rOPC == 6'o56);
67
 
68
   wire [31:0]      wREGA;
69
   assign          wREGA = (rMXALT == 2'o2) ? rDWBDI :
70
                           (rMXALT == 2'o1) ? rRESULT :
71
                           rREGA;
72
 
73
   wire            wBEQ = (wREGA == 32'd0);
74
   wire            wBNE = ~wBEQ;
75
   wire            wBLT = wREGA[31];
76
   wire            wBLE = wBLT | wBEQ;
77
   wire            wBGE = ~wBLT;
78
   wire            wBGT = ~wBLE;
79
 
80
   reg             xXCC;
81
   always @(/*AUTOSENSE*/rRD or wBEQ or wBGE or wBGT or wBLE or wBLT
82
            or wBNE)
83
     case (rRD[2:0])
84
       3'o0: xXCC <= wBEQ;
85
       3'o1: xXCC <= wBNE;
86
       3'o2: xXCC <= wBLT;
87
       3'o3: xXCC <= wBLE;
88
       3'o4: xXCC <= wBGT;
89
       3'o5: xXCC <= wBGE;
90
       default: xXCC <= 1'bX;
91
     endcase // case (rRD[2:0])
92
 
93
   reg             rBRA, xBRA;
94
   reg             rDLY, xDLY;
95
   wire            fSKIP = rBRA & !rDLY;
96
 
97
   always @(/*AUTOSENSE*/fBCC or fBRU or fRTD or rBRA or rRA or rRD
98 44 sybreon
            or rXCE or xXCC)
99
     if (rBRA | |rXCE) begin
100 41 sybreon
        /*AUTORESET*/
101
        // Beginning of autoreset for uninitialized flops
102
        xBRA <= 1'h0;
103
        xDLY <= 1'h0;
104
        // End of automatics
105
     end else begin
106
        xDLY <= (fBRU & rRA[4]) | (fBCC & rRD[4]) | fRTD;
107
        xBRA <= (fRTD | fBRU) ? 1'b1 :
108
                (fBCC) ? xXCC :
109
                1'b0;
110
     end
111
 
112 44 sybreon
   // --- PC PIPELINE ------------------------------------------------
113
   // PC and related changes
114 41 sybreon
 
115
   reg [31:2]      rIPC, xIPC;
116
   reg [31:2]      rPC, xPC;
117 44 sybreon
   reg [31:2]      rPCLNK, xPCLNK;
118 41 sybreon
 
119
   assign          iwb_adr_o = rIPC[IW-1:2];
120
 
121 44 sybreon
   always @(/*AUTOSENSE*/rATOM or rBRA or rIPC or rPC or rRESULT
122
            or rXCE) begin
123
      xPCLNK <= (^rATOM) ? rPC : rPC;
124
      //xPCLNK <= rPC;
125
      //xPC <= (^rATOM) ? rIPC : rRESULT[31:2]; 
126
      xPC <= rIPC;
127
      //xIPC <= (rBRA) ? rRESULT[31:2] : (rIPC + 1);
128
     case (rXCE)
129
       2'o1: xIPC <= 30'h2;
130
       2'o2: xIPC <= 30'h4;
131
       2'o3: xIPC <= 30'h6;
132
       default: xIPC <= (rBRA) ? rRESULT[31:2] : (rIPC + 1);
133
     endcase // case (rXCE)      
134
   end
135 41 sybreon
 
136 44 sybreon
   // --- ATOMIC CONTROL ---------------------------------------------
137
   // This is used to indicate 'safe' instruction borders.
138
 
139
   wire         wIMM = (rOPC == 6'o54) & !fSKIP;
140
   wire         wRTD = (rOPC == 6'o55) & !fSKIP;
141
   wire         wBCC = xXCC & ((rOPC == 6'o47) | (rOPC == 6'o57)) & !fSKIP;
142
   wire         wBRU = ((rOPC == 6'o46) | (rOPC == 6'o56)) & !fSKIP;
143
 
144
   wire         fATOM = ~(wIMM | wRTD | wBCC | wBRU | rBRA);
145
   reg [1:0]     rATOM, xATOM;
146
 
147
   always @(/*AUTOSENSE*/fATOM or rATOM)
148
     xATOM <= {rATOM[0], (rATOM[0] ^ fATOM)};
149
 
150
 
151
   // --- SYNC PIPELINE ----------------------------------------------
152
 
153 41 sybreon
   always @(posedge gclk)
154
     if (grst) begin
155
        /*AUTORESET*/
156
        // Beginning of autoreset for uninitialized flops
157 44 sybreon
        rATOM <= 2'h0;
158 41 sybreon
        rBRA <= 1'h0;
159
        rDLY <= 1'h0;
160
        rIPC <= 30'h0;
161
        rPC <= 30'h0;
162
        rPCLNK <= 30'h0;
163
        // End of automatics
164
     end else if (gena) begin
165
        rIPC <= #1 xIPC;
166
        rBRA <= #1 xBRA;
167
        rPC <= #1 xPC;
168
        rPCLNK <= #1 xPCLNK;
169 44 sybreon
        rDLY <= #1 xDLY;
170
        rATOM <= #1 xATOM;
171 41 sybreon
     end
172 44 sybreon
 
173 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.