Memory-Mapped Register Project
Build a reusable UVM environment that verifies register maps, access policies, reset values, and bus-visible behavior.
Learning objectives
- Explain how a memory-mapped register interface connects bus transactions to DUT state.
- Model register addresses, fields, reset values, and access policies in a verification environment.
- Verify read, write, read-only, write-only, and reserved-bit behavior.
- Use a UVM register model or equivalent reference model to predict expected register state.
- Validate register behavior with scoreboards, assertions, reports, and functional coverage.
Step 1: Understand the register map
A memory-mapped register block presents internal DUT state through addresses on a bus. The verification environment must understand more than the address alone: each register has a reset value, access policy, field layout, and defined behavior.
For example, consider a small control block:
| Address | Register | Reset | Access | Purpose |
|---|---|---|---|---|
0x00 |
CTRL | 0x00 |
RW | Enable and mode control |
0x04 |
STATUS | 0x01 |
RO | Current DUT status |
0x08 |
IRQ_EN | 0x00 |
RW | Interrupt enables |
0x0C |
RESERVED | 0x00 |
Reserved | No defined software access |
The testbench should treat the register specification as a contract. A successful write is not simply “the bus accepted the transfer.” The final register state must obey the documented field-level access rules.
Step 2: Define register fields and access policies
Registers are usually composed of fields rather than being treated as one unrestricted word. Consider a control register with the following layout:
// CTRL register
// [31:4] Reserved
// [3:2] MODE - RW
// [1] IRQ_EN - RW
// [0] ENABLE - RW
logic [31:0] ctrl_reg;
A write of 32'hFFFFFFFF should not necessarily result in ctrl_reg == 32'hFFFFFFFF. Reserved bits may remain zero, while only the defined fields are updated.
For a verification model, define the expected behavior explicitly:
expected_ctrl[0] = write_data[0];
expected_ctrl[1] = write_data[1];
expected_ctrl[3:2] = write_data[3:2];
expected_ctrl[31:4] = '0;
This distinction becomes especially important when random tests generate values containing ones in reserved or read-only fields.
Step 3: Build a reusable UVM environment
The environment should have a clear separation between bus stimulus, protocol observation, register prediction, and checking.
class reg_env extends uvm_env;
bus_agent agent;
reg_model model;
reg_scoreboard scoreboard;
function void build_phase(uvm_phase phase);
super.build_phase(phase);
agent = bus_agent::type_id::create("agent", this);
model = reg_model::type_id::create("model", this);
scoreboard = reg_scoreboard::type_id::create(
"scoreboard", this);
endfunction
function void connect_phase(uvm_phase phase);
agent.monitor.ap.connect(scoreboard.analysis_export);
endfunction
endclass
The bus agent handles protocol-specific activity. The register model describes the address map and register structure. The scoreboard compares observed behavior against the expected register state.
Step 4: Verify reset values first
Reset establishes the starting state of the register block. Before testing writes, verify that every architecturally visible register returns its documented reset value.
task check_reset_values();
bit [31:0] ctrl;
bit [31:0] status;
bit [31:0] irq_en;
ctrl = read_reg('h00);
status = read_reg('h04);
irq_en = read_reg('h08);
if (ctrl !== 32'h00000000)
`uvm_error("RESET",
$sformatf("CTRL reset mismatch: 0x%08h", ctrl))
if (status !== 32'h00000001)
`uvm_error("RESET",
$sformatf("STATUS reset mismatch: 0x%08h", status))
if (irq_en !== 32'h00000000)
`uvm_error("RESET",
$sformatf("IRQ_EN reset mismatch: 0x%08h", irq_en))
endtask
Reset testing should also establish the expected state of the reference model. Otherwise, later scoreboard mismatches can be caused by an incorrectly initialized prediction rather than by the DUT.
Step 5: Verify read and write behavior
Build the project around small, observable scenarios. Start with one register and expand gradually.
- Read a register immediately after reset.
- Write a legal value to a read/write register.
- Read the register back and compare it with the predicted value.
- Attempt to write a read-only register and verify the documented behavior.
- Read a write-only or restricted register if the specification defines its behavior.
- Access an unmapped address and check the expected bus response.
- Write values containing ones in reserved fields and verify that reserved bits behave correctly.
The important comparison is:
observed register state
==
expected state after applying
the register's access policy
This is more robust than comparing every returned bus word directly because some registers are dynamic, read-only, write-one-to-clear, or otherwise have side effects.
Step 6: Handle byte enables correctly
Many memory-mapped buses support partial writes. A register model must account for byte enables or write strobes when predicting the resulting value.
// Example: 32-bit register with four byte lanes.
// Only enabled bytes are replaced.
for (int i = 0; i < 4; i++) begin
if (write_strb[i])
expected_reg[i*8 +: 8] = write_data[i*8 +: 8];
end
A useful test is to initialize a register with a known pattern and then modify exactly one byte. The scoreboard should prove that the other bytes remain unchanged.
Step 7: Use a UVM register model
For larger register blocks, a UVM register model can centralize addresses, fields, access policies, and reset values. This reduces duplicated register knowledge across sequences and scoreboards.
class ctrl_reg extends uvm_reg;
rand uvm_reg_field enable;
rand uvm_reg_field irq_en;
rand uvm_reg_field mode;
function new(string name = "ctrl_reg");
super.new(name, 32, UVM_NO_COVERAGE);
endfunction
virtual function void build();
enable = uvm_reg_field::type_id::create("enable");
enable.configure(this, 1, 0, "RW", 0, 1'b0, 1, 1, 0);
irq_en = uvm_reg_field::type_id::create("irq_en");
irq_en.configure(this, 1, 1, "RW", 0, 1'b0, 1, 1, 0);
mode = uvm_reg_field::type_id::create("mode");
mode.configure(this, 2, 2, "RW", 0, 2'b0, 1, 1, 0);
endfunction
endclass
The exact register-model implementation depends on the bus adapter and DUT architecture. The important concept is that the register model becomes a reusable description of the register interface rather than a collection of hard-coded addresses scattered through tests.
Step 8: Add coverage
Register coverage should measure meaningful access behavior, not merely the number of reads and writes.
- All architecturally visible registers accessed.
- Read and write operations exercised where legal.
- Reset values observed.
- Partial and full-width writes exercised.
- Different field values exercised.
- Reserved-bit accesses tested where appropriate.
- Invalid or unmapped addresses exercised.
- Register accesses combined with reset, interrupts, or other relevant DUT states.
For field-heavy designs, cross coverage can reveal gaps such as a mode field being tested only while the enable bit is zero.
Step 9: Build the project incrementally
- Document the map: record addresses, reset values, fields, and access policies.
- Verify reset: prove the initial register state.
- Verify one RW register: write and read it back.
- Add field checking: verify masking and reserved bits.
- Add RO behavior: prove that writes do not incorrectly modify read-only state.
- Add partial writes: exercise byte enables or write strobes.
- Add negative cases: access invalid and unmapped addresses.
- Add the register model: centralize register knowledge.
- Add randomization and coverage: explore legal combinations and measure progress.
Try it yourself
Build a small register-block test using the following conceptual map:
| Register | Address | Reset | Access |
|---|---|---|---|
| CTRL | 0x00 |
0x00000000 |
RW |
| STATUS | 0x04 |
0x00000001 |
RO |
| IRQ_EN | 0x08 |
0x00000000 |
RW |
Then perform these checks:
- Reset the DUT and verify all three reset values.
- Write several legal values to
CTRL. - Read
CTRLback and compare against the predicted state. - Attempt to write
STATUSand confirm its defined read-only behavior. - Enable and disable selected interrupt bits in
IRQ_EN. - Perform a partial write and verify that unaffected bytes remain unchanged.
- Access an unmapped address and check the expected error response.
Capture the test log, at least one monitored register transaction, one scoreboard result, and coverage showing which register scenarios were exercised.
Key takeaways
- A memory-mapped register project verifies both bus transactions and their effect on architectural state.
- Model addresses, fields, reset values, and access policies explicitly rather than treating every register as a generic 32-bit word.
- Use a register model or reference model to maintain expected state independently from the DUT.
- Verify read-only behavior, reserved bits, partial writes, invalid addresses, and reset values—not just successful read/write operations.
- Use monitors, scoreboards, assertions, reports, and coverage to produce concrete evidence that the register interface is behaving as specified.