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.

One Register Write, Seen by a Passive MonitorStep through one store to TB_PUTC: from the core, across the buses, into ap_sysctl. The bench logs it without driving a wire.
  • Processor
  • Bus
  • Peripheral
  • Debug
  • External
  • Data
  • Debug
One Register Write, Seen by a Passive MonitorStep through one store to TB_PUTC: from the core, across the buses, into ap_sysctl. The bench logs it without driving a wire. processor Core sw to 0x1000_4024at cycle 206 bus AHB fabric the core's data port bus AHB to APBbridge setup, then access peripheral ap_sysctl TB_STATUS,TB_PUTC,TB_EVENT, TB_ARGat 0x20 to 0x2C debug Mailbox monitor reads the bus; drivesnothing external Bench log CONSOLE, EVENT,the end of test storetransferAPB writewatchedone character
  1. processor Coresw to 0x1000_4024 at cycle 206
    • store → AHB fabric
  2. bus AHB fabricthe core's data port
    • transfer → AHB to APB bridge
  3. bus AHB to APB bridgesetup, then access
    • APB write → ap_sysctl
  4. peripheral ap_sysctlTB_STATUS, TB_PUTC, TB_EVENT, TB_ARG at 0x20 to 0x2C
    • watched → Mailbox monitor
  5. debug Mailbox monitorreads the bus; drives nothing
    • one character → Bench log
  6. external Bench logCONSOLE, EVENT, the end of test
  1. A store

    tb_putc is one store of a word to the address of TB_PUTC.

  2. Across the chip

    The store crosses the fabric and the bridge like any register write. Nothing about it is special.

  3. A real register

    ap_sysctl keeps the word. Firmware could read it back; a reset other than power-on keeps it.

  4. 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.

Five questions this page answers
Question
1Why does a test on the processor need a channel to the bench?
2Which registers form the mailbox, and what does each carry?
3Which status word ends a test, and what happens to later ones?
4How should a test choose its fail codes?
5Why 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

New words on this page
WordMeaning
MailboxThe four scratch registers of ap_sysctl that a test and the bench use to talk.
TB_STATUSAt 0x1000_4020: 1 boot ROM reached, 2 main entered, 0x900D pass, 0xBAD0_0000 + code fail.
TB_PUTCAt 0x1000_4024: one character of the console; the monitor builds lines from them.
TB_EVENTAt 0x1000_4028: a number for the bench, such as "send a byte now".
TB_ARGAt 0x1000_402C: a word from the bench, deposited by the back door.
Passive monitorBench 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.

Two runs, by hand
Words written, in orderVerdictWhy
2, then 0x900DPassmain entered, then the pass word
2, 0xBAD0_0007, then 0x900DFail, code 7The fail word is the end; the pass word after it changes nothing
0x900D aloneFailA pass word with no "main entered" before it
2, and nothing moreFail at a limitNo 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

  1. Rule 1: The first pass or fail word is the end.

    Write it last, once, when every check has run.

  2. Rule 2: "Main entered" must come before the pass.

    Start-up code writes 2; a pass without it is a fail.

  3. Rule 3: A fail code is 16 bits and names one check.

    Codes wider than 16 bits lose their top half.

  4. Rule 4: The console is for people, the status word for machines.

    Print what helps a human debug; put the verdict in TB_STATUS.

  5. 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

MAIL_C: a line, an event, three checks.
#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.

Measured on our bench (soc_tb, Verilator 5.052 2026-09-05): the good run, then the run with TB_ARG = 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=bad00003

In 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:

The first store to TB_PUTC (cycle, pc, instruction, effect).
  206 | 80000230 | sw a4, 0(a5)               | mem[10004024] = 0000006d

Two 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

ap_soc~12 blocks
Phone-class SoChundreds of blocks

This section looks ahead. Four registers serve one core here.

  1. 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.

  2. Richer logs

    Big benches turn the log channel into messages: an ID and arguments, decoded by the bench. Firmware then prints numbers, not text.

  3. 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?

RUNIcarus Verilog · in your browser
Edit the code, then run it
Expected: cycle 183: main entered cycle 430: pass

Check Yourself

Predict the outputThe slice now reads the status words of the run that wrote a fail word and then the pass word. What is the last line it prints?
// The words one run wrote to TB_STATUS, with their cycles. The bench's rules: 1 is boot ROM, 2 is main
// entered, 0x900D is pass, 0xBAD0_xxxx is fail with code xxxx; the first pass or fail word is the end.
module tb;
  localparam int N = 3;
  int          cycle [N];
  logic [31:0] word  [N];
  bit main_seen = 0, ended = 0;
  initial begin
    cycle[0] = 183; word[0] = 32'h00000002;
    cycle[1] = 191; word[1] = 32'hbad00007;
    cycle[2] = 195; word[2] = 32'h0000900d;
    for (int i = 0; i < N; i++) begin
      if (ended) $display("cycle %0d: %h comes after the end and changes nothing", cycle[i], word[i]);
      else if (word[i] == 32'h1) $display("cycle %0d: boot ROM reached", cycle[i]);
      else if (word[i] == 32'h2) begin main_seen = 1; $display("cycle %0d: main entered", cycle[i]); end
      else if (word[i] == 32'h900d) begin
        ended = 1;
        if (main_seen) $display("cycle %0d: pass", cycle[i]);
        else $display("cycle %0d: pass word, but main was never entered: fail", cycle[i]);
      end else if (word[i][31:16] == 16'hbad0) begin ended = 1; $display("cycle %0d: fail, code %h", cycle[i], word[i][15:0]); end
      else $display("cycle %0d: %h is no status word", cycle[i], word[i]);
    end
    if (!ended) $display("no pass or fail word: the run ends at a limit");
  end
endmodule
ConceptWhich mailbox register does the bench write?
Concepttb_fail(0x10003) is called. What reaches TB_STATUS?
ConceptWhy are the mailbox registers real registers of the chip?
ConceptWhat does the mailbox monitor do with the chip's signals?

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.

Practice

Report a problem with this page