V2.2.2 The Greeting That Never Ends

MediumDebug25 minap_soc v1.5 · assembly · serverReview the topic

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:

The given program, the first two cases, run on the chip bench. The console repeats the boot line until the cycle limit.
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
Six records of its retire trace around the first trap: cycle, pc, instruction, effect.
   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
RegisterAddressUse
UART0 TXDATA0x1000_0000The next byte to send
UART0 STATUS0x1000_0004Bit 0 ROOM
UART0 IRQ_ENABLE0x1000_0008Interrupt enables
UART0 RXDATA0x1000_000CThe oldest received byte (read only)
UART0 DIV0x1000_0010clk_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
OffsetRegisterBitsFieldAccessResetHeld byMeaning
0x000TXDATA7:0datawonot storedThe low byte is the next byte to send. Byte to send.
0x004STATUS0roomroblockTransmit room and receive queue state. The transmitter can take a byte.
0x004STATUS1rx_readyroblockAt least one received byte waits.
0x004STATUS2rx_fullroblockThe receive queue is full.
0x008IRQ_ENABLE0roomrw0x0regsWhich status bits raise interrupt source 1. ROOM raises the request.
0x008IRQ_ENABLE1rx_readyrw0x0regsRX_READY raises the request (new in v1.5).
0x00CRXDATA7:0dataroblockThe oldest received byte. The read removes it from the queue. Received byte.
0x010DIV15:0cyclesrw0x0010regsBit 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

Report a problem with this page

Your code RISC-V assemblySaved locally
Ln 1, Col 1Tab indents · Ctrl/⌘ + Enter runs samples
Not run yet

TB_ARG = 7

Input
TB_ARG = 7
Expected output
console: "boot\nhi\nH\n"

TB_ARG = 7: the letter is H.

Run samples executes all 3 public checks. Check all tests runs 4 checks on the server.

ap_soc v1.5 · assembly · server