V5.2.1 The Lockstep Loop

MediumImplement35 minVerilator + your C over DPI · serverReview the topic

Write the loop at the heart of a lockstep bench. Step the instruction-level model once beside each recorded chip record. Give it what only the chip can know, and report the first field that differs.

Hardware context: ap_iss, the C model of ap_rv32, in lockstep with the core of ap_soc v1.5 through DPI. The lockstep loop against recorded records.

A lockstep bench runs the core and a model of it side by side. After every record the core retires, the model takes one step, and the two records must agree in every field. The model holds its own ROM and SRAM. Everything else it cannot know: a device answers whatever it answered on the chip.

Write three functions in lockstep.c. device_read and device_write answer the model's accesses outside ROM and SRAM from the chip's current record, ctx->now. lockstep steps the model once per chip record, in order. It returns the first record and field that differ, packed as in lockstep.h.

Your code runs against recorded records of ap_soc v1.5, three programs in traces.h. The device program reads registers the model cannot predict and takes three access faults. The other two do arithmetic, one on a chip whose SUB is reversed.

Full specification
The model asksYour answer
A fetch outside ROM and SRAM at addressThe record's insn. A bus error when the record trapped with cause 1 at that pc.
A load outside ROM and SRAMThe record's mem_rdata, which is already right-justified. A bus error when the record trapped with cause 5.
A store outside ROM and SRAMAccepted. A bus error when the record trapped with cause 7.
FieldNameFieldNameFieldName
1order9rs1_addr17mem_wmask
2pc10rs1_rdata18mem_rdata
3insn11rs2_addr19mem_wdata
4next_pc12rs2_rdata20csr_write
5priv13rd_addr21csr_addr
6trap14rd_wdata22csr_wdata
7cause15mem_addr23mstatus
8tval16mem_rmask24mip

The bench makes a fresh model for every case: ap_rv32 v1.2 on ROM and SRAM, reset vector 0x8000_0000. The program's image is in SRAM. It points the model's context at a replay structure and passes it to you. These programs take no interrupt and run no wfi, so the model always gives a record.

Examples

Example 1

The Device Program on the Good Chip
Input
device program as recorded
Output
record_index_plus_1 = 0, field = 0

Every one of the 64 records agrees, including the five device reads and the four traps.

Example 2

Arithmetic on the Good Chip
Input
alu program as recorded
Output
record_index_plus_1 = 0, field = 0

All 24 records agree.

Example 3

Arithmetic on a Chip Whose SUB Is Reversed (Recorded)
Input
faulty-alu program as recorded
Output
record_index_plus_1 = 10, field = 14

The chip's SUB gives edcbaa88, the model what SUB means: record 9 (counting from 0), field 14 (rd_wdata).

Constraints and Contract

  • One file, lockstep.c, with the three functions of lockstep.h. Use only ap_iss.h calls and the record you are given.
  • Compare the order as 64 bits and the other 23 fields as 32 bits each. The first field that differs, in the numbering of the table, is the one to report.
  • Each case returns one 32-bit word. Some cases change one field of one recorded record, the way a faulty chip would; their labels say only "Private".

Hints

Hint 1

The model asks for a device inside ap_iss_step. So ctx->now must point at this record before the step.

Hint 2

A device load's value is in mem_rdata. rd_wdata is what the core did with it afterwards, and that is what you are checking.

Hint 3

ap_iss_record keeps pc to mip as 23 words in a row after order.

What the grader checks: Each case runs your lockstep over one recorded program of ap_soc v1.5, some with one field of one record changed. It checks the record and field you report. It cannot see how fast your loop runs, and these programs take no interrupt.

16 checks on Verilator + your C over DPI · server. Run the examples first, then check the full regression. Full checks use the server judge. Downloads contain public samples only. A passing result establishes the tested cases, not a proof for all possible inputs.

See all 2 problems on this path

Report a problem with this page

Your code CSaved locally
Ln 1, Col 1Tab indents · Ctrl/⌘ + Enter runs samples
Not run yet

The Device Program on the Good Chip

Input
device program as recorded
Expected output
record_index_plus_1 = 0, field = 0

Every one of the 64 records agrees, including the five device reads and the four traps.

Run samples executes all 3 public checks. Check all tests runs 16 checks on the server.

Verilator + your C over DPI · server