V13.4.3 Portable or Not

EasyImplement12 minIcarus Verilog · serverReview the topic

Sort lines of a C test by where they work. Some work on all four targets, some need a processor, and some give answers that differ by target or by timing.

Hardware context: One C test built for the host (DPI on the bus-manager seat), the core, the VP and the hybrid. Lines that are portable and lines that are not.

The four targets: host-native C on the bus-manager seat, the chip's processor on chip RTL, the virtual platform and the hybrid. Recorded on the host: "sizeof(void ) 00000008 (char)0xff == 0xff: 00000000". On the processor: "sizeof(void ) 00000004 (char)0xff == 0xff: 00000001".

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

SignalWidthRole
question8input of each check
Full specification
CodeWhere the line works
1Runs and agrees on all four targets
2Works on the core and the platforms, not host-native
3Runs everywhere, but the host and RV32 print different results
4Runs everywhere, but its result depends on a platform's timing

Host-native, hal.h's two calls are DPI transfers of the bench's seat. The host test has no processor: no CSR, no RISC-V assembly and no trap. A pointer to a register address is just a host address.

EntryYour decision
HAL_WRITELine: reg_write32(SYSCTL_PINMUX, 0xaaa);
POINTERLine: (volatile unsigned )0x10004010 = 0xaaa;
CSRLine: __asm__ volatile ("csrr %0, mcycle" : "=r"(c));
IRQLine: irq_enable(SPI_IRQ, on_spi);
POINTER_SIZELine: tb_put_hex(sizeof(void *));
CHAR_FFLine: char c = reg_read32(GPIO_IN); if (c == 0xff) all_high = 1;
NOPSPrint mtime ticks across 64 nops
POLLSPrint how many polls SPI DONE took
PUTSLine: tb_puts("pass\n");
TOP_BYTE_HOSTOn the host build, what is ((unsigned)(int)(char)X) >> 24 for the byte X? (decimal)

Examples

Example 1

HAL WRITE
Input
Line: reg_write32(SYSCTL_PINMUX, 0xaaa);
Output
matches = 1

hal.h is the portable layer.

Example 2

POINTER
Input
Line: *(volatile unsigned *)0x10004010 = 0xaaa;
Output
matches = 1

On the host that address is not the chip.

Example 3

CSR
Input
Line: __asm__ volatile ("csrr %0, mcycle" : "=r"(c));
Output
matches = 1

There is no RISC-V register on the host.

Constraints and Contract

  • Keep the parameter and named constants. Use the numeric codes and units on this page.
  • For TOP_BYTE_HOST, enter a constant expression using X. Only this entry changes with the parameter. The supported integer range is 65 through 255, inclusive.

Hints

Hint 1

CSRs, assembly, traps and raw addresses need it.

Hint 2

long, pointers and plain char differ between the host and RV32.

Hint 3

Anything counted against time differs between platforms.

What the grader checks: Each check compares the full eight-bit answer. Parameter trials change one condition and keep the other decisions fixed.

14 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 3 problems on this path

Report a problem with this page

Your code SystemVerilogSaved locally
Ln 1, Col 1Tab indents · Ctrl/⌘ + Enter runs samples
Not run yet

HAL WRITE

Input
Line: reg_write32(SYSCTL_PINMUX, 0xaaa);
Expected output
matches = 1

hal.h is the portable layer.

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

Icarus Verilog · server