Virtual Platforms

A virtual platform replaces every block of the chip with a model that answers the same registers. It runs software long before RTL exists, and hundreds of times faster. It cannot find what it does not model.

You Will Be Able To

  • Describe a virtual platform: an instruction-level core, device models, the chip's memory map.
  • Say what a virtual platform finds early, and which classes of bug it cannot find.
  • Read a platform failure and tell a model gap from a firmware bug.
  • Use a virtual platform as a check against RTL at transaction boundaries.
Lesson
V13.2
Time
25 min
Runs on
Your browser
Check
5 questions

The RTL of the SPI controller is not written yet. The driver team cannot wait for it. They need something that answers SPI_DATA and SPI_STATUS today.

The Chip Redrawn with Models in Place of RTLThe virtual platform keeps the chip's memory map and registers. Each block's RTL becomes a C model.
  • File
  • Model
  • Memory
  • Neutral
  • Result
  • Data
  • Control
The Chip Redrawn With Models in Place of RTLThe virtual platform keeps the chip's memory map and registers. Each block's RTL becomes a C model. file Firmware image the same bytes as onRTL model ap_iss instruction-levelcore memory ROM, SRAM byte arrays model Device models UART, GPIO, timer,SPI, PLIC, CLINT,mailbox neutral Not modelled DMA, watchdog,pwrctl, most ofsysctl, pads result Console, status what the testreports loadedfetch, load, storeregister accessbus faultmailbox
  1. file Firmware imagethe same bytes as on RTL
    • loaded → ap_iss
  2. model ap_issinstruction-level core
    • fetch, load, store → ROM, SRAM
    • register access → Device models
    • bus fault → Not modelled
  3. memory ROM, SRAMbyte arrays
  4. model Device modelsUART, GPIO, timer, SPI, PLIC, CLINT, mailbox
    • mailbox → Console, status
  5. result Console, statuswhat the test reports
  6. neutral Not modelledDMA, watchdog, pwrctl, most of sysctl, pads
  1. The same image

    The VP loads the firmware image the RTL bench loads.

  2. A core with no pipeline

    ap_iss executes one instruction a step and reads its memories at once.

  3. Registers, not wires

    Each device is C code that answers register accesses and keeps state.

  4. The edge of the model

    A block the VP does not model answers with a bus fault.

Read the diagram as text
  • Firmware image: the same bytes as on RTL
  • ap_iss: instruction-level core
  • ROM, SRAM: byte arrays
  • Device models: UART, GPIO, timer, SPI, PLIC, CLINT, mailbox
  • Not modelled: DMA, watchdog, pwrctl, most of sysctl, pads
  • Console, status: what the test reports
  • Firmware image → ap_iss: loaded
  • ap_iss → ROM, SRAM: fetch, load, store
  • ap_iss → Device models: register access
  • ap_iss → Not modelled: bus fault
  • Device models → Console, status: mailbox

tools/soc/ap_vp. Its README lists the blocks it models and what it leaves out.

Before You Start

Read Why Simulation Is Too Slow: the Speed Ladder first. The register map comes from The Generated Header.

Five questions this page answers
Question
1What is a virtual platform made of?
2Why can a team run software on it before RTL exists?
3What kinds of bug can it find, and which can it not?
4What does a register it does not model do?
5How does a virtual platform help check RTL?

The Idea: The Programmer's View, and Nothing Below It

Software sees a chip as a memory map: addresses that hold code, data and device registers. A virtual platform models exactly that view. Each register answers a read and takes a write, with the effect the specification describes.

Below that view sit wires, bus phases, wait states and pads. A virtual platform leaves them out. That is why it is fast, and why it can be written from the specification alone, before any RTL.

Ours keeps one coarse clock. Each instruction advances the device models by one system clock, so timers count and the SPI transfer takes its 128 clocks. That clock is not the chip's: there are no wait states and no pipeline behind it.

The same choices set its limits. A bug below the programmer's view, in timing, wiring or pads, cannot show on a model that leaves it out.

New Words

New words on this page
WordMeaning
Programmer's viewThe chip as software sees it: addresses, registers and their effects, with no timing below that.
Device modelC code that answers one block's registers the way its specification says.
Model gapA block or behaviour the model leaves out. Firmware that touches it fails on the model only.
Bus faultAn access the platform refuses. The core takes an access-fault trap.
Transaction boundaryA point where model and RTL must agree: the end of a read, a retired instruction.
ESLElectronic system level: modelling above RTL, at the level of transactions.

The Smallest Example: One Read, Two Models

Firmware writes a command to SPI_DATA and polls SPI_STATUS until DONE. A functional model can finish the transfer at once. A timed model raises DONE 128 clocks later, as ap_spi does.

The same wait loop, two models
ModelWhen DONE risesPolls the loop makes
Functionalwith the command1
Timed128 clocks laterabout 128 / (clocks a poll costs)

The data read at the end is the same in both. The number of polls is not. Firmware that is correct does not care. Firmware that counts on the time a wait takes will behave differently on the two models.

The Rules

  1. Rule 1: Model what software can see.

    Every register, field and side effect the specification names. Not the wires, the phases or the pads.

  2. Rule 2: Fault on what you do not model.

    A silent zero hides a gap. A bus fault tells the firmware writer at once that the model has stopped.

  3. Rule 3: Run the same image as RTL.

    Then a disagreement points at the model, the firmware or the RTL, never at a build difference.

  4. Rule 4: Trust it for function, not for time.

    Results of correct software agree. Counts of polls, cycles and interrupt moments do not.

  5. Rule 5: Compare at transaction boundaries.

    Model and RTL agree at the end of each read and at each retired instruction, not at each clock.

Sources for These Rules

ESL and transaction-level models, software and tests before RTL: MEHTA-DV 11.1.

A virtual platform example and its use for verification, including comparing at transaction or instruction boundaries: MEHTA-DV 11.3, 11.4.

The virtual platform before RTL as the preferred method: MEHTA-DV 16.12.

ap_vp, its models, its gaps and its gate against RTL: tools/soc/ap_vp/README.md. Plan §3.10, E10: the VP gate compared 63,994 RTL edges and caught 30 of 30 seeded model faults.

The Lab: Where the Model Stops

First, rule 3 at work. In the ladder of V13.1, six images printed the same console and left the same SRAM on the VP and on RTL. Function agreed.

Rule 4 at work in the same table: the SPI image retired 571 instructions on the VP and 349 on RTL. It polls SPI_STATUS, and the two platforms take different times per poll.

Now an image that reads CHIP_ID, a register of ap_sysctl that the VP does not model:

The lab image
#include "hal.h"
#include "tb.h"

int main(void)
{
    tb_puts("reading CHIP_ID\n");
    unsigned id = reg_read32(SYSCTL_CHIP_ID);
    tb_puts("chip id "); tb_put_hex(id); tb_putc('\n');
    return 0;
}
PlatformConsoleEnd
Chip RTLreading CHIP_ID / chip id 2a5310c5The test ended with the pass word.
Virtual platformreading CHIP_IDThe test reported a failure: fail code 0xffff (TB_STATUS = 0xbad0ffff).
Hybridreading CHIP_ID / chip id 2a5310c5The test ended with the pass word.

Rule 2 at work. On the VP the read became a bus fault. The kit's trap handler did not expect it and failed with code 0xFFFF. On the hybrid the read crossed into the RTL sysctl and returned the chip's ID.

This failure is a model gap, not a bug. Three facts say so. The same image passes on RTL. The address is a real register. The VP's README lists it as not modelled.

Why It Is Built This Way

Why a bus fault and not zero? A model that returns zero for every unknown register lets firmware carry on with wrong data. The bug report then arrives far from its cause. A fault stops at the line that touched the gap.

Why write the VP from the specification and not from the RTL? So it is an independent view. When the VP and RTL disagree on a register, one of them misread the specification, and the comparison has found something.

Why is it fast? It does no work per clock. A register access is a function call. A thousand instructions that stay in SRAM are a thousand steps of a C loop.

Traps

The first trap is a VP that is too kind. It answers registers the chip does not have, or ignores the pin mux. Firmware that passes on it then fails on silicon, and the VP has taught the team to trust it.

The second is a test that measures time on the VP. A count of polls, or of instructions until an interrupt, differs from platform to platform. Neither count is about the chip.

The third is a model that drifts. The RTL changes a field, the VP does not. Rule 5 is the cure: compare them regularly, at transaction boundaries, on the same images.

The fourth runs the other way: calling every failure that only the VP shows a model gap. The VP's timing differs from the chip's, and firmware that leans on timing can fail there first. Check the list of gaps before you blame the model.

At Scale

ap_soc~12 blocks
Phone-class SoChundreds of blocks

This section looks ahead. Our VP is a few hundred lines of C per block.

  1. Standard models

    Large teams build VPs from transaction-level models with a standard interface, such as SystemC TLM 2.0, so models can be reused.

  2. Many cores

    A VP of a phone chip runs several processor models and boots an operating system.

  3. The VP as reference

    Its device models become reference models in UVM scoreboards of the RTL bench.

Try It

Run it: one wait loop on a functional and on a timed model. Each poll costs what one hybrid bus request cost in the lab.

The data would be the same on both. What differs?

Change the cost of a poll. Which line changes, and which does not?

RUNIcarus Verilog · in your browser
Edit the code, then run it
Expected: functional model: 1 poll(s), 4 clocks timed model: 33 poll(s), 132 clocks

Check Yourself

Predict the outputNow each poll costs one clock. What is the last line printed?
// A firmware wait, "poll SPI STATUS until DONE", against two models of the controller.
// functional: the reply is ready when the command is written. timed: DONE rises 128 clocks later.
module tb;
  int clock, polls;
  task automatic wait_done(input bit timed, input int cost);
    int done_at;
    clock = 0; polls = 0;
    done_at = timed ? 128 : 0;
    do begin
      polls++;
      clock += 1;
    end while (clock <= done_at);
  endtask
  initial begin
    wait_done(0, 1);
    $display("functional model: %0d poll(s), %0d clocks", polls, clock);
    wait_done(1, 1);
    $display("timed model:      %0d poll(s), %0d clocks", polls, clock);
    $finish;
  end
endmodule
ConceptWhat is a virtual platform made of?
ConceptWhy can it run before RTL exists?
ConceptIn the lab, why did the CHIP_ID read fail on the VP only?
ConceptWhich bug can a virtual platform not find?

Common Mistakes

Wrong Return zero for registers the model does not have.

Firmware carries on with wrong data, and the failure shows far from its cause.

Fix Answer with a bus fault, and list the gaps.

Wrong Count polls or cycles on the VP and expect the same on RTL.

The VP does not model time below the programmer's view.

Fix Check results; leave timing to RTL.

Wrong Call a failure on the VP a chip bug.

It may be a model gap; the chip may be right.

Fix Run the image on RTL and read the VP's list of gaps first.

Remember

  • A virtual platform models the programmer's view: registers and their effects, with no wires, phases or pads.
  • It runs software before RTL exists and much faster than RTL.
  • What it does not model should fault; a gap is not a chip bug.
  • Trust it for function; compare with RTL at transaction boundaries; leave timing to RTL.

Practice

Report a problem with this page