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
_startsection. - 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.