A boundary test raises two external interrupt sources at once, at different priorities. Its handler claims a source, and the test fails with its code 4. The model compare saw nothing wrong. Find the first transfer the chip got wrong.
This chip is a build under bring-up. The test gives ap_plic source 1 (UART0) priority 1 and source 2 (GPIO) priority 5, and enables both. It makes both ask, and waits until PENDING shows them together. Only then does it let the core take the external interrupt. The handler claims one source, keeps its number in a word called got, and completes it. The test then checks that got is 2. Its assembly is in the full specification.
The run ended with TB_STATUS = 0xbad00004: fail code 4. The core took 1 external interrupt. The model compared 57 records and found 0 mismatches.
Name the first transfer that went wrong: its cycle, the wrong part, its address and its register. Then choose the cause.
Full specification
la t0, trap
csrw mtvec, t0
li s0, SYSCTL
la s1, got
li t0, PLIC
li t1, 1
sw t1, 4(t0) # priority of source 1 (UART0) = 1
li t1, 5
sw t1, 8(t0) # priority of source 2 (GPIO) = 5
lw t2, 8(t0) # read it back, for the log
li t0, PLIC + 0x2000
li t1, 6
sw t1, 0(t0) # enable sources 1 and 2
li t0, GPIO
li t1, 0x100
sw t1, 0x18(t0) # GPIO: pin 8 may interrupt
li t1, 5
sw t1, TB_EVENT(s0) # the board pulses IO8
li t0, UART
li t1, 1
sw t1, 8(t0) # UART0: room to send may interrupt
li t0, PLIC + 0x1000
li t3, 200
1: lw t1, 0(t0) # PENDING: wait until both sources ask
li t2, 6
beq t1, t2, 2f
addi t3, t3, -1
bnez t3, 1b
li t1, 0xBAD00002 # fail code 2: the two sources never asked together
sw t1, TB_STATUS(s0)
8: j 8b
2: li t1, 2048
csrs mie, t1 # MEIE
csrsi mstatus, 8 # MIE: the interrupt is taken now
li t3, 200
3: bnez s4, 4f # wait for the handler
addi t3, t3, -1
bnez t3, 3b
li t1, 0xBAD00003 # fail code 3: no external interrupt
sw t1, TB_STATUS(s0)
8: j 8b
4: lw t1, 0(s1)
li t2, 2
beq t1, t2, 5f
li t1, 0xBAD00004 # fail code 4: the first claim was not source 2
sw t1, TB_STATUS(s0)
8: j 8b
5: li t1, 0x900D
sw t1, TB_STATUS(s0)
9: j 9b
trap:
li t5, PLIC + 0x200004
lw t6, 0(t5) # claim
sw t6, 0(s1) # keep it in got
sw t6, 0(t5) # complete
li t4, 2048
csrc mie, t4 # one interrupt is enough for this test
li s4, 1
mret
got: .word 0
ap_plic: PRIORITY of source n at 0x0C00_0000 + 4n (0 to 7); PENDING at 0x0C00_1000, bit n for source n; ENABLE at 0x0C00_2000. A source competes when it is pending, enabled and has a priority above 0. A read of CLAIM (0x0C20_0004) returns the winner, the highest priority, and the lower number on a tie. A write of that number completes it.
Data in the trace is the word as the bus carried it: what a load returned, what a store wrote.
Diagnose the Failing Run
Recorded Console and Result
verdict=fail reason=status_fail status=bad00004 cycles=101 retired=57 compares=57 mismatches=0 traps=1 interrupts=1 irq_software=0 irq_external=1
Retired Memory Transfers
| Cycle | PC (hex) | Operation | Address (hex) | Data (hex) |
|---|---|---|---|---|
| 12 | 80000008 | store | 10004020 | 00000002 |
| 24 | 8000002c | store | 0c000004 | 00000001 |
| 26 | 80000034 | store | 0c000008 | 00000005 |
| 27 | 80000038 | load | 0c000008 | 00000005 |
| 30 | 80000044 | store | 0c002000 | 00000006 |
| 34 | 80000050 | store | 10001018 | 00000100 |
| 37 | 80000058 | store | 10004028 | 00000005 |
| 41 | 80000064 | store | 10000008 | 00000001 |
| 44 | 80000070 | load | 0c001000 | 00000006 |
| 65 | 800000f8 | load | 0c200004 | 00000001 |
| 67 | 800000fc | store | 80000118 | 00000001 |
| 68 | 80000100 | store | 0c200004 | 00000001 |
| 86 | 800000c4 | load | 80000118 | 00000001 |
| 93 | 800000d8 | store | 10004020 | bad00004 |
Given Files
Use the register map to identify the transfer in the recording.
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_plic · register manual
| Offset | Register | Bits | Field | Access | Reset | Held by | Meaning |
|---|---|---|---|---|---|---|---|
0x004 + 4 × (n − 1), n = 1 to 16 | PRIORITY | 2:0 | level | rw | 0x0 | block | Priority of source n, 0 to 7. 0 never competes. Priority. |
0x001000 | PENDING | 16:1 | sources | ro | block | Pending bits; bit number = source ID. One bit for each source. | |
0x002000 | ENABLE | 16:1 | sources | rw | 0x0000 | block | Enable bits; bit number = source ID. One bit for each source. |
0x200000 | THRESHOLD | 2:0 | level | rw | 0x0 | block | The core sees a request only above this priority. Threshold. |
0x200004 | CLAIM | 4:0 | id | rw | 0x00 | block | Read: claim, returns the winner's ID and clears its pending bit. Write: complete, names the ID that is done. Source ID. |
## ap_plic (base 0x0C00_0000, clk_sys, PD_MAIN) | Offset | Register | Bits | Field | Access | Reset | Held by | Meaning | | --- | --- | --- | --- | --- | --- | --- | --- | | `0x004` + 4 × (n − 1), n = 1 to 16 | PRIORITY | 2:0 | level | rw | `0x0` | block | Priority of source n, 0 to 7. 0 never competes. Priority. | | `0x001000` | PENDING | 16:1 | sources | ro | | block | Pending bits; bit number = source ID. One bit for each source. | | `0x002000` | ENABLE | 16:1 | sources | rw | `0x0000` | block | Enable bits; bit number = source ID. One bit for each source. | | `0x200000` | THRESHOLD | 2:0 | level | rw | `0x0` | block | The core sees a request only above this priority. Threshold. | | `0x200004` | CLAIM | 4:0 | id | rw | `0x00` | block | Read: claim, returns the winner's ID and clears its pending bit. Write: complete, names the ID that is done. Source ID. |