Overview
riscv_asm_program_gen is described as the class behind complete RISC-V assembly-program generation in the open-source riscv-dv random instruction generator used for RISC-V processor verification. The generated random test can be run with a design IP, and the class can address customization of RISC-V GPRs or instructions. [C1]
The class generates multiple sections of an assembly program, including initialization, instruction, data, stack, page-table, interrupt-handling, and exception-handling sections. [C2]
Configuration dependency
Before program generation, riscv_instr_gen_config is randomized from riscv_instr_base_test.sv. That configuration determines the RISC-V extension being run, supported privilege mode, instruction counts for the main program and subprograms, and configuration flags such as no_ebreak, no_dret, no_fence, and no_wfi. [C3]
Main generation flow
gen_program() is the main function used to generate all program sections. When called by an upper layer, it invokes other functions in riscv_asm_program_gen sequentially. [C4]
A documented generation flow includes:
- Calling
get_directed_instr_stream()and selecting directed-instruction generation ratios throughadd_directed_instr_stream(). [C5] - Calling
gen_program_header(), which fills theinstr_streamstring array with header content such as.include "user_init.s". [C6] - Having
gen_program_header()callgen_section("_start", str), which inserts header instructions intoinstr_stream. [C7] - Calling
init_gpr(), which initializes general-purpose registers with random values. [C8] - Calling
generate_directed_instr_stream(), which decides ratios, inserts directed instruction streams, randomizes instructions, and selectsrs1,rs2, andrdbased on instruction type. [C9] - Using
riscv_instr_sequence.generate_instr_stream()andconvert2asm()to turn available instruction streams into assembly form. [C10] - Calling
main_program[hart].generate_instr_stream()fromriscv_asm_program_gento convert the instruction stream to string format. [C11] - Inserting subprogram code with
insert_sub_program(sub_program[hart], instr_stream)when subprogram instructions are generated. [C12] - Adding host-interface-related instructions through
gen_section, including labels and instructions such aswrite_tohost:,sw gp, tohost, t1, and_exit:. [C13] - Calling
push_gpr_to_kernel_stack()to push general-purpose registers to the stack for trap handling, and usinggen_section()to select anmtvec_handlerstring that includes exception and interrupt handlers. [C14]
The flow also checks illegal-instruction and HINT-instruction ratios; when those ratios are zero, illegal or HINT instructions are not generated. [C15]
Generated output
The gen_program() function, related helper functions, riscv_instruction_sequence, base test classes, and configuration helpers together generate a full RISC-V assembly program. The resulting programs contain randomized instructions and randomized GPR selections, with different instruction patterns suitable for IP verification. [C16]
Role in verification
Within the described riscv-dv ecosystem, riscv_asm_program_gen is presented as a comprehensive utility for automating generation of RISC-V assembly programs. Its modular function calls and configuration support make it a central component for producing random assembly tests used in RISC-V IP verification. [C17]