-
Notifications
You must be signed in to change notification settings - Fork 1
/
mem_ctrl.v
80 lines (70 loc) · 1.21 KB
/
mem_ctrl.v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
`include "global_config.h"
`include "nettype.h"
`include "stddef.h"
`include "cpu.h"
`include "isa.h"
module mem_ctrl(
ex_en,ex_mem_op,ex_mem_wr_data,ex_out,
rd_data,addr,as_,rw,wr_data,
out,miss_align
);
input ex_en;
input[1:0] ex_mem_op;
input[31:0] ex_mem_wr_data;
input[31:0] ex_out;
input[31:0] rd_data;
output[29:0] addr;
output as_;
output rw;
output[31:0] wr_data;
output[31:0] out;
output miss_align;
reg as_;
reg rw;
reg[31:0] out;
reg miss_align;
wire[1:0] offset;
assign wr_data = ex_mem_wr_data;
assign addr = ex_out[`WordAddrLoc];
assign offset = ex_out[`ByteOffsetLoc];
always@(*)
begin
miss_align = `DISABLE;
out = `WORD_DATA_W'h0;
as_ = `DISABLE_;
rw = `READ;
if(ex_en == `ENABLE)
begin
case(ex_mem_op)
`MEM_OP_LDW:
begin
if(offset == `BYTE_OFFSET_WORD)
begin
out = rd_data;
as_ = `ENABLE_;
end
else
begin
miss_align = `ENABLE;
end
end
`MEM_OP_STW:
begin
if(offset == `BYTE_OFFSET_WORD)
begin
rw = `WRITE;
as_ = `ENABLE_;
end
else
begin
miss_align = `ENABLE;
end
end
default:
begin
out = ex_out;
end
endcase
end
end
endmodule