V0.4.2 Works Once, Fails After a Warm Reset

MediumDebug25 minap_soc v1.5 · assembly · serverReview the topic

A ROM program prints the same sums on every boot, until a warm reset. Read the failing run, find the start-up step that is missing, and repair the start-up code.

Hardware context: The firmware kit's start-up code and linker script on ap_soc v1.5, in the ROM and SRAM layouts. Debugging a test that never reaches main.

A ROM program for ap_soc prints the reset cause and five numbers. Then it asks for a software reset and prints them again. The five numbers depend only on TB_ARG and the program, so they should match on both lines. On the second boot they do not.

Here is its run on the chip, as this page shows it. Read it before the code: which numbers changed, and which stayed?

The given program, the first two cases, run on the chip bench.
n = 5:
  The console text is not the expected text.
  console:
    c=00000001 n=00000005 t=0000000f h=00000005 m=00000039 k=0000005a
    c=00000009 n=0000000a t=0000001e h=00000005 m=00000759 k=0000005a
  status=0000900d resets=1 cycles=1821

n = 1:
  The console text is not the expected text.
  console:
    c=00000001 n=00000001 t=00000003 h=00000001 m=00000001 k=0000005a
    c=00000009 n=00000002 t=00000006 h=00000001 m=00000003 k=0000005a
  status=0000900d resets=1 cycles=1624

n = 0:
  The test ended with the pass word.
  console:
    c=00000001 n=00000000 t=00000000 h=00000000 m=00000000 k=0000005a
    c=00000009 n=00000000 t=00000000 h=00000000 m=00000000 k=0000005a
  status=0000900d resets=1 cycles=1574

Find the start-up step that is missing and put it back. The step belongs in start-up code, before main; the bench checks what the two boots print.

Full specification
NameValue
DATA0x8000_0000, two words with first values in data_init
BSS0x8000_0008 to 0x8000_0018 (end not included), four words C expects at 0
RESET_CAUSEap_sysctl 0x04: 0x01 after power-on, 0x09 after a software reset (bits 0 and 3)
SOFT_RESETap_sysctl 0x08: a written 2 asks for a software reset of the chip

A warm reset keeps SRAM: every word holds what it held. The scratch registers of ap_sysctl keep their values too.

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

ap_sysctl · register manual
OffsetRegisterBitsFieldAccessResetHeld byMeaning
0x000CHIP_ID31:0valuero0x2A5310C5constThe chip's identity: the IDCODE of the TAP. Fixed number.
0x004RESET_CAUSE0power_onroblockSticky record of reset sources since power-on. Power-on reset.
0x004RESET_CAUSE1pinroblockReset pin.
0x004RESET_CAUSE2watchdogroblockWatchdog.
0x004RESET_CAUSE3softwareroblockSoftware request.
0x004RESET_CAUSE4debugroblockDebug request.
0x008SOFT_RESET0timerwonot storedReset requests from software. 1 arms one restart of the timer.
0x008SOFT_RESET1chipwonot stored1 requests the software reset (new in v1.5).
0x00CSTRAPS0bootroblockStraps as sampled at power-up (new in v1.5). 0: start in the boot ROM. 1: start in SRAM.
0x010PINMUX31:0selectrw0x00000000regsTwo bits for each of sixteen pads: 0 released, 1 GPIO, 2 serial, 3 auxiliary. Pad n uses bits 2n+1 and 2n.
0x014CLK_GATE0uart0rw0x1regs1 lets that block's clock run (new in v1.5). UART0.
0x014CLK_GATE1gpiorw0x1regsGPIO.
0x014CLK_GATE2timerrw0x1regsTimer and PWM.
0x014CLK_GATE3spirw0x1regsSPI.
0x014CLK_GATE4dmarw0x1regsDMA.
0x018LOCK0pinmuxw1s0x0regsWrite-once locks. Only a reset clears one (new in v1.5). 1: PINMUX ignores writes.
0x018LOCK1clk_gatew1s0x0regs1: CLK_GATE ignores writes.
0x018LOCK2debugw1s0x0regs1: the debug lock is closed.
0x020TB_STATUS31:0valuerw0x00000000regs (power-on reset only)Scratch word 0. The firmware kit reports progress, pass and fail here. Plain storage.
0x024TB_PUTC31:0valuerw0x00000000regs (power-on reset only)Scratch word 1. The firmware kit writes one character here. Plain storage.
0x028TB_EVENT31:0valuerw0x00000000regs (power-on reset only)Scratch word 2. The firmware kit writes an event number here. Plain storage.
0x02CTB_ARG31:0valuerw0x00000000regs (power-on reset only)Scratch word 3. A bench leaves a word for the firmware here. Plain storage.

Examples

Example 1

n = 5
Input
n = 5
Output
console: " c=00000001 n=00000005 t=0000000f h=00000005 m=00000039 k=0000005a\n c=00000009 n=00000005 t=0000000f h=00000005 m=00000039 k=0000005a\n"

n = 5: five passes. Both lines show the same counts; only c changes, from 1 to 9.

Example 2

n = 1
Input
n = 1
Output
console: " c=00000001 n=00000001 t=00000003 h=00000001 m=00000001 k=0000005a\n c=00000009 n=00000001 t=00000003 h=00000001 m=00000001 k=0000005a\n"

n = 1: one pass on each boot.

Example 3

n = 0
Input
n = 0
Output
console: " c=00000001 n=00000000 t=00000000 h=00000000 m=00000000 k=0000005a\n c=00000009 n=00000000 t=00000000 h=00000000 m=00000000 k=0000005a\n"

n = 0: no pass at all. Every counter stays 0 on both boots, so this case cannot tell a missing clear.

Constraints and Contract

  • Assembly for the ROM layout: the chip starts at 0x0000_0000.
  • Keep the two boots and the line format. The bench checks both lines for several values of TB_ARG, and that exactly one reset happened.

Hints

Hint 1

Compare the two lines field by field. Which values depend on where they started?

Hint 2

The bench fills SRAM with zeros before the first boot. Who fills it before the second?

Hint 3

Count how many words your fix writes, and check both ends of the section.

What the grader checks: Each case runs the program on the chip bench: two boots and one software reset, with the console text compared exactly. It cannot see start-up steps that leave no trace in the five printed values.

5 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

n = 5

Input
n = 5
Expected output
console: " c=00000001 n=00000005 t=0000000f h=00000005 m=00000039 k=0000005a\n c=00000009 n=00000005 t=0000000f h=00000005 m=00000039 k=0000005a\n"

n = 5: five passes. Both lines show the same counts; only c changes, from 1 to 9.

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

ap_soc v1.5 · assembly · server