libmicroemu 0.2.0
ARM Microcontroller Emulator Library
Loading...
Searching...
No Matches
binary_load_instr_with_imm.h
1#pragma once
2#include "libmicroemu/internal/decoder/decoder.h"
3#include "libmicroemu/internal/executor/instr_context.h"
4#include "libmicroemu/internal/executor/instr_exec_results.h"
5#include "libmicroemu/internal/logic/reg_ops.h"
7#include "libmicroemu/internal/utils/rarg.h"
8#include "libmicroemu/register_details.h"
9#include "libmicroemu/types.h"
10
11namespace libmicroemu::internal {
12
16template <typename TLoadOp, typename TInstrContext> class BinaryLoadInstrWithImm {
17public:
18 using It = typename TInstrContext::It;
19 using Pc = typename TInstrContext::Pc;
20
21 using ExcTrig = typename TInstrContext::ExcTrig;
22
23 template <typename TTgt, typename TArg0>
24 static Result<InstrExecResult> Call(TInstrContext &ictx, const InstrFlagsSet &iflags,
25 const TTgt &rt, const TArg0 &rn, const u32 &imm32) {
26 const bool is_index = (iflags & static_cast<InstrFlagsSet>(InstrFlags::kIndex)) != 0U;
27 const bool is_add = (iflags & static_cast<InstrFlagsSet>(InstrFlags::kAdd)) != 0U;
28
29 TRY_ASSIGN(condition_passed, InstrExecResult, It::ConditionPassed(ictx.cpua));
30 if (!condition_passed) {
31 PostExecAdvancePcAndIt::Call(ictx, iflags);
32 return Ok(InstrExecResult{kNoInstrExecFlags});
33 }
34 const auto n = ictx.cpua.ReadRegister(rn.Get());
35 const me_adr_t offset_addr = is_add == true ? n + imm32 : n - imm32;
36 const me_adr_t address = is_index == true ? offset_addr : n;
37
38 TRY_ASSIGN(data, InstrExecResult, TLoadOp::Read(ictx, address));
39
40 const bool is_wback = (iflags & static_cast<InstrFlagsSet>(InstrFlags::kWBack)) != 0U;
41 if (is_wback) {
42 PostExecWriteRegPcExcluded::Call(ictx, rn, offset_addr);
43 }
44 const bool is_aligned = (address & 0x3U) == 0U;
45 TRY(InstrExecResult, PostExecWriteRegPcIncluded::Call(ictx, iflags, rt, data, is_aligned));
46 return Ok(InstrExecResult{kNoInstrExecFlags});
47 }
48
49private:
53 BinaryLoadInstrWithImm() = delete;
54
58 ~BinaryLoadInstrWithImm() = delete;
59
64 BinaryLoadInstrWithImm(const BinaryLoadInstrWithImm &r_src) = delete;
65
70 BinaryLoadInstrWithImm &operator=(const BinaryLoadInstrWithImm &r_src) = delete;
71
76 BinaryLoadInstrWithImm(BinaryLoadInstrWithImm &&r_src) = delete;
77
82 BinaryLoadInstrWithImm &operator=(BinaryLoadInstrWithImm &&r_src) = delete;
83};
84
85} // namespace libmicroemu::internal
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
#define TRY(OUT_TYPE, CALL)
Try to call a function and return an error if the call fails.
Definition result.h:138
Definition instr_exec_results.h:23
Definition result.h:15