libmicroemu 0.2.0
ARM Microcontroller Emulator Library
Loading...
Searching...
No Matches
fetcher.h
1#pragma once
2
3#include "libmicroemu/internal/fetcher/raw_instr.h"
4#include "libmicroemu/internal/fetcher/raw_instr_flags_table.h"
6#include "libmicroemu/internal/utils/bit_manip.h"
7#include "libmicroemu/types.h"
8#include <cstddef>
9#include <cstdint>
10
11namespace libmicroemu::internal {
12
13template <typename TCpuAccessor, typename TBus> class Fetcher {
14public:
15 static Result<RawInstr> Fetch(TCpuAccessor &cpua, TBus &bus, const me_adr_t pc) {
16
17 // make first 16 bit access to fetch instruction
19 instr_l, RawInstr,
20 bus.template ReadOrRaise<u16>(cpua, pc, BusExceptionType::kRaiseInstructionBusError));
21
23
24 // Check if a 32-bit instruction was loaded
25 u16 instr_h{0x0U};
26 const auto flags = kRawInstrFlagsTable[opc];
27
28 if ((flags & static_cast<RawInstrFlagsSet>(RawInstrFlagsMsk::k32Bit)) != 0U) {
29 // make the second access
30 TRY_ASSIGN(instr_h_im, RawInstr,
31 bus.template ReadOrRaise<u16>(cpua, pc + 2U,
32 BusExceptionType::kRaiseInstructionBusError));
33 instr_h = instr_h_im;
34 }
35
36 return Ok(RawInstr{instr_l, instr_h, flags});
37 }
38
39private:
43 Fetcher() = delete;
44
48 ~Fetcher() = delete;
49
54 Fetcher &operator=(const Fetcher &r_src) = delete;
55
60 Fetcher(Fetcher &&r_src) = delete;
61
66 Fetcher &operator=(Fetcher &&r_src) = delete;
67};
68
69} // namespace libmicroemu::internal
static constexpr u32 ExtractBits1R(const u32 &value)
Definition bit_manip.h:136
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 raw_instr.h:7
Definition result.h:15