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

Subversion Repositories steelcore

[/] [rtl/] [store_unit.v] - Blame information for rev 11

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 11 rafaelcalc
//////////////////////////////////////////////////////////////////////////////////
2
// Engineer: Rafael de Oliveira Calçada (rafaelcalcada@gmail.com)
3
// 
4
// Create Date: 02.06.2020 01:28:57
5
// Module Name: store_unit
6
// Project Name: Steel Core 
7
// Description: Controls the data memory interface
8
// 
9
// Dependencies: globals.vh
10
// 
11
// Version 0.01
12
// 
13
//////////////////////////////////////////////////////////////////////////////////
14
 
15
/*********************************************************************************
16
 
17
MIT License
18
 
19
Copyright (c) 2020 Rafael de Oliveira Calçada
20
 
21
Permission is hereby granted, free of charge, to any person obtaining a copy
22
of this software and associated documentation files (the "Software"), to deal
23
in the Software without restriction, including without limitation the rights
24
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
25
copies of the Software, and to permit persons to whom the Software is
26
furnished to do so, subject to the following conditions:
27
 
28
The above copyright notice and this permission notice shall be included in all
29
copies or substantial portions of the Software.
30
 
31
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
32
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
33
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
34
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
35
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
36
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
37
SOFTWARE.
38
 
39
********************************************************************************/
40
 
41
`timescale 1ns / 1ps
42
`include "globals.vh"
43
 
44
module store_unit(
45
 
46
    input wire [1:0] FUNCT3,
47
    input wire [31:0] IADDER_OUT,
48
    input wire [31:0] RS2,
49
    input wire MEM_WR_REQ,
50
    output reg [31:0] DATA_OUT,
51
    output wire [31:0] D_ADDR,
52
    output reg [3:0] WR_MASK,
53
    output wire WR_REQ
54
 
55
    );
56
 
57
    reg [3:0] half_wr_mask;
58
    reg [3:0] byte_wr_mask;
59
    reg [31:0] half_dout;
60
    reg [31:0] byte_dout;
61
 
62
    assign D_ADDR = {IADDER_OUT[31:2], 2'b0};
63
    assign WR_REQ = MEM_WR_REQ;
64
 
65
    always @*
66
    begin
67
 
68
        case(FUNCT3[1:0])
69
 
70
            2'b00: WR_MASK = byte_wr_mask;
71
            2'b01: WR_MASK = half_wr_mask;
72
            2'b10: WR_MASK = {4{MEM_WR_REQ}};
73
            2'b11: WR_MASK = {4{MEM_WR_REQ}};
74
 
75
        endcase
76
 
77
    end
78
 
79
    always @*
80
    begin
81
 
82
        case(FUNCT3[1:0])
83
 
84
            2'b00: DATA_OUT = byte_dout;
85
            2'b01: DATA_OUT = half_dout;
86
            2'b10: DATA_OUT = RS2;
87
            2'b11: DATA_OUT = RS2;
88
 
89
        endcase
90
 
91
    end
92
 
93
    always @*
94
    begin
95
 
96
        case(IADDER_OUT[1:0])
97
 
98
            2'b00: byte_dout = {24'b0, RS2[7:0]};
99
            2'b01: byte_dout = {16'b0, RS2[7:0], 8'b0};
100
            2'b10: byte_dout = {8'b0, RS2[7:0], 16'b0};
101
            2'b11: byte_dout = {RS2[7:0], 24'b0};
102
 
103
        endcase
104
 
105
    end
106
 
107
    always @*
108
    begin
109
 
110
        case(IADDER_OUT[1:0])
111
 
112
            2'b00: byte_wr_mask = {3'b0, MEM_WR_REQ};
113
            2'b01: byte_wr_mask = {2'b0, MEM_WR_REQ, 1'b0};
114
            2'b10: byte_wr_mask = {1'b0, MEM_WR_REQ, 2'b0};
115
            2'b11: byte_wr_mask = {MEM_WR_REQ, 3'b0};
116
 
117
        endcase
118
 
119
    end
120
 
121
    always @*
122
    begin
123
 
124
        case(IADDER_OUT[1])
125
 
126
            1'b0: half_dout = {16'b0, RS2[15:0]};
127
            1'b1: half_dout = {RS2[15:0], 16'b0};
128
 
129
        endcase
130
 
131
    end
132
 
133
    always @*
134
    begin
135
 
136
        case(IADDER_OUT[1])
137
 
138
            1'b0: half_wr_mask = {2'b0, {2{MEM_WR_REQ}}};
139
            1'b1: half_wr_mask = {{2{MEM_WR_REQ}}, 2'b0};
140
 
141
        endcase
142
 
143
    end
144
 
145
endmodule

powered by: WebSVN 2.1.0

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