aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlavian Kaufmann <flavian@flaviankaufmann.ch>2024-05-05 19:03:07 +0200
committerFlavian Kaufmann <flavian@flaviankaufmann.ch>2024-05-05 19:03:07 +0200
commit3fcb15193438661bd975c7b624f76fa9d130f14b (patch)
tree99d9fe2866e288a241a8c842b089ec65cd932f4f
parent90a684ff92f68ec818349d1df626fcb06e8de2a1 (diff)
downloadriscv_cpu-3fcb15193438661bd975c7b624f76fa9d130f14b.tar.gz
riscv_cpu-3fcb15193438661bd975c7b624f76fa9d130f14b.zip
genrom
-rw-r--r--genrom/genrom.c10
-rw-r--r--rom/rom.hex1024
-rw-r--r--sim/testbench_alu.v8
-rw-r--r--sim/testbench_register_file.v12
-rw-r--r--src/rom.v2
5 files changed, 1043 insertions, 13 deletions
diff --git a/genrom/genrom.c b/genrom/genrom.c
new file mode 100644
index 0000000..4bb5bf2
--- /dev/null
+++ b/genrom/genrom.c
@@ -0,0 +1,10 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+int main(int argc, char *argv[]) {
+ int rom_size = 1024;
+
+ for (uint32_t i = 0; i < rom_size; ++i) {
+ printf("%02x\n", i % 32);
+ }
+}
diff --git a/rom/rom.hex b/rom/rom.hex
index e69de29..6ea4d64 100644
--- a/rom/rom.hex
+++ b/rom/rom.hex
@@ -0,0 +1,1024 @@
+00
+01
+02
+03
+04
+05
+06
+07
+08
+09
+0a
+0b
+0c
+0d
+0e
+0f
+10
+11
+12
+13
+14
+15
+16
+17
+18
+19
+1a
+1b
+1c
+1d
+1e
+1f
+00
+01
+02
+03
+04
+05
+06
+07
+08
+09
+0a
+0b
+0c
+0d
+0e
+0f
+10
+11
+12
+13
+14
+15
+16
+17
+18
+19
+1a
+1b
+1c
+1d
+1e
+1f
+00
+01
+02
+03
+04
+05
+06
+07
+08
+09
+0a
+0b
+0c
+0d
+0e
+0f
+10
+11
+12
+13
+14
+15
+16
+17
+18
+19
+1a
+1b
+1c
+1d
+1e
+1f
+00
+01
+02
+03
+04
+05
+06
+07
+08
+09
+0a
+0b
+0c
+0d
+0e
+0f
+10
+11
+12
+13
+14
+15
+16
+17
+18
+19
+1a
+1b
+1c
+1d
+1e
+1f
+00
+01
+02
+03
+04
+05
+06
+07
+08
+09
+0a
+0b
+0c
+0d
+0e
+0f
+10
+11
+12
+13
+14
+15
+16
+17
+18
+19
+1a
+1b
+1c
+1d
+1e
+1f
+00
+01
+02
+03
+04
+05
+06
+07
+08
+09
+0a
+0b
+0c
+0d
+0e
+0f
+10
+11
+12
+13
+14
+15
+16
+17
+18
+19
+1a
+1b
+1c
+1d
+1e
+1f
+00
+01
+02
+03
+04
+05
+06
+07
+08
+09
+0a
+0b
+0c
+0d
+0e
+0f
+10
+11
+12
+13
+14
+15
+16
+17
+18
+19
+1a
+1b
+1c
+1d
+1e
+1f
+00
+01
+02
+03
+04
+05
+06
+07
+08
+09
+0a
+0b
+0c
+0d
+0e
+0f
+10
+11
+12
+13
+14
+15
+16
+17
+18
+19
+1a
+1b
+1c
+1d
+1e
+1f
+00
+01
+02
+03
+04
+05
+06
+07
+08
+09
+0a
+0b
+0c
+0d
+0e
+0f
+10
+11
+12
+13
+14
+15
+16
+17
+18
+19
+1a
+1b
+1c
+1d
+1e
+1f
+00
+01
+02
+03
+04
+05
+06
+07
+08
+09
+0a
+0b
+0c
+0d
+0e
+0f
+10
+11
+12
+13
+14
+15
+16
+17
+18
+19
+1a
+1b
+1c
+1d
+1e
+1f
+00
+01
+02
+03
+04
+05
+06
+07
+08
+09
+0a
+0b
+0c
+0d
+0e
+0f
+10
+11
+12
+13
+14
+15
+16
+17
+18
+19
+1a
+1b
+1c
+1d
+1e
+1f
+00
+01
+02
+03
+04
+05
+06
+07
+08
+09
+0a
+0b
+0c
+0d
+0e
+0f
+10
+11
+12
+13
+14
+15
+16
+17
+18
+19
+1a
+1b
+1c
+1d
+1e
+1f
+00
+01
+02
+03
+04
+05
+06
+07
+08
+09
+0a
+0b
+0c
+0d
+0e
+0f
+10
+11
+12
+13
+14
+15
+16
+17
+18
+19
+1a
+1b
+1c
+1d
+1e
+1f
+00
+01
+02
+03
+04
+05
+06
+07
+08
+09
+0a
+0b
+0c
+0d
+0e
+0f
+10
+11
+12
+13
+14
+15
+16
+17
+18
+19
+1a
+1b
+1c
+1d
+1e
+1f
+00
+01
+02
+03
+04
+05
+06
+07
+08
+09
+0a
+0b
+0c
+0d
+0e
+0f
+10
+11
+12
+13
+14
+15
+16
+17
+18
+19
+1a
+1b
+1c
+1d
+1e
+1f
+00
+01
+02
+03
+04
+05
+06
+07
+08
+09
+0a
+0b
+0c
+0d
+0e
+0f
+10
+11
+12
+13
+14
+15
+16
+17
+18
+19
+1a
+1b
+1c
+1d
+1e
+1f
+00
+01
+02
+03
+04
+05
+06
+07
+08
+09
+0a
+0b
+0c
+0d
+0e
+0f
+10
+11
+12
+13
+14
+15
+16
+17
+18
+19
+1a
+1b
+1c
+1d
+1e
+1f
+00
+01
+02
+03
+04
+05
+06
+07
+08
+09
+0a
+0b
+0c
+0d
+0e
+0f
+10
+11
+12
+13
+14
+15
+16
+17
+18
+19
+1a
+1b
+1c
+1d
+1e
+1f
+00
+01
+02
+03
+04
+05
+06
+07
+08
+09
+0a
+0b
+0c
+0d
+0e
+0f
+10
+11
+12
+13
+14
+15
+16
+17
+18
+19
+1a
+1b
+1c
+1d
+1e
+1f
+00
+01
+02
+03
+04
+05
+06
+07
+08
+09
+0a
+0b
+0c
+0d
+0e
+0f
+10
+11
+12
+13
+14
+15
+16
+17
+18
+19
+1a
+1b
+1c
+1d
+1e
+1f
+00
+01
+02
+03
+04
+05
+06
+07
+08
+09
+0a
+0b
+0c
+0d
+0e
+0f
+10
+11
+12
+13
+14
+15
+16
+17
+18
+19
+1a
+1b
+1c
+1d
+1e
+1f
+00
+01
+02
+03
+04
+05
+06
+07
+08
+09
+0a
+0b
+0c
+0d
+0e
+0f
+10
+11
+12
+13
+14
+15
+16
+17
+18
+19
+1a
+1b
+1c
+1d
+1e
+1f
+00
+01
+02
+03
+04
+05
+06
+07
+08
+09
+0a
+0b
+0c
+0d
+0e
+0f
+10
+11
+12
+13
+14
+15
+16
+17
+18
+19
+1a
+1b
+1c
+1d
+1e
+1f
+00
+01
+02
+03
+04
+05
+06
+07
+08
+09
+0a
+0b
+0c
+0d
+0e
+0f
+10
+11
+12
+13
+14
+15
+16
+17
+18
+19
+1a
+1b
+1c
+1d
+1e
+1f
+00
+01
+02
+03
+04
+05
+06
+07
+08
+09
+0a
+0b
+0c
+0d
+0e
+0f
+10
+11
+12
+13
+14
+15
+16
+17
+18
+19
+1a
+1b
+1c
+1d
+1e
+1f
+00
+01
+02
+03
+04
+05
+06
+07
+08
+09
+0a
+0b
+0c
+0d
+0e
+0f
+10
+11
+12
+13
+14
+15
+16
+17
+18
+19
+1a
+1b
+1c
+1d
+1e
+1f
+00
+01
+02
+03
+04
+05
+06
+07
+08
+09
+0a
+0b
+0c
+0d
+0e
+0f
+10
+11
+12
+13
+14
+15
+16
+17
+18
+19
+1a
+1b
+1c
+1d
+1e
+1f
+00
+01
+02
+03
+04
+05
+06
+07
+08
+09
+0a
+0b
+0c
+0d
+0e
+0f
+10
+11
+12
+13
+14
+15
+16
+17
+18
+19
+1a
+1b
+1c
+1d
+1e
+1f
+00
+01
+02
+03
+04
+05
+06
+07
+08
+09
+0a
+0b
+0c
+0d
+0e
+0f
+10
+11
+12
+13
+14
+15
+16
+17
+18
+19
+1a
+1b
+1c
+1d
+1e
+1f
+00
+01
+02
+03
+04
+05
+06
+07
+08
+09
+0a
+0b
+0c
+0d
+0e
+0f
+10
+11
+12
+13
+14
+15
+16
+17
+18
+19
+1a
+1b
+1c
+1d
+1e
+1f
+00
+01
+02
+03
+04
+05
+06
+07
+08
+09
+0a
+0b
+0c
+0d
+0e
+0f
+10
+11
+12
+13
+14
+15
+16
+17
+18
+19
+1a
+1b
+1c
+1d
+1e
+1f
+00
+01
+02
+03
+04
+05
+06
+07
+08
+09
+0a
+0b
+0c
+0d
+0e
+0f
+10
+11
+12
+13
+14
+15
+16
+17
+18
+19
+1a
+1b
+1c
+1d
+1e
+1f
diff --git a/sim/testbench_alu.v b/sim/testbench_alu.v
index 45cce1b..6403cd7 100644
--- a/sim/testbench_alu.v
+++ b/sim/testbench_alu.v
@@ -9,16 +9,14 @@ module testbench_alu();
initial begin
if ($value$plusargs("testvec=%s", testvec_filename)) begin
- $display("Using test vector file: %s", testvec_filename);
end else begin
- $display("Error: no test vector file specified.");
+ $display("ERROR: testvec not specified");
$finish;
end
if ($value$plusargs("waveform=%s", waveform_filename)) begin
- $display("Using waveform file: %s", waveform_filename);
end else begin
- $display("Error: no waveform file specified.");
+ $display("ERROR: waveform not specified");
$finish;
end
end
@@ -65,7 +63,7 @@ module testbench_alu();
alu_test_count = alu_test_count + 1;
if ((alu_test_count == 9027)) begin
- $display("FINISHED (ALU), %d tests completed with %d errors", alu_test_count, alu_error_count);
+ $display("FINISHED (ALU), with %d errors out of %d tests.", alu_error_count, alu_test_count);
#16;
$finish;
diff --git a/sim/testbench_register_file.v b/sim/testbench_register_file.v
index 07fa3e0..79825dc 100644
--- a/sim/testbench_register_file.v
+++ b/sim/testbench_register_file.v
@@ -35,16 +35,14 @@ reg [1023:0] waveform_filename;
initial begin
if ($value$plusargs("testvec=%s", testvec_filename)) begin
- $display("Using test vector file: %s", testvec_filename);
end else begin
- $display("Error: no test vector file specified.");
+ $display("ERROR: testvec not specified");
$finish;
end
if ($value$plusargs("waveform=%s", waveform_filename)) begin
- $display("Using waveform file: %s", waveform_filename);
end else begin
- $display("Error: no waveform file specified.");
+ $display("ERROR: waveform not specified");
$finish;
end
end
@@ -73,7 +71,7 @@ initial begin
file = $fopen(testvec_filename, "r");
if (file == 0) begin
- $display("Failed to open testvector file.");
+ $display("ERROR: failed to open testvec");
$finish;
end
@@ -87,7 +85,7 @@ initial begin
@(negedge clk);
if (data_rs0 !== expected_data_rs0 || data_rs1 !== expected_data_rs1) begin
- $display("ERROR (register_file) in test %d: addr_rs0: %08h, addr_rs1: %08h, addr_rd2: %08h, data_rd2: %08h, we: %b",
+ $display("ERROR (register_file), test %d: addr_rs0: %08h, addr_rs1: %08h, addr_rd2: %08h, data_rd2: %08h, we: %b",
test_count, addr_rs0, addr_rs1, addr_rd2, data_rd2, we);
$display(" data_rs0: %08h (expected: %08h)", data_rs0, expected_data_rs0);
$display(" data_rs1: %08h (expected: %08h)", data_rs1, expected_data_rs1);
@@ -95,7 +93,7 @@ initial begin
end
test_count = test_count + 1;
end
- $display("FINISHED with %d errors out of %d tests", error_count, test_count);
+ $display("FINISHED (register_file) with %d errors out of %d tests", error_count, test_count);
$fclose(file);
$finish;
end
diff --git a/src/rom.v b/src/rom.v
index c85335b..aa8c359 100644
--- a/src/rom.v
+++ b/src/rom.v
@@ -12,7 +12,7 @@ module rom #(
reg [7:0] memory [SIZE-1:0];
initial begin
- $readmemh("rom/rom.hex", memory);
+ $readmemh("rom/rom.hex", memory, 0, SIZE-1);
end
always @(posedge clk) begin