A test that printed the right line host-native prints a wrong one on the chip's processor and on the virtual platform. Find what the host let it assume, and fix it so all targets agree.
Hardware context: One C test built for the host (DPI on the bus-manager seat), the core, the VP and the hybrid. A test that passed on the host and failed on the core.
The test below was written and run host-native first, on the bus-manager seat, and it printed the right line. Built for RV32 and run on the chip's processor, it prints another. The virtual platform agrees with the processor, so the chip is not to blame.
Recorded with the same flash image: the host printed high 00000006 sig 0001fd944a9a61af; the processor printed high 00000000 sig 000000004a980710.
Fix the source so it prints the host's line on every target. It runs on chip RTL and on the virtual platform, and both must agree with the expected line.
Full specification
The host build is x86-64 with the LP64 rules. The core build is RV32 with the ilp32 ABI, from the same source.
The signature is 64 bits: rotate left by 7, then XOR in the byte, for every byte in flash order. high counts the bytes whose top bit is set. The line is high , eight hex digits, sig , sixteen hex digits.
The kit has no 64-bit multiply or divide: soft/arithmetic.c has the 32-bit helpers only. Keep to shifts, OR and XOR on 64-bit values.
Given Files
Read-only files supplied by the bench.
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
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
SPI · register manual
| Offset | Register | Bits | Field | Access | Reset | Held by | Meaning |
|---|---|---|---|---|---|---|---|
0x000 | DATA | 7:0 | command | wo | not stored | Write: a command byte; the write starts a frame of 32 serial clocks. Read: the last 24 bits received. Command byte. | |
0x000 | DATA | 23:0 | received | ro | block | Last 24 bits received. | |
0x004 | STATUS | 0 | busy | ro | block | Frame state. A frame is running, and chip select is low. | |
0x004 | STATUS | 1 | done | w1c | block | A frame has ended (new in v1.5). | |
0x008 | IRQ_ENABLE | 0 | done | rw | 0x0 | regs | Lets DONE raise interrupt source 4 (new in v1.5). 1 enables the request. |
## SPI (base 0x1000_5000, interrupt source 4, clk_sys, PD_PER) | Offset | Register | Bits | Field | Access | Reset | Held by | Meaning | | --- | --- | --- | --- | --- | --- | --- | --- | | `0x000` | DATA | 7:0 | command | wo | | not stored | Write: a command byte; the write starts a frame of 32 serial clocks. Read: the last 24 bits received. Command byte. | | `0x000` | DATA | 23:0 | received | ro | | block | Last 24 bits received. | | `0x004` | STATUS | 0 | busy | ro | | block | Frame state. A frame is running, and chip select is low. | | `0x004` | STATUS | 1 | done | w1c | | block | A frame has ended (new in v1.5). | | `0x008` | IRQ_ENABLE | 0 | done | rw | `0x0` | regs | Lets DONE raise interrupt source 4 (new in v1.5). 1 enables the request. |
Examples
Example 1
The Host Run's Image- Input
The image of the host run
- Output
`high 00000006 sig 0001fd944a9a61af` on both targets
The line the host printed, now on the processor and the VP too.
Example 2
Another Image- Input
Another image
- Output
one line
Six frames.
Example 3
Only One of the Two Causes Fixed- Input
a source whose sig is now right on the core
- Output
the right sig, high 00000000
Each field has its own cause. Fixing one leaves the other line wrong.
Constraints and Contract
- Change only what is needed; the output format stays.
- The same source must print the same line on chip RTL and on the VP.
Hints
Hint 1
Both fields of the line are wrong on the core. Treat them as two separate questions.
Hint 2
For each declaration, ask what the C standard fixes about it and what it leaves to the platform.
Hint 3
Print what you suspect on both targets: a size, or whether a value is below zero.
What the grader checks: Each case runs your source on chip RTL and on the VP. It compares the console with the expected line, and the two platforms with each other. The grader does not run the host build; the recorded host line is on the page.
5 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 3 problems on this path