ELF loader and program image#
ProgramImage loads an RV32 program into simulated memory and records its
entry address and segment permissions. The memory model takes ownership of this
image before the CPU starts fetching instructions.
Connections#
Input: ELF file bytes, RAM base and size; raw input also supplies a load address.
Output: initialized RAM, mapped segments and the initial PC for
MemoryModeland the CPU.Scheduling: loading runs once during application setup and consumes no simulated time.
Loading and access checks#
ProgramImage::elf() accepts little-endian ELF32 RISC-V executables.
It validates loadable segments, permissions and the aligned executable
entry, copies segment data into RAM and zero-fills BSS.
ProgramImage::raw() loads a nonempty sequence of 32-bit machine words
at the specified address. Assemble and link source text before loading it.
Runtime accesses check range, alignment and permissions. Unmapped RAM can hold data; instruction fetches require an executable segment. See program input for format requirements.
Objects and state#
Object or member |
Representation |
Role |
|---|---|---|
|
|
RAM bytes, including loaded segments and zero-filled BSS. |
|
|
Mapped ranges and read, write and execute permissions. |
|
32-bit addresses |
Memory base and initial CPU PC. |
Reset and errors#
A malformed image fails before simulation starts. Misaligned, out-of-range or disallowed runtime accesses return typed faults through the memory model. Session reset restores the CPU entry PC and preserves all memory bytes, including stores already completed. Reload the image to start with its original contents.
Implementation and tests#
Source: image.cpp and image.hpp.
CTest: core.image, systemc.use_cases.
The tests reject malformed images and disallowed accesses, load raw programs, and check diagnostics for missing files.