V4.5.1 One Image, Many Runs

MediumImplement25 minap_soc v1.5 · firmware · serverReview the topic

Build one firmware image that serves many runs. The bench sets three knobs through the symbol table, some before the first instruction and some after a hand-shake. Each knob must take effect whenever it is written.

Hardware context: Knobs of one firmware image written by the bench through apcc's symbol table. A family of runs from one image.

One image of this test must serve a whole family of runs. It makes count values with the generator x = x × 1,103,515,245 + 12,345, starting from x = seed. For each value it adds x >> 16 into a sum. In mode 0 it also prints x >> 16 as eight hex digits on a line of its own. In any mode it ends with sum and the sum.

The three knobs are C variables named count, seed and mode, with defaults 8, 1 and 0. The bench may write any of them through the symbol table. It writes before the first instruction, or between your TB_EVENT 0x5E01 and its reply 0x5E02 in TB_ARG. A run uses the values it holds after the hand-shake.

Full specification
When the bench writesHowWhat start-up code does next
Before the first instructionOne symbol, in the bench's argumentsCopies nothing in this SRAM image, and clears .bss
After TB_EVENT 0x5E01Table rows named by symbolNothing: main is already running

The symbol table gives each variable its address and size. The bench writes 4 bytes for a 4-byte variable.

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

The Defaults
Input
no writes: the defaults
Output
eight values, then "sum ..."

count 8, seed 1, mode 0.

Example 2

An Early Seed
Input
seed = 7, before the first instruction
Output
eight other values

The bench wrote seed = 7 before start-up code ran. seed has a first value, so it lives in .data and keeps the write.

Example 3

Late Count and Mode
Input
count = 3 and mode = 1, after the hand-shake
Output
one line: "sum ..."

Three values, mode 1: only the sum.

Constraints and Contract

  • C firmware with the kit, SRAM layout.
  • Keep the names count, seed and mode, each a 32-bit unsigned variable, and the output format.
  • Every case writes a different mix of knobs, at different times.

Hints

Hint 1

When must main read the knobs, given that the bench may write them during the hand-shake?

Hint 2

Which section does a variable with a nonzero first value live in? And one whose first value is 0?

Hint 3

GCC can place a variable in a named section with __attribute__((section(".data"))).

What the grader checks: Each case writes chosen knobs before the first instruction and after the hand-shake, and compares the console text. It cannot see your declarations, only whether each write took effect.

9 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

The Defaults

Input
no writes: the defaults
Expected output
eight values, then "sum ..."

count 8, seed 1, mode 0.

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

ap_soc v1.5 · firmware · server