PipelineRegisters.v
6.3 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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
module PCregister(clk, stall, flush, in_pc, out_nextpc);
input clk, stall, flush;
input[31:0] in_pc;
output reg[31:0] out_nextpc;
reg[31:0] PC;
reg tempstall;
initial begin
PC = 32'h00000000;
tempstall = 1'b1;
end
always @(posedge clk) begin
if(tempstall == 1'b1) tempstall = 1'b0;
else if(stall == 1'b0 && flush == 1'b0) PC = PC+4;
out_nextpc = PC;
end
always @(negedge flush) begin
if(tempstall == 1'b0) PC = in_pc;
tempstall = 1'b1;
end
endmodule
module IF_ID(clk, stall, flush, in_instruction, in_PC_4,
out_instruction, out_PC_4);
input clk, stall, flush;
input[31:0] in_instruction, in_PC_4;
output reg[31:0] out_instruction, out_PC_4;
reg[31:0] temp_instruction, temp_PC_4;
always @(posedge clk) begin
if(stall == 1'b1) begin
out_instruction <= temp_instruction;
out_PC_4 <= temp_PC_4;
end else if(flush == 1'b1) begin
out_instruction <= 32'h00000000;
out_PC_4 <= 32'h00000000;
end else begin
out_instruction <= in_instruction;
out_PC_4 <= in_PC_4;
end
end
always @(posedge stall) begin
temp_instruction <= out_instruction;
temp_PC_4 <= out_PC_4;
end
endmodule
module ID_EX(clk, flush,
in_writereg_num, in_readreg_num1, in_readreg_num2, in_regwrite, in_alusrc, in_aluctrl, in_memread, in_memwrite, in_memtoreg, in_branch, in_jump, in_jumpreg, in_link,
in_readdata1, in_readdata2, in_extenddata, in_PC_4, in_tempPCjump,
out_writereg_num, out_readreg_num1, out_readreg_num2, out_regwrite, out_alusrc, out_aluctrl, out_memread, out_memwrite, out_memtoreg, out_branch, out_jump, out_jumpreg, out_link,
out_readdata1, out_readdata2, out_extenddata, out_PC_4, out_tempPCjump);
input clk, flush;
input[4:0] in_writereg_num, in_readreg_num1, in_readreg_num2;
input in_regwrite, in_alusrc, in_memread, in_memwrite, in_memtoreg, in_jump, in_jumpreg, in_link;
input[3:0] in_aluctrl;
input[2:0] in_branch;
input[31:0] in_readdata1, in_readdata2, in_extenddata, in_PC_4, in_tempPCjump;
output reg[4:0] out_writereg_num, out_readreg_num1, out_readreg_num2;
output reg out_regwrite, out_alusrc, out_memread, out_memwrite, out_memtoreg, out_jump, out_jumpreg, out_link;
output reg[3:0] out_aluctrl;
output reg[2:0] out_branch;
output reg[31:0] out_readdata1, out_readdata2, out_extenddata, out_PC_4, out_tempPCjump;
always @(posedge clk) begin
if(flush == 1'b1) begin
out_writereg_num <= 5'b00000;
out_readreg_num1 <= 5'b00000;
out_readreg_num2 <= 5'b00000;
out_regwrite <= 1'b0;
out_alusrc <= 1'b0;
out_aluctrl <= 4'b0000;
out_memread <= 1'b0;
out_memwrite <= 1'b0;
out_memtoreg <= 1'b0;
out_branch <= 3'b000;
out_jump <= 1'b0;
out_jumpreg <= 1'b0;
out_link <= 1'b0;
out_readdata1 <= 32'h00000000;
out_readdata2 <= 32'h00000000;
out_extenddata <= 32'h00000000;
out_PC_4 <= 32'h00000000;
out_tempPCjump <= 32'h00000000;
end else begin
out_writereg_num <= in_writereg_num;
out_readreg_num1 <= in_readreg_num1;
out_readreg_num2 <= in_readreg_num2;
out_regwrite <= in_regwrite;
out_alusrc <= in_alusrc;
out_aluctrl <= in_aluctrl;
out_memread <= in_memread;
out_memwrite <= in_memwrite;
out_memtoreg <= in_memtoreg;
out_branch <= in_branch;
out_jump <= in_jump;
out_jumpreg <= in_jumpreg;
out_link <= in_link;
out_readdata1 <= in_readdata1;
out_readdata2 <= in_readdata2;
out_extenddata <= in_extenddata;
out_PC_4 <= in_PC_4;
out_tempPCjump <= in_tempPCjump;
end
end
endmodule
module EX_MEM(clk, flush, in_writereg_num, in_regwrite, in_memread, in_memwrite, in_memtoreg, in_branch, in_jump, in_link,
in_aluresult, in_mem_writedata, in_PC_4, in_PCjump, in_tempPCbranch,
out_writereg_num, out_regwrite, out_memread, out_memwrite, out_memtoreg, out_branch, out_jump, out_link,
out_aluresult, out_mem_writedata, out_PC_4, out_PCjump, out_tempPCbranch);
input clk, flush;
input[4:0] in_writereg_num;
input in_regwrite, in_memread, in_memwrite, in_memtoreg, in_branch, in_jump, in_link;
input[31:0] in_aluresult, in_mem_writedata, in_PC_4, in_PCjump, in_tempPCbranch;
output reg[4:0] out_writereg_num;
output reg out_regwrite, out_memread, out_memwrite, out_memtoreg, out_branch, out_jump, out_link;
output reg[31:0] out_aluresult, out_mem_writedata, out_PC_4, out_PCjump, out_tempPCbranch;
always @(posedge clk) begin
if(flush == 1'b1) begin
out_writereg_num <= 5'b00000;
out_regwrite <= 1'b0;
out_memread <= 1'b0;
out_memwrite <= 1'b0;
out_memtoreg <= 1'b0;
out_branch <= 1'b0;
out_jump <= 1'b0;
out_link <= 1'b0;
out_aluresult <= 32'h00000000;
out_mem_writedata <= 32'h00000000;
out_PC_4 <= 32'h00000000;
out_PCjump <= 32'h00000000;
out_tempPCbranch <= 32'h00000000;
end else begin
out_writereg_num <= in_writereg_num;
out_regwrite <= in_regwrite;
out_memread <= in_memread;
out_memwrite <= in_memwrite;
out_memtoreg <= in_memtoreg;
out_branch <= in_branch;
out_jump <= in_jump;
out_link <= in_link;
out_aluresult <= in_aluresult;
out_mem_writedata <= in_mem_writedata;
out_PC_4 <= in_PC_4;
out_PCjump <= in_PCjump;
out_tempPCbranch <= in_tempPCbranch;
end
end
endmodule
module MEM_WB(clk, flush, in_writereg_num, in_regwrite, in_memtoreg, in_branch, in_jump, in_link, in_aluresult, in_memreaddata, in_PC_4, in_PCjump, in_PCbranch,
out_writereg_num, out_regwrite, out_memtoreg, out_branch, out_jump, out_link, out_aluresult, out_memreaddata, out_PC_4, out_PCjump, out_PCbranch);
input clk, flush;
input[4:0] in_writereg_num;
input in_regwrite, in_memtoreg, in_branch, in_jump, in_link;
input[31:0] in_aluresult, in_memreaddata, in_PC_4, in_PCjump, in_PCbranch;
output reg[4:0] out_writereg_num;
output reg out_regwrite, out_memtoreg, out_branch, out_jump, out_link;
output reg[31:0] out_aluresult, out_memreaddata, out_PC_4, out_PCjump, out_PCbranch;
always @(posedge clk) begin
if(flush == 1'b1) begin
out_writereg_num <= 5'b00000;
out_regwrite <= 1'b0;
out_memtoreg <= 1'b0;
out_branch <= 1'b0;
out_jump <= 1'b0;
out_link <= 1'b0;
out_aluresult <= 32'h00000000;
out_memreaddata <= 32'h00000000;
out_PC_4 <= 32'h00000000;
out_PCjump <= 32'h00000000;
out_PCbranch <= 32'h00000000;
end else begin
out_writereg_num <= in_writereg_num;
out_regwrite <= in_regwrite;
out_memtoreg <= in_memtoreg;
out_branch <= in_branch;
out_jump <= in_jump;
out_link <= in_link;
out_aluresult <= in_aluresult;
out_memreaddata <= in_memreaddata;
out_PC_4 <= in_PC_4;
out_PCjump <= in_PCjump;
out_PCbranch <= in_PCbranch;
end
end
endmodule