libmicroemu 0.2.0
ARM Microcontroller Emulator Library
Loading...
Searching...
No Matches
libmicroemu Namespace Reference

The libmicroemu namespace contains all classes and functions of the libmicroemu which are public. More...

Namespaces

namespace  internal
 The libmicroemu::internal namespace contains all classes and functions of libmicroemu which are private.
 

Classes

struct  ApsrRegister
 
struct  CcrRegister
 
struct  CfsrBusFault
 
struct  CfsrMemManage
 
struct  CfsrUsageFault
 
struct  ControlRegister
 
class  CpuStates
 Cpu states class. More...
 
class  EmuContext
 
struct  EpsrRegister
 
struct  ExceptionStates
 
class  ExecResult
 Returned by the libmicroemu::Machine::Exec method. Contains the status code of the execution and the program exit code. More...
 
class  IInstrToMnemonic
 
struct  IpsrRegister
 
class  IRegAccessor
 Interface for accessing general-purpose registers. More...
 
class  ISpecialRegAccessor
 Interface for accessing special registers. More...
 
struct  IstateRegister
 
class  Machine
 Represents the main emulation machine for handling microcontroller emulation. More...
 
class  NullLogger
 Null logger class Used to disable logging. More...
 
struct  OpCode
 
struct  RawInstr
 
struct  RegisterOffsets
 
struct  SingleExceptionState
 Represents the state of a single exception. More...
 
class  StaticLogger
 Static logger class. More...
 
struct  SysCtrlRegister
 
struct  SysTickRegister
 
struct  ThumbImmediateResult
 
union  U32_parts
 

Typedefs

using RawInstrFlagsSet = u8
 
using ExceptionFlagsSet = u8
 
using FPreExecStepCallback = std::function<void(EmuContext &ctx)>
 Callback function to be called before each instruction is executed.
 
using FPostExecStepCallback = std::function<void(EmuContext &ctx)>
 Callback function to be called after each instruction is executed.
 
using FStateCallback
 Callback function to evaluate the state of the processor.
 
using u64 = uint64_t
 
using u32 = uint32_t
 
using u16 = uint16_t
 
using u8 = uint8_t
 
using i64 = int64_t
 
using i32 = int32_t
 
using i16 = int16_t
 
using i8 = int8_t
 
using me_adr_t = u32
 
using me_size_t = u32
 
using me_offset_t = u32
 

Enumerations

enum class  RawInstrFlagsPos { k32Bit = 0U }
 
enum class  RawInstrFlagsMsk : RawInstrFlagsSet { k32Bit = 1U << static_cast<u8>(RawInstrFlagsPos::k32Bit) }
 
enum class  ExceptionFlags : ExceptionFlagsSet { kPending = 1U << 0U , kActive = 1U << 1U }
 
enum class  ExceptionType {
  kReset = 1U , kNMI = 2U , kHardFault = 3U , kMemoryManagementFault = 4U ,
  kBusFault = 5U , kUsageFault = 6U , kReserved1 = 7U , kReserved2 = 8U ,
  kReserved3 = 9U , kReserved4 = 9U , kReserved5 = 10U , kSVCall = 11U ,
  kDebugMonitor = 12U , kReserved6 = 13U , kPendSV = 14U , kSysTick = 15U
}
 Exception enumeration. More...
 
enum class  LogLevel {
  kTrace , kDebug , kInfo , kWarn ,
  kError , kCritical
}
 Enum class for log levels Used to indicate the log level of a message. More...
 
enum class  RegisterId : u8 {
  kR0 = 0U , kR1 = 1U , kR2 = 2U , kR3 = 3U ,
  kR4 = 4U , kR5 = 5U , kR6 = 6U , kR7 = 7U ,
  kR8 = 8U , kR9 = 9U , kR10 = 10U , kR11 = 11U ,
  kR12 = 12U , kSp = 13U , kR13 = 13U , kLr = 14U ,
  kR14 = 14U , kPc = 15U , kR15 = 15U
}
 Enumeration of register IDs. More...
 
enum class  SpecialRegisterId : u8 {
  kSysCtrl = 0U , kApsr , kIstate , kIpsr ,
  kVtor , kCcr , kCfsr , kBfar ,
  kSpMain , kSpProcess , kSysTickCsr , kSysTickRvr ,
  kSysTickCvr , kSysTickCalib , kEpsr , kXpsr ,
  kControl
}
 Enumeration of special register IDs. More...
 
enum class  StatusCode : u32 {
  kSuccess = 0x0U , kError = 0x1U , kUnexpected = 0x1002U , kUnsuporrted = 0x1003U ,
  kNotImplemented = 0x1004U , kOutOfRange = 0x2001U , kIteratorExhausted = 0x2002U , kBufferTooSmall = 0x2003U ,
  kOpenFileFailed = 0x2004U , kMemInaccesible = 0x3001U , kMemWriteNotAllowed = 0x3002U , kDecoderUnknownOpCode = 0x4001U ,
  kDecoderUnpredictable = 0x4002U , kDecoderUndefined = 0x4003U , kExecutorUnpredictable = 0x5001U , kExecutorUndefined = 0x5002U ,
  kExecutorExitWithError = 0x5003U , kElfNotValid = 0x6001U , kElfWrongHeader = 0x6002U , kUsageFault = 0x7001U ,
  kMaxInstructionsReached = 0x8001U
}
 Enum representing various status codes used throughout the system. More...
 

Functions

template<std::size_t... Indices>
constexpr auto MakeExceptionArray (std::index_sequence< Indices... >)
 
static constexpr u32 CountInternalExceptions () noexcept
 
static constexpr u32 CountExceptions () noexcept
 
template<unsigned last_bit, unsigned first_bit>
static constexpr u32 BitMask ()
 
static constexpr u32 CountRegisters () noexcept
 Returns the number of general-purpose registers.
 
static constexpr u32 CountPersistentSpecialRegisters () noexcept
 Returns the number of persistent special registers.
 
static constexpr u32 CountSpecialRegisters () noexcept
 Returns the number of special registers.
 
static std::string_view StatusCodeToString (const StatusCode &status_code) noexcept
 Converts a status code to a string.
 

Variables

static constexpr i16 kLowestExceptionPriority = 255U
 
static constexpr auto kNoOfExternalIrqs = 32U
 
static constexpr auto kLastInternalException = ExceptionType::kSysTick
 
constexpr auto kLastRegister = RegisterId::kR15
 The last register ID.
 
constexpr auto kLastPersistentSpecialRegister = SpecialRegisterId::kSysTickCalib
 
constexpr auto kFirstRuntimeSpecialRegister = SpecialRegisterId::kEpsr
 
constexpr auto kLastRuntimeSpecialRegister = SpecialRegisterId::kControl
 
constexpr auto kLastSpecialRegister = kLastRuntimeSpecialRegister
 

Detailed Description

The libmicroemu namespace contains all classes and functions of the libmicroemu which are public.

Typedef Documentation

◆ FPostExecStepCallback

using libmicroemu::FPostExecStepCallback = std::function<void(EmuContext &ctx)>

Callback function to be called after each instruction is executed.

Parameters
ctxThe context of the emulator

◆ FPreExecStepCallback

using libmicroemu::FPreExecStepCallback = std::function<void(EmuContext &ctx)>

Callback function to be called before each instruction is executed.

Parameters
ctxThe context of the emulator

◆ FStateCallback

Initial value:
std::function<void(IRegAccessor &reg_access, ISpecialRegAccessor &spec_reg_access)>
Interface for accessing general-purpose registers.
Definition emu_context.h:25
Interface for accessing special registers.
Definition emu_context.h:52

Callback function to evaluate the state of the processor.

Parameters
reg_accessThe register accessor
spec_reg_accessThe special register accessor

Enumeration Type Documentation

◆ ExceptionType

enum class libmicroemu::ExceptionType
strong

Exception enumeration.

The enumeration of ExceptionsOps that can be triggered by the processor.

Enumerator
kReset 

Special exception to reset the processor.

kNMI 

Highest priority exception (for except the reset) that cannot be ever masked away. Can be triggered by a peripheral or triggered by software.

kHardFault 

Hard fault exception, triggered by faults that cannot be handled by any other exception.

kMemoryManagementFault 

Memory related fault (bus access error either for instructions or data)

kBusFault 

Bus fault exception, triggered by bus errors on instruction fetches and data accesses.

kUsageFault 

Usage fault exception, triggered by errors in the usage of the processor.

kReserved1 

Reserved for future use.

kReserved2 

Reserved for future use.

kReserved3 

Reserved for future use.

kReserved4 

Reserved for future use.

kReserved5 

Reserved for future use.

kSVCall 

Exception for system calls.

kDebugMonitor 

Debugging related ExceptionsOps.

kReserved6 

Reserved for future use.

kPendSV 

PendSV exception, used for context switching.

kSysTick 

SysTick exception, used for system timer.

◆ LogLevel

enum class libmicroemu::LogLevel
strong

Enum class for log levels Used to indicate the log level of a message.

Enumerator
kTrace 

Trace log level.

kDebug 

Debug log level.

kInfo 

Info log level.

kWarn 

Warn log level.

kError 

Error log level.

kCritical 

Critical log level.

◆ RegisterId

enum class libmicroemu::RegisterId : u8
strong

Enumeration of register IDs.

This enumeration represents the IDs of general-purpose registers. General-purpose registers are used for storing data and intermediate results.

Enumerator
kSp 

Stack-pointer register.

kLr 

Link-register.

kPc 

Program-counter register.

◆ SpecialRegisterId

enum class libmicroemu::SpecialRegisterId : u8
strong

Enumeration of special register IDs.

This enumeration represents the IDs of special registers. Special registers are used for storing specific system information or control flags.

Enumerator
kSysCtrl 

System Control Register, SYSCTRL.

kApsr 

Application Program Status Register, APSR.

kIstate 

If-Then Execution state bits.

kIpsr 

Interrupt Program Status Register, IPSR.

kVtor 

Vector Table Offset Register, VTOR.

kCcr 

Configuration and Control Register, CCR.

kCfsr 

Configurable Fault Status Register, CFSR.

kBfar 

Bus Fault Address Register, BFAR.

kSpMain 

Main Stack Pointer, MSP.

kSpProcess 

Process Stack Pointer, PSP.

kSysTickCsr 

SYSTICK_CSR - SysTick Control and Status Register.

kSysTickRvr 

SYSTICK_RVR - SysTick Reload Value Register.

kSysTickCvr 

SYST_CVR - SysTick Current Value Register.

kSysTickCalib 

SYST_CALIB - SysTick Calibration Value Register.

kEpsr 

Execution Program Status Register, EPSR.

kXpsr 

Program status register, XPSR.

kControl 

Control register, CONTROL.

◆ StatusCode

enum class libmicroemu::StatusCode : u32
strong

Enum representing various status codes used throughout the system.

Enumerator
kSuccess 

Operation succeeded successfully.

kError 

An unspecified error occurred.

kUnexpected 

An unexpected error occurred.

kUnsuporrted 

Operation or feature is unsupported.

kNotImplemented 

Operation or feature is not implemented.

kOutOfRange 

Value is out of the allowed range.

kIteratorExhausted 

Iterator has been exhausted.

kBufferTooSmall 

Provided buffer is too small.

kOpenFileFailed 

Failed to open the file.

kMemInaccesible 

Memory is inaccessible.

kMemWriteNotAllowed 

Memory write operation is not allowed.

kDecoderUnknownOpCode 

Decoder encountered an unknown opcode.

kDecoderUnpredictable 

Decoder encountered an unpredictable operation.

kDecoderUndefined 

Decoder encountered an undefined operation.

kExecutorUnpredictable 

Executor encountered an unpredictable operation.

kExecutorUndefined 

Executor encountered an undefined operation.

kExecutorExitWithError 

Executor exited with an error.

kElfNotValid 

ELF file is not valid.

kElfWrongHeader 

ELF file has a wrong header.

kUsageFault 

Usage fault occurred.

kMaxInstructionsReached 

Maximum instruction count reached.

Function Documentation

◆ CountPersistentSpecialRegisters()

static constexpr u32 libmicroemu::CountPersistentSpecialRegisters ( )
staticconstexprnoexcept

Returns the number of persistent special registers.

This function returns the total number of persistent special registers, i.e., registers that are part of the processor and have a state that persists.

Returns
The number of persistent special registers.

◆ CountRegisters()

static constexpr u32 libmicroemu::CountRegisters ( )
staticconstexprnoexcept

Returns the number of general-purpose registers.

Returns
The number of general-purpose registers.

◆ CountSpecialRegisters()

static constexpr u32 libmicroemu::CountSpecialRegisters ( )
staticconstexprnoexcept

Returns the number of special registers.

This function returns the total number of special registers.

Returns
The number of special registers.

◆ StatusCodeToString()

static std::string_view libmicroemu::StatusCodeToString ( const StatusCode & status_code)
staticnoexcept

Converts a status code to a string.

Parameters
status_codethe status code to convert
Returns
a string representation of the status code