Module 8: Protocol Projects | Intermediate UVM

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.

Verification mindset: Always separate the bus operation from the register effect. A bus write can complete successfully while only some bits are allowed to change.

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.

Design rule: Do not make the bus driver responsible for deciding whether a register write is correct. The driver should perform the bus operation; the register model and checker should determine the expected effect.

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.

  1. Read a register immediately after reset.
  2. Write a legal value to a read/write register.
  3. Read the register back and compare it with the predicted value.
  4. Attempt to write a read-only register and verify the documented behavior.
  5. Read a write-only or restricted register if the specification defines its behavior.
  6. Access an unmapped address and check the expected bus response.
  7. 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.

Common mistake: Treating every write as a full-word replacement. Partial writes can expose incorrect byte-lane mapping, masking, alignment, and scoreboard prediction.

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

  1. Document the map: record addresses, reset values, fields, and access policies.
  2. Verify reset: prove the initial register state.
  3. Verify one RW register: write and read it back.
  4. Add field checking: verify masking and reserved bits.
  5. Add RO behavior: prove that writes do not incorrectly modify read-only state.
  6. Add partial writes: exercise byte enables or write strobes.
  7. Add negative cases: access invalid and unmapped addresses.
  8. Add the register model: centralize register knowledge.
  9. Add randomization and coverage: explore legal combinations and measure progress.
Debug strategy: When a register test fails, determine whether the error is in the bus transaction, register prediction, DUT state, or readback path. Compare the transaction observed by the monitor with the expected register-model operation before changing the DUT or sequence.

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:

  1. Reset the DUT and verify all three reset values.
  2. Write several legal values to CTRL.
  3. Read CTRL back and compare against the predicted state.
  4. Attempt to write STATUS and confirm its defined read-only behavior.
  5. Enable and disable selected interrupt bits in IRQ_EN.
  6. Perform a partial write and verify that unaffected bytes remain unchanged.
  7. 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.