V4.9.2 A Jump to Nowhere

MediumDebug20 minap_soc v1.5 · recorded bootReview the topic

A small C test runs a list of operations the bench chooses. It prints three results and ends with fail code 0xFFFF, the kit's code for a trap. Find the first wrong transfer behind the trap.

TB_ARG was 3 for this run. The retire trace has one trap: at pc 00000000, mcause 2. The kit's trap handler then saved registers and wrote fail code 0xFFFF.

The firmware of the recorded run (main.c).
#include "hal.h"
#include "tb.h"

/* The operations a bench run may ask for, by number. */
static void op_identity(void) { tb_put_hex(reg_read32(SYSCTL_CHIP_ID)); tb_putc('\n'); }
static void op_straps(void)   { tb_put_hex(reg_read32(SYSCTL_STRAPS)); tb_putc('\n'); }
static void op_gates(void)    { tb_put_hex(reg_read32(SYSCTL_CLK_GATE)); tb_putc('\n'); }
static void (* volatile ops[3])(void) = { op_identity, op_straps, op_gates };
static const char banner[] = "ops: run";

int main(void)
{
    unsigned count = tb_arg(0);                    /* the bench asks for operations 0 .. count */
    tb_puts(banner);
    tb_putc('\n');
    for (unsigned n = 0; n <= count; n++) ops[n]();
    return 0;
}

In main, addi a5, s2, 928 makes the address of ops, and the loop adds the offset of entry n. Then lw a5, 0(a5) loads the pointer and jalr a5 calls it. The register list gives the addresses of the variables near ops. The full specification holds the listing of main.

The trace below shows 35 of 126 retired loads and stores, cycles 664 to 868. Name the first transfer that went wrong: its cycle, the wrong part, its address and its register or variable. Then choose the cause.

Full specification
main in the listing of this image (riscv64-unknown-elf-gcc (14.2.0+19) 14.2.0): address and instruction.
8000030c <main>:
8000030c:  addi  sp,sp,-16
80000310:  li  a0,0
80000314:  sw  ra,12(sp)
80000318:  sw  s0,8(sp)
8000031c:  sw  s1,4(sp)
80000320:  sw  s2,0(sp)
80000324:  jal  8000027c <tb_arg>
80000328:  mv  s1,a0
8000032c:  lui  a0,0x80000
80000330:  addi  a0,a0,916
80000334:  jal  80000224 <tb_puts>
80000338:  li  a0,10
8000033c:  jal  80000218 <tb_putc>
80000340:  li  s0,0
80000344:  lui  s2,0x80000
80000348:  slli  a4,s0,0x2
8000034c:  addi  a5,s2,928
80000350:  add  a5,a5,a4
80000354:  lw  a5,0(a5)
80000358:  addi  s0,s0,1
8000035c:  jalr  a5
80000360:  bgeu  s1,s0,80000348 <main+0x3c>
80000364:  lw  ra,12(sp)
80000368:  lw  s0,8(sp)
8000036c:  lw  s1,4(sp)
80000370:  lw  s2,0(sp)
80000374:  li  a0,0
80000378:  addi  sp,sp,16
8000037c:  ret

The register list names every address the answer may use. Addresses are in hex without 0x in the trace; write them with or without 0x in the form.

Data in the trace is the word as the bus carried it. A load's data is what came back; a store's is what was written.

Diagnose the Failing Run

Recorded Console and Result

ARG 1: 00000003
CONSOLE 331: ops: run
CONSOLE 467: 2a5310c5
CONSOLE 604: 00000001
CONSOLE 741: 0000001f
verdict=fail
reason=status_fail
status=bad0ffff
cycles=876
traps=1
interrupts=0
mismatches=0

Retired Memory Transfers

CyclePC (hex)OperationAddress (hex)Data (hex)
66480000268load8000038000000030
66780000270store1000402400000030
67680000268load8000038000000030
67980000270store1000402400000030
68880000268load8000038000000030
69180000270store1000402400000030
70080000268load8000038000000030
70380000270store1000402400000030
71280000268load8000038100000031
71580000270store1000402400000031
72480000268load8000038f00000066
72780000270store1000402400000066
733800002b4load8000ffec80000360
7428000021cstore100040240000000a
75280000354load800003ac00000000
76380000094store8000ffb080000360
76680000098store8000ffb410004020
7698000009cstore8000ffb800000002
774800000a0store8000ffbc800003ac
777800000a4store8000ffc000000000
780800000a8store8000ffc400000000
785800000acstore8000ffc800000000
788800000b0store8000ffcc00000000
791800000b4store8000ffd00000000a
796800000b8store8000ffd4fffffffc
799800000bcstore8000ffd80000000f
802800000c0store8000ffdc00000066
807800000c4store8000ffe00000000c
810800000c8store8000ffe400000000
813800000ccstore8000ffe880000000
818800000d0store8000ffec00000000
8308000012cstore8000ffac800000dc
83380000130store8000ffa800000004
83680000134store8000ffa400000003
86880000210store10004020bad0ffff
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.

tb.h
#ifndef AP_TB_H
#define AP_TB_H
_Noreturn void tb_pass(void);
_Noreturn void tb_fail(unsigned code);
void tb_putc(char byte);
void tb_puts(const char *text);
void tb_put_hex(unsigned value);
void tb_event(unsigned id);
/* Slot zero is the single bench-to-firmware argument word. */
unsigned tb_arg(unsigned n);
void tb_wait_event(unsigned id);
#endif

hal.h
#ifndef AP_HAL_H
#define AP_HAL_H
#include "ap_soc_regs.h"

/* V13.4 supplies these two functions through DPI in a host-native build. */
#ifdef AP_HOST_DPI
unsigned reg_read32(unsigned address);
void reg_write32(unsigned address, unsigned value);
#else
static inline unsigned reg_read32(unsigned address)
{
    return *(volatile unsigned *)address;
}
static inline void reg_write32(unsigned address, unsigned value)
{
    *(volatile unsigned *)address = value;
}
#endif

#define FIELD_GET(field, word) (((word) & field##_MASK) >> field##_SHIFT)
#define FIELD_PREP(field, value) (((unsigned)(value) << field##_SHIFT) & field##_MASK)
#endif

ap_sysctl · register manual
OffsetRegisterBitsFieldAccessResetHeld byMeaning
0x000CHIP_ID31:0valuero0x2A5310C5constThe chip's identity: the IDCODE of the TAP. Fixed number.
0x004RESET_CAUSE0power_onroblockSticky record of reset sources since power-on. Power-on reset.
0x004RESET_CAUSE1pinroblockReset pin.
0x004RESET_CAUSE2watchdogroblockWatchdog.
0x004RESET_CAUSE3softwareroblockSoftware request.
0x004RESET_CAUSE4debugroblockDebug request.
0x008SOFT_RESET0timerwonot storedReset requests from software. 1 arms one restart of the timer.
0x008SOFT_RESET1chipwonot stored1 requests the software reset (new in v1.5).
0x00CSTRAPS0bootroblockStraps as sampled at power-up (new in v1.5). 0: start in the boot ROM. 1: start in SRAM.
0x010PINMUX31:0selectrw0x00000000regsTwo bits for each of sixteen pads: 0 released, 1 GPIO, 2 serial, 3 auxiliary. Pad n uses bits 2n+1 and 2n.
0x014CLK_GATE0uart0rw0x1regs1 lets that block's clock run (new in v1.5). UART0.
0x014CLK_GATE1gpiorw0x1regsGPIO.
0x014CLK_GATE2timerrw0x1regsTimer and PWM.
0x014CLK_GATE3spirw0x1regsSPI.
0x014CLK_GATE4dmarw0x1regsDMA.
0x018LOCK0pinmuxw1s0x0regsWrite-once locks. Only a reset clears one (new in v1.5). 1: PINMUX ignores writes.
0x018LOCK1clk_gatew1s0x0regs1: CLK_GATE ignores writes.
0x018LOCK2debugw1s0x0regs1: the debug lock is closed.
0x020TB_STATUS31:0valuerw0x00000000regs (power-on reset only)Scratch word 0. The firmware kit reports progress, pass and fail here. Plain storage.
0x024TB_PUTC31:0valuerw0x00000000regs (power-on reset only)Scratch word 1. The firmware kit writes one character here. Plain storage.
0x028TB_EVENT31:0valuerw0x00000000regs (power-on reset only)Scratch word 2. The firmware kit writes an event number here. Plain storage.
0x02CTB_ARG31:0valuerw0x00000000regs (power-on reset only)Scratch word 3. A bench leaves a word for the firmware here. Plain storage.