libmicroemu 0.2.0
ARM Microcontroller Emulator Library
Loading...
Searching...
No Matches
machine.h
Go to the documentation of this file.
1
6#pragma once
7
8#include "libmicroemu/cpu_states.h"
9#include "libmicroemu/emu_context.h"
11#include "libmicroemu/logger.h"
13#include "libmicroemu/types.h"
14
15#include <array>
16#include <functional>
17
22namespace libmicroemu {
23
28namespace internal {
29// forward declarations
30template <typename TCpuStates> class Emulator;
31}; // namespace internal
32
35using FPreExecStepCallback = std::function<void(EmuContext &ctx)>;
36
39using FPostExecStepCallback = std::function<void(EmuContext &ctx)>;
40
45 std::function<void(IRegAccessor &reg_access, ISpecialRegAccessor &spec_reg_access)>;
46
54class Machine {
55public:
59 Machine() noexcept;
60
64 ~Machine() noexcept;
65
79 StatusCode Load(const char *elf_file, bool set_entry_point = false) noexcept;
80
81 StatusCode Reset() noexcept;
82
90 ExecResult Exec(i64 max_instructions = -1, FPreExecStepCallback cb_pre_exec = nullptr,
91 FPostExecStepCallback cb_post_exec = nullptr) noexcept;
92
101 void SetFlashSegment(u8 *seg_ptr, me_size_t seg_size, me_adr_t seg_vadr) noexcept;
102
111 void SetRam1Segment(u8 *seg_ptr, me_size_t seg_size, me_adr_t seg_vadr) noexcept;
112
121 void SetRam2Segment(u8 *seg_ptr, me_size_t seg_size, me_adr_t seg_vadr) noexcept;
122
130 void EvaluateState(FStateCallback cb) noexcept;
131
132 static void RegisterLoggerCallback(void (*callback)(libmicroemu::LogLevel level, const char *,
133 ...) noexcept) noexcept;
134
139 std::string_view GetVersion() noexcept;
140
141private:
142 internal::Emulator<CpuStates> BuildEmulator();
143 u8 *flash_{nullptr};
144 me_size_t flash_size_{0U};
145 me_adr_t flash_vadr_{0x0U};
146
147 u8 *ram1_{nullptr};
148 me_size_t ram1_size_{0U};
149 me_adr_t ram1_vadr_{0x0U};
150
151 u8 *ram2_{nullptr};
152 me_size_t ram2_size_{0U};
153 me_adr_t ram2_vadr_{0x0U};
154
155 CpuStates cpu_states_{};
156};
157
158} // namespace libmicroemu
Cpu states class.
Definition cpu_states.h:21
Definition emu_context.h:79
Returned by the libmicroemu::Machine::Exec method. Contains the status code of the execution and the ...
Definition exec_result.h:18
Interface for accessing general-purpose registers.
Definition emu_context.h:25
Interface for accessing special registers.
Definition emu_context.h:52
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 r...
Definition machine.cpp:107
std::string_view GetVersion() noexcept
Gets the version of the library.
Definition machine.cpp:146
~Machine() noexcept
Definition machine.cpp:25
ExecResult Exec(i64 max_instructions=-1, FPreExecStepCallback cb_pre_exec=nullptr, FPostExecStepCallback cb_post_exec=nullptr) noexcept
Executes the loaded program.
Definition machine.cpp:123
Machine() noexcept
Definition machine.cpp:24
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....
Definition machine.cpp:101
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....
Definition machine.cpp:95
void EvaluateState(FStateCallback cb) noexcept
Evaluates the state of the processor This function evaluates the state of the processor by calling a ...
Definition machine.cpp:130
StatusCode Load(const char *elf_file, bool set_entry_point=false) noexcept
Loads an ELF file into memory and optionally sets the entry point.
Definition machine.cpp:27
Definition emulator.h:31
Contains the ExecResult class which is returned by the Executor::Exec method.
The libmicroemu::internal namespace contains all classes and functions of libmicroemu which are priva...
Definition bkpt_flags.h:6
The libmicroemu namespace contains all classes and functions of the libmicroemu which are public.
Definition bkpt_flags.h:6
LogLevel
Enum class for log levels Used to indicate the log level of a message.
Definition logger.h:13
std::function< void(IRegAccessor &reg_access, ISpecialRegAccessor &spec_reg_access)> FStateCallback
Callback function to evaluate the state of the processor.
Definition machine.h:44
StatusCode
Enum representing various status codes used throughout the system.
Definition status_code.h:17
std::function< void(EmuContext &ctx)> FPreExecStepCallback
Callback function to be called before each instruction is executed.
Definition machine.h:35
std::function< void(EmuContext &ctx)> FPostExecStepCallback
Callback function to be called after each instruction is executed.
Definition machine.h:39
File contains enum class for status codes.