The Mailbox: Telling the Bench What Happened
A test on the chip's processor has no screen and no file. It tells the bench what happened by writing four ordinary registers that a passive monitor watches. Learn the words, the codes and the rules, and why the mailbox is a real part of the chip.
You Will Be Able To
- Name the four mailbox registers and what each carries, and in which direction.
- Apply the bench's rules to a list of TB_STATUS words and say how the test ended.
- Design fail codes that a regression report can act on.
- Explain why the mailbox is made of real registers and not of a bench-only device.
- Lesson
- V4.2
- Time
- 24 min
- Runs on
- Your browser
- Check
- 5 questions
A night of C tests ends in a report with one line each: pass, or fail with a number. The person who reads it has never seen the tests. Whatever a test wanted to say, it had to say through four registers.
- Processor
- Bus
- Peripheral
- Debug
- External
- Data
- Debug
- A store
tb_putc is one store of a word to the address of TB_PUTC.
- Across the chip
The store crosses the fabric and the bridge like any register write. Nothing about it is special.
- A real register
ap_sysctl keeps the word. Firmware could read it back; a reset other than power-on keeps it.
- Seen, not driven
The bench's monitor sees the completed write and adds the low byte to the console line. It never touches the chip.
Read the diagram as text
- Core: sw to 0x1000_4024 at cycle 206
- AHB fabric: the core's data port
- AHB to APB bridge: setup, then access
- ap_sysctl: TB_STATUS, TB_PUTC, TB_EVENT, TB_ARG at 0x20 to 0x2C
- Mailbox monitor: reads the bus; drives nothing
- Bench log: CONSOLE, EVENT, the end of test
- Core → AHB fabric: store
- AHB fabric → AHB to APB bridge: transfer
- AHB to APB bridge → ap_sysctl: APB write
- ap_sysctl → Mailbox monitor: watched
- Mailbox monitor → Bench log: one character
The path of a mailbox write on ap_soc v1.5. The cycle is from the run below.
Before You Start
Read The Life of a C Test first. APB in One Picture shows the setup and access phases of the write in the picture.
| Question | |
|---|---|
| 1 | Why does a test on the processor need a channel to the bench? |
| 2 | Which registers form the mailbox, and what does each carry? |
| 3 | Which status word ends a test, and what happens to later ones? |
| 4 | How should a test choose its fail codes? |
| 5 | Why real registers, and not a device only the bench has? |
The Idea: Four Registers and a Listener
A firmware test runs where nothing can see it except the chip. It needs a way to say "I started", "I failed check 3", "print this", and "bench, do something now". The bench, in turn, needs a way to hand it a number. On ap_soc that channel is four 32-bit registers in ap_sysctl, which real chips also have as scratch registers.
The firmware writes them with ordinary stores. The bench never drives the chip to read them. A passive monitor watches the bus, sees each completed write and acts on it. Only TB_ARG goes the other way: the bench deposits a word there by the back door.
Because the channel is part of the chip, the same image works wherever the chip does. That means simulation, a faster model, an emulator, and silicon with a debugger.
New Words
| Word | Meaning |
|---|---|
| Mailbox | The four scratch registers of ap_sysctl that a test and the bench use to talk. |
| TB_STATUS | At 0x1000_4020: 1 boot ROM reached, 2 main entered, 0x900D pass, 0xBAD0_0000 + code fail. |
| TB_PUTC | At 0x1000_4024: one character of the console; the monitor builds lines from them. |
| TB_EVENT | At 0x1000_4028: a number for the bench, such as "send a byte now". |
| TB_ARG | At 0x1000_402C: a word from the bench, deposited by the back door. |
| Passive monitor | Bench code that watches the chip's signals and never drives them. |
The Smallest Example: Read a Status Sequence by Hand
The bench reads every word written to TB_STATUS, in order, and stops at the first pass or fail word. Apply the rules to two sequences.
| Words written, in order | Verdict | Why |
|---|---|---|
| 2, then 0x900D | Pass | main entered, then the pass word |
| 2, 0xBAD0_0007, then 0x900D | Fail, code 7 | The fail word is the end; the pass word after it changes nothing |
| 0x900D alone | Fail | A pass word with no "main entered" before it |
| 2, and nothing more | Fail at a limit | No pass or fail word: the cycle or no-progress limit ends the run |
The bench's rules from its manual (tools/soc/ap_soc/bench/soc_tb/README.md).
The Rules
Rule 1: The first pass or fail word is the end.
Write it last, once, when every check has run.
Rule 2: "Main entered" must come before the pass.
Start-up code writes 2; a pass without it is a fail.
Rule 3: A fail code is 16 bits and names one check.
Codes wider than 16 bits lose their top half.
Rule 4: The console is for people, the status word for machines.
Print what helps a human debug; put the verdict in TB_STATUS.
Rule 5: The bench only listens.
Its monitor reads the bus; only TB_ARG and named variables are written by the back door.
Sources for These Rules
The registers: docs/soc/ap_soc-facts.md 27.3 (fixed at stage E0). The bench's end of test and the first-word rule: facts 27.12 and the bench manual.
The kit's tb_fail keeps the low 16 bits: tools/soc/fwkit/tb.c.
Status words and a log channel through memory-mapped registers are a common pattern in open chip projects (plan §7). Ours are real registers of the chip, not a simulation-only memory: our design choice.
Now Run It: Three Checks and Two Wrong Words
#include "hal.h"
#include "tb.h"
int main(void)
{
tb_puts("mail: 3 checks\n"); /* TB_PUTC, one character a write */
tb_event(0x7701); /* TB_EVENT: a number the bench may act on */
if (reg_read32(SYSCTL_CHIP_ID) != 0x2a5310c5u) return 1;
if (reg_read32(SYSCTL_CLK_GATE) != 0x1f) return 2;
if (reg_read32(SYSCTL_TB_ARG) != 0x5a) return 3; /* TB_ARG: the bench put 0x5a there, or not */
return 0;
}The test ran twice: once with TB_ARG = 0x5A, as its third check expects, and once with 0x5B.
ARG 1: 0000005a
CONSOLE 373: mail: 3 checks
EVENT 391: 00007701
verdict=pass status=0000900d events=1 console_bytes=15
ARG 1: 0000005b
CONSOLE 373: mail: 3 checks
EVENT 391: 00007701
verdict=fail status=bad00003In the good run the bench logged the line, the event 0x7701 and the pass. In the second, check 3 failed and TB_STATUS read 0xbad00003: rule 3, one code for one check. The store behind the console line was an ordinary write in the retire trace:
206 | 80000230 | sw a4, 0(a5) | mem[10004024] = 0000006dTwo more runs test the rules. The first wrote the fail word 7 and then the pass word. The bench ended at the fail word, status 0xbad00007: rule 1. The second called tb_fail(0x10003): status 0xbad00003, the code cut to its low 16 bits, rule 3.
Why It Is Built This Way
Many benches use a device that exists only in simulation: a magic address, or a port the testbench owns. It is easy to add and it costs no gates. It also changes the memory map. The same image then fails on an emulator, on an FPGA and on silicon, where the magic address is a hole.
ap_soc uses scratch registers that the chip really has. They cost a few flops. In return the image is the same everywhere. The fast-platform stage of this chip ran six firmware images on four platforms, with the same console bytes. The scratch registers also survive a warm reset, so a test can carry a step number through one.
The Trap: The Test That Says Pass Too Soon
A test writes 0x900D at its start "to show it is alive", then runs its checks. Every run passes, because the bench stopped listening at the first pass word. Nobody notices until someone asks why that test never fails.
The second trap is a code that names nothing. A test that returns 1 for every failure makes the report useless: it says that something failed, not what. Codes per check cost nothing, and the second practice problem repairs a test with both faults. The first has you write the bench's ear itself: the monitor that decides which writes count.
At Scale
This section looks ahead. Four registers serve one core here.
Many cores
A chip with several processors gives each its own status word, or a field in a shared one. Then one core's pass cannot end another's test.
Richer logs
Big benches turn the log channel into messages: an ID and arguments, decoded by the bench. Firmware then prints numbers, not text.
Silicon
On silicon a debugger reads the same registers, so the test's verdict is visible on the lab bench too.
Try It
Run the slice: it applies the bench's rules to the status words of the good run.
Add a fail word before the pass word and predict the last line.
Remove the word 2. What does the slice say about the pass?
cycle 183: main entered cycle 430: passCheck Yourself
Common Mistakes
Wrong Write the pass word early to show the test is alive.
The first pass word ends the test; nothing after it counts.
Fix Let start-up code write 2; write pass or fail once, at the end.
Wrong Return the same code for every failure.
The report cannot say which check failed.
Fix Give each check its own 16-bit code.
Wrong Add a simulation-only device to talk to the bench.
The image then fails on every platform without that device.
Fix Use registers the chip really has, watched by a passive monitor.
Remember
- TB_STATUS, TB_PUTC and TB_EVENT go from firmware to bench; TB_ARG from bench to firmware.
- The first pass or fail word ends the test; a pass needs "main entered" before it.
- A fail code is 16 bits and should name one check.
- Real registers, watched passively, keep the same image working on every platform.