V9.2.2 The Copy That Came Back Empty

MediumDebug20 minap_soc v1.5 · recorded bootReview the topic

A DMA test passes on its own. In a regression where the bench restarts the core in the middle of the copy, it fails with an empty destination word. Find the first transfer that broke what the test assumed, and say why.

The test copies 2,048 bytes of SRAM with the DMA and sleeps until the DMA's interrupt. It fills the source only on a cold boot, because SRAM keeps its words through a warm reset. On every boot it clears the destination first.

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

#define LEN 2048u
static volatile unsigned *const src = (volatile unsigned *)0x80004000u;
static volatile unsigned *const dst = (volatile unsigned *)0x80008000u;
static volatile unsigned done;

static void on_dma(void) { dma_ack(dma_status()); done = 1; }

int main(void)
{
    tb_puts("boot, cause "); tb_put_hex(reg_read32(SYSCTL_RESET_CAUSE)); tb_putc('\n');
    unsigned cause = reg_read32(SYSCTL_RESET_CAUSE);
    if (cause == SYSCTL_RESET_CAUSE_POWER_ON_MASK)           /* SRAM keeps the source through a warm reset */
        for (unsigned i = 0; i < LEN / 4; i++) src[i] = 0xa5000000u | (i << 12) | i;
    for (unsigned i = 0; i < LEN / 4; i++) dst[i] = 0;      /* a clean destination */
    irq_enable(DMA_IRQ, on_dma);
    dma_start_copy(0x80004000u, 0x80008000u, LEN, DMA_IRQ_ENABLE_DONE_MASK);
    tb_event(0x922);                                      /* the copy runs */
    while (!done) __asm__ volatile ("wfi");            /* sleep until the DMA's interrupt */
    for (unsigned i = 0; i < LEN / 4; i++)
        if (dst[i] != src[i]) {
            tb_puts("dst word "); tb_put_hex(i); tb_puts(" = "); tb_put_hex(dst[i]); tb_putc('\n');
            return 1;
        }
    tb_puts("copy ok\n");
    return 0;
}

In this run the bench raised a debug reset 200 cycles after the test's event 0x922, while the first copy ran. A debug reset is one of the chip's five sources (V9.1). On v1.5 only the bench can raise it: the chip ties the debug module's request low. The test then ran again from the top and failed with code 1.

The reference model ran beside the chip for the whole run and reported no mismatch. The core executed the program as written.

dma_start_copy is the kit's: it reads STATUS, returns 0 if BUSY is set, and otherwise writes the registers and START. The full specification holds the driver.

The trace shows 12 of 1803 retired loads and stores, cycles 9374 to 22753. Name the first transfer whose data broke an assumption of the test. Give its cycle, the wrong part, its address and its register or variable. Then choose the cause.

Full specification
dma_start_copy, from the kit (drivers/dma.c)
int dma_start_copy(unsigned src, unsigned dst, unsigned bytes, unsigned irq_enable)
{
    if (dma_status() & DMA_STATUS_BUSY_MASK) return 0;
    dma_ack(DMA_STATUS_DONE_MASK | DMA_STATUS_FAULT_MASK);
    reg_write32(DMA_SRC, src);
    reg_write32(DMA_DST, dst);
    reg_write32(DMA_LEN, bytes);
    reg_write32(DMA_IRQ_ENABLE, irq_enable & (DMA_IRQ_ENABLE_DONE_MASK | DMA_IRQ_ENABLE_FAULT_MASK));
    reg_write32(DMA_START, DMA_START_START_MASK);
    return 1;
}

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

A load's data is what came back; a store's is what was written. A byte store shows its byte in the low eight bits.

Diagnose the Failing Run

Recorded Console and Result

CONSOLE 478: boot, cause 00000001
EVENT 8772: 00000922
CONSOLE 9923: boot, cause 00000011
EVENT 17247: 00000922
CONSOLE 22723: dst word 00000000 = 00000000
verdict=fail
reason=status_fail
status=bad00001
cycles=22761
traps=1
interrupts=1
mismatches=0
checker_errors=0
reset_debug=1
dma_bytes=2048
spi_frames=0

Retired Memory Transfers

CyclePC (hex)OperationAddress (hex)Data (hex)
93748000007cstore1000402000000002
969880000340load1000400400000011
995680000398store8000800000000000
1710880000398store800087fc00000000
1717380000180store0c00200000000020
1721680000490load1000601400000001
17248800002f4store1000402800000922
2223180000474load1000601400000002
2224180000484store1000601400000002
22326800003f4load8000800000000000
22328800003f8load80004000a5000000
2275380000284store10004020bad00001
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

irq.h
#ifndef AP_IRQ_H
#define AP_IRQ_H
typedef void (*irq_handler)(void);
unsigned plic_claim(void);
void plic_complete(unsigned id);
void irq_enable(unsigned id, irq_handler handler);
unsigned long long mtime_read(void);
void mtime_set_compare(unsigned long long deadline);
void msip_enable(irq_handler handler);
void mtime_enable(irq_handler handler);
#endif

drivers/dma.h
#ifndef AP_DMA_H
#define AP_DMA_H
#include "hal.h"

/* Addresses are chip byte addresses in either the CPU or the bus-manager seat.
 * Start returns zero if a transfer already owns the engine. */
int dma_start_copy(unsigned src, unsigned dst, unsigned bytes, unsigned irq_enable);
unsigned dma_status(void);
unsigned dma_wait(void);
void dma_ack(unsigned status);
#endif

DMA · register manual
OffsetRegisterBitsFieldAccessResetHeld byMeaning
0x000SRC31:0addressrw0x00000000regsThe address of the first byte to read. Byte address.
0x004DST31:0addressrw0x00000000regsThe address of the first byte to write. Byte address.
0x008LEN31:0bytesrw0x00000000regsThe number of bytes. Byte count.
0x00CSTART0startwonot storedBit 0 = 1 starts the job. Software writes it last. 1 starts the job.
0x014STATUS0busyroblockJob state (new in v1.5). A job is running.
0x014STATUS1donew1cblockThe last write of a job has finished.
0x014STATUS2faultw1cblockA bus error stopped the job.
0x018IRQ_ENABLE0donerw0x0regsWhich status bits raise interrupt source 5 (new in v1.5). DONE raises the request.
0x018IRQ_ENABLE1faultrw0x0regsFAULT raises the request.
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.