V5.6.2 The Interrupt Claimed Out of Turn

MediumDebug20 minap_soc v1.5 · recorded bootReview the topic

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
The assembly of the recorded run, after three instructions put in front of it (TB_STATUS = 2).
    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

CyclePC (hex)OperationAddress (hex)Data (hex)
1280000008store1000402000000002
248000002cstore0c00000400000001
2680000034store0c00000800000005
2780000038load0c00000800000005
3080000044store0c00200000000006
3480000050store1000101800000100
3780000058store1000402800000005
4180000064store1000000800000001
4480000070load0c00100000000006
65800000f8load0c20000400000001
67800000fcstore8000011800000001
6880000100store0c20000400000001
86800000c4load8000011800000001
93800000d8store10004020bad00004
Step 1 · The first bad cycle and signal
Step 2 · The cause

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
OffsetRegisterBitsFieldAccessResetHeld byMeaning
0x004 + 4 × (n − 1), n = 1 to 16PRIORITY2:0levelrw0x0blockPriority of source n, 0 to 7. 0 never competes. Priority.
0x001000PENDING16:1sourcesroblockPending bits; bit number = source ID. One bit for each source.
0x002000ENABLE16:1sourcesrw0x0000blockEnable bits; bit number = source ID. One bit for each source.
0x200000THRESHOLD2:0levelrw0x0blockThe core sees a request only above this priority. Threshold.
0x200004CLAIM4:0idrw0x00blockRead: claim, returns the winner's ID and clears its pending bit. Write: complete, names the ID that is done. Source ID.