update todos

This commit is contained in:
2026-10-06 01:06:49 -04:00
parent 681985322e
commit 79246e7d3b
2 changed files with 148 additions and 148 deletions
+1 -1
View File
@@ -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
+25 -25
View File
@@ -3,14 +3,17 @@
* 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();
@@ -18,23 +21,22 @@ class cpu_sequencer #(int DataSize=32, int AddrSize=14);
foreach (shadow_dmem[i]) begin foreach (shadow_dmem[i]) begin
shadow_dmem[i] = '0; shadow_dmem[i] = '0;
end end
endfunction: new endfunction : new
// Build a random program and enqueue frontdoor instruction writes. // Build a random program and enqueue frontdoor instruction writes.
// idx and prog_len are assigned before randomization because branch // idx and prog_len are assigned before randomization because branch
// constraints depend on the instruction's position. // constraints depend on the instruction's position.
task gen_program(input int num, input bit verbose=1'b1); task gen_program(input int num, input bit verbose = 1'b1);
cpu_seq_item #(DataSize, AddrSize) instr; cpu_seq_item #(DataSize, AddrSize) instr;
cpu_ref_model shadow; cpu_ref_model shadow;
logic [31:0] program_words [$]; logic [31:0] program_words[$];
logic [31:0] effective_addr; logic [31:0] effective_addr;
bit reachable; bit reachable;
int prog_len; int prog_len;
if ((num < 0) || (num >= ISRAM_WORDS)) begin if ((num < 0) || (num >= ISRAM_WORDS)) begin
$fatal(1, $fatal(1, "%0t Seq: program needs 0..%0d random instructions, got %0d", $time,
"%0t Seq: program needs 0..%0d random instructions, got %0d", ISRAM_WORDS - 1, num);
$time, ISRAM_WORDS - 1, num);
end end
prog_len = num + 1; // +1 for the ebreak prog_len = num + 1; // +1 for the ebreak
@@ -49,19 +51,16 @@ class cpu_sequencer #(int DataSize=32, int AddrSize=14);
instr.reg_snapshot[r] = shadow.regs[r]; instr.reg_snapshot[r] = shadow.regs[r];
end end
if (!instr.randomize()) begin if (!instr.randomize()) begin
$fatal(1, "%0t Seq: state-aware randomization failed for instruction %0d", $fatal(1, "%0t Seq: state-aware randomization failed for instruction %0d", $time, i);
$time, i);
end end
// Keep this independent diagnostic while c_mem_align is a member // Keep this independent diagnostic while c_mem_align is a member
// TODO. If it fires, the generated instruction violated the // If it fires, the generated instruction violated the
// effective-address contract described on that constraint. // effective-address contract described on that constraint.
if (instr.op inside {OP_LW, OP_SW}) begin if (instr.op inside {OP_LW, OP_SW}) begin
effective_addr = instr.reg_snapshot[instr.rs1] + instr.imm; effective_addr = instr.reg_snapshot[instr.rs1] + instr.imm;
if ((effective_addr[1:0] != 2'b00) || if ((effective_addr[1:0] != 2'b00) || (effective_addr > ((DSRAM_WORDS * 4) - 4))) begin
(effective_addr > ((DSRAM_WORDS * 4) - 4))) begin $fatal(1, "%0t Seq: illegal effective byte address 0x%08x for %s; complete c_mem_align",
$fatal(1,
"%0t Seq: illegal effective byte address 0x%08x for %s; complete c_mem_align",
$time, effective_addr, instr.asm()); $time, effective_addr, instr.asm());
end end
end end
@@ -99,7 +98,8 @@ class cpu_sequencer #(int DataSize=32, int AddrSize=14);
shadow.step(); shadow.step();
end end
if (!shadow.halted) begin if (!shadow.halted) begin
$fatal(1, $fatal(
1,
"%0t Seq: generated control flow missed the final ebreak (pc=0x%08x); complete c_branch_target", "%0t Seq: generated control flow missed the final ebreak (pc=0x%08x); complete c_branch_target",
$time, shadow.pc); $time, shadow.pc);
end end
@@ -107,7 +107,7 @@ class cpu_sequencer #(int DataSize=32, int AddrSize=14);
foreach (program_words[i]) begin foreach (program_words[i]) begin
send_write_trans(word_addr(ISRAM_BASE, i), program_words[i]); send_write_trans(word_addr(ISRAM_BASE, i), program_words[i]);
end end
endtask: gen_program endtask : gen_program
// Stage one external write transaction // Stage one external write transaction
task send_write_trans(input logic [AddrSize-1:0] addr, input logic [DataSize-1:0] data); task send_write_trans(input logic [AddrSize-1:0] addr, input logic [DataSize-1:0] data);
@@ -122,7 +122,7 @@ class cpu_sequencer #(int DataSize=32, int AddrSize=14);
shadow_dmem[addr[11:2]] = data; shadow_dmem[addr[11:2]] = data;
end end
xbar_box.put(trans); xbar_box.put(trans);
endtask: send_write_trans endtask : send_write_trans
// Stage one external read transaction // Stage one external read transaction
task send_read_trans(input logic [AddrSize-1:0] addr); task send_read_trans(input logic [AddrSize-1:0] addr);
@@ -133,18 +133,18 @@ class cpu_sequencer #(int DataSize=32, int AddrSize=14);
trans.addr = addr; trans.addr = addr;
trans.is_write = 1'b0; trans.is_write = 1'b0;
xbar_box.put(trans); xbar_box.put(trans);
endtask: send_read_trans endtask : send_read_trans
// Stage a program as instruction-memory writes starting at word zero // Stage a program as instruction-memory writes starting at word zero
task load_program(const ref logic [31:0] prog [$]); task load_program(const ref logic [31:0] prog[$]);
foreach (prog[i]) begin foreach (prog[i]) begin
send_write_trans(word_addr(ISRAM_BASE, i), prog[i]); send_write_trans(word_addr(ISRAM_BASE, i), prog[i]);
end end
endtask: load_program endtask : load_program
// Generate external-port traffic. cpu_xbar_item constraints define the // Generate external-port traffic. cpu_xbar_item constraints define the
// useful behavior; the mailbox mechanics are supplied. // useful behavior; the mailbox mechanics are supplied.
task gen_xbar(input int num, input bit verbose=1'b0); task gen_xbar(input int num, input bit verbose = 1'b0);
cpu_xbar_item #(DataSize, AddrSize) trans; cpu_xbar_item #(DataSize, AddrSize) trans;
for (int i = 0; i < num; i++) begin for (int i = 0; i < num; i++) begin
@@ -157,13 +157,13 @@ class cpu_sequencer #(int DataSize=32, int AddrSize=14);
end end
xbar_box.put(trans); xbar_box.put(trans);
end end
endtask: gen_xbar endtask : gen_xbar
// Wait until the driver has pulled every staged mailbox transaction // Wait until the driver has pulled every staged mailbox transaction
task wait_for_empty(); task wait_for_empty();
while (xbar_box.num() != 0) begin while (xbar_box.num() != 0) begin
#10; #10;
end end
endtask: wait_for_empty endtask : wait_for_empty
endclass: cpu_sequencer endclass : cpu_sequencer