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.
- File
- Model
- Memory
- Neutral
- Result
- Data
- Control
- The same image
The VP loads the firmware image the RTL bench loads.
- A core with no pipeline
ap_iss executes one instruction a step and reads its memories at once.
- Registers, not wires
Each device is C code that answers register accesses and keeps state.
- 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.
| Question | |
|---|---|
| 1 | What is a virtual platform made of? |
| 2 | Why can a team run software on it before RTL exists? |
| 3 | What kinds of bug can it find, and which can it not? |
| 4 | What does a register it does not model do? |
| 5 | How 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
| Word | Meaning |
|---|---|
| Programmer's view | The chip as software sees it: addresses, registers and their effects, with no timing below that. |
| Device model | C code that answers one block's registers the way its specification says. |
| Model gap | A block or behaviour the model leaves out. Firmware that touches it fails on the model only. |
| Bus fault | An access the platform refuses. The core takes an access-fault trap. |
| Transaction boundary | A point where model and RTL must agree: the end of a read, a retired instruction. |
| ESL | Electronic 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.
| Model | When DONE rises | Polls the loop makes |
|---|---|---|
| Functional | with the command | 1 |
| Timed | 128 clocks later | about 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
Rule 1: Model what software can see.
Every register, field and side effect the specification names. Not the wires, the phases or the pads.
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.
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.
Rule 4: Trust it for function, not for time.
Results of correct software agree. Counts of polls, cycles and interrupt moments do not.
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:
#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;
}
| Platform | Console | End |
|---|---|---|
| Chip RTL | reading CHIP_ID / chip id 2a5310c5 | The test ended with the pass word. |
| Virtual platform | reading CHIP_ID | The test reported a failure: fail code 0xffff (TB_STATUS = 0xbad0ffff). |
| Hybrid | reading CHIP_ID / chip id 2a5310c5 | The 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
This section looks ahead. Our VP is a few hundred lines of C per block.
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.
Many cores
A VP of a phone chip runs several processor models and boots an operating system.
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?
functional model: 1 poll(s), 4 clocks timed model: 33 poll(s), 132 clocksCheck Yourself
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.