Protected Course Page
Enter the password to view Day 16 of the UVM 30-Day plan.
Day 16: Building a Register Model — Access Types, configure(), Reset, Volatile, Generators
A 30-day SystemVerilog/UVM verification series. Yesterday you learned the four classes. Today you learn how to fill them in correctly.
The RAL classes from Day 15 are containers. What actually matters is what goes inside them: the access policy, the reset value, the volatility, and the bit position. Get those right and the model catches bugs the scoreboard cannot. Get them wrong and the model lies — sometimes loudly, more often quietly, in a way that costs a week of debugging.
Today is about those details, and then about how to avoid typing them by hand. Real register maps have hundreds of registers. Nobody writes them out manually. You write them once in a CSV or IP-XACT file, feed it to a generator, and commit the generated SV. Today shows how that pipeline works.
1. Access Types in Detail
The access policy is the model's expectation of how the DUT responds to reads and writes. If the DUT behaves differently, the model catches it. So the policy has to be exactly right.
| Policy | Write behavior | Read behavior | Common use |
|---|---|---|---|
"RO" | Ignored | Returns current value | Status bits, ID registers |
"RW" | Stores new value | Returns stored value | Configuration registers |
"WO" | Stores new value | Returns 0 or undefined | Command registers, doorbells |
"W1C" | 1 in a bit clears that bit; 0 leaves it | Returns current value | Interrupt flags |
"W1S" | 1 sets, 0 leaves | Returns current value | Bit-set registers |
"RC" | Ignored | Reading clears to 0 | Counters, snapshot registers |
"RSVD" | Ignored | Returns 0 | Reserved bits |
Two common near-misses that cause real bugs:
- Declaring an interrupt-flag field
RWinstead ofW1C. The model expects "write 1 stores 1." The DUT clears the flag. The model reports a mismatch on every read after write. Someone spends a day thinking the DUT is broken. - Declaring a status field
RWinstead ofRO. The model allows the test to write garbage into the mirror. The DUT ignores it. Reads return the real value. The model thinks the write succeeded and the read is wrong — or vice versa depending on timing.
2. configure() — Every Argument
The uvm_reg_field::configure() signature:
function void configure(
uvm_reg parent, // the register that contains this field
int unsigned size, // width in bits
int unsigned lsb_pos, // starting bit position
string access, // "RW", "RO", "W1C", etc.
bit volatile, // 1 = value can change without a write
uvm_reg_data_t reset, // reset value
bit has_reset, // 1 = reset value is applied at reset
bit is_rand, // 1 = field is randomized by sequence items
bit individually_accessible // 1 = field can be read/written without the full register
);
Most of these are obvious. Two deserve extra attention:
volatile
volatile=1 means "this field can change without a register write." The predictor uses this to decide whether to update the mirror on a write. A status bit that reflects the FIFO's full state is volatile — a write to the CTRL register does not change it, but the FIFO filling up does. If you mark it non-volatile, the model expects the write to update it, which produces false mismatches.
Rule of thumb: if the field can change for reasons other than a write to its own register, mark it volatile. That includes status flags, counters, and anything driven by hardware.
has_reset
has_reset=1 means the reset value is applied when the DUT resets. This is almost always what you want. has_reset=0 is for registers whose value is undefined at reset — rare, and a red flag if the spec says so.
3. Reset Values
The reset value is what the field returns after reset deasserts, before any writes. Get this wrong and every test that reads a register immediately after reset reports a mismatch.
Two failure modes:
- Wrong reset value in the model. Spec says CTRL resets to 0x0000_0000. Model says 0x0000_0010. Reading CTRL after reset returns 0x0000_0000 and the model reports a mismatch.
- Reset never applied to the model. The model was built with the reset value, but
reset()was never called after the RTL reset fired. The model holds the reset values, but any subsequent writes are applied to a wrong baseline.
Standard pattern in a test:
phase.raise_objection(this);
fork
// Apply DUT reset
begin
vif.rst_n = 0;
repeat (5) @(posedge vif.clk);
vif.rst_n = 1;
end
// Reset the model at the same time
begin
reg_model.reset();
end
join
@(posedge vif.clk);
phase.drop_objection(this);
rst_n; the model is reset by an explicit reset() call. If the two are not aligned in time, the model's view of the registers is stale relative to the DUT, and every subsequent comparison fails.
4. Volatile Fields and Prediction
Prediction is the model's process of keeping its mirror in sync with the DUT. When the test writes a value, the model updates its mirror. When the test reads, the model checks the observed value against the mirror. If the DUT changes a volatile field without a write, the predictor learns the new value from the read response.
Two prediction modes:
- Auto-prediction — the model updates itself on each read and write it performs. Simple, but does not see changes from non-RAL accesses (e.g., a driver writing to the bus directly, or the DUT changing a volatile field).
- Explicit prediction — a
uvm_reg_predictorobserves bus traffic (typically via the monitor) and updates the model from actual observed transactions. More setup, but it catches everything the bus sees.
Day 18 covers the predictor in detail. For today, the important point is: volatile fields almost always require explicit prediction, because auto-prediction only knows what the model itself did, not what the DUT did between accesses.
5. Register Generators
Writing registers by hand is fine for five. It is a waste of time and a source of typos for five hundred. The standard is a register generator: a script that reads a spec file (CSV, IP-XACT, or a tool-specific format) and emits the SV classes.
The workflow:
registers.csv → ralgen or reggen or vendor-specific → dut_reg_block.sv
(the spec) (generated SV)
Two things matter about the generated code:
- Commit it, don't regenerate it per build. Regenerate only when the spec changes, then diff the generated file. That way, a spec change shows up as a reviewable diff in the SV, not a silent runtime surprise.
- Do not edit generated code. If the model needs a change, change the spec and regenerate. Hand-editing gets lost on the next regenerate and creates two sources of truth.
Common generator inputs:
| Format | Typical tool | Pros | Cons |
|---|---|---|---|
| CSV | In-house scripts, ralgen | Easy to write and review | No schema validation |
| IP-XACT (XML) | Vendor tools (Cadence, Synopsys) | Standard, schema-validated | Verbose to write by hand |
| RALF | Vendor-specific | Rich, expressive | Tool-locked |
6. What Day 17 Will Add
Tomorrow: Address Mapping. You will build the uvm_reg_map that connects the register model to the bus, understand how base addresses and offsets resolve to absolute addresses, and handle DUTs with multiple maps (e.g., a fast bus and a slow bus both reaching the same registers).
7. Quiz
Ten questions on access types, configure(), reset, volatility, and generators.
Coming Up Next: Day 17 — Address Mapping
- uvm_reg_map — base address, bus width, endianness, and how addresses resolve.
- Multiple maps — the same block reached over two busses with different offsets.
- Sub-blocks in a top block — how address translation works when blocks are nested.
- Adding memories —
add_memand how memory arrays map into the same address space.
Series: 30 days of SystemVerilog/UVM verification. Day 16's register-model details.
No comments:
Post a Comment