-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdatamemory.sv
More file actions
136 lines (120 loc) · 2.91 KB
/
datamemory.sv
File metadata and controls
136 lines (120 loc) · 2.91 KB
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
module datamemory
#(
BUS_DATA_WIDTH = 64,
BUS_TAG_WIDTH = 13
)
(
input clk,
// bus interface
input bus_respcyc,
input [BUS_DATA_WIDTH-1:0] bus_resp,
input [BUS_TAG_WIDTH-1:0] bus_resptag,
input bus_reqack,
output bus_reqcyc,
output [BUS_DATA_WIDTH-1:0] bus_req,
output [BUS_TAG_WIDTH-1:0] bus_reqtag,
output bus_respack,
output outStall,
output out_do_invalidate,
input inMiss,
input inMemWrite,
input [511:0] inDataWriteBack,
input [BUS_DATA_WIDTH-1 : 0] inAddress,
output [63:0] out_invalid_phys_addr,
output [9:0] out_write_offset,
output [9:0] out_offset,
output [511:0] out_data
);
`include "Sysbus.defs"
enum {
STATE_FETCH = 2'b00,
STATE_WAIT = 2'b01,
STATE_WAIT_ONE_CLK = 2'b10,
STATE_GET_READY_TO_WRITE = 2'b11
} state;
logic [BUS_DATA_WIDTH-1:0] result;
logic [BUS_DATA_WIDTH-1:0] addrJump, readData, dataReg2;
logic [4:0] destRegister;
logic memWrite;
logic memOrReg, regWrite;
// TODO : handle forwarding logic for stores
always_ff @ (posedge clk) begin
if(inMiss && state == STATE_FETCH) begin
if(!inMemWrite) begin
bus_req <= inAddress & ~63;
bus_reqtag[12] <= 1;
bus_reqtag[11:8] <= 4'b0001;
bus_reqcyc <= 1;
state <= STATE_WAIT;
end else begin
bus_req <= inAddress;
bus_reqtag[12] <= 0; // write
bus_reqtag[11:8] <= 4'b0001;
bus_reqcyc <= 1;
state <= STATE_GET_READY_TO_WRITE;
end
end else begin
bus_req <= 0;
bus_reqtag <= 0;
bus_reqcyc <= 0;
end
end
always_ff @ (posedge clk) begin
if(state == STATE_GET_READY_TO_WRITE) begin
if(write_offset < 64 * 8) begin
bus_req <= inDataWriteBack[write_offset +: 64];
write_offset <= write_offset + 64;
bus_reqcyc <= 1;
end else begin
bus_req <= 0;
bus_reqcyc <= 0;
state <= STATE_FETCH;
write_offset <= 0;
out_write_offset <= write_offset;
end
end
end
logic [9:0] write_offset = 0;
logic [511:0] buffer;
logic [9:0] offset = 0;
logic do_invalidate = 0;
logic [63:0] invalid_phys_addr;
always_ff @ (posedge clk) begin
if(bus_respcyc && offset <= 64 * 8) begin
if(bus_resptag == 13'b0100000000000) begin
do_invalidate <= 1;
invalid_phys_addr <= bus_resp;
bus_respack <= 1;
end else begin
buffer[offset +: 64] <= bus_resp ;
bus_respack <= 1;
offset <= offset + 64;
do_invalidate <= 0;
invalid_phys_addr <= 0;
end
end else begin
bus_respack <= 0;
offset <= 0;
out_offset <= offset;
out_data <= buffer;
if(offset >= 64 * 8 && state == STATE_WAIT) begin
state <= STATE_WAIT_ONE_CLK;
end
do_invalidate <= 0;
invalid_phys_addr <= 0;
end
end
// pause for 2 clock cycles
logic wait_time = 0;
always_ff @ (posedge clk) begin
if(state == STATE_WAIT_ONE_CLK) begin
wait_time <= 1;
if(wait_time) begin
wait_time <= 0;
state <= STATE_FETCH;
end
end
end
assign out_invalid_phys_addr = invalid_phys_addr;
assign out_do_invalidate = do_invalidate;
endmodule