Protected Course Page
Enter the password to view Day 17 of the UVM 30-Day plan.
Day 17: Address Mapping — uvm_reg_map, Base Addresses, Offsets, Multiple Maps
A 30-day SystemVerilog/UVM verification series. The map is how the register model talks to the bus. Get it wrong and every access goes to the wrong address.
Yesterday's register model knows what registers exist and what fields they have. It does not yet know where they live. That is the map's job. A uvm_reg_map connects a block's registers to a bus interface, translates register names to absolute addresses, and handles the bus-width and endianness conversions that a real bus requires.
Getting the map right is the difference between "write CTRL" reaching the CTRL register and "write CTRL" silently hitting a reserved address. Both compile. Only one works.
1. create_map — the Four Parameters
default_map = create_map("default_map", 'h0, 4, UVM_LITTLE_ENDIAN);
| Parameter | Meaning | Common values |
|---|---|---|
| name | Map name, used in messages | "default_map" is standard |
| base_addr | Starting address of this map | 'h0 unless the block is offset from the bus |
| n_bytes | Bus width in bytes | 4 for a 32-bit bus, 8 for 64-bit |
| endian | Byte order within a bus word | UVM_LITTLE_ENDIAN or UVM_BIG_ENDIAN |
The base_addr matters when your DUT is behind an address offset. If the DUT's register file starts at 0x1000 on the bus, the map's base address is 'h1000, and every register's offset is relative to that. If the DUT is the bus, base is 'h0.
n_bytes is the width of the bus interface the map connects to, not the width of the registers. A 32-bit register on a 64-bit bus is still n_bytes=8. The map handles the splitting and merging.
2. add_reg — Offset and Access Policy
default_map.add_reg(ctrl, 'h00, "RW");
default_map.add_reg(status, 'h04, "RO");
The offset is the register's address within the block. The access policy here is a map-level restriction on top of the field-level policies. "RO" on the register means no write can reach it through this map, regardless of what the fields say. That is useful when the same register block is exposed on two buses, one read-write and one read-only.
Absolute address calculation:
absolute_addr = map.base_addr + reg_offset
For a block at base 0x1000 with CTRL at offset 0x00, the absolute address is 0x1000. STATUS at offset 0x04 is 0x1004. If you then nest this block inside a top block at base 0x4000, the absolute addresses become 0x5000 and 0x5004.
3. Multiple Maps
Some DUTs expose the same registers on two buses. For example, a fast APB bus for the CPU and a slow SPI bus for the debug interface, both reaching the same CTRL register but at different offsets. RAL handles this by letting a single block own multiple maps.
class dut_reg_block extends uvm_reg_block;
`uvm_object_utils(dut_reg_block)
uvm_reg_map apb_map;
uvm_reg_map spi_map;
rand ctrl_reg ctrl;
virtual function void build();
apb_map = create_map("apb_map", 'h0, 4, UVM_LITTLE_ENDIAN);
spi_map = create_map("spi_map", 'h10000, 4, UVM_LITTLE_ENDIAN);
ctrl = ctrl_reg::type_id::create("ctrl");
ctrl.configure(this, null, "");
ctrl.build();
apb_map.add_reg(ctrl, 'h00, "RW");
spi_map.add_reg(ctrl, 'h40, "RW");
endfunction
endclass
When a sequence writes to ctrl, RAL asks "through which map?" and looks up the offset for that map. The two maps produce two different absolute addresses, but they refer to the same register. This is exactly what the RTL does when it has an address decoder that routes both buses to the register file.
ctrl.write(status, value, UVM_FRONTDOOR, apb_map, this). Without the map argument, RAL defaults to the block's default map, which is whichever map was created first. Silent wrong-bus bugs.
4. Sub-Blocks and Address Translation
Real DUTs have nested blocks. The top block contains the CPU subsystem, the memory subsystem, the peripherals. Each subsystem has its own block with its own map. The top block's map translates between the top-level bus address and the sub-block's local offset.
class top_reg_block extends uvm_reg_block;
`uvm_object_utils(top_reg_block)
uvm_reg_map top_map;
dut_reg_block dut_blk;
virtual function void build();
top_map = create_map("top_map", 'h0, 4, UVM_LITTLE_ENDIAN);
dut_blk = dut_reg_block::type_id::create("dut_blk");
dut_blk.configure(this, "");
dut_blk.build();
// The DUT block is mapped at offset 0x4000 on the top-level bus
top_map.add_submap(dut_blk.default_map, 'h4000);
endfunction
endclass
Now top.dut_blk.ctrl resolves to the absolute address 0x4000 + 0x00 = 0x4000 on the top bus. The sub-block does not need to know its own absolute address; the parent map provides the offset.
This is the correct way to compose multi-subsystem DUTs. Do not add registers directly to the top block's map from inside a sub-block. Let each block own its map, and let the parent block place it.
5. Adding Memories
Memories are added to the map the same way registers are, but the offset is the memory's base address, and the memory's size determines how much address space it occupies:
scratch = new("scratch", 1024, 32, "RW", UVM_NO_COVERAGE);
scratch.configure(this, "");
default_map.add_mem(scratch, 'h1000, "RW");
This maps a 1024-word, 32-bit memory at offset 0x1000. The memory occupies 1024 × 4 = 4096 bytes, so the address range is 0x1000–0x1FFF. Word N is at 0x1000 + 4*N.
A common pattern in DUTs is a memory-mapped FIFO data port — a small memory where each write pushes a value and each read pops. Model it as a memory only if the access semantics are truly random-access. A FIFO should be modeled with a register or a small agent, not a memory, because memory access does not have FIFO ordering semantics.
## 6. Checking the Map
After building the model, before writing any test, verify the map is correct:
// In the test's build_phase, after building and locking the model:
uvm_reg_data_t addr;
addr = reg_model.dut_blk.ctrl.get_offset(reg_model.dut_blk.default_map, UVM_NO_HIER);
`uvm_info("MAP", $sformatf("ctrl offset = 0x%0h", addr), UVM_LOW)
addr = reg_model.dut_blk.ctrl.get_address(reg_model.dut_blk.default_map, UVM_NO_HIER);
`uvm_info("MAP", $sformatf("ctrl absolute = 0x%0h", addr), UVM_LOW)
If get_address returns something the spec does not say, the map is wrong. Fix it before writing any access tests. A wrong map is indistinguishable from a wrong DUT until you check.
reg_model.print() or reg_model.default_map.print(). Read the address column. Cross-reference against the spec's register table. This five-minute check saves hours.
7. What Day 18 Will Add
Tomorrow: Integrating RAL. The model is built, mapped, and locked. Now it must connect to the actual bus. That means an adapter that translates register operations into bus transactions, and a predictor that updates the model's mirror from observed bus traffic. This is where RAL stops being an offline documentation tool and starts checking the DUT.
8. Quiz
Ten questions on the register map.
Coming Up Next: Day 18 — Integrating RAL
- uvm_reg_adapter — translating register operations into bus transactions.
- uvm_reg_predictor — updating the model's mirror from observed bus traffic.
- Wiring the adapter to the sequencer — how register operations become sequence items.
- Predictor vs auto-prediction — when explicit prediction is required.
Series: 30 days of SystemVerilog/UVM verification. Day 17 maps the model to the bus.
No comments:
Post a Comment