-
Notifications
You must be signed in to change notification settings - Fork 2
/
test_stages.v
223 lines (161 loc) · 4.82 KB
/
test_stages.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
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
214
215
216
217
218
219
220
221
222
/*
module testStage;
reg clk;
reg reset;
always
#5 clk=~clk;
initial
begin
clk=0; reset=1;
#10 reset=0;
#100 $finish;
end
endmodule
*/
module testIF;
reg clk;
reg reset;
// inputs
reg p1_pipeline_regWrite, IF_flush, pcWrite;
reg [1:0] pcSrc;
reg [31:0] p2_pc_branchTarget, pc_jumpTarget;
// outputs
wire [15:0] p1_aluInstr, p1_memInstr;
wire [31:0] p1_pc_plus4;
IFStage the_IFStage(
clk, reset, p1_pipeline_regWrite, IF_flush,
pcWrite, p2_pc_branchTarget, pc_jumpTarget,
pcSrc, // From other stages
p1_aluInstr, p1_memInstr, p1_pc_plus4
);
always
#5 clk=~clk;
initial
begin
clk=0; reset=1;
p1_pipeline_regWrite = 1'b1;
IF_flush = 1'b0;
pcWrite = 1'b1;
pcSrc = 2'b00;
p2_pc_branchTarget = 32'b0000_0000_0000_0000_0000_0000_1010_1010;
pc_jumpTarget = 32'b0000_0000_0000_0000_0000_0000_1000_1000;
#10 reset=0;
#30
pcSrc = 2'b01;
#20
pcSrc = 2'b10;
#20
pcSrc = 2'b11;
#20
pcSrc = 2'b00;
#20
IF_flush = 1'b1;
#50 $finish;
end
endmodule
module testID;
reg clk;
reg reset;
// inputs
reg p2_pipeline_regWrite, p2_pipeline_stall;
reg [15:0] p1_aluInstr, p1_memInstr;
reg p3_flag_v, p3_flag_n;
reg p4_flag_z, p4_flag_n, p4_flag_c, p4_flag_v;
reg p4_mem_regWrite, p4_alu_regWrite;
reg [2:0] p4_alu_rd, p4_mem_rd;
reg [31:0] p4_alu_aluOut, p4_mem_memOut;
// outputs
wire [2:0] p2_alu_rm, p2_alu_rn, p2_alu_rd, p2_mem_rn, p2_mem_rd;
wire [31:0] p2_alu_reg_rm, p2_alu_reg_rn, p2_mem_reg_rn, p2_mem_reg_rd;
wire [31:0] p2_alu_imm, p2_memOffset;
wire [31:0] p2_pc_branchTarget, pc_jumpTarget;
//flags
wire flag_z, flag_n, flag_c, flag_v; // Formality to check flags
// Signals
wire p2_memRead, p2_memWrite, p2_alu_regWrite, p2_mem_regWrite, p2_flag_regWrite;
wire p2_aluOp, p2_aluSrcB;
wire p2_isBranch, p2_isJump;
wire [1:0] pcSrc;
// Flush signals
wire IF_flush, ID_flush, EX_flush;
IDStage theIDStage(
clk, reset, p2_pipeline_regWrite, p2_pipeline_stall, // ID_Flush is generated here itself, but p2_stall isn't
p1_aluInstr, p1_memInstr,
p3_flag_v, p3_flag_n, // p2_isBranch, // Already declared in the pipeline output vars // Look down
p4_mem_regWrite, p4_alu_regWrite,
p4_alu_rd, p4_mem_rd,
p4_alu_aluOut, p4_mem_memOut,
p4_flag_z, p4_flag_n, p4_flag_c, p4_flag_v,
// Our output
p2_alu_rm, p2_alu_rn, p2_alu_rd, p2_mem_rn, p2_mem_rd,
p2_alu_reg_rm, p2_alu_reg_rn, p2_mem_reg_rn, p2_mem_reg_rd,
p2_alu_imm, p2_memOffset,
p2_pc_branchTarget, pc_jumpTarget,
//flags
flag_z, flag_n, flag_c, flag_v, // Formality to check flags
// Signals
p2_memRead, p2_memWrite, p2_alu_regWrite, p2_mem_regWrite, p2_flag_regWrite,
p2_aluOp, p2_aluSrcB,
p2_isBranch, p2_isJump, pcSrc, // p2_isBranch is here
// Flush signals
IF_flush, ID_flush, EX_flush
// output p2_alu_undefinedInstruction, p2_mem_undefinedInstruction, // Deprecated
);
always
#5 clk=~clk;
initial
begin
clk=0; reset=1;
p2_pipeline_regWrite=1;
p2_pipeline_stall = 0;
p1_aluInstr = 16'b0;
p1_memInstr = 16'b0;
p3_flag_v = 0; p3_flag_n=0;
p4_flag_z = 0;p4_flag_n = 0; p4_flag_c = 0; p4_flag_v = 0;
p4_mem_regWrite=0; p4_alu_regWrite=0;
p4_alu_aluOut =0; p4_mem_memOut=0;
#10 reset=0;
#10 // Set the flag registers
p4_flag_z = 1;p4_flag_n = 0; p4_flag_c = 1; p4_flag_v = 0;
#10
p4_flag_z = 0;p4_flag_n = 1; p4_flag_c = 0; p4_flag_v = 1;
#10
p4_flag_z = 1;p4_flag_n = 1; p4_flag_c = 1; p4_flag_v = 1;
// 40 ns have elapsed
#50
p4_mem_regWrite = 1'b1; p4_alu_regWrite = 1'b1;
#10// 100 ns
// Write some data into the registers
p4_alu_rd= 3'd0; p4_mem_rd = 3'd1;
p4_alu_aluOut = 32'h0000_f0f0;
p4_mem_memOut = 32'h0000_1111;
#10
p4_alu_rd= 3'd2; p4_mem_rd = 3'd3;
p4_alu_aluOut = 32'h0000_2222;
p4_mem_memOut = 32'h0000_3333;
#10
p4_alu_rd= 3'd4; p4_mem_rd = 3'd5;
p4_alu_aluOut = 32'h0000_4444;
p4_mem_memOut = 32'h0000_5555;
#10
p4_alu_rd= 3'd6; p4_mem_rd = 3'd7;
p4_alu_aluOut = 32'h0000_6666;
p4_mem_memOut = 32'h0000_7777;
// 130 seconds elapsed. Try reading them back
#10
p4_mem_regWrite = 1'b1; p4_alu_regWrite = 1'b1;
#10
p1_aluInstr = 16'b000_001_000010100_1; p1_memInstr = 16'b01010_010_011_01100; // cmp a0, a1; store 10, a2, a3
#20
p1_aluInstr = 16'b100_101_000010100_1; p1_memInstr = 16'b01010_110_111_01101; // cmp a0, a1; load 10, a2, a3
// 170 up. Try new instructions for the control signals
#20
p1_aluInstr = 16'b000_001_000010100_1; p1_memInstr = 16'b01010_000_000_01100; // cmp a0, a1; store 10, a0, a0
#20
p1_aluInstr = 16'b100_110_111_01_00011; p1_memInstr = 16'b00010001000_1111_0; // shift a4, a6, a7; jmp 136
#20
// Try the stall ?
p2_pipeline_stall = 1'b1;
#50 $finish;
end
endmodule