libmicroemu 0.2.0
ARM Microcontroller Emulator Library
Loading...
Searching...
No Matches
binary_store_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"
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 TStoreOp, typename TInstrContext> class BinaryStoreInstrWithImm {
16public:
17 using It = typename TInstrContext::It;
18 using Pc = typename TInstrContext::Pc;
19
20 template <typename TTgt, typename TArg0>
21 static Result<InstrExecResult> Call(TInstrContext &ictx, const InstrFlagsSet &iflags,
22 const TTgt &rt, const TArg0 &rn, const u32 &imm32) {
23 const bool is_index = (iflags & static_cast<InstrFlagsSet>(InstrFlags::kIndex)) != 0U;
24 const bool is_add = (iflags & static_cast<InstrFlagsSet>(InstrFlags::kAdd)) != 0U;
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
32 const auto n = ictx.cpua.ReadRegister(rn.Get());
33 const me_adr_t offset_addr = is_add == true ? n + imm32 : n - imm32;
34 const me_adr_t address = is_index == true ? offset_addr : n;
35
36 const auto t = ictx.cpua.ReadRegister(rt.Get());
37 TRY(InstrExecResult, TStoreOp::Write(ictx, address, t));
38
39 const bool is_wback = (iflags & static_cast<InstrFlagsSet>(InstrFlags::kWBack)) != 0U;
40 if (is_wback) {
41 PostExecWriteRegPcExcluded::Call(ictx, rn, offset_addr);
42 }
43 PostExecAdvancePcAndIt::Call(ictx, iflags);
44 return Ok(InstrExecResult{kNoInstrExecFlags});
45 }
46
47private:
51 BinaryStoreInstrWithImm() = delete;
52
56 ~BinaryStoreInstrWithImm() = delete;
57
62 BinaryStoreInstrWithImm(const BinaryStoreInstrWithImm &r_src) = delete;
63
68 BinaryStoreInstrWithImm &operator=(const BinaryStoreInstrWithImm &r_src) = delete;
69
74 BinaryStoreInstrWithImm(BinaryStoreInstrWithImm &&r_src) = delete;
75
80 BinaryStoreInstrWithImm &operator=(BinaryStoreInstrWithImm &&r_src) = delete;
81};
82
83} // 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