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

Subversion Repositories aemb

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

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

Line No. Rev Author Line
1 147 sybreon
/* $Id: aeMB2_dwbif.v,v 1.7 2008-04-27 16:41:55 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
 * Data Wishbone Interface
23
 * @file aeMB2_dwbif.v
24
 
25
 * This sets up the Wishbone control signals for the DATA bus
26
   interfaces. Bus transactions are independent of the pipeline.
27
 
28
 */
29
 
30
module aeMB2_dwbif (/*AUTOARG*/
31
   // Outputs
32
   dwb_adr_o, dwb_sel_o, dwb_stb_o, dwb_cyc_o, dwb_tag_o, dwb_wre_o,
33 202 sybreon
   dwb_dat_o, dwb_fb, sel_mx, dwb_mx, exc_dwb,
34 118 sybreon
   // Inputs
35 203 sybreon
   dwb_dat_i, dwb_ack_i, imm_of, opd_of, opc_of, opa_of,
36 202 sybreon
   opb_of, msr_ex, mem_ex, sfr_mx, gclk, grst, dena, gpha
37 118 sybreon
   );
38
   parameter AEMB_DWB = 32; ///< data bus address width   
39
 
40
   // DWB control signals
41
   output [AEMB_DWB-1:2] dwb_adr_o;
42
   output [3:0]   dwb_sel_o;
43
   output                dwb_stb_o,
44
                         dwb_cyc_o,
45
                         dwb_tag_o, // cache enable
46
                         dwb_wre_o;
47
   output [31:0]          dwb_dat_o;
48
   input [31:0]   dwb_dat_i;
49
   input                 dwb_ack_i;
50 203 sybreon
   //input               dwb_err_i; // for bus error exception
51 118 sybreon
 
52
   // INTERNAL
53
   output                dwb_fb;
54
   output [3:0]   sel_mx;
55
   output [31:0]          dwb_mx;
56
   input [15:0]   imm_of;
57
   input [31:0]   opd_of;
58
   input [5:0]            opc_of;
59
   input [1:0]            opa_of;
60
   input [1:0]            opb_of;
61
   input [7:0]            msr_ex;
62
   input [AEMB_DWB-1:2]  mem_ex;
63 131 sybreon
   input [7:5]           sfr_mx;
64 202 sybreon
 
65
   // EXC signals
66
   output [1:0]   exc_dwb; // 1: unaligned; 0: bus error
67
 
68 118 sybreon
   // SYS signals
69
   input                 gclk,
70
                         grst,
71
                         dena,
72
                         gpha;
73
 
74
   /*AUTOREG*/
75 202 sybreon
   reg [3:0]              dwb_sel_o;
76
   reg                   dwb_stb_o, dwb_cyc_o, dwb_wre_o;
77
   reg [31:0]             dwb_dat_o;
78
   reg [3:0]              sel_mx;
79
   reg [31:0]             dwb_mx;
80
   reg                   dwb_exc;
81
 
82 131 sybreon
   wire [1:0]            wOFF = (opa_of[1:0] + opb_of[1:0]); // small adder   
83 202 sybreon
   wire [3:0]            wSEL = {opc_of[1:0], wOFF}; // byte selector info
84 118 sybreon
 
85 202 sybreon
   assign               dwb_fb = (dwb_stb_o ~^ dwb_ack_i); // feedback
86
   assign               dwb_adr_o = mem_ex; // data-bus passthru
87 203 sybreon
 
88
   // TODO: enable dwb_err_i exception pass-thru
89
   assign               exc_dwb = {dwb_exc, 1'b0};
90 202 sybreon
 
91 125 sybreon
   // STORE SIZER
92
   // TODO: Move the right words to the right place
93
   // TODO: Make this work with dwb_mx to for partial word loads.
94
 
95 131 sybreon
   reg [31:0]            dwb_lat;
96
   reg [31:0]            opd_ex;
97
 
98 118 sybreon
   always @(posedge gclk)
99
     if (grst) begin
100
        /*AUTORESET*/
101
        // Beginning of autoreset for uninitialized flops
102
        dwb_dat_o <= 32'h0;
103
        // End of automatics
104 125 sybreon
     end else if (dena) begin
105 131 sybreon
        //opd_ex <= #1 opd_of;  
106 118 sybreon
        case (opc_of[1:0])
107
          2'o0: dwb_dat_o <= #1 {(4){opd_of[7:0]}};
108
          2'o1: dwb_dat_o <= #1 {(2){opd_of[15:0]}};
109
          2'o2: dwb_dat_o <= #1 opd_of;
110
          default: dwb_dat_o <= #1 32'hX;
111
        endcase // case (opc_of[1:0])
112 131 sybreon
     end
113 118 sybreon
 
114
   // WISHBONE PIPELINE
115
   always @(posedge gclk)
116
     if (grst) begin
117
        /*AUTORESET*/
118
        // Beginning of autoreset for uninitialized flops
119 202 sybreon
        dwb_exc <= 1'h0;
120 131 sybreon
        dwb_mx <= 32'h0;
121 118 sybreon
        dwb_sel_o <= 4'h0;
122
        dwb_wre_o <= 1'h0;
123
        sel_mx <= 4'h0;
124
        // End of automatics
125
     end else if (dena) begin
126 125 sybreon
        sel_mx <= #1 dwb_sel_o; // FIXME: do away with this! Combine
127
                                // dwb_dat_o & dwb_mx. dwb_dat_o can
128
                                // hold the existing RD value and have
129
                                // dwb_mx latch the correct bytes
130
                                // depending on dwb_sel_o.
131
 
132 118 sybreon
        dwb_wre_o <= #1 opc_of[2]; // SXX
133 127 sybreon
 
134 147 sybreon
        dwb_mx <= #1
135
                  (dwb_ack_i) ?
136
                  dwb_dat_i : // stalled from RAM
137
                  dwb_lat; // latch earlier data
138 118 sybreon
 
139 134 sybreon
        case (wSEL) // Latch output
140 118 sybreon
          // 32'bit
141
          4'h8: dwb_sel_o <= #1 4'hF;
142
          // 16'bit
143
          4'h4: dwb_sel_o <= #1 4'hC;
144
          4'h6: dwb_sel_o <= #1 4'h3;
145
          // 8'bit
146
          4'h0: dwb_sel_o <= #1 4'h8;
147
          4'h1: dwb_sel_o <= #1 4'h4;
148
          4'h2: dwb_sel_o <= #1 4'h2;
149
          4'h3: dwb_sel_o <= #1 4'h1;
150 134 sybreon
          // XSL bus
151
          4'hC, 4'hD, 4'hE, 4'hF:
152
            dwb_sel_o <= #1 4'h0;
153 118 sybreon
          // TODO: ILLEGAL
154 131 sybreon
          default: dwb_sel_o <= #1 4'hX;
155 118 sybreon
        endcase // case (wSEL)
156 202 sybreon
 
157
        // exception checking
158 203 sybreon
        dwb_exc <= #1 &opc_of[5:4] & // only for LD/ST commands
159
                   ((opc_of[0] & wOFF[0]) | // misaligned 16-bit
160
                    (opc_of[1] & |wOFF[1:0]) // misaligned 32-bit
161
                    );
162
        /*
163 202 sybreon
        case (opc_of[1:0])
164 203 sybreon
          2'o2: dwb_exc <= #1 |wOFF[1:0] & &opc_of[5:4];
165
          2'o1: dwb_exc <= #1 wOFF[0] & &opc_of[5:4];
166 202 sybreon
          default: dwb_exc <= #1 1'b0;
167
        endcase // case (opc_of[1:0])
168 203 sybreon
        */
169 202 sybreon
 
170 203 sybreon
 
171 118 sybreon
     end // if (dena)
172
 
173 202 sybreon
   // Independent of pipeline
174 131 sybreon
 
175 118 sybreon
   always @(posedge gclk)
176
     if (grst) begin
177
        /*AUTORESET*/
178
        // Beginning of autoreset for uninitialized flops
179 127 sybreon
        dwb_lat <= 32'h0;
180
        // End of automatics
181 202 sybreon
     end else if (dwb_ack_i) begin // if (grst)
182 127 sybreon
        // LATCH READS
183
        dwb_lat <= #1 dwb_dat_i;
184
     end
185
 
186
   always @(posedge gclk)
187
     if (grst) begin
188
        /*AUTORESET*/
189
        // Beginning of autoreset for uninitialized flops
190 118 sybreon
        dwb_cyc_o <= 1'h0;
191
        dwb_stb_o <= 1'h0;
192
        // End of automatics
193 131 sybreon
     //end else if (dwb_fb) begin
194 202 sybreon
     end else if (dwb_fb) begin // if (grst)
195 118 sybreon
        dwb_stb_o <= #1
196
                     (dena) ? &opc_of[5:4] : // LXX/SSS
197
                     (dwb_stb_o & !dwb_ack_i); // LXX/SSS
198
        dwb_cyc_o <= #1
199
                     (dena) ? &opc_of[5:4] | msr_ex[0] :
200
                     (dwb_stb_o & !dwb_ack_i) | msr_ex[0];
201
     end
202 125 sybreon
 
203
   assign dwb_tag_o = msr_ex[7]; // MSR_DCE     
204 118 sybreon
 
205 202 sybreon
endmodule // unmatched end(function|task|module|primitive|interface|package|class|clocking)

powered by: WebSVN 2.1.0

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