Skip to main content

Module emulator

Module emulator 

Source
Expand description

The emulator core — CPU execution loop, image loading, and run control.

Emulator is the central type. It owns the CpuState, the RAM buffer, and optional debug state (symbol table, output buffer). Everything else — time, keyboard, sleep — is delegated to a Platform implementation.

§Execution flow

Emulator::run()
  └─ loop {
       tick_timer(elapsed_us)       // advance mtime, check MTIP
       check WFI / pending IRQ
       'iloop: for 0..count {
           fetch instruction
           decode opcode
           execute → update regs / pc / trap
       }
       commit_trap() if any trap fired
       update cycle counter
     }

§Loading images

MethodUse case
Emulator::load_rawLinux kernel raw image + DTB
Emulator::load_raw_from_bytesSame, but from an in-memory slice (WASM)
Emulator::load_elfBare-metal ELF or FreeRTOS

§ISA coverage

ExtensionInstructions
RV32IAll base integer instructions
RV32MMUL, MULH, MULHSU, MULHU, DIV, DIVU, REM, REMU
RV32ALR.W, SC.W, AMOSWAP/ADD/XOR/AND/OR/MIN/MAX/MINU/MAXU.W
ZicsrCSRRW, CSRRS, CSRRC, CSRRWI, CSRRSI, CSRRCI
PrivilegedMRET, WFI, ECALL, EBREAK
FENCETreated as no-op (no cache model)

Structs§

Emulator
A complete RV32IMA emulator instance.
RunConfig
Parameters that control the Emulator::run loop.

Constants§

RAM_BASE
Physical base address of emulated RAM.