libmicroemu 0.2.0
ARM Microcontroller Emulator Library
Loading...
Searching...
No Matches
unary_instr_imm.h
1#pragma once
2#include "libmicroemu/internal/decoder/decoder.h"
3#include "libmicroemu/internal/executor/instr/post_exec.h"
4#include "libmicroemu/internal/executor/instr_context.h"
5#include "libmicroemu/internal/executor/instr_exec_results.h"
7#include "libmicroemu/internal/utils/rarg.h"
8#include "libmicroemu/register_details.h"
9#include "libmicroemu/types.h"
10
11namespace libmicroemu::internal {
12
18template <typename TInstrContext> class AddToPcImmOp {
19public:
20 template <typename TDest>
21 static Result<InstrExecFlagsSet> Call(TInstrContext &ictx, const InstrFlagsSet &iflags,
22 const TDest &rd, const u32 &imm32) {
23 const me_adr_t pc = static_cast<me_adr_t>(ictx.cpua.template ReadRegister<RegisterId::kPc>());
24 const auto apc = Bm32::AlignDown<4>(pc);
25 const bool is_add = (iflags & static_cast<InstrFlagsSet>(InstrFlags::kAdd)) != 0U;
26 const auto result = is_add != false ? apc + imm32 : apc - imm32;
27 const auto op_res = OpResult{result, false, false};
28 PostExecWriteRegPcExcluded::Call(ictx, rd, op_res.value);
29 PostExecOptionalSetFlags::Call(ictx, iflags, op_res);
30 PostExecAdvancePcAndIt::Call(ictx, iflags);
31 return Ok(kNoInstrExecFlags);
32 }
33};
34
35template <typename TOp, typename TInstrContext> class UnaryInstrImm {
36public:
37 using It = typename TInstrContext::It;
38 using Pc = typename TInstrContext::Pc;
39
40 template <typename TDest>
41 static Result<InstrExecResult> Call(TInstrContext &ictx, const InstrFlagsSet &iflags,
42 const TDest &rd, const u32 &imm32) {
43 TRY_ASSIGN(condition_passed, InstrExecResult, It::ConditionPassed(ictx.cpua));
44 if (!condition_passed) {
45 PostExecAdvancePcAndIt::Call(ictx, iflags);
46 return Ok(InstrExecResult{kNoInstrExecFlags});
47 }
48
49 TRY_ASSIGN(eflags, InstrExecResult, TOp::Call(ictx, iflags, rd, imm32));
50 return Ok(InstrExecResult{eflags});
51 }
52
53private:
57 UnaryInstrImm() = delete;
58
62 ~UnaryInstrImm() = delete;
63
68 UnaryInstrImm(const UnaryInstrImm &r_src) = delete;
69
74 UnaryInstrImm &operator=(const UnaryInstrImm &r_src) = delete;
75
80 UnaryInstrImm(UnaryInstrImm &&r_src) = delete;
81
86 UnaryInstrImm &operator=(UnaryInstrImm &&r_src) = delete;
87};
88
89} // namespace libmicroemu::internal
Add to pc.
Definition unary_instr_imm.h:18
static constexpr u32 AlignDown(const u32 &address)
Definition bit_manip.h:35
The libmicroemu::internal namespace contains all classes and functions of libmicroemu which are priva...
Definition bkpt_flags.h:6
Contains the Result class which is used to return the result of a function.
#define TRY_ASSIGN(NAME, OUT_TYPE, CALL)
Try to assign a value to a variable and return an error if the assignment fails.
Definition result.h:123
Definition instr_exec_results.h:23
Definition post_exec.h:12
Definition result.h:15