libmicroemu 0.2.0
ARM Microcontroller Emulator Library
Loading...
Searching...
No Matches
binary_null_instr_with_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 Cmp1ImmOp {
19public:
20 template <typename TArg0>
21 static Result<InstrExecFlagsSet> Call(TInstrContext &ictx, const InstrFlagsSet &iflags,
22 const TArg0 &rn, const u32 &imm) {
23 const auto n = ictx.cpua.ReadRegister(rn.Get());
24
25 const u32 n_imm32 = ~imm;
26 const auto result = Alu32::AddWithCarry(n, n_imm32, true);
27
28 const auto op_res = OpResult{result.value, result.carry_out, result.overflow};
29 PostExecSetFlags::Call(ictx, op_res);
30 PostExecAdvancePcAndIt::Call(ictx, iflags);
31 return Ok(kNoInstrExecFlags);
32 }
33};
34
40template <typename TInstrContext> class Cmn1ImmOp {
41public:
42 template <typename TArg0>
43 static Result<InstrExecFlagsSet> Call(TInstrContext &ictx, const InstrFlagsSet &iflags,
44 const TArg0 &rn, const u32 &imm) {
45 const auto n = ictx.cpua.ReadRegister(rn.Get());
46 const auto result = Alu32::AddWithCarry(n, imm, false);
47
48 const auto op_res = OpResult{result.value, result.carry_out, result.overflow};
49 PostExecSetFlags::Call(ictx, op_res);
50 PostExecAdvancePcAndIt::Call(ictx, iflags);
51 return Ok(kNoInstrExecFlags);
52 }
53};
54
55template <typename TOp, typename TInstrContext> class BinaryNullInstrWithImm {
56public:
57 using It = typename TInstrContext::It;
58 using Pc = typename TInstrContext::Pc;
59
60 template <typename TArg0>
61 static Result<InstrExecResult> Call(TInstrContext &ictx, const InstrFlagsSet &iflags,
62 const TArg0 &rn, const u32 &imm) {
63 TRY_ASSIGN(condition_passed, InstrExecResult, It::ConditionPassed(ictx.cpua));
64 if (!condition_passed) {
65 PostExecAdvancePcAndIt::Call(ictx, iflags);
66 return Ok(InstrExecResult{kNoInstrExecFlags});
67 }
68
69 TRY_ASSIGN(eflags, InstrExecResult, TOp::Call(ictx, iflags, rn, imm));
70 return Ok(InstrExecResult{eflags});
71 }
72
73private:
77 BinaryNullInstrWithImm() = delete;
78
82 ~BinaryNullInstrWithImm() = delete;
83
88 BinaryNullInstrWithImm(const BinaryNullInstrWithImm &r_src) = delete;
89
94 BinaryNullInstrWithImm &operator=(const BinaryNullInstrWithImm &r_src) = delete;
95
100 BinaryNullInstrWithImm(BinaryNullInstrWithImm &&r_src) = delete;
101
106 BinaryNullInstrWithImm &operator=(BinaryNullInstrWithImm &&r_src) = delete;
107};
108
109} // namespace libmicroemu::internal
Cmn.
Definition binary_null_instr_with_imm.h:40
Cmp.
Definition binary_null_instr_with_imm.h:18
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