One firmware image passes on chip RTL and on the hybrid, and hangs on the virtual platform. Read the three recorded runs and say who is wrong, where and why.
Hardware context: ap_vp: the instruction-level core with C models of ap_soc's devices. A firmware failure read from recorded platform runs.
The image sends 6 bytes from the SPI flash out of the UART, each wait asleep in wfi. It prints S when spi() starts, s in on_spi(), P when put() starts and u in on_uart(). The same image ran on each platform (riscv64-unknown-elf-gcc 14.2).
This worksheet uses named constants. The first three entries show how to record your decisions.
Replace each unresolved value of 65535 with your result.
Signals in the Timeline
| Signal | Width | Role |
|---|---|---|
question | 8 | input of each check |
Full specification
#include "hal.h"
#include "tb.h"
#include "irq.h"
static volatile unsigned spi_done, room;
static void on_spi(void) { tb_putc('s'); reg_write32(SPI_STATUS, SPI_STATUS_DONE_MASK); spi_done = 1; }
static void on_uart(void) { tb_putc('u'); reg_write32(UART0_IRQ_ENABLE, 0); room = 1; }
static unsigned spi(unsigned command)
{
tb_putc('S');
spi_done = 0;
reg_write32(SPI_DATA, command);
while (!spi_done) __asm__ volatile ("wfi");
return reg_read32(SPI_DATA) & 0xffffff;
}
static void put(unsigned char c)
{
tb_putc('P');
room = 0;
reg_write32(UART0_IRQ_ENABLE, UART0_IRQ_ENABLE_ROOM_MASK);
while (!room) __asm__ volatile ("wfi");
reg_write32(UART0_TXDATA, c);
}
int main(void)
{
unsigned n = tb_arg(0);
reg_write32(SYSCTL_PINMUX, 0xaaa);
reg_write32(UART0_DIV, 64);
reg_write32(SPI_IRQ_ENABLE, SPI_IRQ_ENABLE_DONE_MASK);
irq_enable(SPI_IRQ, on_spi);
irq_enable(UART0_IRQ, on_uart);
spi(0x66);
for (unsigned i = 0; i < n; i += 3) {
unsigned w = spi(0x03);
for (unsigned b = 0; b < 3 && i + b < n; b++) put(w >> (16 - 8 * b));
}
room = 0;
reg_write32(UART0_IRQ_ENABLE, UART0_IRQ_ENABLE_ROOM_MASK);
while (!room) __asm__ volatile ("wfi");
return 0;
}
| Platform | Console | End |
|---|---|---|
| Virtual platform | SsSsPu | The run reached the limit of 200,000 cycles before a pass or fail word was written to TB_STATUS. |
| Hybrid, IPC 1 | SsSsPuPuPuSsPuPuPuu | The test ended with the pass word. |
| Hybrid, IPC 16 | SsSsPuPuPuSsPuPuPuu | The test ended with the pass word. |
| Chip RTL | SsSsPuPuPuSsPuPuPuu | The test ended with the pass word. |
| Code | Who is wrong |
|---|---|
| 1 | The VP has a bug in how it raises interrupts |
| 2 | The firmware has a bug that the VP's timing shows |
| 3 | The chip RTL has a bug that the VP does not have |
| 4 | The bench of the RTL run hides a hang |
| Code | Where it stops |
|---|---|
| 1 | spi() |
| 2 | put() |
| 3 | on_spi() |
| 4 | on_uart() |
| 5 | the last wait of main() |
| Code | What happens |
|---|---|
| 1 | put() reads ROOM from the wrong bit of UART0 STATUS |
| 2 | The VP never raises the UART interrupt after the first byte |
| 3 | The flag is tested, then wfi sleeps; a wake in between is lost |
| 4 | The handler clears its source after the PLIC completes the claim |
| Code | The fix |
|---|---|
| 1 | Give the UART interrupt a higher PLIC priority |
| 2 | Run the VP with more clocks per instruction |
| 3 | Poll the flag without wfi, on the VP only |
| 4 | Mask interrupts around the test of the flag and the wfi |
| Entry | Your decision |
|---|---|
| HANDLERS_VP | How many times did a handler run on the VP before the hang? |
| BYTES_HYBRID | How many times did put() start on the hybrid at IPC 1? |
| FRAMES_HYBRID | How many times did spi() start on the hybrid at IPC 1? |
| WHO | Who is wrong? (code) |
| WHERE | In which function does the VP stop? (code) |
| WHAT | What happens there? (code) |
| FIX | Which change makes the image correct on every platform? (code) |
| SLEEPS_FOREVER | After put() writes IRQ_ENABLE (step 1) it loads room (step 2), branches on it (step 3) and runs wfi (step 4). ROOM's interrupt is taken just before step D; D = 5 means while asleep in wfi. Enter 1 if the core then sleeps for ever, else 0. |
Examples
Example 1
HANDLERS VP- Input
How many times did a handler run on the VP before the hang?
- Output
matches = 1
Count the lower-case letters of the VP console.
Example 2
BYTES HYBRID- Input
How many times did put() start on the hybrid at IPC 1?
- Output
matches = 1
One P for each byte.
Example 3
FRAMES HYBRID- Input
How many times did spi() start on the hybrid at IPC 1?
- Output
matches = 1
One S for the pointer reset and one for each frame of three bytes.
Constraints and Contract
- Keep the parameter and named constants. Use the numeric codes and units on this page.
- For SLEEPS_FOREVER, enter a constant expression using D. Only this entry changes with the parameter. The supported integer range is 2 through 5, inclusive.
Hints
Hint 1
All four agree until the VP stops after P and u.
Hint 2
The VP takes one clock per instruction and no bus wait states, so interrupts land at other instructions.
Hint 3
Between the test of the flag and the wfi, a handler can run and leave nothing to wake the core.
What the grader checks: Each check compares the full eight-bit answer. Parameter trials change one condition and keep the other decisions fixed.
12 checks on Icarus Verilog · server. Run the examples first, then check the full regression. Full checks use the server judge. Downloads contain your source only; samples require the simulation service. A passing result establishes the tested cases, not a proof for all possible inputs.
See all 2 problems on this path