Protected Course Page
Enter the password to view Day 19 of the UVM 30-Day plan.
Day 19: RAL Operations — read, write, mirror, update, poke, peek
A 30-day SystemVerilog/UVM verification series. Six operations. Each answers a different verification question. Mixing them up produces bugs that look like DUT bugs but aren't.
Yesterday you wired the model to the bus. Today you learn the operations that use that wire. The six operations are easy to write and easy to confuse. write() and read() are what software does. mirror() is what verification does — it compares the model's belief against the DUT's reality. update() is the inverse — it pushes the model's belief back to the DUT. poke() and peek() bypass the bus entirely and write directly into the RTL via a hierarchical path.
Each operation is a different question. Which one you call determines what you're testing.
1. Frontdoor write() and read()
Frontdoor access goes through the bus. This is what software sees, so it is the default for any test that wants to verify the DUT's behavior from the outside.
uvm_status_e status;
uvm_reg_data_t value;
// Write 0x05 to CTRL (address computed by the map)
reg_model.ctrl.write(status, 'h05);
if (status != UVM_IS_OK)
`uvm_error("RAL", "ctrl write failed")
// Read STATUS
reg_model.status.read(status, value);
if (status != UVM_IS_OK)
`uvm_error("RAL", "status read failed")
`uvm_info("RAL", $sformatf("status = 0x%0h", value), UVM_LOW)
Question answered: does the DUT behave correctly when software writes and reads it?
The path argument is optional and defaults to UVM_FRONTDOOR. You can name it explicitly for clarity:
reg_model.ctrl.write(status, 'h05, UVM_FRONTDOOR);
2. mirror() — Check the DUT Against the Model
mirror() reads the DUT through the bus (frontdoor) and compares the result against the model's mirror. If they differ, it reports a mismatch. This is the operation that actually checks register state.
reg_model.ctrl.mirror(status, UVM_CHECK);
if (status != UVM_IS_OK)
`uvm_error("RAL", "mirror failed — ctrl does not match model")
The UVM_CHECK flag says "compare and report mismatches." Without it, mirror() updates the mirror but does not check. Forgetting the flag is a common bug — the test "passes" because it never compared anything.
| Flag | Behavior |
|---|---|
UVM_CHECK | Compare DUT value against mirror; report mismatch if different |
UVM_NO_CHECK | Update mirror from the DUT; no comparison |
3. update() — Push Mirror to the DUT
update() takes the model's mirror value and writes it to the DUT. This is useful in one specific scenario: when the testbench changes the model's mirror without a real write, and wants the DUT to match.
reg_model.ctrl.set('h0F); // change the mirror directly, no bus write
reg_model.ctrl.update(status); // now push that value to the DUT
Question answered: can I make the DUT match the model after changing the model's belief?
Common uses:
- Bring-up: set the model's initial state to the DUT's power-on state, then
update()to confirm they match. - Forcing: after a backdoor poke (below), call
update()to write the poke's value through the bus as well. - Restore: after a test that deliberately corrupted the DUT, write the model's known-good value back.
update() on volatile fields is usually a no-op or worse. Do not use update() to "fix" a volatile field; it will not stay fixed.
4. poke() and peek() — Backdoor Access
Backdoor access bypasses the bus entirely, writing directly to the RTL signal via a hierarchical path. This is fast and it does not disturb bus state, but it also does not verify anything about the bus.
To use backdoor access, each register needs an HDL path — usually set via configure(this, "path") or via the block's add_hdl_path:
// In the block's build():
default_map = create_map("default_map", 0, 4, UVM_LITTLE_ENDIAN);
add_hdl_path("tb.dut", "RTL"); // root of the DUT's hierarchy
ctrl = ctrl_reg::type_id::create("ctrl");
ctrl.configure(this, "regs.ctrl_reg", ""); // relative path from the block root
ctrl.add_hdl_path_slice("q", 0, 32); // slice: which signal, which bit, how many
ctrl.build();
Then:
uvm_status_e status;
uvm_reg_data_t value;
// peek: read the DUT's register via hierarchy (no bus activity)
reg_model.ctrl.peek(status, value);
// poke: write the DUT's register via hierarchy (no bus activity)
reg_model.ctrl.poke(status, 'hFF);
Questions answered:
- peek() — what does the DUT's register actually contain right now, independent of what the bus shows?
- poke() — can I force a value into the DUT to test downstream logic without running a bus transaction?
Common uses:
- Fault injection: poke a corrupt value to simulate an error condition (e.g., a bit-flip in a status register) and check the DUT's error handling.
- Fast initialization: poke a large set of registers to a known state without hundreds of bus transactions.
- Checking: peek at a register the software cannot read (e.g., a hidden counter), to check its value from the testbench.
poke(), the mirror still holds the pre-poke value. Use set() or poke() followed by mirror(..., UVM_NO_CHECK) to resync. Otherwise the next mirror(status, UVM_CHECK) will report a mismatch that is not a DUT bug.
5. Choosing the Right Operation
| I want to… | Use |
|---|---|
| Verify that software reads/writes work | write() / read() |
| Verify that the DUT's register state matches the model | mirror(status, UVM_CHECK) |
| Push the model's mirror value to the DUT | update() |
| Force a register value bypassing the bus | poke() |
| Read a register bypassing the bus (e.g., a hidden counter) | peek() |
| Set the mirror value directly without bus activity | set() |
| Compare the whole block against the DUT | block.mirror(status, UVM_CHECK) |
Notice that mirror(status, UVM_CHECK) on a block traverses every register in the block. That is the standard end-of-test check: "did every register in the DUT end up exactly where the model says it should?" One call. One line in the log. Massive coverage.
## 6. The End-of-Test Register Check
The cleanest possible register test pattern:
virtual task run_phase(uvm_phase phase);
phase.raise_objection(this);
phase.phase_done.set_drain_time(this, 200ns);
// ... run stimulus that does writes and reads ...
// At the end, check every register against the model
reg_model.mirror(status, UVM_CHECK);
if (status != UVM_IS_OK)
`uvm_error("RAL", "post-test mirror check failed")
phase.drop_objection(this);
endtask
If reg_model.mirror() returns UVM_IS_OK, every register in the DUT matches the model. That is a much stronger statement than "the test ran." It is worth adding to every test that touches registers.
7. What Day 20 Will Add
Tomorrow: RAL Sequences and Callbacks. You have the operations. Tomorrow you learn the standard RAL sequence library — built-in sequences like uvm_reg_hw_reset_seq and uvm_reg_bit_bash_seq that you can plug into any register model and run as-is. You will also learn how to write custom RAL sequences and how to use uvm_reg_cbs to add checks and side-effects to register operations.
8. Quiz
Ten questions on RAL operations.
Coming Up Next: Day 20 — RAL Sequences and Callbacks
- Built-in RAL sequences —
uvm_reg_hw_reset_seq,uvm_reg_bit_bash_seq,uvm_reg_access_seq. - Writing custom RAL sequences — the standard
uvm_reg_sequencepattern. - uvm_reg_cbs — pre/post hooks on read and write that add checks and side effects.
- Register coverage — using
uvm_reg_hw_reset_seq's coverage as a starting point.
Series: 30 days of SystemVerilog/UVM verification. Day 19's six operations.
No comments:
Post a Comment