Skip to content
STIMSMITH

insert_sub_program

CodeArtifact WIKI v1 · 5/26/2026

`insert_sub_program` is a code artifact invoked as `insert_sub_program(sub_program[hart], instr_stream)` during RISC-V assembly program generation. In the evidenced flow, it is called after sub-program instructions are selected or generated, and before host-interface and trap-handling sections are added.

Overview

insert_sub_program appears in the RISC-V assembly program generation flow as the function call:

insert_sub_program(sub_program[hart], instr_stream);

The call is used after sub-program instruction generation or selection, inserting the per-hart sub_program[hart] content into an instruction stream named instr_stream.

Role in the generation sequence

The documented sequence places insert_sub_program in the middle of the broader riscv_asm_program_gen program-generation flow:

  1. Sub-program instructions are generated or selected.
  2. insert_sub_program(sub_program[hart], instr_stream) is called.
  3. After main-program and sub-program generation is complete, host-interface instructions are added through gen_section.
  4. The host-interface section includes labels and instructions such as:
write_tohost:
sw gp, tohost, t1
_exit:
  1. Trap-handling setup follows, including push_gpr_to_kernel_stack(), which pushes general-purpose registers to the stack for trap handling.
  2. gen_section() is also used to select an mtvec_handler section containing exception_hander and interrupt_handler definitions.

Context in generated programs

The surrounding generator flow is described as producing complete RISC-V assembly programs. The gen_program() function, other functions in the same class, riscv_instruction_sequence, base-test classes, and helper classes work together to generate randomized instructions, randomized general-purpose register choices, and different instruction patterns for IP verification use cases.

Inputs visible from the call site

The visible call signature shows two arguments:

  • sub_program[hart]: a per-hart sub-program object or collection referenced by hart index.
  • instr_stream: the instruction stream into which the sub-program is inserted.

No further implementation details, return value, side effects beyond insertion into the instruction stream, or error behavior are provided in the available evidence.

CITATIONS

5 sources
5 citations
[1] `insert_sub_program` is called as `insert_sub_program(sub_program[hart], instr_stream)` after sub-program instruction generation or selection. RISC-V source class riscv_asm_program_gen, the brain behind ...
[2] After main and sub-program generation is complete, host-interface instructions such as `write_tohost`, `sw gp, tohost, t1`, and `_exit` are added by `gen_section`. RISC-V source class riscv_asm_program_gen, the brain behind ...
[3] `push_gpr_to_kernel_stack()` pushes general-purpose registers to the stack for trap handling. RISC-V source class riscv_asm_program_gen, the brain behind ...
[4] `gen_section()` selects an `mtvec_handler` section containing `exception_hander` and `interrupt_handler` definitions. RISC-V source class riscv_asm_program_gen, the brain behind ...
[5] `gen_program()` and related helpers generate complete RISC-V assembly programs with randomized instructions, randomized GPR selections, and varied instruction patterns. RISC-V source class riscv_asm_program_gen, the brain behind ...