libmicroemu 0.2.0
ARM Microcontroller Emulator Library
Loading...
Searching...
No Matches
delegates.h
1#pragma once
2
3#include "libmicroemu/internal/bkpt_flags.h"
4#include "libmicroemu/internal/i_breakpoint.h"
6#include "libmicroemu/internal/svc_flags.h"
8
9namespace libmicroemu::internal {
10class Delegates {
11public:
12 using PreExecDelegate = FPreExecStepCallback;
13 using PostExecDelegate = FPostExecStepCallback;
14 using BkptDelegate = std::function<Result<BkptFlagsSet>(const u32 &)>;
15 using SvcDelegate = std::function<Result<SvcFlagsSet>(const u32 &)>;
16
17 explicit Delegates(PreExecDelegate pre_exec_delegate, PostExecDelegate post_exec_delegate,
18 BkptDelegate bkpt_delegate, SvcDelegate svc_delegate)
19 : pre_exec_delegate_(pre_exec_delegate), post_exec_delegate_(post_exec_delegate),
20 bkpt_delegate_(bkpt_delegate), svc_delegate_(svc_delegate) {}
21
22 Delegates() = delete;
23 ~Delegates() = default;
24 Delegates(const Delegates &) = default;
25 Delegates &operator=(const Delegates &) = default;
26 Delegates(Delegates &&) = default;
27 Delegates &operator=(Delegates &&) = default;
28
29 bool IsPreExecSet() { return pre_exec_delegate_ != nullptr; }
30 bool IsPostExecSet() { return post_exec_delegate_ != nullptr; }
31 bool IsBkptSet() { return bkpt_delegate_ != nullptr; }
32 bool IsSvcSet() { return svc_delegate_ != nullptr; }
33
34 void PreExec(EmuContext &emu_ctx) { pre_exec_delegate_(emu_ctx); }
35
36 void PostExec(EmuContext &emu_ctx) { post_exec_delegate_(emu_ctx); }
37
38 Result<BkptFlagsSet> Bkpt(const u32 &imm32) { return bkpt_delegate_(imm32); }
39 Result<SvcFlagsSet> Svc(const u32 &imm32) { return svc_delegate_(imm32); }
40
41private:
42 PreExecDelegate pre_exec_delegate_{nullptr};
43 PostExecDelegate post_exec_delegate_{nullptr};
44 BkptDelegate bkpt_delegate_{nullptr};
45 SvcDelegate svc_delegate_{nullptr};
46};
47
48} // namespace libmicroemu::internal
Definition emu_context.h:79
Contains the Machine class which is the main emulation machine for handling microcontroller emulation...
The libmicroemu::internal namespace contains all classes and functions of libmicroemu which are priva...
Definition bkpt_flags.h:6
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
Contains the Result class which is used to return the result of a function.
Definition result.h:15