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.
#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
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
| Cycle | PC (hex) | Operation | Address (hex) | Data (hex) |
|---|---|---|---|---|
| 664 | 80000268 | load | 80000380 | 00000030 |
| 667 | 80000270 | store | 10004024 | 00000030 |
| 676 | 80000268 | load | 80000380 | 00000030 |
| 679 | 80000270 | store | 10004024 | 00000030 |
| 688 | 80000268 | load | 80000380 | 00000030 |
| 691 | 80000270 | store | 10004024 | 00000030 |
| 700 | 80000268 | load | 80000380 | 00000030 |
| 703 | 80000270 | store | 10004024 | 00000030 |
| 712 | 80000268 | load | 80000381 | 00000031 |
| 715 | 80000270 | store | 10004024 | 00000031 |
| 724 | 80000268 | load | 8000038f | 00000066 |
| 727 | 80000270 | store | 10004024 | 00000066 |
| 733 | 800002b4 | load | 8000ffec | 80000360 |
| 742 | 8000021c | store | 10004024 | 0000000a |
| 752 | 80000354 | load | 800003ac | 00000000 |
| 763 | 80000094 | store | 8000ffb0 | 80000360 |
| 766 | 80000098 | store | 8000ffb4 | 10004020 |
| 769 | 8000009c | store | 8000ffb8 | 00000002 |
| 774 | 800000a0 | store | 8000ffbc | 800003ac |
| 777 | 800000a4 | store | 8000ffc0 | 00000000 |
| 780 | 800000a8 | store | 8000ffc4 | 00000000 |
| 785 | 800000ac | store | 8000ffc8 | 00000000 |
| 788 | 800000b0 | store | 8000ffcc | 00000000 |
| 791 | 800000b4 | store | 8000ffd0 | 0000000a |
| 796 | 800000b8 | store | 8000ffd4 | fffffffc |
| 799 | 800000bc | store | 8000ffd8 | 0000000f |
| 802 | 800000c0 | store | 8000ffdc | 00000066 |
| 807 | 800000c4 | store | 8000ffe0 | 0000000c |
| 810 | 800000c8 | store | 8000ffe4 | 00000000 |
| 813 | 800000cc | store | 8000ffe8 | 80000000 |
| 818 | 800000d0 | store | 8000ffec | 00000000 |
| 830 | 8000012c | store | 8000ffac | 800000dc |
| 833 | 80000130 | store | 8000ffa8 | 00000004 |
| 836 | 80000134 | store | 8000ffa4 | 00000003 |
| 868 | 80000210 | store | 10004020 | bad0ffff |
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
| Offset | Register | Bits | Field | Access | Reset | Held by | Meaning |
|---|---|---|---|---|---|---|---|
0x000 | CHIP_ID | 31:0 | value | ro | 0x2A5310C5 | const | The chip's identity: the IDCODE of the TAP. Fixed number. |
0x004 | RESET_CAUSE | 0 | power_on | ro | block | Sticky record of reset sources since power-on. Power-on reset. | |
0x004 | RESET_CAUSE | 1 | pin | ro | block | Reset pin. | |
0x004 | RESET_CAUSE | 2 | watchdog | ro | block | Watchdog. | |
0x004 | RESET_CAUSE | 3 | software | ro | block | Software request. | |
0x004 | RESET_CAUSE | 4 | debug | ro | block | Debug request. | |
0x008 | SOFT_RESET | 0 | timer | wo | not stored | Reset requests from software. 1 arms one restart of the timer. | |
0x008 | SOFT_RESET | 1 | chip | wo | not stored | 1 requests the software reset (new in v1.5). | |
0x00C | STRAPS | 0 | boot | ro | block | Straps as sampled at power-up (new in v1.5). 0: start in the boot ROM. 1: start in SRAM. | |
0x010 | PINMUX | 31:0 | select | rw | 0x00000000 | regs | Two bits for each of sixteen pads: 0 released, 1 GPIO, 2 serial, 3 auxiliary. Pad n uses bits 2n+1 and 2n. |
0x014 | CLK_GATE | 0 | uart0 | rw | 0x1 | regs | 1 lets that block's clock run (new in v1.5). UART0. |
0x014 | CLK_GATE | 1 | gpio | rw | 0x1 | regs | GPIO. |
0x014 | CLK_GATE | 2 | timer | rw | 0x1 | regs | Timer and PWM. |
0x014 | CLK_GATE | 3 | spi | rw | 0x1 | regs | SPI. |
0x014 | CLK_GATE | 4 | dma | rw | 0x1 | regs | DMA. |
0x018 | LOCK | 0 | pinmux | w1s | 0x0 | regs | Write-once locks. Only a reset clears one (new in v1.5). 1: PINMUX ignores writes. |
0x018 | LOCK | 1 | clk_gate | w1s | 0x0 | regs | 1: CLK_GATE ignores writes. |
0x018 | LOCK | 2 | debug | w1s | 0x0 | regs | 1: the debug lock is closed. |
0x020 | TB_STATUS | 31:0 | value | rw | 0x00000000 | regs (power-on reset only) | Scratch word 0. The firmware kit reports progress, pass and fail here. Plain storage. |
0x024 | TB_PUTC | 31:0 | value | rw | 0x00000000 | regs (power-on reset only) | Scratch word 1. The firmware kit writes one character here. Plain storage. |
0x028 | TB_EVENT | 31:0 | value | rw | 0x00000000 | regs (power-on reset only) | Scratch word 2. The firmware kit writes an event number here. Plain storage. |
0x02C | TB_ARG | 31:0 | value | rw | 0x00000000 | regs (power-on reset only) | Scratch word 3. A bench leaves a word for the firmware here. Plain storage. |
## ap_sysctl (base 0x1000_4000, clk_sys, PD_MAIN) | Offset | Register | Bits | Field | Access | Reset | Held by | Meaning | | --- | --- | --- | --- | --- | --- | --- | --- | | `0x000` | CHIP_ID | 31:0 | value | ro | `0x2A5310C5` | const | The chip's identity: the IDCODE of the TAP. Fixed number. | | `0x004` | RESET_CAUSE | 0 | power_on | ro | | block | Sticky record of reset sources since power-on. Power-on reset. | | `0x004` | RESET_CAUSE | 1 | pin | ro | | block | Reset pin. | | `0x004` | RESET_CAUSE | 2 | watchdog | ro | | block | Watchdog. | | `0x004` | RESET_CAUSE | 3 | software | ro | | block | Software request. | | `0x004` | RESET_CAUSE | 4 | debug | ro | | block | Debug request. | | `0x008` | SOFT_RESET | 0 | timer | wo | | not stored | Reset requests from software. 1 arms one restart of the timer. | | `0x008` | SOFT_RESET | 1 | chip | wo | | not stored | 1 requests the software reset (new in v1.5). | | `0x00C` | STRAPS | 0 | boot | ro | | block | Straps as sampled at power-up (new in v1.5). 0: start in the boot ROM. 1: start in SRAM. | | `0x010` | PINMUX | 31:0 | select | rw | `0x00000000` | regs | Two bits for each of sixteen pads: 0 released, 1 GPIO, 2 serial, 3 auxiliary. Pad n uses bits 2n+1 and 2n. | | `0x014` | CLK_GATE | 0 | uart0 | rw | `0x1` | regs | 1 lets that block's clock run (new in v1.5). UART0. | | `0x014` | CLK_GATE | 1 | gpio | rw | `0x1` | regs | GPIO. | | `0x014` | CLK_GATE | 2 | timer | rw | `0x1` | regs | Timer and PWM. | | `0x014` | CLK_GATE | 3 | spi | rw | `0x1` | regs | SPI. | | `0x014` | CLK_GATE | 4 | dma | rw | `0x1` | regs | DMA. | | `0x018` | LOCK | 0 | pinmux | w1s | `0x0` | regs | Write-once locks. Only a reset clears one (new in v1.5). 1: PINMUX ignores writes. | | `0x018` | LOCK | 1 | clk_gate | w1s | `0x0` | regs | 1: CLK_GATE ignores writes. | | `0x018` | LOCK | 2 | debug | w1s | `0x0` | regs | 1: the debug lock is closed. | | `0x020` | TB_STATUS | 31:0 | value | rw | `0x00000000` | regs (power-on reset only) | Scratch word 0. The firmware kit reports progress, pass and fail here. Plain storage. | | `0x024` | TB_PUTC | 31:0 | value | rw | `0x00000000` | regs (power-on reset only) | Scratch word 1. The firmware kit writes one character here. Plain storage. | | `0x028` | TB_EVENT | 31:0 | value | rw | `0x00000000` | regs (power-on reset only) | Scratch word 2. The firmware kit writes an event number here. Plain storage. | | `0x02C` | TB_ARG | 31:0 | value | rw | `0x00000000` | regs (power-on reset only) | Scratch word 3. A bench leaves a word for the firmware here. Plain storage. |