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

Subversion Repositories mips789

[/] [mips789/] [tags/] [v001/] [verilog/] [mips_core/] [mem_ctl.v] - Blame information for rev 62

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

Line No. Rev Author Line
1 2 mcupro
/////////////////////////////////////////////////////////////////////
2
////  Author: Liwei                                              ////
3
////                                                             ////
4
////                                                             ////
5
////  If you encountered any problem, please contact :           ////
6
////  Email: mcupro@yahoo.com.hk or mcupro@opencores.org         ////
7
////                                                             ////
8
////  Downloaded from:                                           ////
9
////     http://www.opencores.org/pdownloads.cgi/list/mips789    ////
10
/////////////////////////////////////////////////////////////////////
11
////                                                             ////
12
//// Copyright (C) 2006-2007 Liwei                               ////
13
////                         mcupro@yahoo.com.hk                 ////
14
////                                                             ////
15
////                                                             ////
16
//// This source file may be used and distributed freely without ////
17
//// restriction provided that this copyright statement is not   ////
18
//// removed from the file and any derivative work contains the  ////
19
//// original copyright notice and the associated disclaimer.    ////
20
////                                                             ////
21
//// Please let the author know if it is used                    ////
22
//// for commercial purpose.                                     ////
23
////                                                             ////
24
////     THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY     ////
25
//// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED   ////
26
//// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS   ////
27
//// FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL THE AUTHOR      ////
28
//// OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,         ////
29
//// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES    ////
30
//// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE   ////
31
//// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR        ////
32
//// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF  ////
33
//// LIABILITY, WHETHER IN  CONTRACT, STRICT LIABILITY, OR TORT  ////
34
//// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT  ////
35
//// OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE         ////
36
//// POSSIBILITY OF SUCH DAMAGE.                                 ////
37
////                                                             ////
38
/////////////////////////////////////////////////////////////////////
39
////                                                             ////
40
////                                                             ////
41
//// Date of Creation: 2007.8.1                                  ////
42
////                                                             ////
43
//// Version: 0.0.1                                              ////
44
////                                                             ////
45
//// Description:                                                ////
46
////                                                             ////
47
////                                                             ////
48
/////////////////////////////////////////////////////////////////////
49
////                                                             ////
50
//// Change log:                                                 ////
51
////                                                             ////
52
/////////////////////////////////////////////////////////////////////
53
 
54
`define DMEM_SB    1
55
`define DMEM_LBS   2
56
`define DMEM_LB    3
57
`define DMEM_LBU   4
58
`define DMEM_SW    5
59
`define DMEM_LW    6
60
`define DMEM_SH    7
61
`define DMEM_LHS   8
62
`define DMEM_LH    9
63
`define DMEM_LHU   10
64
`define DMEM_NOP   0
65
 
66
 
67
module infile_dmem_ctl_reg(
68
        input clk,
69
        input [3:0]ctl_i,
70
        input [31:0]dmem_addr_i,
71
        output reg [1:0]byte_addr_o,
72
        output reg [3:0]ctl_o
73
    );
74
 
75
    wire   [1:0]byte_addr_i;
76
    assign byte_addr_i = dmem_addr_i[1:0] ;
77
    always @(posedge clk)
78
    begin
79
        ctl_o<=(dmem_addr_i[31]==0)?ctl_i:0;
80
        byte_addr_o<=byte_addr_i;
81
    end
82
 
83
endmodule
84
 
85
module mem_addr_ctl(
86
        input [3:0]ctl,
87
        input [31:0]addr_i,
88
        output reg[3:0]wr_en
89
    );
90
    always@(*)
91
    case (ctl)
92
        `DMEM_SB:
93
        begin
94
            case(addr_i[1:0])
95
                0:wr_en = 4'b1000;
96
                1:wr_en = 4'b0100;
97
                2:wr_en = 4'b0010;
98
                3:wr_en = 4'b0001;
99
            endcase
100
        end
101
        `DMEM_SH  :
102
        begin
103
            case(addr_i[1:0])
104
                'd0:wr_en=4'b1100;
105
                'd2:wr_en=4'b0011;
106
            endcase
107
        end
108
        `DMEM_SW :
109
        begin
110
            wr_en=4'b1111;
111
        end
112
        default wr_en=4'b0000;
113
    endcase
114
 
115
endmodule
116
 
117
 
118
 
119
module mem_dout_ctl(
120
        input [1:0]byte_addr,
121
        input [3:0]ctl,
122
        input [31:0] din,
123
        output reg [31:0] dout
124
    );
125
 
126
    always @(*)
127
    case (ctl)
128
 
129
        `DMEM_LBS :
130
        case (byte_addr)
131
            'd0:dout={{24{din[31]}},din[31:24]};
132
            'd1:dout={{24{din[23]}},din[23:16]};
133
            'd2:dout={{24{din[15]}},din[15:8]};
134
            'd3:dout={{24{din[7]}},din[7:0] };
135
            default :
136
                dout=32'b0;
137
        endcase//checked
138
        `DMEM_LBU :
139
        case (byte_addr)
140
            'd3:dout={24'b0,din[7:0]};
141
            'd2:dout={24'b0,din[15:8]};
142
            'd1:dout={24'b0,din[23:16]};
143
            'd0:dout={24'b0,din[31:24]};
144
            default :
145
                dout=32'b0;
146
        endcase
147
        `DMEM_LHU :
148
        case (byte_addr)
149
            'd0:dout={16'b0,din[23:16],din[31:24]};
150
            'd2:dout={16'b0,din[7:0],din[15:8]};
151
        endcase
152
        `DMEM_LHS :
153
        case (byte_addr)
154
            'd0 :dout={{16{din[23]}},din[23:16],din[31:24]};
155
            'd2 :dout={{16{din[7 ]}},din[7 :0],din[15:8]};
156
            default:dout=0;
157
        endcase
158
        `DMEM_LW  :
159
            dout=din;
160
        default :
161
            dout=32'b0;
162
    endcase
163
endmodule
164
 
165
module mem_din_ctl(
166
        input [3:0]ctl,
167
        input [31:0]din,
168
        output reg [31:0]dout
169
    );
170
 
171
    always @(*)
172
 
173
    case (ctl)
174
        `DMEM_SB   :
175
            dout={din[7:0],din[7:0],din[7:0],din[7:0]};
176
        `DMEM_SH   :
177
            dout = {din[15:0],din[15:0]};
178
        `DMEM_SW   :
179
            dout =din;
180
        default dout=din;
181
    endcase
182
 
183
endmodule
184
 
185
/*
186
 
187
ex. 1,
188
unsigned short a[4]={0,1,2,3};
189
00000001
190
00020003
191
 
192
ex. 2
193
unsigned char a[4]={0,1,2,3};
194
00010203
195
 
196
 
197
ex.  3
198
unsigned int b[3]={0x12345678,0,0x12345678};
199
12345678
200
00000000
201
12345678
202
 
203
*/

powered by: WebSVN 2.1.0

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