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?
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
| Name | Value |
|---|---|
| DATA | 0x8000_0000, two words with first values in data_init |
| BSS | 0x8000_0008 to 0x8000_0018 (end not included), four words C expects at 0 |
| RESET_CAUSE | ap_sysctl 0x04: 0x01 after power-on, 0x09 after a software reset (bits 0 and 3) |
| SOFT_RESET | ap_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
| Offset | Register | Bits | Field | Access | Reset | Held by | Meaning |
|---|---|---|---|---|---|---|---|
0x000 | CHIP_ID | 31:0 | value | ro | 0x2A5310C5 | const | The chip's identity: the IDCODE of the TAP. Fixed number. |
0x004 | RESET_CAUSE | 0 | power_on | ro | block | Sticky record of reset sources since power-on. Power-on reset. | |
0x004 | RESET_CAUSE | 1 | pin | ro | block | Reset pin. | |
0x004 | RESET_CAUSE | 2 | watchdog | ro | block | Watchdog. | |
0x004 | RESET_CAUSE | 3 | software | ro | block | Software request. | |
0x004 | RESET_CAUSE | 4 | debug | ro | block | Debug request. | |
0x008 | SOFT_RESET | 0 | timer | wo | not stored | Reset requests from software. 1 arms one restart of the timer. | |
0x008 | SOFT_RESET | 1 | chip | wo | not stored | 1 requests the software reset (new in v1.5). | |
0x00C | STRAPS | 0 | boot | ro | block | Straps as sampled at power-up (new in v1.5). 0: start in the boot ROM. 1: start in SRAM. | |
0x010 | PINMUX | 31:0 | select | rw | 0x00000000 | regs | Two bits for each of sixteen pads: 0 released, 1 GPIO, 2 serial, 3 auxiliary. Pad n uses bits 2n+1 and 2n. |
0x014 | CLK_GATE | 0 | uart0 | rw | 0x1 | regs | 1 lets that block's clock run (new in v1.5). UART0. |
0x014 | CLK_GATE | 1 | gpio | rw | 0x1 | regs | GPIO. |
0x014 | CLK_GATE | 2 | timer | rw | 0x1 | regs | Timer and PWM. |
0x014 | CLK_GATE | 3 | spi | rw | 0x1 | regs | SPI. |
0x014 | CLK_GATE | 4 | dma | rw | 0x1 | regs | DMA. |
0x018 | LOCK | 0 | pinmux | w1s | 0x0 | regs | Write-once locks. Only a reset clears one (new in v1.5). 1: PINMUX ignores writes. |
0x018 | LOCK | 1 | clk_gate | w1s | 0x0 | regs | 1: CLK_GATE ignores writes. |
0x018 | LOCK | 2 | debug | w1s | 0x0 | regs | 1: the debug lock is closed. |
0x020 | TB_STATUS | 31:0 | value | rw | 0x00000000 | regs (power-on reset only) | Scratch word 0. The firmware kit reports progress, pass and fail here. Plain storage. |
0x024 | TB_PUTC | 31:0 | value | rw | 0x00000000 | regs (power-on reset only) | Scratch word 1. The firmware kit writes one character here. Plain storage. |
0x028 | TB_EVENT | 31:0 | value | rw | 0x00000000 | regs (power-on reset only) | Scratch word 2. The firmware kit writes an event number here. Plain storage. |
0x02C | TB_ARG | 31:0 | value | rw | 0x00000000 | regs (power-on reset only) | Scratch word 3. A bench leaves a word for the firmware here. Plain storage. |
## ap_sysctl (base 0x1000_4000, clk_sys, PD_MAIN) | Offset | Register | Bits | Field | Access | Reset | Held by | Meaning | | --- | --- | --- | --- | --- | --- | --- | --- | | `0x000` | CHIP_ID | 31:0 | value | ro | `0x2A5310C5` | const | The chip's identity: the IDCODE of the TAP. Fixed number. | | `0x004` | RESET_CAUSE | 0 | power_on | ro | | block | Sticky record of reset sources since power-on. Power-on reset. | | `0x004` | RESET_CAUSE | 1 | pin | ro | | block | Reset pin. | | `0x004` | RESET_CAUSE | 2 | watchdog | ro | | block | Watchdog. | | `0x004` | RESET_CAUSE | 3 | software | ro | | block | Software request. | | `0x004` | RESET_CAUSE | 4 | debug | ro | | block | Debug request. | | `0x008` | SOFT_RESET | 0 | timer | wo | | not stored | Reset requests from software. 1 arms one restart of the timer. | | `0x008` | SOFT_RESET | 1 | chip | wo | | not stored | 1 requests the software reset (new in v1.5). | | `0x00C` | STRAPS | 0 | boot | ro | | block | Straps as sampled at power-up (new in v1.5). 0: start in the boot ROM. 1: start in SRAM. | | `0x010` | PINMUX | 31:0 | select | rw | `0x00000000` | regs | Two bits for each of sixteen pads: 0 released, 1 GPIO, 2 serial, 3 auxiliary. Pad n uses bits 2n+1 and 2n. | | `0x014` | CLK_GATE | 0 | uart0 | rw | `0x1` | regs | 1 lets that block's clock run (new in v1.5). UART0. | | `0x014` | CLK_GATE | 1 | gpio | rw | `0x1` | regs | GPIO. | | `0x014` | CLK_GATE | 2 | timer | rw | `0x1` | regs | Timer and PWM. | | `0x014` | CLK_GATE | 3 | spi | rw | `0x1` | regs | SPI. | | `0x014` | CLK_GATE | 4 | dma | rw | `0x1` | regs | DMA. | | `0x018` | LOCK | 0 | pinmux | w1s | `0x0` | regs | Write-once locks. Only a reset clears one (new in v1.5). 1: PINMUX ignores writes. | | `0x018` | LOCK | 1 | clk_gate | w1s | `0x0` | regs | 1: CLK_GATE ignores writes. | | `0x018` | LOCK | 2 | debug | w1s | `0x0` | regs | 1: the debug lock is closed. | | `0x020` | TB_STATUS | 31:0 | value | rw | `0x00000000` | regs (power-on reset only) | Scratch word 0. The firmware kit reports progress, pass and fail here. Plain storage. | | `0x024` | TB_PUTC | 31:0 | value | rw | `0x00000000` | regs (power-on reset only) | Scratch word 1. The firmware kit writes one character here. Plain storage. | | `0x028` | TB_EVENT | 31:0 | value | rw | `0x00000000` | regs (power-on reset only) | Scratch word 2. The firmware kit writes an event number here. Plain storage. | | `0x02C` | TB_ARG | 31:0 | value | rw | `0x00000000` | regs (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