libmicroemu 0.2.0
ARM Microcontroller Emulator Library
Loading...
Searching...
No Matches
ternary_load_instr_with_shift.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"
6#include "libmicroemu/internal/utils/rarg.h"
7#include "libmicroemu/register_details.h"
8#include "libmicroemu/types.h"
9
10namespace libmicroemu::internal {
11
15template <typename TLoadOp, typename TInstrContext> class TernaryLoadInstrWithShift {
16public:
17 using It = typename TInstrContext::It;
18 using Pc = typename TInstrContext::Pc;
19
20 using ExcTrig = typename TInstrContext::ExcTrig;
21
22 template <typename TTgt, typename TArg0, typename TArg1>
23 static Result<InstrExecResult> Call(TInstrContext &ictx, const InstrFlagsSet &iflags,
24 const TTgt &rt, const TArg0 &rn, const TArg1 &rm,
25 const ImmShiftResults &shift_res) {
26 const bool is_wback = (iflags & static_cast<InstrFlagsSet>(InstrFlags::kWBack)) != 0U;
27 const bool is_index = (iflags & static_cast<InstrFlagsSet>(InstrFlags::kIndex)) != 0U;
28 const bool is_add = (iflags & static_cast<InstrFlagsSet>(InstrFlags::kAdd)) != 0U;
29
30 TRY_ASSIGN(condition_passed, InstrExecResult, It::ConditionPassed(ictx.cpua));
31 if (!condition_passed) {
32 PostExecAdvancePcAndIt::Call(ictx, iflags);
33 return Ok(InstrExecResult{kNoInstrExecFlags});
34 }
35 const auto n = ictx.cpua.ReadRegister(rn.Get());
36 const auto m = ictx.cpua.ReadRegister(rm.Get());
37
38 auto apsr = ictx.cpua.template ReadSpecialRegister<SpecialRegisterId::kApsr>();
39 auto offset = Alu32::Shift(m, shift_res.type, shift_res.value,
40 (apsr & ApsrRegister::kCMsk) == ApsrRegister::kCMsk);
41
42 const u32 offset_addr = is_add == true ? n + offset : n - offset;
43 const u32 address = is_index == true ? offset_addr : n;
44
45 TRY_ASSIGN(data, InstrExecResult, TLoadOp::Read(ictx, address));
46 if (is_wback) {
47 PostExecWriteRegPcExcluded::Call(ictx, rn, offset_addr);
48 }
49 const bool is_aligned = (address & 0x3U) == 0U;
50 TRY(InstrExecResult, PostExecWriteRegPcIncluded::Call(ictx, iflags, rt, data, is_aligned));
51 return Ok(InstrExecResult{kNoInstrExecFlags});
52 }
53
54private:
58 TernaryLoadInstrWithShift() = delete;
59
63 ~TernaryLoadInstrWithShift() = delete;
64
69 TernaryLoadInstrWithShift(const TernaryLoadInstrWithShift &r_src) = delete;
70
75 TernaryLoadInstrWithShift &operator=(const TernaryLoadInstrWithShift &r_src) = delete;
76
81 TernaryLoadInstrWithShift(TernaryLoadInstrWithShift &&r_src) = delete;
82
87 TernaryLoadInstrWithShift &operator=(TernaryLoadInstrWithShift &&r_src) = delete;
88};
89
90} // 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 imm_shift_results.h:15
Definition instr_exec_results.h:23
Definition result.h:15