A first run prints its boot line again and again and never says hello on the pad. Read the console and the trace, find the access that restarts the chip, and repair the program.
Hardware context: The first run of ap_soc v1.5 from power-on reset to a console line. Triage of a chip run that never prints.
A ROM program should print a boot line and hi on the console. Then it should send one letter and a new line out of the UART pad. It never gets that far. Here is its run:
TB_ARG = 7:
The run reached the limit of 40,000 cycles before a pass or fail word was written to TB_STATUS.
console:
boot
boot
boot
boot
... 541 lines in all
status=00000002 traps=540 uart_bytes=0
TB_ARG = 0:
The run reached the limit of 40,000 cycles before a pass or fail word was written to TB_STATUS.
console:
boot
boot
boot
boot
... 541 lines in all
status=00000002 traps=540 uart_bytes=0
TB_ARG = 15:
The run reached the limit of 40,000 cycles before a pass or fail word was written to TB_STATUS.
console:
boot
boot
boot
boot
... 541 lines in all
status=00000002 traps=540 uart_bytes=0
73 | 00000024 | addi t1, zero, 2 | x6 = 00000002
75 | 00000028 | sw t1, 16(s0) | mem[10004010] = 00000002
76 | 0000002c | addi t1, zero, 8 | x6 = 00000008
79 | 00000030 | sw t1, 20(s1) | trap, mcause = 00000007
83 | 00000000 | lui t0, 0x10004 | x5 = 10004000
84 | 00000004 | addi t1, zero, 2 | x6 = 00000002
Read the trace: which instruction trapped, and where did the core go next? Repair the program so that every case passes.
Full specification
| Register | Address | Use |
|---|---|---|
| UART0 TXDATA | 0x1000_0000 | The next byte to send |
| UART0 STATUS | 0x1000_0004 | Bit 0 ROOM |
| UART0 IRQ_ENABLE | 0x1000_0008 | Interrupt enables |
| UART0 RXDATA | 0x1000_000C | The oldest received byte (read only) |
| UART0 DIV | 0x1000_0010 | clk_sys cycles a bit; resets to 16 |
mcause 7 is a store access fault. In every register block of ap_soc, a write to an offset that holds no register, or to a read-only register, answers ERROR. mtvec is 0 after reset.
Given Files
Read-only files supplied by the bench.
defs.S
# defs.S: addresses and helpers of the smoke programs of ap_soc v1.5 (stage E4).
# check-soc-top.mjs puts this text in front of every program. Numbers: gen/ap_soc_regs.h.
.equ ROM, 0x00000000
.equ CLINT, 0x02000000
.equ PLIC, 0x0C000000
.equ UART, 0x10000000
.equ GPIO, 0x10001000
.equ TIMER, 0x10002000
.equ WDOG, 0x10003000
.equ SYSCTL, 0x10004000
.equ SPI, 0x10005000
.equ DMA, 0x10006000
.equ HOLE, 0x10007000
.equ PWRCTL, 0x10008000
.equ SRAM, 0x80000000
.equ TB_STATUS, 0x20
.equ TB_PUTC, 0x24
.equ TB_EVENT, 0x28
.equ TB_ARG, 0x2C
UART0 · register manual
| Offset | Register | Bits | Field | Access | Reset | Held by | Meaning |
|---|---|---|---|---|---|---|---|
0x000 | TXDATA | 7:0 | data | wo | not stored | The low byte is the next byte to send. Byte to send. | |
0x004 | STATUS | 0 | room | ro | block | Transmit room and receive queue state. The transmitter can take a byte. | |
0x004 | STATUS | 1 | rx_ready | ro | block | At least one received byte waits. | |
0x004 | STATUS | 2 | rx_full | ro | block | The receive queue is full. | |
0x008 | IRQ_ENABLE | 0 | room | rw | 0x0 | regs | Which status bits raise interrupt source 1. ROOM raises the request. |
0x008 | IRQ_ENABLE | 1 | rx_ready | rw | 0x0 | regs | RX_READY raises the request (new in v1.5). |
0x00C | RXDATA | 7:0 | data | ro | block | The oldest received byte. The read removes it from the queue. Received byte. | |
0x010 | DIV | 15:0 | cycles | rw | 0x0010 | regs | Bit time in clk_sys cycles (new in v1.5). clk_sys cycles a bit. |
## UART0 (base 0x1000_0000, interrupt source 1, clk_sys, PD_MAIN) | Offset | Register | Bits | Field | Access | Reset | Held by | Meaning | | --- | --- | --- | --- | --- | --- | --- | --- | | `0x000` | TXDATA | 7:0 | data | wo | | not stored | The low byte is the next byte to send. Byte to send. | | `0x004` | STATUS | 0 | room | ro | | block | Transmit room and receive queue state. The transmitter can take a byte. | | `0x004` | STATUS | 1 | rx_ready | ro | | block | At least one received byte waits. | | `0x004` | STATUS | 2 | rx_full | ro | | block | The receive queue is full. | | `0x008` | IRQ_ENABLE | 0 | room | rw | `0x0` | regs | Which status bits raise interrupt source 1. ROOM raises the request. | | `0x008` | IRQ_ENABLE | 1 | rx_ready | rw | `0x0` | regs | RX_READY raises the request (new in v1.5). | | `0x00C` | RXDATA | 7:0 | data | ro | | block | The oldest received byte. The read removes it from the queue. Received byte. | | `0x010` | DIV | 15:0 | cycles | rw | `0x0010` | regs | Bit time in clk_sys cycles (new in v1.5). clk_sys cycles a bit. |
Examples
Example 1
TB_ARG = 7- Input
TB_ARG = 7
- Output
console: "boot\nhi\nH\n"
TB_ARG = 7: the letter is H.
Example 2
TB_ARG = 0- Input
TB_ARG = 0
- Output
console: "boot\nhi\nA\n"
TB_ARG = 0: the letter is A.
Example 3
TB_ARG = 15- Input
TB_ARG = 15
- Output
console: "boot\nhi\nP\n"
TB_ARG = 15: the letter is P.
Constraints and Contract
- Assembly for the ROM layout.
- The console, the bytes on the pad and the number of traps are compared, for several values of TB_ARG. The board's UART runs at 8 cycles a bit.
Hints
Hint 1
The trapped store wrote to which address?
Hint 2
After the trap the core fetched from 0. What lives there in this image?
Hint 3
Making the trap harmless is not the same as doing what the store meant to do.
What the grader checks: Each case compares the console, the pad bytes and requires zero traps. The board's UART is fixed at 8 cycles a bit, so a wrong divider garbles every frame.
4 checks on ap_soc v1.5 · assembly · server. Run the examples first, then check the full regression. Full checks use the server judge. Downloads contain your text only; the chip, the bench and the hidden checks stay on the server. A passing result establishes the tested cases, not a proof for all possible inputs.
See all 2 problems on this path