1 |
11 |
rafaelcalc |
//////////////////////////////////////////////////////////////////////////////////
|
2 |
|
|
// Engineer: Rafael de Oliveira Calçada (rafaelcalcada@gmail.com)
|
3 |
|
|
//
|
4 |
|
|
// Create Date: 30.07.2020 18:18:32
|
5 |
|
|
// Module Name: tb_compliance
|
6 |
|
|
// Project Name: Steel Core
|
7 |
|
|
// Description: RISC-V compliance testbench
|
8 |
|
|
//
|
9 |
|
|
// Dependencies: globals.vh
|
10 |
|
|
// machine_control.v
|
11 |
|
|
// alu.v
|
12 |
|
|
// integer_file.v
|
13 |
|
|
// branch_unit.v
|
14 |
|
|
// decoder.v
|
15 |
|
|
// csr_file.v
|
16 |
|
|
// imm_generator.v
|
17 |
|
|
// load_unit.v
|
18 |
|
|
// store_unit.v
|
19 |
|
|
//
|
20 |
|
|
// Version 0.01
|
21 |
|
|
//
|
22 |
|
|
//////////////////////////////////////////////////////////////////////////////////
|
23 |
|
|
|
24 |
|
|
/*********************************************************************************
|
25 |
|
|
|
26 |
|
|
MIT License
|
27 |
|
|
|
28 |
|
|
Copyright (c) 2020 Rafael de Oliveira Calçada
|
29 |
|
|
|
30 |
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
31 |
|
|
of this software and associated documentation files (the "Software"), to deal
|
32 |
|
|
in the Software without restriction, including without limitation the rights
|
33 |
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
34 |
|
|
copies of the Software, and to permit persons to whom the Software is
|
35 |
|
|
furnished to do so, subject to the following conditions:
|
36 |
|
|
|
37 |
|
|
The above copyright notice and this permission notice shall be included in all
|
38 |
|
|
copies or substantial portions of the Software.
|
39 |
|
|
|
40 |
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
41 |
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
42 |
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
43 |
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
44 |
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
45 |
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
46 |
|
|
SOFTWARE.
|
47 |
|
|
|
48 |
|
|
********************************************************************************/
|
49 |
|
|
|
50 |
|
|
`timescale 1ns / 1ps
|
51 |
|
|
`include "../globals.vh"
|
52 |
|
|
|
53 |
|
|
module tb_compliance();
|
54 |
|
|
|
55 |
|
|
reg CLK;
|
56 |
|
|
reg RESET;
|
57 |
|
|
wire [31:0] I_ADDR;
|
58 |
|
|
reg [31:0] INSTR;
|
59 |
|
|
wire [31:0] D_ADDR;
|
60 |
|
|
wire [31:0] DATA_OUT;
|
61 |
|
|
wire WR_REQ;
|
62 |
|
|
wire [3:0] WR_MASK;
|
63 |
|
|
reg [31:0] DATA_IN;
|
64 |
|
|
reg E_IRQ;
|
65 |
|
|
reg T_IRQ;
|
66 |
|
|
reg S_IRQ;
|
67 |
|
|
|
68 |
|
|
reg [8*50:0] tests [0:53] = {
|
69 |
|
|
"I-ADD-01.elf.mem",
|
70 |
|
|
"I-BLT-01.elf.mem",
|
71 |
|
|
"I-JAL-01.elf.mem",
|
72 |
|
|
"I-MISALIGN_JMP-01.elf.mem",
|
73 |
|
|
"I-SB-01.elf.mem",
|
74 |
|
|
"I-SRA-01.elf.mem",
|
75 |
|
|
"I-ADDI-01.elf.mem",
|
76 |
|
|
"I-BLTU-01.elf.mem",
|
77 |
|
|
"I-JALR-01.elf.mem",
|
78 |
|
|
"I-MISALIGN_LDST-01.elf.mem",
|
79 |
|
|
"I-SH-01.elf.mem",
|
80 |
|
|
"I-SRAI-01.elf.mem",
|
81 |
|
|
"I-AND-01.elf.mem",
|
82 |
|
|
"I-BNE-01.elf.mem",
|
83 |
|
|
"I-LB-01.elf.mem",
|
84 |
|
|
"I-NOP-01.elf.mem",
|
85 |
|
|
"I-SLL-01.elf.mem",
|
86 |
|
|
"I-SRL-01.elf.mem",
|
87 |
|
|
"I-ANDI-01.elf.mem",
|
88 |
|
|
"I-DELAY_SLOTS-01.elf.mem",
|
89 |
|
|
"I-LBU-01.elf.mem",
|
90 |
|
|
"I-OR-01.elf.mem",
|
91 |
|
|
"I-SLLI-01.elf.mem",
|
92 |
|
|
"I-SRLI-01.elf.mem",
|
93 |
|
|
"I-AUIPC-01.elf.mem",
|
94 |
|
|
"I-EBREAK-01.elf.mem",
|
95 |
|
|
"I-LH-01.elf.mem",
|
96 |
|
|
"I-ORI-01.elf.mem",
|
97 |
|
|
"I-SLT-01.elf.mem",
|
98 |
|
|
"I-SUB-01.elf.mem",
|
99 |
|
|
"I-BEQ-01.elf.mem",
|
100 |
|
|
"I-ECALL-01.elf.mem",
|
101 |
|
|
"I-LHU-01.elf.mem",
|
102 |
|
|
"I-RF_size-01.elf.mem",
|
103 |
|
|
"I-SLTI-01.elf.mem",
|
104 |
|
|
"I-SW-01.elf.mem",
|
105 |
|
|
"I-BGE-01.elf.mem",
|
106 |
|
|
"I-ENDIANESS-01.elf.mem",
|
107 |
|
|
"I-LUI-01.elf.mem",
|
108 |
|
|
"I-RF_width-01.elf.mem",
|
109 |
|
|
"I-SLTIU-01.elf.mem",
|
110 |
|
|
"I-XOR-01.elf.mem",
|
111 |
|
|
"I-BGEU-01.elf.mem",
|
112 |
|
|
"I-IO-01.elf.mem",
|
113 |
|
|
"I-LW-01.elf.mem",
|
114 |
|
|
"I-RF_x0-01.elf.mem",
|
115 |
|
|
"I-SLTU-01.elf.mem",
|
116 |
|
|
"I-XORI-01.elf.mem",
|
117 |
|
|
"I-CSRRC-01.elf.mem",
|
118 |
|
|
"I-CSRRCI-01.elf.mem",
|
119 |
|
|
"I-CSRRS-01.elf.mem",
|
120 |
|
|
"I-CSRRSI-01.elf.mem",
|
121 |
|
|
"I-CSRRW-01.elf.mem",
|
122 |
|
|
"I-CSRRWI-01.elf.mem"
|
123 |
|
|
};
|
124 |
|
|
|
125 |
|
|
reg [8*256:0] signatures [0:53] = {
|
126 |
|
|
"../../../../../compliance/I-ADD-01.signature.output",
|
127 |
|
|
"../../../../../compliance/I-BLT-01.signature.output",
|
128 |
|
|
"../../../../../compliance/I-JAL-01.signature.output",
|
129 |
|
|
"../../../../../compliance/I-MISALIGN_JMP-01.signature.output",
|
130 |
|
|
"../../../../../compliance/I-SB-01.signature.output",
|
131 |
|
|
"../../../../../compliance/I-SRA-01.signature.output",
|
132 |
|
|
"../../../../../compliance/I-ADDI-01.signature.output",
|
133 |
|
|
"../../../../../compliance/I-BLTU-01.signature.output",
|
134 |
|
|
"../../../../../compliance/I-JALR-01.signature.output",
|
135 |
|
|
"../../../../../compliance/I-MISALIGN_LDST-01.signature.output",
|
136 |
|
|
"../../../../../compliance/I-SH-01.signature.output",
|
137 |
|
|
"../../../../../compliance/I-SRAI-01.signature.output",
|
138 |
|
|
"../../../../../compliance/I-AND-01.signature.output",
|
139 |
|
|
"../../../../../compliance/I-BNE-01.signature.output",
|
140 |
|
|
"../../../../../compliance/I-LB-01.signature.output",
|
141 |
|
|
"../../../../../compliance/I-NOP-01.signature.output",
|
142 |
|
|
"../../../../../compliance/I-SLL-01.signature.output",
|
143 |
|
|
"../../../../../compliance/I-SRL-01.signature.output",
|
144 |
|
|
"../../../../../compliance/I-ANDI-01.signature.output",
|
145 |
|
|
"../../../../../compliance/I-DELAY_SLOTS-01.signature.output",
|
146 |
|
|
"../../../../../compliance/I-LBU-01.signature.output",
|
147 |
|
|
"../../../../../compliance/I-OR-01.signature.output",
|
148 |
|
|
"../../../../../compliance/I-SLLI-01.signature.output",
|
149 |
|
|
"../../../../../compliance/I-SRLI-01.signature.output",
|
150 |
|
|
"../../../../../compliance/I-AUIPC-01.signature.output",
|
151 |
|
|
"../../../../../compliance/I-EBREAK-01.signature.output",
|
152 |
|
|
"../../../../../compliance/I-LH-01.signature.output",
|
153 |
|
|
"../../../../../compliance/I-ORI-01.signature.output",
|
154 |
|
|
"../../../../../compliance/I-SLT-01.signature.output",
|
155 |
|
|
"../../../../../compliance/I-SUB-01.signature.output",
|
156 |
|
|
"../../../../../compliance/I-BEQ-01.signature.output",
|
157 |
|
|
"../../../../../compliance/I-ECALL-01.signature.output",
|
158 |
|
|
"../../../../../compliance/I-LHU-01.signature.output",
|
159 |
|
|
"../../../../../compliance/I-RF_size-01.signature.output",
|
160 |
|
|
"../../../../../compliance/I-SLTI-01.signature.output",
|
161 |
|
|
"../../../../../compliance/I-SW-01.signature.output",
|
162 |
|
|
"../../../../../compliance/I-BGE-01.signature.output",
|
163 |
|
|
"../../../../../compliance/I-ENDIANESS-01.signature.output",
|
164 |
|
|
"../../../../../compliance/I-LUI-01.signature.output",
|
165 |
|
|
"../../../../../compliance/I-RF_width-01.signature.output",
|
166 |
|
|
"../../../../../compliance/I-SLTIU-01.signature.output",
|
167 |
|
|
"../../../../../compliance/I-XOR-01.signature.output",
|
168 |
|
|
"../../../../../compliance/I-BGEU-01.signature.output",
|
169 |
|
|
"../../../../../compliance/I-IO-01.signature.output",
|
170 |
|
|
"../../../../../compliance/I-LW-01.signature.output",
|
171 |
|
|
"../../../../../compliance/I-RF_x0-01.signature.output",
|
172 |
|
|
"../../../../../compliance/I-SLTU-01.signature.output",
|
173 |
|
|
"../../../../../compliance/I-XORI-01.signature.output",
|
174 |
|
|
"../../../../../compliance/I-CSRRC-01.signature.output",
|
175 |
|
|
"../../../../../compliance/I-CSRRCI-01.signature.output",
|
176 |
|
|
"../../../../../compliance/I-CSRRS-01.signature.output",
|
177 |
|
|
"../../../../../compliance/I-CSRRSI-01.signature.output",
|
178 |
|
|
"../../../../../compliance/I-CSRRW-01.signature.output",
|
179 |
|
|
"../../../../../compliance/I-CSRRWI-01.signature.output"
|
180 |
|
|
};
|
181 |
|
|
|
182 |
|
|
steel_top #(
|
183 |
|
|
|
184 |
|
|
.BOOT_ADDRESS(32'h00000000)
|
185 |
|
|
|
186 |
|
|
) dut (
|
187 |
|
|
|
188 |
|
|
.CLK(CLK),
|
189 |
|
|
.RESET(RESET),
|
190 |
|
|
.REAL_TIME(64'b0),
|
191 |
|
|
.I_ADDR(I_ADDR),
|
192 |
|
|
.INSTR(INSTR),
|
193 |
|
|
.D_ADDR(D_ADDR),
|
194 |
|
|
.DATA_OUT(DATA_OUT),
|
195 |
|
|
.WR_REQ(WR_REQ),
|
196 |
|
|
.WR_MASK(WR_MASK),
|
197 |
|
|
.DATA_IN(DATA_IN),
|
198 |
|
|
.E_IRQ(E_IRQ),
|
199 |
|
|
.T_IRQ(T_IRQ),
|
200 |
|
|
.S_IRQ(S_IRQ)
|
201 |
|
|
|
202 |
|
|
);
|
203 |
|
|
|
204 |
|
|
reg [31:0] ram [0:16383]; // 4KB RAM
|
205 |
|
|
integer f;
|
206 |
|
|
integer i;
|
207 |
|
|
integer j;
|
208 |
|
|
integer k;
|
209 |
|
|
integer m;
|
210 |
|
|
integer n;
|
211 |
|
|
|
212 |
|
|
always
|
213 |
|
|
begin
|
214 |
|
|
#10 CLK = !CLK;
|
215 |
|
|
end
|
216 |
|
|
|
217 |
|
|
initial
|
218 |
|
|
begin
|
219 |
|
|
|
220 |
|
|
for(k = 0; k < 54; k=k+1)
|
221 |
|
|
begin
|
222 |
|
|
|
223 |
|
|
// LOADS PROGRAM INTO MEMORY
|
224 |
|
|
for(i = 0; i < 65535; i=i+1) ram[i] = 32'b0;
|
225 |
|
|
$display("Running %s...", tests[k]);
|
226 |
|
|
f = $fopen(signatures[k], "w");
|
227 |
|
|
$readmemh(tests[k],ram);
|
228 |
|
|
|
229 |
|
|
// INITIAL VALUES
|
230 |
|
|
RESET = 1'b0;
|
231 |
|
|
CLK = 1'b0;
|
232 |
|
|
E_IRQ = 1'b0;
|
233 |
|
|
T_IRQ = 1'b0;
|
234 |
|
|
S_IRQ = 1'b0;
|
235 |
|
|
|
236 |
|
|
// RESET
|
237 |
|
|
#5;
|
238 |
|
|
RESET = 1'b1;
|
239 |
|
|
#15;
|
240 |
|
|
RESET = 1'b0;
|
241 |
|
|
|
242 |
|
|
// one second loop
|
243 |
|
|
for(j = 0; j < 50000000; j = j + 1)
|
244 |
|
|
begin
|
245 |
|
|
#20;
|
246 |
|
|
if(WR_REQ == 1'b1 && D_ADDR == 32'h00001000)
|
247 |
|
|
begin
|
248 |
|
|
m = ram[2047][16:2];
|
249 |
|
|
n = ram[2046][16:2];
|
250 |
|
|
for(m = ram[2047][16:2]; m < n; m=m+1)
|
251 |
|
|
begin
|
252 |
|
|
$fwrite(f, "%h\n", ram[m]);
|
253 |
|
|
$display("%h", ram[m]);
|
254 |
|
|
end
|
255 |
|
|
#20;
|
256 |
|
|
j = 50000000;
|
257 |
|
|
end
|
258 |
|
|
end
|
259 |
|
|
|
260 |
|
|
$fclose(f);
|
261 |
|
|
|
262 |
|
|
end
|
263 |
|
|
|
264 |
|
|
$display("All signatures generated. Run the verify.sh script located inside the compliance folder.");
|
265 |
|
|
|
266 |
|
|
end
|
267 |
|
|
|
268 |
|
|
always @(posedge CLK or posedge RESET)
|
269 |
|
|
begin
|
270 |
|
|
if(RESET)
|
271 |
|
|
begin
|
272 |
|
|
INSTR = ram[I_ADDR[15:2]];
|
273 |
|
|
DATA_IN = ram[D_ADDR[15:2]];
|
274 |
|
|
end
|
275 |
|
|
else
|
276 |
|
|
begin
|
277 |
|
|
INSTR = ram[I_ADDR[15:2]];
|
278 |
|
|
DATA_IN = ram[D_ADDR[15:2]];
|
279 |
|
|
if(WR_REQ)
|
280 |
|
|
begin
|
281 |
|
|
if(WR_MASK[0])
|
282 |
|
|
begin
|
283 |
|
|
ram[D_ADDR[15:2]][7:0] <= DATA_OUT[7:0];
|
284 |
|
|
end
|
285 |
|
|
if(WR_MASK[1])
|
286 |
|
|
begin
|
287 |
|
|
ram[D_ADDR[15:2]][15:8] <= DATA_OUT[15:8];
|
288 |
|
|
end
|
289 |
|
|
if(WR_MASK[2])
|
290 |
|
|
begin
|
291 |
|
|
ram[D_ADDR[15:2]][23:16] <= DATA_OUT[23:16];
|
292 |
|
|
end
|
293 |
|
|
if(WR_MASK[3])
|
294 |
|
|
begin
|
295 |
|
|
ram[D_ADDR[15:2]][31:24] <= DATA_OUT[31:24];
|
296 |
|
|
end
|
297 |
|
|
end
|
298 |
|
|
end
|
299 |
|
|
end
|
300 |
|
|
|
301 |
|
|
endmodule
|
302 |
|
|
|