Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9faf4c7dd1 | ||
|
|
79246e7d3b | ||
|
|
681985322e |
@@ -4,7 +4,7 @@
|
|||||||
../../src/verilog/memory_controller.sv
|
../../src/verilog/memory_controller.sv
|
||||||
../../src/verilog/chip_top.sv
|
../../src/verilog/chip_top.sv
|
||||||
|
|
||||||
// TODO: Your CPU RTL. Update this section with your added files.
|
// Your CPU RTL. Update this section with your added files.
|
||||||
../../src/verilog/cpu/cpu_pkg.sv
|
../../src/verilog/cpu/cpu_pkg.sv
|
||||||
../../src/verilog/cpu/reg_file.sv
|
../../src/verilog/cpu/reg_file.sv
|
||||||
../../src/verilog/cpu/fetch.sv
|
../../src/verilog/cpu/fetch.sv
|
||||||
|
|||||||
+147
-147
@@ -3,167 +3,167 @@
|
|||||||
* driver through xbar_box. The sequencer describes intent but never drives or
|
* driver through xbar_box. The sequencer describes intent but never drives or
|
||||||
* observes the DUT directly.
|
* observes the DUT directly.
|
||||||
*/
|
*/
|
||||||
class cpu_sequencer #(int DataSize=32, int AddrSize=14);
|
class cpu_sequencer #(
|
||||||
|
int DataSize = 32,
|
||||||
|
int AddrSize = 14
|
||||||
|
);
|
||||||
|
|
||||||
mailbox #(cpu_xbar_item #(DataSize, AddrSize)) xbar_box;
|
mailbox #(cpu_xbar_item #(DataSize, AddrSize)) xbar_box;
|
||||||
|
|
||||||
// Mirror data-memory initialization writes. gen_program starts a private
|
// Mirror data-memory initialization writes. gen_program starts a private
|
||||||
// reference model from this image and advances it only along the generated
|
// reference model from this image and advances it only along the generated
|
||||||
// program's reachable path. This is generation context, not DUT checking.
|
// program's reachable path. This is generation context, not DUT checking.
|
||||||
logic [31:0] shadow_dmem [DSRAM_WORDS];
|
logic [31:0] shadow_dmem[DSRAM_WORDS];
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
function new();
|
function new();
|
||||||
xbar_box = new();
|
xbar_box = new();
|
||||||
foreach (shadow_dmem[i]) begin
|
foreach (shadow_dmem[i]) begin
|
||||||
shadow_dmem[i] = '0;
|
shadow_dmem[i] = '0;
|
||||||
|
end
|
||||||
|
endfunction : new
|
||||||
|
|
||||||
|
// Build a random program and enqueue frontdoor instruction writes.
|
||||||
|
// idx and prog_len are assigned before randomization because branch
|
||||||
|
// constraints depend on the instruction's position.
|
||||||
|
task gen_program(input int num, input bit verbose = 1'b1);
|
||||||
|
cpu_seq_item #(DataSize, AddrSize) instr;
|
||||||
|
cpu_ref_model shadow;
|
||||||
|
logic [31:0] program_words[$];
|
||||||
|
logic [31:0] effective_addr;
|
||||||
|
bit reachable;
|
||||||
|
int prog_len;
|
||||||
|
|
||||||
|
if ((num < 0) || (num >= ISRAM_WORDS)) begin
|
||||||
|
$fatal(1, "%0t Seq: program needs 0..%0d random instructions, got %0d", $time,
|
||||||
|
ISRAM_WORDS - 1, num);
|
||||||
|
end
|
||||||
|
|
||||||
|
prog_len = num + 1; // +1 for the ebreak
|
||||||
|
shadow = new();
|
||||||
|
shadow.load_dmem(shadow_dmem);
|
||||||
|
|
||||||
|
for (int i = 0; i < num; i++) begin
|
||||||
|
instr = new();
|
||||||
|
instr.idx = i;
|
||||||
|
instr.prog_len = prog_len;
|
||||||
|
foreach (shadow.regs[r]) begin
|
||||||
|
instr.reg_snapshot[r] = shadow.regs[r];
|
||||||
|
end
|
||||||
|
if (!instr.randomize()) begin
|
||||||
|
$fatal(1, "%0t Seq: state-aware randomization failed for instruction %0d", $time, i);
|
||||||
|
end
|
||||||
|
|
||||||
|
// Keep this independent diagnostic while c_mem_align is a member
|
||||||
|
// If it fires, the generated instruction violated the
|
||||||
|
// effective-address contract described on that constraint.
|
||||||
|
if (instr.op inside {OP_LW, OP_SW}) begin
|
||||||
|
effective_addr = instr.reg_snapshot[instr.rs1] + instr.imm;
|
||||||
|
if ((effective_addr[1:0] != 2'b00) || (effective_addr > ((DSRAM_WORDS * 4) - 4))) begin
|
||||||
|
$fatal(1, "%0t Seq: illegal effective byte address 0x%08x for %s; complete c_mem_align",
|
||||||
|
$time, effective_addr, instr.asm());
|
||||||
end
|
end
|
||||||
endfunction: new
|
end
|
||||||
|
if (verbose) begin
|
||||||
|
instr.display();
|
||||||
|
end
|
||||||
|
program_words.push_back(instr.encode());
|
||||||
|
|
||||||
// Build a random program and enqueue frontdoor instruction writes.
|
// Taken forward branches may skip generated slots. They still
|
||||||
// idx and prog_len are assigned before randomization because branch
|
// belong in instruction memory, but skipped instructions must not
|
||||||
// constraints depend on the instruction's position.
|
// change the state supplied to a later reachable instruction.
|
||||||
task gen_program(input int num, input bit verbose=1'b1);
|
reachable = !shadow.halted && (shadow.pc[11:2] == i);
|
||||||
cpu_seq_item #(DataSize, AddrSize) instr;
|
shadow.imem[i] = instr.encode();
|
||||||
cpu_ref_model shadow;
|
if (reachable) begin
|
||||||
logic [31:0] program_words [$];
|
shadow.step();
|
||||||
logic [31:0] effective_addr;
|
end
|
||||||
bit reachable;
|
end
|
||||||
int prog_len;
|
|
||||||
|
|
||||||
if ((num < 0) || (num >= ISRAM_WORDS)) begin
|
// Append ebreak explicitly so a random program cannot halt early
|
||||||
$fatal(1,
|
instr = new();
|
||||||
"%0t Seq: program needs 0..%0d random instructions, got %0d",
|
instr.idx = num;
|
||||||
$time, ISRAM_WORDS - 1, num);
|
instr.prog_len = prog_len;
|
||||||
end
|
instr.op = OP_EBREAK;
|
||||||
|
instr.rs1 = '0;
|
||||||
|
instr.rs2 = '0;
|
||||||
|
instr.rd = '0;
|
||||||
|
instr.imm = 0;
|
||||||
|
if (verbose) begin
|
||||||
|
instr.display();
|
||||||
|
end
|
||||||
|
program_words.push_back(instr.encode());
|
||||||
|
shadow.imem[num] = instr.encode();
|
||||||
|
|
||||||
prog_len = num + 1; // +1 for the ebreak
|
if (!shadow.halted && (shadow.pc[11:2] == num)) begin
|
||||||
shadow = new();
|
shadow.step();
|
||||||
shadow.load_dmem(shadow_dmem);
|
end
|
||||||
|
if (!shadow.halted) begin
|
||||||
|
$fatal(
|
||||||
|
1,
|
||||||
|
"%0t Seq: generated control flow missed the final ebreak (pc=0x%08x); complete c_branch_target",
|
||||||
|
$time, shadow.pc);
|
||||||
|
end
|
||||||
|
|
||||||
for (int i = 0; i < num; i++) begin
|
foreach (program_words[i]) begin
|
||||||
instr = new();
|
send_write_trans(word_addr(ISRAM_BASE, i), program_words[i]);
|
||||||
instr.idx = i;
|
end
|
||||||
instr.prog_len = prog_len;
|
endtask : gen_program
|
||||||
foreach (shadow.regs[r]) begin
|
|
||||||
instr.reg_snapshot[r] = shadow.regs[r];
|
|
||||||
end
|
|
||||||
if (!instr.randomize()) begin
|
|
||||||
$fatal(1, "%0t Seq: state-aware randomization failed for instruction %0d",
|
|
||||||
$time, i);
|
|
||||||
end
|
|
||||||
|
|
||||||
// Keep this independent diagnostic while c_mem_align is a member
|
// Stage one external write transaction
|
||||||
// TODO. If it fires, the generated instruction violated the
|
task send_write_trans(input logic [AddrSize-1:0] addr, input logic [DataSize-1:0] data);
|
||||||
// effective-address contract described on that constraint.
|
cpu_xbar_item #(DataSize, AddrSize) trans;
|
||||||
if (instr.op inside {OP_LW, OP_SW}) begin
|
|
||||||
effective_addr = instr.reg_snapshot[instr.rs1] + instr.imm;
|
|
||||||
if ((effective_addr[1:0] != 2'b00) ||
|
|
||||||
(effective_addr > ((DSRAM_WORDS * 4) - 4))) begin
|
|
||||||
$fatal(1,
|
|
||||||
"%0t Seq: illegal effective byte address 0x%08x for %s; complete c_mem_align",
|
|
||||||
$time, effective_addr, instr.asm());
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if (verbose) begin
|
|
||||||
instr.display();
|
|
||||||
end
|
|
||||||
program_words.push_back(instr.encode());
|
|
||||||
|
|
||||||
// Taken forward branches may skip generated slots. They still
|
trans = new();
|
||||||
// belong in instruction memory, but skipped instructions must not
|
trans.kind = XBAR_WRITE;
|
||||||
// change the state supplied to a later reachable instruction.
|
trans.addr = addr;
|
||||||
reachable = !shadow.halted && (shadow.pc[11:2] == i);
|
trans.data = data;
|
||||||
shadow.imem[i] = instr.encode();
|
trans.is_write = 1'b1;
|
||||||
if (reachable) begin
|
if ((window_of(addr) == WIN_DSRAM) && (addr[1:0] == 2'b00)) begin
|
||||||
shadow.step();
|
shadow_dmem[addr[11:2]] = data;
|
||||||
end
|
end
|
||||||
end
|
xbar_box.put(trans);
|
||||||
|
endtask : send_write_trans
|
||||||
|
|
||||||
// Append ebreak explicitly so a random program cannot halt early
|
// Stage one external read transaction
|
||||||
instr = new();
|
task send_read_trans(input logic [AddrSize-1:0] addr);
|
||||||
instr.idx = num;
|
cpu_xbar_item #(DataSize, AddrSize) trans;
|
||||||
instr.prog_len = prog_len;
|
|
||||||
instr.op = OP_EBREAK;
|
|
||||||
instr.rs1 = '0;
|
|
||||||
instr.rs2 = '0;
|
|
||||||
instr.rd = '0;
|
|
||||||
instr.imm = 0;
|
|
||||||
if (verbose) begin
|
|
||||||
instr.display();
|
|
||||||
end
|
|
||||||
program_words.push_back(instr.encode());
|
|
||||||
shadow.imem[num] = instr.encode();
|
|
||||||
|
|
||||||
if (!shadow.halted && (shadow.pc[11:2] == num)) begin
|
trans = new();
|
||||||
shadow.step();
|
trans.kind = XBAR_READ;
|
||||||
end
|
trans.addr = addr;
|
||||||
if (!shadow.halted) begin
|
trans.is_write = 1'b0;
|
||||||
$fatal(1,
|
xbar_box.put(trans);
|
||||||
"%0t Seq: generated control flow missed the final ebreak (pc=0x%08x); complete c_branch_target",
|
endtask : send_read_trans
|
||||||
$time, shadow.pc);
|
|
||||||
end
|
|
||||||
|
|
||||||
foreach (program_words[i]) begin
|
// Stage a program as instruction-memory writes starting at word zero
|
||||||
send_write_trans(word_addr(ISRAM_BASE, i), program_words[i]);
|
task load_program(const ref logic [31:0] prog[$]);
|
||||||
end
|
foreach (prog[i]) begin
|
||||||
endtask: gen_program
|
send_write_trans(word_addr(ISRAM_BASE, i), prog[i]);
|
||||||
|
end
|
||||||
|
endtask : load_program
|
||||||
|
|
||||||
// Stage one external write transaction
|
// Generate external-port traffic. cpu_xbar_item constraints define the
|
||||||
task send_write_trans(input logic [AddrSize-1:0] addr, input logic [DataSize-1:0] data);
|
// useful behavior; the mailbox mechanics are supplied.
|
||||||
cpu_xbar_item #(DataSize, AddrSize) trans;
|
task gen_xbar(input int num, input bit verbose = 1'b0);
|
||||||
|
cpu_xbar_item #(DataSize, AddrSize) trans;
|
||||||
|
|
||||||
trans = new();
|
for (int i = 0; i < num; i++) begin
|
||||||
trans.kind = XBAR_WRITE;
|
trans = new();
|
||||||
trans.addr = addr;
|
if (!trans.randomize()) begin
|
||||||
trans.data = data;
|
$error($stime, " Seq: randomization failed for xbar item %0d\n", i);
|
||||||
trans.is_write = 1'b1;
|
end
|
||||||
if ((window_of(addr) == WIN_DSRAM) && (addr[1:0] == 2'b00)) begin
|
if (verbose) begin
|
||||||
shadow_dmem[addr[11:2]] = data;
|
trans.display();
|
||||||
end
|
end
|
||||||
xbar_box.put(trans);
|
xbar_box.put(trans);
|
||||||
endtask: send_write_trans
|
end
|
||||||
|
endtask : gen_xbar
|
||||||
|
|
||||||
// Stage one external read transaction
|
// Wait until the driver has pulled every staged mailbox transaction
|
||||||
task send_read_trans(input logic [AddrSize-1:0] addr);
|
task wait_for_empty();
|
||||||
cpu_xbar_item #(DataSize, AddrSize) trans;
|
while (xbar_box.num() != 0) begin
|
||||||
|
#10;
|
||||||
|
end
|
||||||
|
endtask : wait_for_empty
|
||||||
|
|
||||||
trans = new();
|
endclass : cpu_sequencer
|
||||||
trans.kind = XBAR_READ;
|
|
||||||
trans.addr = addr;
|
|
||||||
trans.is_write = 1'b0;
|
|
||||||
xbar_box.put(trans);
|
|
||||||
endtask: send_read_trans
|
|
||||||
|
|
||||||
// Stage a program as instruction-memory writes starting at word zero
|
|
||||||
task load_program(const ref logic [31:0] prog [$]);
|
|
||||||
foreach (prog[i]) begin
|
|
||||||
send_write_trans(word_addr(ISRAM_BASE, i), prog[i]);
|
|
||||||
end
|
|
||||||
endtask: load_program
|
|
||||||
|
|
||||||
// Generate external-port traffic. cpu_xbar_item constraints define the
|
|
||||||
// useful behavior; the mailbox mechanics are supplied.
|
|
||||||
task gen_xbar(input int num, input bit verbose=1'b0);
|
|
||||||
cpu_xbar_item #(DataSize, AddrSize) trans;
|
|
||||||
|
|
||||||
for (int i = 0; i < num; i++) begin
|
|
||||||
trans = new();
|
|
||||||
if (!trans.randomize()) begin
|
|
||||||
$error($stime, " Seq: randomization failed for xbar item %0d\n", i);
|
|
||||||
end
|
|
||||||
if (verbose) begin
|
|
||||||
trans.display();
|
|
||||||
end
|
|
||||||
xbar_box.put(trans);
|
|
||||||
end
|
|
||||||
endtask: gen_xbar
|
|
||||||
|
|
||||||
// Wait until the driver has pulled every staged mailbox transaction
|
|
||||||
task wait_for_empty();
|
|
||||||
while (xbar_box.num() != 0) begin
|
|
||||||
#10;
|
|
||||||
end
|
|
||||||
endtask: wait_for_empty
|
|
||||||
|
|
||||||
endclass: cpu_sequencer
|
|
||||||
|
|||||||
+432
-232
@@ -3,272 +3,472 @@
|
|||||||
*/
|
*/
|
||||||
module cpu_tb_top;
|
module cpu_tb_top;
|
||||||
|
|
||||||
import cpu_tb_pkg::*;
|
import cpu_tb_pkg::*;
|
||||||
|
|
||||||
parameter int DataSize = DATA_W;
|
parameter int DataSize = DATA_W;
|
||||||
parameter int AddrSize = XBAR_AW;
|
parameter int AddrSize = XBAR_AW;
|
||||||
|
|
||||||
string requested_seed = "default";
|
string requested_seed = "default";
|
||||||
|
|
||||||
int assertion_errors = 0;
|
int assertion_errors = 0;
|
||||||
|
|
||||||
logic clk = 0;
|
logic clk = 0;
|
||||||
always #5 clk = ~clk;
|
always #5 clk = ~clk;
|
||||||
|
|
||||||
// IF instantiation
|
// IF instantiation
|
||||||
cpu_if #(.DataSize(DataSize), .AddrSize(AddrSize)) cpu_if(.clk(clk));
|
cpu_if #(
|
||||||
|
.DataSize(DataSize),
|
||||||
|
.AddrSize(AddrSize)
|
||||||
|
) cpu_if (
|
||||||
|
.clk(clk)
|
||||||
|
);
|
||||||
|
|
||||||
// DUT instantiation
|
// DUT instantiation
|
||||||
chip_top dut (
|
chip_top dut (
|
||||||
.clk_i(clk),
|
.clk_i(clk),
|
||||||
.rst_i(cpu_if.cpu.reset),
|
.rst_i(cpu_if.cpu.reset),
|
||||||
.en_cpu_i(cpu_if.cpu.en_cpu),
|
.en_cpu_i(cpu_if.cpu.en_cpu),
|
||||||
.halt_cpu_i(cpu_if.cpu.halt_cpu),
|
.halt_cpu_i(cpu_if.cpu.halt_cpu),
|
||||||
.cpu_halted_o(cpu_if.cpu.cpu_halted),
|
.cpu_halted_o(cpu_if.cpu.cpu_halted),
|
||||||
.addr_i(cpu_if.cpu.addr),
|
.addr_i(cpu_if.cpu.addr),
|
||||||
.wdata_i(cpu_if.cpu.wdata),
|
.wdata_i(cpu_if.cpu.wdata),
|
||||||
.w_en_i(cpu_if.cpu.w_en),
|
.w_en_i(cpu_if.cpu.w_en),
|
||||||
.r_en_i(cpu_if.cpu.r_en),
|
.r_en_i(cpu_if.cpu.r_en),
|
||||||
.rdata_o(cpu_if.cpu.rdata),
|
.rdata_o(cpu_if.cpu.rdata),
|
||||||
.rready_o(cpu_if.cpu.rready)
|
.rready_o(cpu_if.cpu.rready)
|
||||||
);
|
);
|
||||||
|
|
||||||
// Observation signals from the DUT memory path
|
// Observation signals from the DUT memory path
|
||||||
assign cpu_if.cpu_active = dut.cpu_enable_q;
|
assign cpu_if.cpu_active = dut.cpu_enable_q;
|
||||||
assign cpu_if.dsram_en = dut.dsram_en;
|
assign cpu_if.dsram_en = dut.dsram_en;
|
||||||
assign cpu_if.dsram_write_en = dut.dsram_write_en;
|
assign cpu_if.dsram_write_en = dut.dsram_write_en;
|
||||||
assign cpu_if.dsram_addr = dut.dsram_addr;
|
assign cpu_if.dsram_addr = dut.dsram_addr;
|
||||||
assign cpu_if.dsram_wdata = dut.dsram_wdata;
|
assign cpu_if.dsram_wdata = dut.dsram_wdata;
|
||||||
assign cpu_if.dsram_rdata = dut.dsram_rdata;
|
assign cpu_if.dsram_rdata = dut.dsram_rdata;
|
||||||
|
|
||||||
cpu_tb_pkg::cpu_sequencer #(.DataSize(DataSize), .AddrSize(AddrSize)) seqr;
|
cpu_tb_pkg::cpu_sequencer #(.DataSize(DataSize), .AddrSize(AddrSize)) seqr;
|
||||||
cpu_tb_pkg::cpu_driver #(.DataSize(DataSize), .AddrSize(AddrSize)) drv;
|
cpu_tb_pkg::cpu_driver #(.DataSize(DataSize), .AddrSize(AddrSize)) drv;
|
||||||
cpu_tb_pkg::cpu_monitor #(.DataSize(DataSize), .AddrSize(AddrSize)) mon;
|
cpu_tb_pkg::cpu_monitor #(.DataSize(DataSize), .AddrSize(AddrSize)) mon;
|
||||||
cpu_tb_pkg::cpu_sb #(.DataSize(DataSize), .AddrSize(AddrSize)) sb;
|
cpu_tb_pkg::cpu_sb #(.DataSize(DataSize), .AddrSize(AddrSize)) sb;
|
||||||
|
|
||||||
// Record failed assertion
|
// Record failed assertion
|
||||||
function void assertion_fail(input string message);
|
function void assertion_fail(input string message);
|
||||||
assertion_errors++;
|
assertion_errors++;
|
||||||
$error($stime, " ASSERT: %s\n", message);
|
$error($stime, " ASSERT: %s\n", message);
|
||||||
endfunction: assertion_fail
|
endfunction : assertion_fail
|
||||||
|
|
||||||
// Initialize both memories through the DUT's external memory port
|
// Initialize both memories through the DUT's external memory port
|
||||||
task automatic init_memories();
|
task automatic init_memories();
|
||||||
$display($stime, " TB: Initializing instruction and data memories\n");
|
$display($stime, " TB: Initializing instruction and data memories\n");
|
||||||
mon.log_transactions = 1'b0;
|
mon.log_transactions = 1'b0;
|
||||||
sb.log_transactions = 1'b0;
|
sb.log_transactions = 1'b0;
|
||||||
for (int i = 0; i < ISRAM_WORDS; i++) begin
|
for (int i = 0; i < ISRAM_WORDS; i++) begin
|
||||||
seqr.send_write_trans(word_addr(ISRAM_BASE, i), EBREAK_WORD);
|
seqr.send_write_trans(word_addr(ISRAM_BASE, i), EBREAK_WORD);
|
||||||
end
|
end
|
||||||
for (int i = 0; i < DSRAM_WORDS; i++) begin
|
for (int i = 0; i < DSRAM_WORDS; i++) begin
|
||||||
seqr.send_write_trans(word_addr(DSRAM_BASE, i), $urandom());
|
seqr.send_write_trans(word_addr(DSRAM_BASE, i), $urandom());
|
||||||
end
|
end
|
||||||
seqr.wait_for_empty();
|
seqr.wait_for_empty();
|
||||||
repeat (2) @(cpu_if.cb);
|
repeat (2) @(cpu_if.cb);
|
||||||
mon.log_transactions = 1'b1;
|
mon.log_transactions = 1'b1;
|
||||||
sb.log_transactions = 1'b1;
|
sb.log_transactions = 1'b1;
|
||||||
$display($stime, " TB: Memory initialization complete\n");
|
$display($stime, " TB: Memory initialization complete\n");
|
||||||
endtask: init_memories
|
endtask : init_memories
|
||||||
|
|
||||||
// Queue external reads on a memory window
|
// Queue external reads on a memory window
|
||||||
task automatic readback(input int window, input int num_words, input int start_word=0);
|
task automatic readback(input int window, input int num_words, input int start_word = 0);
|
||||||
logic [AddrSize-1:0] base;
|
logic [AddrSize-1:0] base;
|
||||||
|
|
||||||
case (window)
|
case (window)
|
||||||
0: base = ISRAM_BASE;
|
0: base = ISRAM_BASE;
|
||||||
1: base = DSRAM_BASE;
|
1: base = DSRAM_BASE;
|
||||||
2: base = REG_BASE;
|
2: base = REG_BASE;
|
||||||
default: base = REG_BASE;
|
default: base = REG_BASE;
|
||||||
endcase
|
endcase
|
||||||
|
|
||||||
for (int i = 0; i < num_words; i++) begin
|
for (int i = 0; i < num_words; i++) begin
|
||||||
seqr.send_read_trans(word_addr(base, start_word + i));
|
seqr.send_read_trans(word_addr(base, start_word + i));
|
||||||
end
|
end
|
||||||
seqr.wait_for_empty();
|
seqr.wait_for_empty();
|
||||||
repeat (4) @(cpu_if.cb);
|
repeat (4) @(cpu_if.cb);
|
||||||
endtask: readback
|
endtask : readback
|
||||||
|
|
||||||
task automatic preload_dmem(input logic [31:0] values [$], input int start_word=0);
|
task automatic preload_dmem(input logic [31:0] values[$], input int start_word = 0);
|
||||||
foreach (values[i]) begin
|
foreach (values[i]) begin
|
||||||
seqr.send_write_trans(word_addr(DSRAM_BASE, start_word + i), values[i]);
|
seqr.send_write_trans(word_addr(DSRAM_BASE, start_word + i), values[i]);
|
||||||
end
|
end
|
||||||
seqr.wait_for_empty();
|
seqr.wait_for_empty();
|
||||||
repeat (2) @(cpu_if.cb);
|
repeat (2) @(cpu_if.cb);
|
||||||
endtask: preload_dmem
|
endtask : preload_dmem
|
||||||
|
|
||||||
// Run a directed test
|
// Run a directed test
|
||||||
task automatic run_directed(input string name, const ref logic [31:0] program_words [$],
|
task automatic run_directed(input string name, const ref logic [31:0] program_words[$],
|
||||||
input int max_cycles=2000, input int dmem_words=16);
|
input int max_cycles = 2000, input int dmem_words = 16);
|
||||||
$display("");
|
$display("");
|
||||||
$display("=================================================================");
|
$display("=================================================================");
|
||||||
$display(" TEST: %s", name);
|
$display(" TEST: %s", name);
|
||||||
$display("=================================================================");
|
$display("=================================================================");
|
||||||
sb.set_test(name);
|
sb.set_test(name);
|
||||||
|
|
||||||
drv.reset_task();
|
drv.reset_task();
|
||||||
seqr.load_program(program_words);
|
seqr.load_program(program_words);
|
||||||
seqr.wait_for_empty();
|
seqr.wait_for_empty();
|
||||||
repeat (2) @(cpu_if.cb);
|
repeat (2) @(cpu_if.cb);
|
||||||
drv.run_program(max_cycles);
|
drv.run_program(max_cycles);
|
||||||
|
|
||||||
if (drv.last_run_completed) begin
|
if (drv.last_run_completed) begin
|
||||||
readback(2, REG_COUNT);
|
readback(2, REG_COUNT);
|
||||||
readback(1, dmem_words);
|
readback(1, dmem_words);
|
||||||
end else begin
|
end else begin
|
||||||
$display($stime, " TB: Skipping %s readback after CPU timeout\n", name);
|
$display($stime, " TB: Skipping %s readback after CPU timeout\n", name);
|
||||||
drv.reset_task();
|
drv.reset_task();
|
||||||
end
|
end
|
||||||
endtask: run_directed
|
endtask : run_directed
|
||||||
|
|
||||||
// Basic smoke test for loading, running, and observing a program that halts
|
// Basic smoke test for loading, running, and observing a program that halts
|
||||||
task automatic run_smoke_test();
|
task automatic run_smoke_test();
|
||||||
logic [31:0] smoke_prog [$];
|
logic [31:0] smoke_prog[$];
|
||||||
smoke_prog = '{ EBREAK_WORD };
|
smoke_prog = '{EBREAK_WORD};
|
||||||
run_directed("smoke_ebreak", smoke_prog, 100, 1);
|
run_directed("smoke_ebreak", smoke_prog, 100, 1);
|
||||||
endtask: run_smoke_test
|
endtask : run_smoke_test
|
||||||
|
|
||||||
// Smoke test for stopping the CPU from outside the program
|
// Smoke test for stopping the CPU from outside the program
|
||||||
// Readback is skipped because the CPU stops before the program completes
|
// Readback is skipped because the CPU stops before the program completes
|
||||||
task automatic run_external_halt_smoke();
|
task automatic run_external_halt_smoke();
|
||||||
logic [31:0] long_prog [$];
|
logic [31:0] long_prog[$];
|
||||||
|
|
||||||
for (int i = 0; i < 32; i++) begin
|
for (int i = 0; i < 32; i++) begin
|
||||||
long_prog.push_back(asm_instr(.op(OP_ADDI), .rd(1), .rs1(1), .imm(1)));
|
long_prog.push_back(asm_instr(.op(OP_ADDI), .rd(1), .rs1(1), .imm(1)));
|
||||||
end
|
end
|
||||||
long_prog.push_back(EBREAK_WORD);
|
long_prog.push_back(EBREAK_WORD);
|
||||||
|
|
||||||
$display("");
|
$display("");
|
||||||
$display("=================================================================");
|
$display("=================================================================");
|
||||||
$display(" TEST: smoke_external_halt");
|
$display(" TEST: smoke_external_halt");
|
||||||
$display("=================================================================");
|
$display("=================================================================");
|
||||||
sb.set_test("smoke_external_halt");
|
sb.set_test("smoke_external_halt");
|
||||||
|
|
||||||
drv.reset_task();
|
drv.reset_task();
|
||||||
seqr.load_program(long_prog);
|
seqr.load_program(long_prog);
|
||||||
seqr.wait_for_empty();
|
seqr.wait_for_empty();
|
||||||
repeat (2) @(cpu_if.cb);
|
repeat (2) @(cpu_if.cb);
|
||||||
drv.start_cpu();
|
drv.start_cpu();
|
||||||
repeat (12) @(cpu_if.cb);
|
repeat (12) @(cpu_if.cb);
|
||||||
drv.halt_cpu_now();
|
drv.halt_cpu_now();
|
||||||
drv.reset_task();
|
drv.reset_task();
|
||||||
endtask: run_external_halt_smoke
|
endtask : run_external_halt_smoke
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// TEST PROGRAM
|
// TEST PROGRAM
|
||||||
logic [31:0] prog [$];
|
logic [31:0] prog[$];
|
||||||
logic [31:0] data [$];
|
logic [31:0] data[$];
|
||||||
|
|
||||||
int NUM_RANDOM_PROGRAMS = 20;
|
int NUM_RANDOM_PROGRAMS = 20;
|
||||||
int NUM_RANDOM_XBAR = 300;
|
int NUM_RANDOM_XBAR = 300;
|
||||||
|
|
||||||
initial begin
|
initial begin
|
||||||
int total_errors;
|
int total_errors;
|
||||||
|
|
||||||
mon = new(cpu_if);
|
mon = new(cpu_if);
|
||||||
sb = new(mon.mon_box);
|
sb = new(mon.mon_box);
|
||||||
seqr = new();
|
seqr = new();
|
||||||
drv = new(cpu_if, seqr.xbar_box);
|
drv = new(cpu_if, seqr.xbar_box);
|
||||||
|
|
||||||
void'($value$plusargs("NUM_RANDOM_PROGRAMS=%d", NUM_RANDOM_PROGRAMS));
|
void'($value$plusargs("NUM_RANDOM_PROGRAMS=%d", NUM_RANDOM_PROGRAMS));
|
||||||
void'($value$plusargs("NUM_RANDOM_XBAR=%d", NUM_RANDOM_XBAR));
|
void'($value$plusargs("NUM_RANDOM_XBAR=%d", NUM_RANDOM_XBAR));
|
||||||
if ($test$plusargs("REF_TRACE")) begin
|
if ($test$plusargs("REF_TRACE")) begin
|
||||||
sb.ref_model.trace = 1'b1;
|
sb.ref_model.trace = 1'b1;
|
||||||
end
|
|
||||||
|
|
||||||
fork
|
|
||||||
mon.run();
|
|
||||||
sb.run();
|
|
||||||
drv.run();
|
|
||||||
join_none
|
|
||||||
|
|
||||||
drv.reset_task();
|
|
||||||
init_memories();
|
|
||||||
|
|
||||||
run_smoke_test();
|
|
||||||
run_external_halt_smoke();
|
|
||||||
|
|
||||||
|
|
||||||
// DIRECTED TESTS
|
|
||||||
drv.reset_task();
|
|
||||||
init_memories();
|
|
||||||
|
|
||||||
// TODO: Add directed test cases from the test plan
|
|
||||||
// Use the existing helpers
|
|
||||||
|
|
||||||
// Example Test: addi with a positive immediate
|
|
||||||
prog = '{
|
|
||||||
asm_instr(.op(OP_ADDI), .rd(1), .rs1(0), .imm(5)),
|
|
||||||
asm_instr(.op(OP_ADDI), .rd(2), .rs1(1), .imm(100)),
|
|
||||||
EBREAK_WORD
|
|
||||||
};
|
|
||||||
run_directed("addi_positive", prog);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// CONSTRAINED-RANDOM TESTS
|
|
||||||
// TODO: Add constrained-randomized testing for cpu_seq_item and cpu_xbar_item
|
|
||||||
// For every random CPU program:
|
|
||||||
// 1. print an iteration label so the seed and failure are reproducible,
|
|
||||||
// 2. reset the CPU and call init_memories() before gen_program(),
|
|
||||||
// 3. wait for program writes, run with the supplied bounded helper,
|
|
||||||
// 4. queue the register and relevant memory reads needed by the scoreboard.
|
|
||||||
// Keep randomized external-port traffic in a phase where the CPU is stopped.
|
|
||||||
// The README explains why memory must be reinitialized every iteration.
|
|
||||||
|
|
||||||
|
|
||||||
// TEST FINISH
|
|
||||||
repeat (20) @(cpu_if.cb);
|
|
||||||
total_errors = sb.errors + drv.timeouts + mon.errors + assertion_errors;
|
|
||||||
if (sb.checks == 0) begin
|
|
||||||
$error("Testbench performed zero checks; no results were verified");
|
|
||||||
end
|
|
||||||
|
|
||||||
$display("=================================================================");
|
|
||||||
$display(" Scoreboard mismatches : %0d", sb.errors);
|
|
||||||
$display(" Driver timeouts : %0d", drv.timeouts);
|
|
||||||
$display(" Monitor protocol errs : %0d", mon.errors);
|
|
||||||
$display(" Assertion failures : %0d", assertion_errors);
|
|
||||||
$display("=================================================================");
|
|
||||||
$display();
|
|
||||||
|
|
||||||
if (total_errors == 0) begin
|
|
||||||
$display("=================================================================");
|
|
||||||
$display(" TEST PASSED!");
|
|
||||||
$display("=================================================================");
|
|
||||||
end else begin
|
|
||||||
$display("=================================================================");
|
|
||||||
$display(" TEST FAILED: %0d error(s)", total_errors);
|
|
||||||
$display("=================================================================");
|
|
||||||
end
|
|
||||||
$finish;
|
|
||||||
end
|
end
|
||||||
|
|
||||||
// Stop a broken DUT or testbench instead of letting the simulation run forever
|
fork
|
||||||
initial begin
|
mon.run();
|
||||||
#10ms;
|
sb.run();
|
||||||
$display(" TEST FAILED - global timeout");
|
drv.run();
|
||||||
$fatal(1, "global timeout");
|
join_none
|
||||||
|
|
||||||
|
drv.reset_task();
|
||||||
|
init_memories();
|
||||||
|
|
||||||
|
run_smoke_test();
|
||||||
|
run_external_halt_smoke();
|
||||||
|
|
||||||
|
|
||||||
|
// DIRECTED TESTS
|
||||||
|
drv.reset_task();
|
||||||
|
init_memories();
|
||||||
|
|
||||||
|
// TODO: Add directed test cases from the test plan
|
||||||
|
// Use the existing helpers
|
||||||
|
|
||||||
|
// Example Test: addi with a positive immediate
|
||||||
|
prog = '{
|
||||||
|
asm_instr(.op(OP_ADDI), .rd(1), .rs1(0), .imm(5)),
|
||||||
|
asm_instr(.op(OP_ADDI), .rd(2), .rs1(1), .imm(100)),
|
||||||
|
EBREAK_WORD
|
||||||
|
};
|
||||||
|
run_directed("addi_positive", prog);
|
||||||
|
|
||||||
|
prog = '{
|
||||||
|
asm_instr(.op(OP_ADDI), .rd(1), .rs1(0), .imm(-1)),
|
||||||
|
asm_instr(.op(OP_ADDI), .rd(2), .rs1(0), .imm(-1)),
|
||||||
|
asm_instr(.op(OP_ADD), .rd(2), .rs1(1), .rs2(2)),
|
||||||
|
EBREAK_WORD
|
||||||
|
};
|
||||||
|
run_directed("add_overflow", prog);
|
||||||
|
|
||||||
|
prog = '{
|
||||||
|
asm_instr(.op(OP_ADDI), .rd(1), .rs1(0), .imm(-1)),
|
||||||
|
asm_instr(.op(OP_ADDI), .rd(1), .rs1(1), .imm(1)),
|
||||||
|
EBREAK_WORD
|
||||||
|
};
|
||||||
|
run_directed("addi_overflow", prog);
|
||||||
|
|
||||||
|
prog = '{
|
||||||
|
asm_instr(.op(OP_ADDI), .rd(1), .rs1(0), .imm(1)),
|
||||||
|
asm_instr(.op(OP_ADDI), .rd(1), .rs1(1), .imm(-1)),
|
||||||
|
EBREAK_WORD
|
||||||
|
};
|
||||||
|
run_directed("addi_negative", prog);
|
||||||
|
|
||||||
|
prog = '{
|
||||||
|
asm_instr(.op(OP_ADDI), .rd(1), .rs1(0), .imm('h123)),
|
||||||
|
asm_instr(.op(OP_ADDI), .rd(2), .rs1(0), .imm('h123)),
|
||||||
|
asm_instr(.op(OP_ADD), .rd(2), .rs1(1), .rs2(2)),
|
||||||
|
EBREAK_WORD
|
||||||
|
};
|
||||||
|
run_directed("add_typical", prog);
|
||||||
|
|
||||||
|
prog = '{asm_instr(.op(OP_ADDI), .rd(1), .rs1(0), .imm('h123)), EBREAK_WORD};
|
||||||
|
run_directed("addi_typical", prog);
|
||||||
|
|
||||||
|
prog = '{asm_instr(.op(OP_ADDI), .rd(1), .rs1(0), .imm(-1)), EBREAK_WORD};
|
||||||
|
run_directed("addi_negative_overflow", prog);
|
||||||
|
|
||||||
|
prog = '{
|
||||||
|
asm_instr(.op(OP_ADDI), .rd(1), .rs1(0), .imm(1)),
|
||||||
|
asm_instr(.op(OP_SUB), .rd(1), .rs1(0), .rs2(1)),
|
||||||
|
EBREAK_WORD
|
||||||
|
};
|
||||||
|
run_directed("sub_overflow", prog);
|
||||||
|
|
||||||
|
prog = '{
|
||||||
|
asm_instr(.op(OP_ADDI), .rd(1), .rs1(0), .imm('h123)),
|
||||||
|
asm_instr(.op(OP_ADDI), .rd(2), .rs1(0), .imm('h23)),
|
||||||
|
asm_instr(.op(OP_SUB), .rd(2), .rs1(1), .rs2(2)),
|
||||||
|
EBREAK_WORD
|
||||||
|
};
|
||||||
|
run_directed("sub_typical", prog);
|
||||||
|
|
||||||
|
prog = '{
|
||||||
|
asm_instr(.op(OP_ADDI), .rd(1), .rs1(0), .imm(-1)),
|
||||||
|
asm_instr(.op(OP_ADDI), .rd(2), .rs1(0), .imm(32)),
|
||||||
|
asm_instr(.op(OP_SRL), .rd(1), .rs1(1), .rs2(2)),
|
||||||
|
EBREAK_WORD
|
||||||
|
};
|
||||||
|
run_directed("srl_oob", prog);
|
||||||
|
|
||||||
|
prog = '{
|
||||||
|
asm_instr(.op(OP_ADDI), .rd(1), .rs1(0), .imm(-1)),
|
||||||
|
asm_instr(.op(OP_ADDI), .rd(2), .rs1(0), .imm(32)),
|
||||||
|
asm_instr(.op(OP_SLL), .rd(1), .rs1(1), .rs2(2)),
|
||||||
|
EBREAK_WORD
|
||||||
|
};
|
||||||
|
run_directed("sll_oob", prog);
|
||||||
|
|
||||||
|
prog = '{
|
||||||
|
asm_instr(.op(OP_ADDI), .rd(1), .rs1(0), .imm(-1)),
|
||||||
|
asm_instr(.op(OP_SLL), .rd(1), .rs1(1), .rs2(0)),
|
||||||
|
EBREAK_WORD
|
||||||
|
};
|
||||||
|
run_directed("sll_zero", prog);
|
||||||
|
|
||||||
|
prog = '{
|
||||||
|
asm_instr(.op(OP_ADDI), .rd(1), .rs1(0), .imm(-1)),
|
||||||
|
asm_instr(.op(OP_SRL), .rd(1), .rs1(1), .rs2(0)),
|
||||||
|
EBREAK_WORD
|
||||||
|
};
|
||||||
|
run_directed("srl_zero", prog);
|
||||||
|
|
||||||
|
prog = '{
|
||||||
|
asm_instr(.op(OP_ADDI), .rd(1), .rs1(0), .imm(-1)),
|
||||||
|
asm_instr(.op(OP_ADDI), .rd(2), .rs1(0), .imm(1)),
|
||||||
|
asm_instr(.op(OP_SLL), .rd(1), .rs1(1), .rs2(2)),
|
||||||
|
EBREAK_WORD
|
||||||
|
};
|
||||||
|
run_directed("sll_one", prog);
|
||||||
|
|
||||||
|
prog = '{
|
||||||
|
asm_instr(.op(OP_ADDI), .rd(1), .rs1(0), .imm(-1)),
|
||||||
|
asm_instr(.op(OP_ADDI), .rd(2), .rs1(0), .imm(1)),
|
||||||
|
asm_instr(.op(OP_SRL), .rd(1), .rs1(1), .rs2(2)),
|
||||||
|
EBREAK_WORD
|
||||||
|
};
|
||||||
|
run_directed("srl_one", prog);
|
||||||
|
|
||||||
|
prog = '{
|
||||||
|
asm_instr(.op(OP_ADDI), .rd(1), .rs1(0), .imm(-1)),
|
||||||
|
asm_instr(.op(OP_ADDI), .rd(2), .rs1(0), .imm(4)),
|
||||||
|
asm_instr(.op(OP_SLL), .rd(1), .rs1(1), .rs2(2)),
|
||||||
|
EBREAK_WORD
|
||||||
|
};
|
||||||
|
run_directed("sll_typical", prog);
|
||||||
|
|
||||||
|
prog = '{
|
||||||
|
asm_instr(.op(OP_ADDI), .rd(1), .rs1(0), .imm(-1)),
|
||||||
|
asm_instr(.op(OP_ADDI), .rd(2), .rs1(0), .imm(4)),
|
||||||
|
asm_instr(.op(OP_SRL), .rd(1), .rs1(1), .rs2(2)),
|
||||||
|
EBREAK_WORD
|
||||||
|
};
|
||||||
|
run_directed("srl_typical", prog);
|
||||||
|
|
||||||
|
prog = '{asm_instr(.op(OP_LW), .rd(1), .rs1(0), .imm(0)), EBREAK_WORD};
|
||||||
|
run_directed("lw_zero_offset", prog);
|
||||||
|
|
||||||
|
prog = '{
|
||||||
|
asm_instr(.op(OP_ADDI), .rd(1), .rs1(0), .imm(-1)),
|
||||||
|
asm_instr(.op(OP_SW), .rs1(0), .rs2(1), .imm(0)),
|
||||||
|
EBREAK_WORD
|
||||||
|
};
|
||||||
|
run_directed("sw_zero_offset", prog);
|
||||||
|
|
||||||
|
prog = '{asm_instr(.op(OP_LW), .rd(1), .rs1(0), .imm(4)), EBREAK_WORD};
|
||||||
|
run_directed("lw_positive", prog);
|
||||||
|
|
||||||
|
prog = '{
|
||||||
|
asm_instr(.op(OP_ADDI), .rd(1), .rs1(0), .imm(-1)),
|
||||||
|
asm_instr(.op(OP_SW), .rs1(0), .rs2(1), .imm(4)),
|
||||||
|
EBREAK_WORD
|
||||||
|
};
|
||||||
|
run_directed("sw_positive", prog);
|
||||||
|
|
||||||
|
prog = '{
|
||||||
|
asm_instr(.op(OP_ADDI), .rd(1), .rs1(0), .imm(64)),
|
||||||
|
asm_instr(.op(OP_LW), .rd(2), .rs1(1), .imm(-4)),
|
||||||
|
EBREAK_WORD
|
||||||
|
};
|
||||||
|
run_directed("lw_negative", prog);
|
||||||
|
|
||||||
|
prog = '{
|
||||||
|
asm_instr(.op(OP_ADDI), .rd(1), .rs1(0), .imm(64)),
|
||||||
|
asm_instr(.op(OP_ADDI), .rd(2), .rs1(0), .imm(-1)),
|
||||||
|
asm_instr(.op(OP_SW), .rs1(1), .rs2(2), .imm(-4)),
|
||||||
|
EBREAK_WORD
|
||||||
|
};
|
||||||
|
run_directed("sw_negative", prog);
|
||||||
|
|
||||||
|
prog = '{asm_instr(.op(OP_LW), .rd(0), .rs1(0), .imm(0)), EBREAK_WORD};
|
||||||
|
run_directed("lw_x0", prog);
|
||||||
|
|
||||||
|
prog = '{
|
||||||
|
asm_instr(.op(OP_BEQ), .rs1(0), .rs2(0), .imm(8)),
|
||||||
|
asm_instr(.op(OP_ADDI), .rd(1), .rs1(0), .imm(1)),
|
||||||
|
asm_instr(.op(OP_ADDI), .rd(1), .rs1(0), .imm(2)),
|
||||||
|
EBREAK_WORD
|
||||||
|
};
|
||||||
|
run_directed("beq_x0", prog);
|
||||||
|
|
||||||
|
prog = '{
|
||||||
|
asm_instr(.op(OP_ADDI), .rd(1), .rs1(0), .imm(-1)),
|
||||||
|
asm_instr(.op(OP_BEQ), .rs1(0), .rs2(1), .imm(8)),
|
||||||
|
asm_instr(.op(OP_ADDI), .rd(2), .rs1(0), .imm(-1)),
|
||||||
|
EBREAK_WORD
|
||||||
|
};
|
||||||
|
run_directed("beq_not_taken", prog);
|
||||||
|
|
||||||
|
prog = '{
|
||||||
|
asm_instr(.op(OP_ADDI), .rd(1), .rs1(0), .imm(-1)),
|
||||||
|
asm_instr(.op(OP_ADDI), .rd(2), .rs1(0), .imm(-1)),
|
||||||
|
asm_instr(.op(OP_BEQ), .rs1(1), .rs2(2), .imm(8)),
|
||||||
|
asm_instr(.op(OP_ADDI), .rd(3), .rs1(0), .imm(1)),
|
||||||
|
asm_instr(.op(OP_ADDI), .rd(3), .rs1(0), .imm(2)),
|
||||||
|
EBREAK_WORD
|
||||||
|
};
|
||||||
|
run_directed("beq_typical", prog);
|
||||||
|
|
||||||
|
prog = '{EBREAK_WORD, asm_instr(.op(OP_ADDI), .rd(1), .rs1(0), .imm(-1))};
|
||||||
|
run_directed("ebreak_immediately", prog);
|
||||||
|
|
||||||
|
prog = '{
|
||||||
|
asm_instr(.op(OP_ADDI), .rd(1), .rs1(0), .imm(3)),
|
||||||
|
asm_instr(.op(OP_ADDI), .rd(1), .rs1(1), .imm(-1)),
|
||||||
|
asm_instr(.op(OP_BEQ), .rs1(1), .rs2(0), .imm(8)),
|
||||||
|
asm_instr(.op(OP_BEQ), .rs1(0), .rs2(0), .imm(-8)),
|
||||||
|
EBREAK_WORD
|
||||||
|
};
|
||||||
|
run_directed("beq_backward_loop", prog);
|
||||||
|
|
||||||
|
// CONSTRAINED-RANDOM TESTS
|
||||||
|
// TODO: Add constrained-randomized testing for cpu_seq_item and cpu_xbar_item
|
||||||
|
// For every random CPU program:
|
||||||
|
// 1. print an iteration label so the seed and failure are reproducible,
|
||||||
|
// 2. reset the CPU and call init_memories() before gen_program(),
|
||||||
|
// 3. wait for program writes, run with the supplied bounded helper,
|
||||||
|
// 4. queue the register and relevant memory reads needed by the scoreboard.
|
||||||
|
// Keep randomized external-port traffic in a phase where the CPU is stopped.
|
||||||
|
// The README explains why memory must be reinitialized every iteration.
|
||||||
|
|
||||||
|
|
||||||
|
// TEST FINISH
|
||||||
|
repeat (20) @(cpu_if.cb);
|
||||||
|
total_errors = sb.errors + drv.timeouts + mon.errors + assertion_errors;
|
||||||
|
if (sb.checks == 0) begin
|
||||||
|
$error("Testbench performed zero checks; no results were verified");
|
||||||
end
|
end
|
||||||
|
|
||||||
initial begin
|
$display("=================================================================");
|
||||||
void'($value$plusargs("SEED_LABEL=%s", requested_seed));
|
$display(" Scoreboard mismatches : %0d", sb.errors);
|
||||||
if ($test$plusargs("BUG_HUNT_WAVES")) begin
|
$display(" Driver timeouts : %0d", drv.timeouts);
|
||||||
$shm_open("bug_hunt_waves.shm");
|
$display(" Monitor protocol errs : %0d", mon.errors);
|
||||||
end else begin
|
$display(" Assertion failures : %0d", assertion_errors);
|
||||||
$shm_open("waves.shm");
|
$display("=================================================================");
|
||||||
end
|
$display();
|
||||||
$shm_probe("AC");
|
|
||||||
|
if (total_errors == 0) begin
|
||||||
|
$display("=================================================================");
|
||||||
|
$display(" TEST PASSED!");
|
||||||
|
$display("=================================================================");
|
||||||
|
end else begin
|
||||||
|
$display("=================================================================");
|
||||||
|
$display(" TEST FAILED: %0d error(s)", total_errors);
|
||||||
|
$display("=================================================================");
|
||||||
end
|
end
|
||||||
|
$finish;
|
||||||
|
end
|
||||||
|
|
||||||
wire rst = cpu_if.reset;
|
// Stop a broken DUT or testbench instead of letting the simulation run forever
|
||||||
// TODO: Add the required protocol or control assertions from the testplan
|
initial begin
|
||||||
|
#10ms;
|
||||||
|
$display(" TEST FAILED - global timeout");
|
||||||
|
$fatal(1, "global timeout");
|
||||||
|
end
|
||||||
|
|
||||||
// Example assertion
|
initial begin
|
||||||
// It checks one interface rule and sends failures through the testbench counter
|
void'($value$plusargs("SEED_LABEL=%s", requested_seed));
|
||||||
NO_SIMULTANEOUS_READ_WRITE:
|
if ($test$plusargs("BUG_HUNT_WAVES")) begin
|
||||||
assert property (@(posedge clk) disable iff (rst)
|
$shm_open("bug_hunt_waves.shm");
|
||||||
!(cpu_if.w_en && cpu_if.r_en))
|
end else begin
|
||||||
else assertion_fail("w_en_i and r_en_i were asserted together");
|
$shm_open("waves.shm");
|
||||||
|
end
|
||||||
|
$shm_probe("AC");
|
||||||
|
end
|
||||||
|
|
||||||
endmodule: cpu_tb_top
|
wire rst = cpu_if.reset;
|
||||||
|
|
||||||
|
// Example assertion
|
||||||
|
// It checks one interface rule and sends failures through the testbench counter
|
||||||
|
NO_SIMULTANEOUS_READ_WRITE :
|
||||||
|
assert property (@(posedge clk) disable iff (rst) !(cpu_if.w_en && cpu_if.r_en))
|
||||||
|
else assertion_fail("w_en_i and r_en_i were asserted together");
|
||||||
|
|
||||||
|
X0_REMAINS_0 :
|
||||||
|
assert property (@(posedge clk) disable iff (rst) dut.register_crossbar[0] == 32'b0)
|
||||||
|
else assertion_fail("x0 is nonzero");
|
||||||
|
|
||||||
|
STABLE_WHEN_DISABLED :
|
||||||
|
assert property (@(posedge clk) disable iff (rst)
|
||||||
|
(!cpu_if.en_cpu || !cpu_if.cpu_active) |=> ($stable(
|
||||||
|
dut.register_crossbar
|
||||||
|
)))
|
||||||
|
else assertion_fail("register file/pc changed while cpu inactive");
|
||||||
|
endmodule : cpu_tb_top
|
||||||
|
|||||||
+108
-78
@@ -49,45 +49,45 @@ small area to debug.
|
|||||||
- SRL
|
- SRL
|
||||||
- EBREAK
|
- EBREAK
|
||||||
|
|
||||||
| Test ID | Test name | Functionality being tested | Expected result | Status |
|
| Test ID | Test name | Functionality being tested | Expected result | Status |
|
||||||
| ------- | -------------------------------- | ---------------------------------------- | ------------------------------------------------------------------ | ------- |
|
| ------- | ---------------------------------- | ---------------------------------------- | ------------------------------------------------------------------ | ------- |
|
||||||
| 1.1 | add overflow | add two regs causing an overflow | overflow discarded | Planned |
|
| 1.1 | `add_overflow` | add two regs causing an overflow | overflow discarded | Planned |
|
||||||
| 1.2 | addi overflow | add imm to reg causing an overflow | overflow discarded | Planned |
|
| 1.2 | `addi_overflow` | add imm to reg causing an overflow | overflow discarded | Planned |
|
||||||
| 1.3 | addi negative | add negative imm | imm is subtracted | Planned |
|
| 1.3 | `addi_negative` | add negative imm | imm is subtracted | Planned |
|
||||||
| 1.4 | add typical | add two regs | regs added properly | Planned |
|
| 1.4 | `add_typical` | add two regs | regs added properly | Planned |
|
||||||
| 1.5 | addi typical | add imm to reg | imm added properly | Planned |
|
| 1.5 | `addi_typical` | add imm to reg | imm added properly | Planned |
|
||||||
| 1.6 | addi negative overflow | add negative numbers causing an overflow | negative overflow wrap around | Planned |
|
| 1.6 | `addi_negative_overflow` | add negative numbers causing an overflow | negative overflow wrap around | Planned |
|
||||||
| 1.7 | sub overflow | subtract two regs causing an overflow | negative overflow wrap around | Planned |
|
| 1.7 | `sub_overflow` | subtract two regs causing an overflow | negative overflow wrap around | Planned |
|
||||||
| 1.8 | sub typical | subtract two regs | regs subtracted properly | Planned |
|
| 1.8 | `sub_typical` | subtract two regs | regs subtracted properly | Planned |
|
||||||
| 1.9 | sll oob | shift left by larger than 2^5 bits | left shift constrainted to 2^5 | Planned |
|
| 1.9 | `sll_oob` | shift left by larger than 2^5 bits | left shift constrainted to 2^5 | Planned |
|
||||||
| 1.10 | srl oob | shift right by larger than 2^5 bits | right shift constrainted to 2^5 | Planned |
|
| 1.10 | `srl_oob` | shift right by larger than 2^5 bits | right shift constrainted to 2^5 | Planned |
|
||||||
| 1.11 | sll zero | shift left by zero bits | no shift | Planned |
|
| 1.11 | `sll_zero` | shift left by zero bits | no shift | Planned |
|
||||||
| 1.12 | srl zero | shift right by zero bits | no shift | Planned |
|
| 1.12 | `srl_zero` | shift right by zero bits | no shift | Planned |
|
||||||
| 1.13 | sll one | shift left by one bit | logical left shift by one bit | Planned |
|
| 1.13 | `sll_one` | shift left by one bit | logical left shift by one bit | Planned |
|
||||||
| 1.14 | srl one | shift right by one bit | logical right shift by one bit | Planned |
|
| 1.14 | `srl_one` | shift right by one bit | logical right shift by one bit | Planned |
|
||||||
| 1.15 | sll typical | shift left by <2^5 bits | correct logical left shift | Planned |
|
| 1.15 | `sll_typical` | shift left by <2^5 bits | correct logical left shift | Planned |
|
||||||
| 1.16 | srl typical | shift right by <2^5 bits | correct logical right shift | Planned |
|
| 1.16 | `srl_typical` | shift right by <2^5 bits | correct logical right shift | Planned |
|
||||||
| 1.17 | lw zero offset | lw with zero offset | zero offset computed | Planned |
|
| 1.17 | `lw_zero_offset` | lw with zero offset | zero offset computed | Planned |
|
||||||
| 1.18 | sw zero offset | sw with zero offset | zero offset computed + stored | Planned |
|
| 1.18 | `sw_zero_offset` | sw with zero offset | zero offset computed + stored | Planned |
|
||||||
| 1.19 | lw positive | lw with positive offset | correct offset computed | Planned |
|
| 1.19 | `lw_positive` | lw with positive offset | correct offset computed | Planned |
|
||||||
| 1.20 | sw positive | sw with positive offset | correct offset computed + stored | Planned |
|
| 1.20 | `sw_positive` | sw with positive offset | correct offset computed + stored | Planned |
|
||||||
| 1.21 | lw negative | lw with negative offset | correct offset computed | Planned |
|
| 1.21 | `lw_negative` | lw with negative offset | correct offset computed | Planned |
|
||||||
| 1.22 | sw negative | sw with negative offset | correct offset computed + stored | Planned |
|
| 1.22 | `sw_negative` | sw with negative offset | correct offset computed + stored | Planned |
|
||||||
| 1.23 | lw x0 | lw into x0 reg | write discarded, x0 remains 0 | Planned |
|
| 1.23 | `lw_x0` | lw into x0 reg | write discarded, x0 remains 0 | Planned |
|
||||||
| 1.24 | beq x0 | beq with both regs as x0 | take branch | Planned |
|
| 1.24 | `beq_x0` | beq with both regs as x0 | take branch | Planned |
|
||||||
| 1.25 | beq not taken | beq with non-equal regs | branch not taken | Planned |
|
| 1.25 | `beq_not_taken` | beq with non-equal regs | branch not taken | Planned |
|
||||||
| 1.26 | beq typical | beq with equal regs | branch taken | Planned |
|
| 1.26 | `beq_typical` | beq with equal regs | branch taken | Planned |
|
||||||
| 1.27 | ebreak immediately | ebreak as first instruction | halt CPU | Planned |
|
| 1.27 | `ebreak_immediately` | ebreak as first instruction | halt CPU | Planned |
|
||||||
| 1.28 | beq backward loop | beq used as a backward branch | loop runs to completion | Planned |
|
| 1.28 | `beq_backward_loop` | beq used as a backward branch | loop runs to completion | Planned |
|
||||||
| 1.29 | reset while running | rst_i asserted mid-program | registers clear, execution does not resume | Planned |
|
| 1.29 | `reset_while_running` | rst_i asserted mid-program | registers clear, execution does not resume | Planned |
|
||||||
| 1.30 | external halt | halt_cpu_i pulsed mid-program | CPU stops short of completion, memory ownership returns externally | Planned |
|
| 1.30 | `external_halt` | halt_cpu_i pulsed mid-program | CPU stops short of completion, memory ownership returns externally | Planned |
|
||||||
| 1.31 | isram boundary words | external access to isram word 0 and 1023 | both words read back correctly, no aliasing | Planned |
|
| 1.31 | `isram_boundary_words` | external access to isram word 0 and 1023 | both words read back correctly, no aliasing | Planned |
|
||||||
| 1.32 | dsram boundary words | external access to dsram word 0 and 1023 | both words read back correctly, no aliasing | Planned |
|
| 1.32 | `dsram_boundary_words` | external access to dsram word 0 and 1023 | both words read back correctly, no aliasing | Planned |
|
||||||
| 1.33 | external register boundary reads | external read of x0 and x31 | x0 reads 0, x31 reads the value the CPU wrote | Planned |
|
| 1.33 | `external_register_boundary_reads` | external read of x0 and x31 | x0 reads 0, x31 reads the value the CPU wrote | Planned |
|
||||||
|
|
||||||
### Functional-test details
|
### Functional-test details
|
||||||
|
|
||||||
### 1.1 — `add overflow`
|
### 1.1 — `add_overflow`
|
||||||
|
|
||||||
**Functionality:** add two registers together that would cause an overflow
|
**Functionality:** add two registers together that would cause an overflow
|
||||||
|
|
||||||
@@ -108,6 +108,7 @@ prog = '{
|
|||||||
asm_instr(.op(OP_ADD), .rd(2), .rs1(1), .rs2(2)),
|
asm_instr(.op(OP_ADD), .rd(2), .rs1(1), .rs2(2)),
|
||||||
EBREAK_WORD
|
EBREAK_WORD
|
||||||
};
|
};
|
||||||
|
run_directed("add_overflow", prog);
|
||||||
```
|
```
|
||||||
|
|
||||||
**Expected result:**
|
**Expected result:**
|
||||||
@@ -120,7 +121,7 @@ prog = '{
|
|||||||
|
|
||||||
**Final result:** <!-- Complete in testplan_final.md: pass/fail and useful log or waveform reference. -->
|
**Final result:** <!-- Complete in testplan_final.md: pass/fail and useful log or waveform reference. -->
|
||||||
|
|
||||||
### 1.2 — `addi overflow`
|
### 1.2 — `addi_overflow`
|
||||||
|
|
||||||
**Functionality:** add an immediate to a register that would cause an overflow
|
**Functionality:** add an immediate to a register that would cause an overflow
|
||||||
|
|
||||||
@@ -140,6 +141,7 @@ prog = '{
|
|||||||
asm_instr(.op(OP_ADDI), .rd(1), .rs1(1), .imm(1)),
|
asm_instr(.op(OP_ADDI), .rd(1), .rs1(1), .imm(1)),
|
||||||
EBREAK_WORD
|
EBREAK_WORD
|
||||||
};
|
};
|
||||||
|
run_directed("addi_overflow", prog);
|
||||||
```
|
```
|
||||||
|
|
||||||
**Expected result:**
|
**Expected result:**
|
||||||
@@ -152,7 +154,7 @@ prog = '{
|
|||||||
|
|
||||||
**Final result:** <!-- Complete in testplan_final.md: pass/fail and useful log or waveform reference. -->
|
**Final result:** <!-- Complete in testplan_final.md: pass/fail and useful log or waveform reference. -->
|
||||||
|
|
||||||
### 1.3 — `addi negative`
|
### 1.3 — `addi_negative`
|
||||||
|
|
||||||
**Functionality:** adds a negative value to a register using addi, effectively subtracting from that register
|
**Functionality:** adds a negative value to a register using addi, effectively subtracting from that register
|
||||||
|
|
||||||
@@ -172,6 +174,7 @@ prog = '{
|
|||||||
asm_instr(.op(OP_ADDI), .rd(1), .rs1(1), .imm(-1)),
|
asm_instr(.op(OP_ADDI), .rd(1), .rs1(1), .imm(-1)),
|
||||||
EBREAK_WORD
|
EBREAK_WORD
|
||||||
};
|
};
|
||||||
|
run_directed("addi_negative", prog);
|
||||||
```
|
```
|
||||||
|
|
||||||
**Expected result:**
|
**Expected result:**
|
||||||
@@ -184,7 +187,7 @@ prog = '{
|
|||||||
|
|
||||||
**Final result:** <!-- Complete in testplan_final.md: pass/fail and useful log or waveform reference. -->
|
**Final result:** <!-- Complete in testplan_final.md: pass/fail and useful log or waveform reference. -->
|
||||||
|
|
||||||
### 1.4 — `add typical`
|
### 1.4 — `add_typical`
|
||||||
|
|
||||||
**Functionality:** add two registers with values that will not cause an overflow
|
**Functionality:** add two registers with values that will not cause an overflow
|
||||||
|
|
||||||
@@ -200,11 +203,12 @@ prog = '{
|
|||||||
|
|
||||||
```systemverilog
|
```systemverilog
|
||||||
prog = '{
|
prog = '{
|
||||||
asm_instr(.op(OP_ADDI), .rd(1), .rs1(0), .imm(0x123)),
|
asm_instr(.op(OP_ADDI), .rd(1), .rs1(0), .imm('h123)),
|
||||||
asm_instr(.op(OP_ADDI), .rd(2), .rs1(0), .imm(0x123)),
|
asm_instr(.op(OP_ADDI), .rd(2), .rs1(0), .imm('h123)),
|
||||||
asm_instr(.op(OP_ADD), .rd(2), .rs1(1), .rs2(2)),
|
asm_instr(.op(OP_ADD), .rd(2), .rs1(1), .rs2(2)),
|
||||||
EBREAK_WORD
|
EBREAK_WORD
|
||||||
};
|
};
|
||||||
|
run_directed("add_typical", prog);
|
||||||
```
|
```
|
||||||
|
|
||||||
**Expected result:**
|
**Expected result:**
|
||||||
@@ -217,7 +221,7 @@ prog = '{
|
|||||||
|
|
||||||
**Final result:** <!-- Complete in testplan_final.md: pass/fail and useful log or waveform reference. -->
|
**Final result:** <!-- Complete in testplan_final.md: pass/fail and useful log or waveform reference. -->
|
||||||
|
|
||||||
### 1.5 — `addi typical`
|
### 1.5 — `addi_typical`
|
||||||
|
|
||||||
**Functionality:** addi with immediate added to register without causing an overflow
|
**Functionality:** addi with immediate added to register without causing an overflow
|
||||||
|
|
||||||
@@ -233,9 +237,10 @@ prog = '{
|
|||||||
|
|
||||||
```systemverilog
|
```systemverilog
|
||||||
prog = '{
|
prog = '{
|
||||||
asm_instr(.op(OP_ADDI), .rd(1), .rs1(0), .imm(0x123)),
|
asm_instr(.op(OP_ADDI), .rd(1), .rs1(0), .imm('h123)),
|
||||||
EBREAK_WORD
|
EBREAK_WORD
|
||||||
};
|
};
|
||||||
|
run_directed("addi_typical", prog);
|
||||||
```
|
```
|
||||||
|
|
||||||
**Expected result:**
|
**Expected result:**
|
||||||
@@ -248,7 +253,7 @@ prog = '{
|
|||||||
|
|
||||||
**Final result:** <!-- Complete in testplan_final.md: pass/fail and useful log or waveform reference. -->
|
**Final result:** <!-- Complete in testplan_final.md: pass/fail and useful log or waveform reference. -->
|
||||||
|
|
||||||
### 1.6 — `addi negative overflow`
|
### 1.6 — `addi_negative_overflow`
|
||||||
|
|
||||||
**Functionality:** addi with a negative number causes an overflow wrap around to the register
|
**Functionality:** addi with a negative number causes an overflow wrap around to the register
|
||||||
|
|
||||||
@@ -267,6 +272,7 @@ prog = '{
|
|||||||
asm_instr(.op(OP_ADDI), .rd(1), .rs1(0), .imm(-1)),
|
asm_instr(.op(OP_ADDI), .rd(1), .rs1(0), .imm(-1)),
|
||||||
EBREAK_WORD
|
EBREAK_WORD
|
||||||
};
|
};
|
||||||
|
run_directed("addi_negative_overflow", prog);
|
||||||
```
|
```
|
||||||
|
|
||||||
**Expected result:**
|
**Expected result:**
|
||||||
@@ -279,7 +285,7 @@ prog = '{
|
|||||||
|
|
||||||
**Final result:** <!-- Complete in testplan_final.md: pass/fail and useful log or waveform reference. -->
|
**Final result:** <!-- Complete in testplan_final.md: pass/fail and useful log or waveform reference. -->
|
||||||
|
|
||||||
### 1.7 — `sub overflow`
|
### 1.7 — `sub_overflow`
|
||||||
|
|
||||||
**Functionality:** sub registers that would cause an overflow wrap around
|
**Functionality:** sub registers that would cause an overflow wrap around
|
||||||
|
|
||||||
@@ -299,6 +305,7 @@ prog = '{
|
|||||||
asm_instr(.op(OP_SUB), .rd(1), .rs1(0), .rs2(1)),
|
asm_instr(.op(OP_SUB), .rd(1), .rs1(0), .rs2(1)),
|
||||||
EBREAK_WORD
|
EBREAK_WORD
|
||||||
};
|
};
|
||||||
|
run_directed("sub_overflow", prog);
|
||||||
```
|
```
|
||||||
|
|
||||||
**Expected result:**
|
**Expected result:**
|
||||||
@@ -311,7 +318,7 @@ prog = '{
|
|||||||
|
|
||||||
**Final result:** <!-- Complete in testplan_final.md: pass/fail and useful log or waveform reference. -->
|
**Final result:** <!-- Complete in testplan_final.md: pass/fail and useful log or waveform reference. -->
|
||||||
|
|
||||||
### 1.8 — `sub typical`
|
### 1.8 — `sub_typical`
|
||||||
|
|
||||||
**Functionality:** sub two registers without causing an overflow
|
**Functionality:** sub two registers without causing an overflow
|
||||||
|
|
||||||
@@ -327,11 +334,12 @@ prog = '{
|
|||||||
|
|
||||||
```systemverilog
|
```systemverilog
|
||||||
prog = '{
|
prog = '{
|
||||||
asm_instr(.op(OP_ADDI), .rd(1), .rs1(0), .imm(0x123)),
|
asm_instr(.op(OP_ADDI), .rd(1), .rs1(0), .imm('h123)),
|
||||||
asm_instr(.op(OP_ADDI), .rd(2), .rs1(0), .imm(0x23)),
|
asm_instr(.op(OP_ADDI), .rd(2), .rs1(0), .imm('h23)),
|
||||||
asm_instr(.op(OP_SUB), .rd(2), .rs1(1), .rs2(2)),
|
asm_instr(.op(OP_SUB), .rd(2), .rs1(1), .rs2(2)),
|
||||||
EBREAK_WORD
|
EBREAK_WORD
|
||||||
};
|
};
|
||||||
|
run_directed("sub_typical", prog);
|
||||||
```
|
```
|
||||||
|
|
||||||
**Expected result:**
|
**Expected result:**
|
||||||
@@ -344,7 +352,7 @@ prog = '{
|
|||||||
|
|
||||||
**Final result:** <!-- Complete in testplan_final.md: pass/fail and useful log or waveform reference. -->
|
**Final result:** <!-- Complete in testplan_final.md: pass/fail and useful log or waveform reference. -->
|
||||||
|
|
||||||
### 1.9 — `srl oob`
|
### 1.9 — `srl_oob`
|
||||||
|
|
||||||
**Functionality:** srl masks to bottom 5 bits of data only, cannot shift more than 31
|
**Functionality:** srl masks to bottom 5 bits of data only, cannot shift more than 31
|
||||||
|
|
||||||
@@ -365,6 +373,7 @@ prog = '{
|
|||||||
asm_instr(.op(OP_SRL), .rd(1), .rs1(1), .rs2(2)),
|
asm_instr(.op(OP_SRL), .rd(1), .rs1(1), .rs2(2)),
|
||||||
EBREAK_WORD
|
EBREAK_WORD
|
||||||
};
|
};
|
||||||
|
run_directed("srl_oob", prog);
|
||||||
```
|
```
|
||||||
|
|
||||||
**Expected result:**
|
**Expected result:**
|
||||||
@@ -377,7 +386,7 @@ prog = '{
|
|||||||
|
|
||||||
**Final result:** <!-- Complete in testplan_final.md: pass/fail and useful log or waveform reference. -->
|
**Final result:** <!-- Complete in testplan_final.md: pass/fail and useful log or waveform reference. -->
|
||||||
|
|
||||||
### 1.10 — `sll oob`
|
### 1.10 — `sll_oob`
|
||||||
|
|
||||||
**Functionality:** sll masks to bottom 5 bits of data only, cannot shift more than 31
|
**Functionality:** sll masks to bottom 5 bits of data only, cannot shift more than 31
|
||||||
|
|
||||||
@@ -398,6 +407,7 @@ prog = '{
|
|||||||
asm_instr(.op(OP_SLL), .rd(1), .rs1(1), .rs2(2)),
|
asm_instr(.op(OP_SLL), .rd(1), .rs1(1), .rs2(2)),
|
||||||
EBREAK_WORD
|
EBREAK_WORD
|
||||||
};
|
};
|
||||||
|
run_directed("sll_oob", prog);
|
||||||
```
|
```
|
||||||
|
|
||||||
**Expected result:**
|
**Expected result:**
|
||||||
@@ -410,7 +420,7 @@ prog = '{
|
|||||||
|
|
||||||
**Final result:** <!-- Complete in testplan_final.md: pass/fail and useful log or waveform reference. -->
|
**Final result:** <!-- Complete in testplan_final.md: pass/fail and useful log or waveform reference. -->
|
||||||
|
|
||||||
### 1.11 — `sll zero`
|
### 1.11 — `sll_zero`
|
||||||
|
|
||||||
**Functionality:** sll with zero, causing no shift
|
**Functionality:** sll with zero, causing no shift
|
||||||
|
|
||||||
@@ -430,6 +440,7 @@ prog = '{
|
|||||||
asm_instr(.op(OP_SLL), .rd(1), .rs1(1), .rs2(0)),
|
asm_instr(.op(OP_SLL), .rd(1), .rs1(1), .rs2(0)),
|
||||||
EBREAK_WORD
|
EBREAK_WORD
|
||||||
};
|
};
|
||||||
|
run_directed("sll_zero", prog);
|
||||||
```
|
```
|
||||||
|
|
||||||
**Expected result:**
|
**Expected result:**
|
||||||
@@ -442,7 +453,7 @@ prog = '{
|
|||||||
|
|
||||||
**Final result:** <!-- Complete in testplan_final.md: pass/fail and useful log or waveform reference. -->
|
**Final result:** <!-- Complete in testplan_final.md: pass/fail and useful log or waveform reference. -->
|
||||||
|
|
||||||
### 1.12 — `srl zero`
|
### 1.12 — `srl_zero`
|
||||||
|
|
||||||
**Functionality:** srl with zero, causing no shift
|
**Functionality:** srl with zero, causing no shift
|
||||||
|
|
||||||
@@ -462,6 +473,7 @@ prog = '{
|
|||||||
asm_instr(.op(OP_SRL), .rd(1), .rs1(1), .rs2(0)),
|
asm_instr(.op(OP_SRL), .rd(1), .rs1(1), .rs2(0)),
|
||||||
EBREAK_WORD
|
EBREAK_WORD
|
||||||
};
|
};
|
||||||
|
run_directed("srl_zero", prog);
|
||||||
```
|
```
|
||||||
|
|
||||||
**Expected result:**
|
**Expected result:**
|
||||||
@@ -474,7 +486,7 @@ prog = '{
|
|||||||
|
|
||||||
**Final result:** <!-- Complete in testplan_final.md: pass/fail and useful log or waveform reference. -->
|
**Final result:** <!-- Complete in testplan_final.md: pass/fail and useful log or waveform reference. -->
|
||||||
|
|
||||||
### 1.13 — `sll one`
|
### 1.13 — `sll_one`
|
||||||
|
|
||||||
**Functionality:** sll with one, causing a shift once to the left
|
**Functionality:** sll with one, causing a shift once to the left
|
||||||
|
|
||||||
@@ -495,6 +507,7 @@ prog = '{
|
|||||||
asm_instr(.op(OP_SLL), .rd(1), .rs1(1), .rs2(2)),
|
asm_instr(.op(OP_SLL), .rd(1), .rs1(1), .rs2(2)),
|
||||||
EBREAK_WORD
|
EBREAK_WORD
|
||||||
};
|
};
|
||||||
|
run_directed("sll_one", prog);
|
||||||
```
|
```
|
||||||
|
|
||||||
**Expected result:**
|
**Expected result:**
|
||||||
@@ -507,7 +520,7 @@ prog = '{
|
|||||||
|
|
||||||
**Final result:** <!-- Complete in testplan_final.md: pass/fail and useful log or waveform reference. -->
|
**Final result:** <!-- Complete in testplan_final.md: pass/fail and useful log or waveform reference. -->
|
||||||
|
|
||||||
### 1.14 — `srl one`
|
### 1.14 — `srl_one`
|
||||||
|
|
||||||
**Functionality:** srl with one, causing a shift once to the right
|
**Functionality:** srl with one, causing a shift once to the right
|
||||||
|
|
||||||
@@ -528,6 +541,7 @@ prog = '{
|
|||||||
asm_instr(.op(OP_SRL), .rd(1), .rs1(1), .rs2(2)),
|
asm_instr(.op(OP_SRL), .rd(1), .rs1(1), .rs2(2)),
|
||||||
EBREAK_WORD
|
EBREAK_WORD
|
||||||
};
|
};
|
||||||
|
run_directed("srl_one", prog);
|
||||||
```
|
```
|
||||||
|
|
||||||
**Expected result:**
|
**Expected result:**
|
||||||
@@ -540,7 +554,7 @@ prog = '{
|
|||||||
|
|
||||||
**Final result:** <!-- Complete in testplan_final.md: pass/fail and useful log or waveform reference. -->
|
**Final result:** <!-- Complete in testplan_final.md: pass/fail and useful log or waveform reference. -->
|
||||||
|
|
||||||
### 1.15 — `sll typical`
|
### 1.15 — `sll_typical`
|
||||||
|
|
||||||
**Functionality:** sll with a shift greater than 1 and less than 2^5
|
**Functionality:** sll with a shift greater than 1 and less than 2^5
|
||||||
|
|
||||||
@@ -561,6 +575,7 @@ prog = '{
|
|||||||
asm_instr(.op(OP_SLL), .rd(1), .rs1(1), .rs2(2)),
|
asm_instr(.op(OP_SLL), .rd(1), .rs1(1), .rs2(2)),
|
||||||
EBREAK_WORD
|
EBREAK_WORD
|
||||||
};
|
};
|
||||||
|
run_directed("sll_typical", prog);
|
||||||
```
|
```
|
||||||
|
|
||||||
**Expected result:**
|
**Expected result:**
|
||||||
@@ -573,7 +588,7 @@ prog = '{
|
|||||||
|
|
||||||
**Final result:** <!-- Complete in testplan_final.md: pass/fail and useful log or waveform reference. -->
|
**Final result:** <!-- Complete in testplan_final.md: pass/fail and useful log or waveform reference. -->
|
||||||
|
|
||||||
### 1.16 — `srl typical`
|
### 1.16 — `srl_typical`
|
||||||
|
|
||||||
**Functionality:** srl with a shift greater than 1 and less than 2^5
|
**Functionality:** srl with a shift greater than 1 and less than 2^5
|
||||||
|
|
||||||
@@ -594,6 +609,7 @@ prog = '{
|
|||||||
asm_instr(.op(OP_SRL), .rd(1), .rs1(1), .rs2(2)),
|
asm_instr(.op(OP_SRL), .rd(1), .rs1(1), .rs2(2)),
|
||||||
EBREAK_WORD
|
EBREAK_WORD
|
||||||
};
|
};
|
||||||
|
run_directed("srl_typical", prog);
|
||||||
```
|
```
|
||||||
|
|
||||||
**Expected result:**
|
**Expected result:**
|
||||||
@@ -606,7 +622,7 @@ prog = '{
|
|||||||
|
|
||||||
**Final result:** <!-- Complete in testplan_final.md: pass/fail and useful log or waveform reference. -->
|
**Final result:** <!-- Complete in testplan_final.md: pass/fail and useful log or waveform reference. -->
|
||||||
|
|
||||||
### 1.17 — `lw zero offset`
|
### 1.17 — `lw_zero_offset`
|
||||||
|
|
||||||
**Functionality:** lw with zero offset, loading in the register rs1
|
**Functionality:** lw with zero offset, loading in the register rs1
|
||||||
|
|
||||||
@@ -625,6 +641,7 @@ prog = '{
|
|||||||
asm_instr(.op(OP_LW), .rd(1), .rs1(0), .imm(0)),
|
asm_instr(.op(OP_LW), .rd(1), .rs1(0), .imm(0)),
|
||||||
EBREAK_WORD
|
EBREAK_WORD
|
||||||
};
|
};
|
||||||
|
run_directed("lw_zero_offset", prog);
|
||||||
```
|
```
|
||||||
|
|
||||||
**Expected result:**
|
**Expected result:**
|
||||||
@@ -637,7 +654,7 @@ prog = '{
|
|||||||
|
|
||||||
**Final result:** <!-- Complete in testplan_final.md: pass/fail and useful log or waveform reference. -->
|
**Final result:** <!-- Complete in testplan_final.md: pass/fail and useful log or waveform reference. -->
|
||||||
|
|
||||||
### 1.18 — `sw zero offset`
|
### 1.18 — `sw_zero_offset`
|
||||||
|
|
||||||
**Functionality:** sw with zero offset, storing in memory addr of rs1
|
**Functionality:** sw with zero offset, storing in memory addr of rs1
|
||||||
|
|
||||||
@@ -657,6 +674,7 @@ prog = '{
|
|||||||
asm_instr(.op(OP_SW), .rs1(0), .rs2(1), .imm(0)),
|
asm_instr(.op(OP_SW), .rs1(0), .rs2(1), .imm(0)),
|
||||||
EBREAK_WORD
|
EBREAK_WORD
|
||||||
};
|
};
|
||||||
|
run_directed("sw_zero_offset", prog);
|
||||||
```
|
```
|
||||||
|
|
||||||
**Expected result:**
|
**Expected result:**
|
||||||
@@ -669,7 +687,7 @@ prog = '{
|
|||||||
|
|
||||||
**Final result:** <!-- Complete in testplan_final.md: pass/fail and useful log or waveform reference. -->
|
**Final result:** <!-- Complete in testplan_final.md: pass/fail and useful log or waveform reference. -->
|
||||||
|
|
||||||
### 1.19 — `lw positive`
|
### 1.19 — `lw_positive`
|
||||||
|
|
||||||
**Functionality:** lw with a positive offset
|
**Functionality:** lw with a positive offset
|
||||||
|
|
||||||
@@ -688,6 +706,7 @@ prog = '{
|
|||||||
asm_instr(.op(OP_LW), .rd(1), .rs1(0), .imm(4)),
|
asm_instr(.op(OP_LW), .rd(1), .rs1(0), .imm(4)),
|
||||||
EBREAK_WORD
|
EBREAK_WORD
|
||||||
};
|
};
|
||||||
|
run_directed("lw_positive", prog);
|
||||||
```
|
```
|
||||||
|
|
||||||
**Expected result:**
|
**Expected result:**
|
||||||
@@ -700,7 +719,7 @@ prog = '{
|
|||||||
|
|
||||||
**Final result:** <!-- Complete in testplan_final.md: pass/fail and useful log or waveform reference. -->
|
**Final result:** <!-- Complete in testplan_final.md: pass/fail and useful log or waveform reference. -->
|
||||||
|
|
||||||
### 1.20 — `sw positive`
|
### 1.20 — `sw_positive`
|
||||||
|
|
||||||
**Functionality:** sw with a positive offset
|
**Functionality:** sw with a positive offset
|
||||||
|
|
||||||
@@ -720,6 +739,7 @@ prog = '{
|
|||||||
asm_instr(.op(OP_SW), .rs1(0), .rs2(1), .imm(4)),
|
asm_instr(.op(OP_SW), .rs1(0), .rs2(1), .imm(4)),
|
||||||
EBREAK_WORD
|
EBREAK_WORD
|
||||||
};
|
};
|
||||||
|
run_directed("sw_positive", prog);
|
||||||
```
|
```
|
||||||
|
|
||||||
**Expected result:**
|
**Expected result:**
|
||||||
@@ -732,7 +752,7 @@ prog = '{
|
|||||||
|
|
||||||
**Final result:** <!-- Complete in testplan_final.md: pass/fail and useful log or waveform reference. -->
|
**Final result:** <!-- Complete in testplan_final.md: pass/fail and useful log or waveform reference. -->
|
||||||
|
|
||||||
### 1.21 — `lw negative`
|
### 1.21 — `lw_negative`
|
||||||
|
|
||||||
**Functionality:** lw with a negative offset from a nonzero base register, landing on a legal, word-aligned address inside DSRAM
|
**Functionality:** lw with a negative offset from a nonzero base register, landing on a legal, word-aligned address inside DSRAM
|
||||||
|
|
||||||
@@ -752,6 +772,7 @@ prog = '{
|
|||||||
asm_instr(.op(OP_LW), .rd(2), .rs1(1), .imm(-4)),
|
asm_instr(.op(OP_LW), .rd(2), .rs1(1), .imm(-4)),
|
||||||
EBREAK_WORD
|
EBREAK_WORD
|
||||||
};
|
};
|
||||||
|
run_directed("lw_negative", prog);
|
||||||
```
|
```
|
||||||
|
|
||||||
**Expected result:**
|
**Expected result:**
|
||||||
@@ -764,7 +785,7 @@ prog = '{
|
|||||||
|
|
||||||
**Final result:** <!-- Complete in testplan_final.md: pass/fail and useful log or waveform reference. -->
|
**Final result:** <!-- Complete in testplan_final.md: pass/fail and useful log or waveform reference. -->
|
||||||
|
|
||||||
### 1.22 — `sw negative`
|
### 1.22 — `sw_negative`
|
||||||
|
|
||||||
**Functionality:** sw with a negative offset from a nonzero base register, landing on a legal, word-aligned address inside DSRAM
|
**Functionality:** sw with a negative offset from a nonzero base register, landing on a legal, word-aligned address inside DSRAM
|
||||||
|
|
||||||
@@ -785,6 +806,7 @@ prog = '{
|
|||||||
asm_instr(.op(OP_SW), .rs1(1), .rs2(2), .imm(-4)),
|
asm_instr(.op(OP_SW), .rs1(1), .rs2(2), .imm(-4)),
|
||||||
EBREAK_WORD
|
EBREAK_WORD
|
||||||
};
|
};
|
||||||
|
run_directed("sw_negative", prog);
|
||||||
```
|
```
|
||||||
|
|
||||||
**Expected result:**
|
**Expected result:**
|
||||||
@@ -797,7 +819,7 @@ prog = '{
|
|||||||
|
|
||||||
**Final result:** <!-- Complete in testplan_final.md: pass/fail and useful log or waveform reference. -->
|
**Final result:** <!-- Complete in testplan_final.md: pass/fail and useful log or waveform reference. -->
|
||||||
|
|
||||||
### 1.23 — `lw x0`
|
### 1.23 — `lw_x0`
|
||||||
|
|
||||||
**Functionality:** attempt to lw into x0 register
|
**Functionality:** attempt to lw into x0 register
|
||||||
|
|
||||||
@@ -816,6 +838,7 @@ prog = '{
|
|||||||
asm_instr(.op(OP_LW), .rd(0), .rs1(0), .imm(0)),
|
asm_instr(.op(OP_LW), .rd(0), .rs1(0), .imm(0)),
|
||||||
EBREAK_WORD
|
EBREAK_WORD
|
||||||
};
|
};
|
||||||
|
run_directed("lw_x0", prog);
|
||||||
```
|
```
|
||||||
|
|
||||||
**Expected result:**
|
**Expected result:**
|
||||||
@@ -828,7 +851,7 @@ prog = '{
|
|||||||
|
|
||||||
**Final result:** <!-- Complete in testplan_final.md: pass/fail and useful log or waveform reference. -->
|
**Final result:** <!-- Complete in testplan_final.md: pass/fail and useful log or waveform reference. -->
|
||||||
|
|
||||||
### 1.24 — `beq x0`
|
### 1.24 — `beq_x0`
|
||||||
|
|
||||||
**Functionality:** beq with both sources as x0
|
**Functionality:** beq with both sources as x0
|
||||||
|
|
||||||
@@ -849,6 +872,7 @@ prog = '{
|
|||||||
asm_instr(.op(OP_ADDI), .rd(1), .rs1(0), .imm(2)),
|
asm_instr(.op(OP_ADDI), .rd(1), .rs1(0), .imm(2)),
|
||||||
EBREAK_WORD
|
EBREAK_WORD
|
||||||
};
|
};
|
||||||
|
run_directed("beq_x0", prog);
|
||||||
```
|
```
|
||||||
|
|
||||||
**Expected result:**
|
**Expected result:**
|
||||||
@@ -861,7 +885,7 @@ prog = '{
|
|||||||
|
|
||||||
**Final result:** <!-- Complete in testplan_final.md: pass/fail and useful log or waveform reference. -->
|
**Final result:** <!-- Complete in testplan_final.md: pass/fail and useful log or waveform reference. -->
|
||||||
|
|
||||||
### 1.25 — `beq not taken`
|
### 1.25 — `beq_not_taken`
|
||||||
|
|
||||||
**Functionality:** beq on two non-equal registers
|
**Functionality:** beq on two non-equal registers
|
||||||
|
|
||||||
@@ -882,6 +906,7 @@ prog = '{
|
|||||||
asm_instr(.op(OP_ADDI), .rd(2), .rs1(0), .imm(-1)),
|
asm_instr(.op(OP_ADDI), .rd(2), .rs1(0), .imm(-1)),
|
||||||
EBREAK_WORD
|
EBREAK_WORD
|
||||||
};
|
};
|
||||||
|
run_directed("beq_not_taken", prog);
|
||||||
```
|
```
|
||||||
|
|
||||||
**Expected result:**
|
**Expected result:**
|
||||||
@@ -894,7 +919,7 @@ prog = '{
|
|||||||
|
|
||||||
**Final result:** <!-- Complete in testplan_final.md: pass/fail and useful log or waveform reference. -->
|
**Final result:** <!-- Complete in testplan_final.md: pass/fail and useful log or waveform reference. -->
|
||||||
|
|
||||||
### 1.26 — `beq typical`
|
### 1.26 — `beq_typical`
|
||||||
|
|
||||||
**Functionality:** beq on two equal registers that are not x0
|
**Functionality:** beq on two equal registers that are not x0
|
||||||
|
|
||||||
@@ -917,6 +942,7 @@ prog = '{
|
|||||||
asm_instr(.op(OP_ADDI), .rd(3), .rs1(0), .imm(2)),
|
asm_instr(.op(OP_ADDI), .rd(3), .rs1(0), .imm(2)),
|
||||||
EBREAK_WORD
|
EBREAK_WORD
|
||||||
};
|
};
|
||||||
|
run_directed("beq_typical", prog);
|
||||||
```
|
```
|
||||||
|
|
||||||
**Expected result:**
|
**Expected result:**
|
||||||
@@ -929,7 +955,7 @@ prog = '{
|
|||||||
|
|
||||||
**Final result:** <!-- Complete in testplan_final.md: pass/fail and useful log or waveform reference. -->
|
**Final result:** <!-- Complete in testplan_final.md: pass/fail and useful log or waveform reference. -->
|
||||||
|
|
||||||
### 1.27 — `ebreak immediately`
|
### 1.27 — `ebreak_immediately`
|
||||||
|
|
||||||
**Functionality:** ebreak as first instruction, subsequent instructions not run
|
**Functionality:** ebreak as first instruction, subsequent instructions not run
|
||||||
|
|
||||||
@@ -948,6 +974,7 @@ prog = '{
|
|||||||
EBREAK_WORD,
|
EBREAK_WORD,
|
||||||
asm_instr(.op(OP_ADDI), .rd(1), .rs1(0), .imm(-1))
|
asm_instr(.op(OP_ADDI), .rd(1), .rs1(0), .imm(-1))
|
||||||
};
|
};
|
||||||
|
run_directed("ebreak_immediately", prog);
|
||||||
```
|
```
|
||||||
|
|
||||||
**Expected result:**
|
**Expected result:**
|
||||||
@@ -960,7 +987,7 @@ prog = '{
|
|||||||
|
|
||||||
**Final result:** <!-- Complete in testplan_final.md: pass/fail and useful log or waveform reference. -->
|
**Final result:** <!-- Complete in testplan_final.md: pass/fail and useful log or waveform reference. -->
|
||||||
|
|
||||||
### 1.28 — `beq backward loop`
|
### 1.28 — `beq_backward_loop`
|
||||||
|
|
||||||
**Functionality:** beq used as a backward branch creating a countdown loop
|
**Functionality:** beq used as a backward branch creating a countdown loop
|
||||||
|
|
||||||
@@ -982,6 +1009,7 @@ prog = '{
|
|||||||
asm_instr(.op(OP_BEQ), .rs1(0), .rs2(0), .imm(-8)),
|
asm_instr(.op(OP_BEQ), .rs1(0), .rs2(0), .imm(-8)),
|
||||||
EBREAK_WORD
|
EBREAK_WORD
|
||||||
};
|
};
|
||||||
|
run_directed("beq_backward_loop", prog);
|
||||||
```
|
```
|
||||||
|
|
||||||
**Expected result:**
|
**Expected result:**
|
||||||
@@ -994,7 +1022,7 @@ prog = '{
|
|||||||
|
|
||||||
**Final result:** <!-- Complete in testplan_final.md: pass/fail and useful log or waveform reference. -->
|
**Final result:** <!-- Complete in testplan_final.md: pass/fail and useful log or waveform reference. -->
|
||||||
|
|
||||||
### 1.29 — `reset while running`
|
### 1.29 — `reset_while_running`
|
||||||
|
|
||||||
**Functionality:** rst_i asserted partway through a running program
|
**Functionality:** rst_i asserted partway through a running program
|
||||||
|
|
||||||
@@ -1038,7 +1066,7 @@ readback(2, 1, 1);
|
|||||||
|
|
||||||
**Final result:** <!-- Complete in testplan_final.md: pass/fail and useful log or waveform reference. -->
|
**Final result:** <!-- Complete in testplan_final.md: pass/fail and useful log or waveform reference. -->
|
||||||
|
|
||||||
### 1.30 — `external halt`
|
### 1.30 — `external_halt`
|
||||||
|
|
||||||
**Functionality:** halt_cpu_i pulsed partway through a running program
|
**Functionality:** halt_cpu_i pulsed partway through a running program
|
||||||
|
|
||||||
@@ -1078,7 +1106,7 @@ readback(2, 1, 1);
|
|||||||
|
|
||||||
**Final result:** <!-- Complete in testplan_final.md: pass/fail and useful log or waveform reference. -->
|
**Final result:** <!-- Complete in testplan_final.md: pass/fail and useful log or waveform reference. -->
|
||||||
|
|
||||||
### 1.31 — `isram boundary words`
|
### 1.31 — `isram_boundary_words`
|
||||||
|
|
||||||
**Functionality:** external port access to the first and last ISRAM words
|
**Functionality:** external port access to the first and last ISRAM words
|
||||||
|
|
||||||
@@ -1111,7 +1139,7 @@ readback(0, 1, 1023);
|
|||||||
|
|
||||||
**Final result:** <!-- Complete in testplan_final.md: pass/fail and useful log or waveform reference. -->
|
**Final result:** <!-- Complete in testplan_final.md: pass/fail and useful log or waveform reference. -->
|
||||||
|
|
||||||
### 1.32 — `dsram boundary words`
|
### 1.32 — `dsram_boundary_words`
|
||||||
|
|
||||||
**Functionality:** external port access to the first and last DSRAM words
|
**Functionality:** external port access to the first and last DSRAM words
|
||||||
|
|
||||||
@@ -1144,7 +1172,7 @@ readback(1, 1, 1023);
|
|||||||
|
|
||||||
**Final result:** <!-- Complete in testplan_final.md: pass/fail and useful log or waveform reference. -->
|
**Final result:** <!-- Complete in testplan_final.md: pass/fail and useful log or waveform reference. -->
|
||||||
|
|
||||||
### 1.33 — `external register boundary reads`
|
### 1.33 — `external_register_boundary_reads`
|
||||||
|
|
||||||
**Functionality:** external, read-only register-file port access to x0 and x31
|
**Functionality:** external, read-only register-file port access to x0 and x31
|
||||||
|
|
||||||
@@ -1277,15 +1305,17 @@ X0_REMAINS_0:
|
|||||||
|
|
||||||
**Evidence that it detects a violation:** <!-- Temporary change, failing log/waveform, and confirmation after reverting it. -->
|
**Evidence that it detects a violation:** <!-- Temporary change, failing log/waveform, and confirmation after reverting it. -->
|
||||||
|
|
||||||
### 3.2 — `NO_RW_CONCURRENCY`
|
### 3.2 — `STABLE_WHEN_DISABLED`
|
||||||
|
|
||||||
**Timing requirement in words:** on every clock pulse, check that read and write are not both enabled
|
**Timing requirement in words:** when the CPU is disabled or inactive, the PC and register file should not change
|
||||||
|
|
||||||
```systemverilog
|
```systemverilog
|
||||||
NO_RW_CONCURRENCY:
|
STABLE_WHEN_DISABLED :
|
||||||
assert property (@(posedge clk) disable iff (rst)
|
assert property (@(posedge clk) disable iff (rst)
|
||||||
!(cpu_if.w_en_i && cpu_if.r_en_i))
|
(!cpu_if.en_cpu || !cpu_if.cpu_active) |=> ($stable(
|
||||||
else assertion_fail("halt did not pulse correctly");
|
dut.register_crossbar
|
||||||
|
)))
|
||||||
|
else assertion_fail("register file/pc changed while cpu inactive");
|
||||||
```
|
```
|
||||||
|
|
||||||
**Evidence that it detects a violation:**
|
**Evidence that it detects a violation:**
|
||||||
|
|||||||
Reference in New Issue
Block a user