libmicroemu 0.2.0
ARM Microcontroller Emulator Library
Loading...
Searching...
No Matches
libmicroemu::Machine Class Reference

Represents the main emulation machine for handling microcontroller emulation. More...

#include <machine.h>

Public Member Functions

 Machine () noexcept
 
 ~Machine () noexcept
 
StatusCode Load (const char *elf_file, bool set_entry_point=false) noexcept
 Loads an ELF file into memory and optionally sets the entry point.
 
StatusCode Reset () noexcept
 
ExecResult Exec (i64 max_instructions=-1, FPreExecStepCallback cb_pre_exec=nullptr, FPostExecStepCallback cb_post_exec=nullptr) noexcept
 Executes the loaded program.
 
void SetFlashSegment (u8 *seg_ptr, me_size_t seg_size, me_adr_t seg_vadr) noexcept
 Sets the Flash segment The flash segment is where a microcontroller stores its program code. A flash segment is read-only.
 
void SetRam1Segment (u8 *seg_ptr, me_size_t seg_size, me_adr_t seg_vadr) noexcept
 Sets the RAM1 segment The RAM1 segment is where a microcontroller stores its data. A RAM1 segment is read-write.
 
void SetRam2Segment (u8 *seg_ptr, me_size_t seg_size, me_adr_t seg_vadr) noexcept
 Sets the RAM2 segment The RAM2 segment is were a microcontroller stores its data. A RAM2 segment is read-write.
 
void EvaluateState (FStateCallback cb) noexcept
 Evaluates the state of the processor This function evaluates the state of the processor by calling a function which gives access to the registers and special registers.
 
std::string_view GetVersion () noexcept
 Gets the version of the library.
 

Static Public Member Functions

static void RegisterLoggerCallback (void(*callback)(libmicroemu::LogLevel level, const char *,...) noexcept) noexcept
 

Detailed Description

Represents the main emulation machine for handling microcontroller emulation.

The Machine class is responsible for loading ELF files, setting up memory segments, executing programs, and evaluating the processor state. It provides various utilities to configure and control the emulation process.

Constructor & Destructor Documentation

◆ Machine()

libmicroemu::Machine::Machine ( )
noexcept

Constructor

◆ ~Machine()

libmicroemu::Machine::~Machine ( )
noexcept

Deconstructor

Member Function Documentation

◆ EvaluateState()

void libmicroemu::Machine::EvaluateState ( FStateCallback cb)
noexcept

Evaluates the state of the processor This function evaluates the state of the processor by calling a function which gives access to the registers and special registers.

Attention
The callback is not allowed to throw exceptions.
Parameters
cbCallback function to evaluate the state

◆ Exec()

ExecResult libmicroemu::Machine::Exec ( i64 max_instructions = -1,
FPreExecStepCallback cb_pre_exec = nullptr,
FPostExecStepCallback cb_post_exec = nullptr )
noexcept

Executes the loaded program.

Parameters
max_instructionsMaximum number of instructions to execute. -1 means infinite
cb_pre_execCallback function to be called before each instruction is executed
cb_post_execCallback function to be called after each instruction is executed
Returns
Result of the execution

◆ GetVersion()

std::string_view libmicroemu::Machine::GetVersion ( )
noexcept

Gets the version of the library.

Returns
The semver version of the library in the format "MAJOR.MINOR.PATCH"

◆ Load()

StatusCode libmicroemu::Machine::Load ( const char * elf_file,
bool set_entry_point = false )
noexcept

Loads an ELF file into memory and optionally sets the entry point.

Initializes memory, reads the ELF file, and loads its segments into appropriate memory regions. Optionally sets the entry point for execution.

Parameters
elf_filePath to the ELF file.
set_entry_pointWhether to set the entry point in the emulator.
Returns
StatusCode indicating success or error (e.g., file open failure, buffer too small, or ELF parsing errors).
Note
Ensures segments fit within memory bounds and resets the emulator state.

◆ SetFlashSegment()

void libmicroemu::Machine::SetFlashSegment ( u8 * seg_ptr,
me_size_t seg_size,
me_adr_t seg_vadr )
noexcept

Sets the Flash segment The flash segment is where a microcontroller stores its program code. A flash segment is read-only.

Parameters
seg_ptrPointer to the flash segment
seg_sizeSize of the flash segment
seg_vadrVirtual address of the flash segment

◆ SetRam1Segment()

void libmicroemu::Machine::SetRam1Segment ( u8 * seg_ptr,
me_size_t seg_size,
me_adr_t seg_vadr )
noexcept

Sets the RAM1 segment The RAM1 segment is where a microcontroller stores its data. A RAM1 segment is read-write.

Parameters
seg_ptrPointer to the RAM1 segment
seg_sizeSize of the RAM1 segment
seg_vadrVirtual address of the RAM1 segment

◆ SetRam2Segment()

void libmicroemu::Machine::SetRam2Segment ( u8 * seg_ptr,
me_size_t seg_size,
me_adr_t seg_vadr )
noexcept

Sets the RAM2 segment The RAM2 segment is were a microcontroller stores its data. A RAM2 segment is read-write.

Parameters
seg_ptrPointer to the RAM2 segment
seg_sizeSize of the RAM2 segment
seg_vadrVirtual address of the RAM2 segment

The documentation for this class was generated from the following files: