Skip to content
STIMSMITH

gen_section

CodeArtifact WIKI v1 · 5/26/2026

gen_section is a helper function used by the riscv_asm_program_gen assembly-program generator to insert named assembly sections into an instruction stream. The evidence shows it being used for the _start header section, host-interface code such as write_tohost and _exit, and trap-vector-related code such as mtvec_handler.

Overview

gen_section is a code-generation helper associated with the riscv_asm_program_gen flow in riscv-dv. The surrounding generator class is described as producing complete RISC-V assembly programs for processor IP verification, including initialization, instruction, data, stack, page-table, interrupt, and exception-handling sections.

Within that flow, gen_section is used to add named assembly sections into the generated instruction stream.

Role in program generation

The main assembly-generation entry point described in the evidence is gen_program(). It calls other functions in riscv_asm_program_gen to build the complete assembly program. Early in that process, gen_program() calls gen_program_header(), which fills a string array named instr_stream with header content. gen_program_header() then calls:

gen_section("_start", str)

The documented purpose of this call is to insert header instructions into instr_stream.

Sections and examples

The evidence shows gen_section being used for multiple generated assembly regions:

  • Header/startup insertion through the _start section.
  • Host-interface-related code after main-program and subprogram generation.
  • Trap-vector-related code through mtvec_handler.

For host-interface code, the evidence lists generated strings and instruction content such as:

write_tohost:
sw gp, tohost, t1
_exit:

The evidence also states that riscv_asm_program uses gen_section() to select the mtvec_handler instruction string, and that mtvec_handler has exception_hander and interrupt_handler defined.

Position in the riscv-dv generation pipeline

In the documented flow, gen_section is not the top-level generator; it is used by higher-level functions while gen_program() coordinates full program construction. The broader sequence described in the evidence includes configuration randomization, directed instruction-stream selection, program-header generation, GPR initialization, directed instruction-stream generation, instruction-stream conversion to assembly, optional subprogram insertion, host-interface insertion, and trap-handling setup.

Generated-output context

The complete generated program is produced by gen_program() and associated helpers working with riscv_instruction_sequence, base test classes, and configuration helpers. The generated assembly can include randomized instructions and randomized general-purpose-register selections for use in RISC-V IP verification.

CITATIONS

6 sources
6 citations
[1] riscv_asm_program_gen generates complete RISC-V assembly programs for RISC-V IP verification and includes functions for sections such as initialization, instruction, data, stack, page table, interrupt, and exception handling. RISC-V source class riscv_asm_program_gen, the brain behind ...
[2] gen_program() is described as the main function that generates all sections of the program and calls other riscv_asm_program_gen functions. RISC-V source class riscv_asm_program_gen, the brain behind ...
[3] gen_program_header() calls gen_section("_start", str), which inserts header instructions into instr_stream. RISC-V source class riscv_asm_program_gen, the brain behind ...
[4] After main-program and subprogram generation, host-interface-related instructions are added by gen_section, including write_tohost, sw gp, tohost, t1, and _exit. RISC-V source class riscv_asm_program_gen, the brain behind ...
[5] riscv_asm_program uses gen_section() to select the mtvec_handler instruction string, which has exception_hander and interrupt_handler defined. RISC-V source class riscv_asm_program_gen, the brain behind ...
[6] The generated program flow uses gen_program() and associated helpers with riscv_instruction_sequence, base test classes, and configuration helpers to produce complete RISC-V assembly programs with randomized instructions and randomized GPR selections. RISC-V source class riscv_asm_program_gen, the brain behind ...