Write a checker of the retire trace's own rules and have it bound at the core's trace port of the chip bench. It must stay silent while the processor runs on the good chip, and report on hidden faulty chips.
Hardware context: The retire trace of ap_rv32 inside ap_soc v1.5: 24 fields a record, recorded on the chip. A checker of the trace's rules bound at the core's trace port, against hidden faulty chips.
Every tool that reads the retire trace trusts its rules: the model compare, coverage, the debug views. A trace port is RTL too, and a fault there misleads all of them while the core itself is right. So a bench checks the trace, record by record, beside everything else.
The bench builds your checker into soc_tb, wired to the retire-trace port of ap_rv32. The processor runs a fixed assembly program of the server, in the full specification. Report on a valid record that breaks a rule of the table there.
Each case runs the program with its own TB_ARG. It runs once on the good chip, and once on each chip of a hidden set. On the good chip your checker must stay silent and the program must pass. On each hidden chip it must report at least once.
Full specification
| Rule | Name | What every valid record must keep |
|---|---|---|
| 1 | Order counts from 0, with no gap | The first record after reset has order 0, and each record after it has the order of the one before plus 1. order is 64 bits. |
| 2 | Machine mode only | priv is 3 on every record: ap_rv32 v1.2 has machine mode and nothing else. |
| 3 | Each record starts where the last one went | From the second record on, pc equals the next_pc of the record before. |
| 4 | A trap writes nothing | On a record with trap = 1, rd_addr is 0, both memory masks are 0 and csr_write is 0. |
| 5 | An interrupt has no tval | A trap whose cause has bit 31 set has tval = 0. An exception may have a tval. |
| 6 | x0 is always 0 | rd_addr = 0 gives rd_wdata = 0. rs1_addr = 0 gives rs1_rdata = 0, and the same for rs2. |
| 7 | No access, no memory values | With both memory masks 0, mem_addr, mem_rdata and mem_wdata are 0. |
| 8 | lui, auipc and jal read no register | lui, auipc and jal (opcodes 37, 17 and 6F in hex) read no register. A record of one that did not trap has rs1_addr = 0 and rs2_addr = 0. |
# ap_soc v1.5: one record of every kind. TB_ARG bit 0: a software interrupt in a loop;
# bit 1: a load from a hole of the map; bit 2: wfi, woken by the timer.
la t0, handler
csrw mtvec, t0
li s0, SYSCTL
lw s1, TB_ARG(s0)
li t2, 0x80003000
li t3, -1
sb t3, 1(t2) # a byte store
lbu t4, 1(t2) # a byte load
add zero, t4, t3 # a write to x0: the value is dropped
add t5, zero, t4 # a read of x0
lui t6, 0x12345
auipc t6, 0
csrrs t1, mscratch, zero # a CSR read that writes nothing
csrw mscratch, t4
ecall # a trap with tval 0
andi t1, s1, 1
beqz t1, 2f
li t1, 8
csrs mie, t1
csrsi mstatus, 8
li t0, CLINT
li t1, 1
sw t1, 0(t0) # MSIP = 1: the software line
li t3, 40
1: addi t3, t3, -1
bnez t3, 1b # the interrupt lands in this loop
csrci mstatus, 8
2: andi t1, s1, 2
beqz t1, 3f
li t0, HOLE
lw t1, 0(t0) # a load fault: tval is the address
3: andi t1, s1, 4
beqz t1, 6f
li t0, CLINT + 0xBFF8
lw t1, 0(t0)
addi t1, t1, 60
li t0, CLINT + 0x4000
sw t1, 0(t0)
sw zero, 4(t0) # MTIMECMP = MTIME + 60
li t1, 128
csrs mie, t1
csrsi mstatus, 8
wfi
csrci mstatus, 8
6: li t1, 0x900d
sw t1, TB_STATUS(s0)
7: j 7b
handler:
csrr t5, mcause
bltz t5, 8f
csrr t5, mepc # an exception: step over the instruction
addi t5, t5, 4
csrw mepc, t5
mret
8: andi t5, t5, 15
li t6, 7
beq t5, t6, 9f
li t5, CLINT # the software line: MSIP = 0
sw zero, 0(t5)
mret
9: li t5, CLINT + 0x4004 # the timer line: push the deadline away
li t6, -1
sw t6, 0(t5)
mret
| Port | Width | Meaning |
|---|---|---|
| clk, resetn | 1 | clk_core and the core's reset. Report is sampled at each rising edge while resetn is 1; reset restarts the numbering |
| trace_valid | 1 | 1 on an edge that carries a record; the other trace ports mean nothing when it is 0 |
| trace_order | 64 | the record number |
| trace_pc, trace_insn, trace_next_pc | 32 each | the instruction's address, its word, and where the core went next |
| trace_priv, trace_trap | 2, 1 | the privilege, and 1 when a trap was taken instead |
| trace_cause, trace_tval | 32 each | mcause and mtval on a trap, else 0 |
| trace_rs1_addr, trace_rs2_addr, trace_rd_addr | 5 each | the registers read and written; 0 when there is none |
| trace_rs1_rdata, trace_rs2_rdata, trace_rd_wdata | 32 each | their values |
| trace_mem_addr, trace_mem_rdata, trace_mem_wdata | 32 each | the access, when a mask is not 0 |
| trace_mem_rmask, trace_mem_wmask | 4 each | the byte lanes read and written |
| trace_csr_write | 1 | 1 when a CSR was written |
Local state is up to 32 bits a variable, so a 64-bit count takes two of them. The fields are those of blueprint section 3.5, the rules a subset of its rules T1 to T10.
Given Files
Read-only files supplied by the bench.
ports.sv
// Observation site: soc_tb.retire_trace
module learner_checker(input logic clk, input logic resetn, input logic trace_valid, input logic [63:0] trace_order, input logic [31:0] trace_pc, input logic [31:0] trace_insn, input logic [31:0] trace_next_pc, input logic [1:0] trace_priv, input logic trace_trap, input logic [31:0] trace_cause, input logic [31:0] trace_tval, input logic [4:0] trace_rs1_addr, input logic [31:0] trace_rs1_rdata, input logic [4:0] trace_rs2_addr, input logic [31:0] trace_rs2_rdata, input logic [4:0] trace_rd_addr, input logic [31:0] trace_rd_wdata, input logic [31:0] trace_mem_addr, input logic [3:0] trace_mem_rmask, input logic [3:0] trace_mem_wmask, input logic [31:0] trace_mem_rdata, input logic [31:0] trace_mem_wdata, input logic trace_csr_write, output logic report);
// Supply the module body only.
endmodule
report.txt
soc_tb samples report on each rising edge of clk with resetn high. Assert report for a sampled violation. The bench counts reports.
defs.S
# defs.S: addresses and helpers of the smoke programs of ap_soc v1.5 (stage E4).
# check-soc-top.mjs puts this text in front of every program. Numbers: gen/ap_soc_regs.h.
.equ ROM, 0x00000000
.equ CLINT, 0x02000000
.equ PLIC, 0x0C000000
.equ UART, 0x10000000
.equ GPIO, 0x10001000
.equ TIMER, 0x10002000
.equ WDOG, 0x10003000
.equ SYSCTL, 0x10004000
.equ SPI, 0x10005000
.equ DMA, 0x10006000
.equ HOLE, 0x10007000
.equ PWRCTL, 0x10008000
.equ SRAM, 0x80000000
.equ TB_STATUS, 0x20
.equ TB_PUTC, 0x24
.equ TB_EVENT, 0x28
.equ TB_ARG, 0x2C
ap_clint · register manual
| Offset | Register | Bits | Field | Access | Reset | Held by | Meaning |
|---|---|---|---|---|---|---|---|
0x000000 | MSIP | 0 | msip | rw | 0x0 | block | Machine software interrupt request of hart 0. 1 raises the request. |
0x004000 | MTIMECMP_LOW | 31:0 | value | rw | 0xFFFFFFFF | block | Low word of mtimecmp. Compare value, low word. |
0x004004 | MTIMECMP_HIGH | 31:0 | value | rw | 0xFFFFFFFF | block | High word of mtimecmp. Compare value, high word. |
0x00BFF8 | MTIME_LOW | 31:0 | value | rw | 0x00000000 | block | Low word of mtime. Time, low word. |
0x00BFFC | MTIME_HIGH | 31:0 | value | rw | 0x00000000 | block | High word of mtime. Time, high word. |
## ap_clint (base 0x0200_0000, clk_sys, PD_MAIN) | Offset | Register | Bits | Field | Access | Reset | Held by | Meaning | | --- | --- | --- | --- | --- | --- | --- | --- | | `0x000000` | MSIP | 0 | msip | rw | `0x0` | block | Machine software interrupt request of hart 0. 1 raises the request. | | `0x004000` | MTIMECMP_LOW | 31:0 | value | rw | `0xFFFFFFFF` | block | Low word of mtimecmp. Compare value, low word. | | `0x004004` | MTIMECMP_HIGH | 31:0 | value | rw | `0xFFFFFFFF` | block | High word of mtimecmp. Compare value, high word. | | `0x00BFF8` | MTIME_LOW | 31:0 | value | rw | `0x00000000` | block | Low word of mtime. Time, low word. | | `0x00BFFC` | MTIME_HIGH | 31:0 | value | rw | `0x00000000` | block | High word of mtime. Time, high word. |
Examples
Example 1
The Program Alone- Input
TB_ARG = 0
- Output
silent on the good chip; reports on every hidden chip
A byte store and load, a write to x0 and a read of it, and lui and auipc. Then a CSR read that writes nothing, and an ecall. Every record keeps every rule.
Example 2
A Software Interrupt- Input
TB_ARG = 1
- Output
silent on the good chip
The interrupt is a record of its own, at the pc of the loop instruction it stopped. Its next_pc is the handler, so the next record starts there.
Example 3
A Load Fault- Input
TB_ARG = 2
- Output
silent on the good chip
The load from the hole traps with cause 5 and its address in tval. That is legal: only an interrupt must have tval 0.
Constraints and Contract
- Use assign, always_comb or always_ff @(posedge clk), with if, else and begin/end. Local state is bit or logic, up to 32 bits a variable. Nothing else of SystemVerilog is accepted.
- Report only on a valid record that breaks a rule: a report on the good chip fails the case.
- Each check builds the chip bench once. That took about 11 s on the laptop (measured); expect an estimated 40 s on the live server.
Hints
Hint 1
What must the checker remember from one record to the next? Count them, and keep the last next_pc.
Hint 2
trace_valid is 0 on many edges. Which of your flops may change on those edges?
Hint 3
Which traps carry a tval in this program, and which may not?
What the grader checks: Five runs of the server's program, two shown. Each runs on the good chip, where your checker stays silent and the program passes. It also runs on each hidden faulty chip, where your checker reports. The grader sees only whether you reported, not when or which rule fired. The hidden chips do not break every rule. A rule no hidden chip breaks is graded only by your silence on the good chip. The core's own faults, such as a wrong sum, leave every record well formed. This checker cannot see them: that is the model compare's work.
5 checks on ap_soc v1.5 · retire trace checker · server. Run the examples first, then check the full regression. Full checks use the server judge. Downloads contain your text only; the chip, the bench and the hidden checks stay on the server. A passing result establishes the tested cases, not a proof for all possible inputs.
See all 2 problems on this path