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 asks | Your answer |
|---|---|
| A fetch outside ROM and SRAM at address | The record's insn. A bus error when the record trapped with cause 1 at that pc. |
| A load outside ROM and SRAM | The record's mem_rdata, which is already right-justified. A bus error when the record trapped with cause 5. |
| A store outside ROM and SRAM | Accepted. A bus error when the record trapped with cause 7. |
| Field | Name | Field | Name | Field | Name |
|---|---|---|---|---|---|
| 1 | order | 9 | rs1_addr | 17 | mem_wmask |
| 2 | pc | 10 | rs1_rdata | 18 | mem_rdata |
| 3 | insn | 11 | rs2_addr | 19 | mem_wdata |
| 4 | next_pc | 12 | rs2_rdata | 20 | csr_write |
| 5 | priv | 13 | rd_addr | 21 | csr_addr |
| 6 | trap | 14 | rd_wdata | 22 | csr_wdata |
| 7 | cause | 15 | mem_addr | 23 | mstatus |
| 8 | tval | 16 | mem_rmask | 24 | mip |
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