Overview
interrupt and exception handling is identified as one of the sections generated in a complete RISC-V assembly program by the riscv_asm_program_gen class in the CHIPS Alliance riscv-dv random instruction generator. The generated assembly program is used for RISC-V processor IP verification and is produced alongside other sections such as initialization routines, instruction sections, data sections, stack sections, and page tables.
Role in generated RISC-V assembly
The riscv_asm_program_gen class generates full RISC-V assembly programs by coordinating multiple functions and helper classes. Its gen_program() function is described as the main function that generates all sections of the program. During program generation, the flow includes header generation, GPR initialization, directed and random instruction stream generation, optional subprogram insertion, host-interface code insertion, and trap-handling support.
Within this flow, interrupt and exception handling is tied to trap handling. The function push_gpr_to_kernel_stack() pushes general-purpose registers to the stack for trap handling. The program generator then uses gen_section() to select an mtvec_handler instruction section, and that mtvec_handler section has exception_handler and interrupt_handler definitions.
Technical elements mentioned in the evidence
push_gpr_to_kernel_stack()saves general-purpose registers to a stack for trap handling.gen_section()is used byriscv_asm_programto select themtvec_handlersection.- The
mtvec_handlersection contains bothexception_handlerandinterrupt_handlerdefinitions. - Interrupt and exception handling is generated as part of a larger RISC-V assembly test program used for RISC-V IP verification.
Verification context
The evidence places interrupt and exception handling in the context of automated RISC-V assembly generation. CHIPS Alliance's open-source riscv-dv generator produces randomized assembly tests for RISC-V processor verification. Configuration randomization determines items such as the RISC-V extension, supported privilege mode, instruction counts for main and subprograms, and whether certain instruction types such as break, debug-return, fence, and wait-for-interrupt instructions are generated.