지노랩 /JinoLab

[UVM] 5.5 레지스터 모델 생성 — “Generator 작성자를 위한 실전 절차” 본문

UVM(Universal Verification Methodology)/5. Register Layer Class 사용하기

[UVM] 5.5 레지스터 모델 생성 — “Generator 작성자를 위한 실전 절차”

지노랩/JinoLab 2025. 5. 6. 12:08

 

1. 모델-생성기의 궁극적 목표

단계 산출물 설명

① 스펙 파싱 CSV / IP-XACT / YAML 등 이름·주소·필드폭·Access Type·Reset 값 추출
② RAL 클래스 생성 my_block.sv 등 uvm_reg_block / reg / field / mem 파생 클래스 소스
③ 커버리지·alias 삽입 선택 covergroup·field alias·user param 등
④ 빌드 스크립트 출력 pkg, include 파일 TB 컴파일 시 RAL 자동 포함

2. 최소 코드 골격

// ---------- Block ----------
class codec_blk extends uvm_reg_block;
  rand uvm_reg    CONFIG;
  rand uvm_mem    BFR;
  `uvm_object_utils(codec_blk)

  function void build();
    default_map = create_map("sfr", 'h0, 4, UVM_LITTLE_ENDIAN);

    // CONFIG reg (32 bit, offset 0x00)
    CONFIG = codec_cfg_reg::type_id::create("CONFIG");
    CONFIG.configure(this, null, "");          // parent, hdl path
    CONFIG.build();

    // map
    default_map.add_reg(CONFIG, 'h0, "RW", 0);

    // BFR mem (256×32, offset 0x100)
    BFR = uvm_mem::type_id::create("BFR");
    BFR.configure(this, 256, 32, "RW", 0);
    default_map.add_mem(BFR, 'h100, "RW", 0);
  endfunction
endclass
// ---------- Register ----------
class codec_cfg_reg extends uvm_reg;
  uvm_reg_field ADDR, DS, OE;
  `uvm_object_utils(codec_cfg_reg)

  function void build();
    // 32-bit register, NO shadow
    configure(null, 32, "RW", 0);

    ADDR = uvm_reg_field::type_id::create("ADDR");
    ADDR.configure(this, 8,  0, "RW", 0, 0, 1, 1, 0);

    DS   = uvm_reg_field::type_id::create("DS");
    DS.configure  (this, 8,  8, "RW", 0, 0, 1, 1, 0);

    OE   = uvm_reg_field::type_id::create("OE");
    OE.configure  (this, 8, 16, "RW", 0, 0, 1, 1, 0);
  endfunction
endclass

configure() 주요 인자
size, lsb_pos, access, reset, has_reset, is_rand, individually_accessible, volatile


3. 주소 맵(uvm_reg_map) 생성 TIP

항목 설명

create_map(name, base, nBytes, endian) 한 블록에 여러 Map 가능(AXI, APB …)
add_reg / add_mem 오프셋·access mode·alignment 지정
Sub-block 포함 add_submap(sub.default_map, offset)

4. 고급 기능 자동화

4-1 Field-Alias

  • 스펙에 alias=global 태그가 있으면 블록 클래스에서
    this.ADDR = CONFIG.ADDR; 처럼 handle 생성.

4-2 Covergroup 삽입

covergroup cg_type @(posedge bus_if.clk);
  cp_val   : coverpoint ADDR.value[7:0];
  cp_rw    : coverpoint is_read;
endgroup
  • include_coverage() 호출 시만 인스턴스화하도록 if(UVM_DATA_WIDTH…) 가드 삽입.

4-3 RTL Path (Back-door)

  • CONFIG.add_hdl_path_slice("rtl_i.cfg_reg", 0, 32);
  • 메모리일 경우 BFR.add_hdl_path("rtl_i.buf_mem");

5. 생성기 워크-플로

graph TD
  A[Spec 파일] -->|parser| B(JSON 구조체)
  B --> C[SystemVerilog Template Engine]
  C --> D(codec_blk.sv 등)
  C --> E[package.sv]
  C --> F[Makefile inc]
  • Python Jinja2, Perl Text::Template, or vendor IP-XACT tool 사용 가능
  • CI 파이프라인에 “스펙 변경 → RAL 재생성 → 컴파일” 자동화

6. 검증 환경 통합 예

class top_env extends uvm_env;
  codec_blk    ral_model;
  axi_reg_adapter axi2ral;
  function void build_phase(uvm_phase phase);
    ral_model = codec_blk::type_id::create("ral_model", this);
    ral_model.build();               // 내부 객체 생성
    ral_model.lock_model();          // 이후 구조 불변

    axi2ral = axi_reg_adapter::type_id::create("axi2ral");
    ral_model.default_map.set_sequencer(axi_seqr, axi2ral);
  endfunction
endclass


 

본 내용은
accellera에서 공개한
Universal Verification Methodology
(UVM) 1.2 User's Guide
를 바탕으로 작성된 글입니다.