V0.6.2 The Knob the Bench Cannot Turn

MediumFix20 minap_soc v1.5 · firmware · serverReview the topic

The bench writes a C variable through the symbol table so that one image serves many tests. The write lands, and the firmware ignores it. Repair the declaration so the knob works.

Hardware context: A firmware image of ap_soc v1.5: object file, linked image, hex file and symbol table. Turning a trace pc back into a line of C.

One image of this firmware serves many tests. Before the first instruction, the bench writes rounds (and sometimes seed) through the symbol table, so no test needs a rebuild. The bench's log shows each write landing. The program ignores it: with the bench writing rounds = 9, it still runs 4 rounds.

Repair the declaration of rounds so that the bench's write takes effect. Keep 4 as its value when the bench writes nothing.

Full specification

The bench writes a variable by name, with the size the symbol table gives, before start-up code runs. The console line shows rounds and the result x.

Given Files

Read-only files supplied by the bench.

tb.h
#ifndef AP_TB_H
#define AP_TB_H
_Noreturn void tb_pass(void);
_Noreturn void tb_fail(unsigned code);
void tb_putc(char byte);
void tb_puts(const char *text);
void tb_put_hex(unsigned value);
void tb_event(unsigned id);
/* Slot zero is the single bench-to-firmware argument word. */
unsigned tb_arg(unsigned n);
void tb_wait_event(unsigned id);
#endif

hal.h
#ifndef AP_HAL_H
#define AP_HAL_H
#include "ap_soc_regs.h"

/* V13.4 supplies these two functions through DPI in a host-native build. */
#ifdef AP_HOST_DPI
unsigned reg_read32(unsigned address);
void reg_write32(unsigned address, unsigned value);
#else
static inline unsigned reg_read32(unsigned address)
{
    return *(volatile unsigned *)address;
}
static inline void reg_write32(unsigned address, unsigned value)
{
    *(volatile unsigned *)address = value;
}
#endif

#define FIELD_GET(field, word) (((word) & field##_MASK) >> field##_SHIFT)
#define FIELD_PREP(field, value) (((unsigned)(value) << field##_SHIFT) & field##_MASK)
#endif

Examples

Example 1

No Write: Rounds Keeps 4
Input
no write: rounds keeps 4
Output
console: "rounds=00000004 x=00001053\n"

No write: rounds keeps its first value, 4.

Example 2

The Bench Writes Rounds = 9
Input
the bench writes rounds = 9
Output
console: "rounds=00000009 x=0821ea53\n"

The bench writes 9: the loop must run 9 times.

Example 3

Rounds = 0
Input
rounds = 0
Output
console: "rounds=00000000 x=00000001\n"

The bench writes 0: the loop never runs, and x keeps the seed, 1.

Constraints and Contract

  • C firmware with the kit, SRAM layout.
  • rounds must be a variable the bench can find by name. Do not change the loop.

Hints

Hint 1

Look at the compiled loop in your mind: where does the 4 come from?

Hint 2

A value the compiler already knows is never read from memory.

Hint 3

And a variable that start-up code clears loses what the bench wrote.

What the grader checks: Each case writes the knobs through the symbol table and compares the console. The write happens before start-up code, in the SRAM layout.

6 checks on ap_soc v1.5 · firmware · 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 CSaved locally
Ln 1, Col 1Tab indents · Ctrl/⌘ + Enter runs samples
Not run yet

No Write: Rounds Keeps 4

Input
no write: rounds keeps 4
Expected output
console: "rounds=00000004 x=00001053\n"

No write: rounds keeps its first value, 4.

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

ap_soc v1.5 · firmware · server