libmicroemu 0.2.0
ARM Microcontroller Emulator Library
Loading...
Searching...
No Matches
unary_load_instr_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/utils/rarg.h"
6#include "libmicroemu/register_details.h"
7
9#include "libmicroemu/types.h"
10
11namespace libmicroemu::internal {
12
16template <typename TLoadOp, typename TInstrContext> class UnaryLoadInstrImm {
17public:
18 using It = typename TInstrContext::It;
19 using Pc = typename TInstrContext::Pc;
20 using ExcTrig = typename TInstrContext::ExcTrig;
21
22 template <typename TTgt>
23 static Result<InstrExecResult> Call(TInstrContext &ictx, const InstrFlagsSet &iflags,
24 const u32 &imm32, const TTgt &rt) {
25
26 TRY_ASSIGN(condition_passed, InstrExecResult, It::ConditionPassed(ictx.cpua));
27 if (!condition_passed) {
28 PostExecAdvancePcAndIt::Call(ictx, iflags);
29 return Ok(InstrExecResult{kNoInstrExecFlags});
30 }
31 const bool is_add = (iflags & static_cast<InstrFlagsSet>(InstrFlags::kAdd)) != 0U;
32
33 // unary loads always refer to the pc
34 const me_adr_t pc = static_cast<me_adr_t>(ictx.cpua.template ReadRegister<RegisterId::kPc>());
35 const me_adr_t base = Bm32::AlignDown<4>(pc);
36 const me_adr_t address = is_add == true ? base + imm32 : base - imm32;
37
38 TRY_ASSIGN(data, InstrExecResult, TLoadOp::Read(ictx, address));
39
40 const bool is_aligned = (address & 0x3U) == 0U;
41 TRY(InstrExecResult, PostExecWriteRegPcIncluded::Call(ictx, iflags, rt, data, is_aligned));
42 return Ok(InstrExecResult{kNoInstrExecFlags});
43 }
44
45private:
49 UnaryLoadInstrImm() = delete;
50
54 ~UnaryLoadInstrImm() = delete;
55
60 UnaryLoadInstrImm(const UnaryLoadInstrImm &r_src) = delete;
61
66 UnaryLoadInstrImm &operator=(const UnaryLoadInstrImm &r_src) = delete;
67
72 UnaryLoadInstrImm(UnaryLoadInstrImm &&r_src) = delete;
73
78 UnaryLoadInstrImm &operator=(UnaryLoadInstrImm &&r_src) = delete;
79};
80
81} // namespace libmicroemu::internal
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
#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