-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathleiwand_rv32_soc_tb.v
145 lines (114 loc) · 3.8 KB
/
leiwand_rv32_soc_tb.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
/*
* This file is part of leiwand_rv32.
* Copyright (c) 2019 Franz Flasch.
*
* leiwand_rv32 is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* leiwand_rv32 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with leiwand_rv32. If not, see <https://www.gnu.org/licenses/>.
*/
`timescale 1ns/1ps
`include "helper.v"
`include "leiwand_rv32_constants.v"
module leiwand_rv32_core_tb();
parameter MEMORY_SIZE = 4096;
reg clk = 0;
reg reset = 0;
wire mem_valid;
wire mem_ready;
wire [(`MEM_WIDTH-1):0] mem_addr;
wire [(`MEM_WIDTH-1):0] mem_data_cpu_in;
wire [(`MEM_WIDTH-1):0] mem_data_cpu_out;
wire mem_read_write;
wire [3:0] mem_wen;
wire [(`MEM_WIDTH-1):0] dummy_irq_status;
leiwand_rv32_core
cpu_core (
clk,
reset,
mem_valid,
mem_ready,
mem_addr,
mem_data_cpu_in,
mem_data_cpu_out,
mem_wen,
dummy_irq_status
);
simple_mem #(
.WORDS(MEMORY_SIZE)
) internal_rom (
.clk(clk),
.rst(reset),
.valid(mem_valid && (mem_addr >= `MEM_WIDTH'h20400000) && (mem_addr < `MEM_WIDTH'h20400000 + (4*MEMORY_SIZE))),
.ready(mem_ready),
.wen(mem_wen),
.addr(mem_addr[31:0]),
.wdata(mem_data_cpu_out),
.rdata(mem_data_cpu_in)
);
initial begin
clk=0;
forever #2 clk=~clk;
end
`define SEEK_SET 0
`define SEEK_CUR 1
`define SEEK_END 2
integer i, j;
integer file_size, file, tmp;
initial begin
file = $fopenr(`BINARY_TO_LOAD);
file_size = $fseek(file, 0, `SEEK_END); /* End of file */
file_size = $ftell(file);
tmp = $fseek(file, 0, `SEEK_SET);
tmp = $fread(internal_rom.mem, file, 0, file_size);
$display("file size: %d", file_size);
for (i = 0; i < MEMORY_SIZE; i = i + 1) begin
internal_rom.mem[i] = {{internal_rom.mem[i][07:00]}, {internal_rom.mem[i][15:08]}, {internal_rom.mem[i][23:16]}, {internal_rom.mem[i][31:24]}};
$display ("internal ram %d: %x", i, internal_rom.mem[i]);
end
$display ("clk: %d", clk);
#5
reset=0;
#10
reset=1;
#5
reset=0;
for (i = 0; i < 10000; i++) begin
wait (cpu_core.cpu_stage == cpu_core.STAGE_INSTR_FETCH);
wait ((cpu_core.cpu_stage == cpu_core.STAGE_INSTR_ALU_PREPARE));
$display("\n");
$display("cycle: %d", i);
$display("stage: %d", cpu_core.cpu_stage);
$display("pc: %x", cpu_core.pc);
$display("instr: %x", cpu_core.instruction);
for(j = 0; j < 32; j++ ) begin
$display("x[%2d]: %x", j, cpu_core.x[j]);
end
if(cpu_core.pc == `SUCCESS_PC) begin
$display("SUCCESS!");
$finish;
end
end
$display("SOMETHING WENT WRONG!");
$finish;
end
// initial begin
// $dumpfile("leiwand_rv32_soc_tb.vcd");
// $dumpvars(0,leiwand_rv32_core_tb);
// for (i = 0; i < `NR_RV_REGS; i = i + 1) begin
// $dumpvars(0, cpu_core.x[i]);
// end
// // for (i = 0; i < MEMORY_SIZE; i = i + 1) begin
// // $dumpvars(0, internal_rom.mem[i]);
// // end
// // # 15000 $finish;
// end
endmodule