libmicroemu 0.2.0
ARM Microcontroller Emulator Library
Loading...
Searching...
No Matches
emu_context.h
1#pragma once
2
3#include "libmicroemu/register_id.h"
5#include "libmicroemu/types.h"
6#include <cstddef>
7#include <string_view>
8
9namespace libmicroemu {
10
11struct OpCode {
12 u16 low;
13 u16 high;
14 bool is_32bit;
15};
16
18public:
19 virtual void Build(char *buf, std::size_t buf_len) const = 0;
20};
21
26public:
32 virtual std::string_view GetRegisterName(const RegisterId &reg_id) const = 0;
33
39 virtual u32 ReadRegister(const RegisterId &reg_id) const = 0;
40
46 virtual void WriteRegister(const RegisterId &reg_id, u32 value) = 0;
47};
48
53public:
60 virtual std::string_view GetRegisterName(const SpecialRegisterId &reg_id) const = 0;
61
68 virtual u32 ReadRegister(const SpecialRegisterId &reg_id) const = 0;
69
76 virtual void WriteRegister(const SpecialRegisterId &reg_id, u32 value) = 0;
77};
78
79class EmuContext {
80public:
81 EmuContext(const me_adr_t &pc, const OpCode &op_code, const IInstrToMnemonic &instr_decoder,
82 IRegAccessor &reg_access, ISpecialRegAccessor &spec_reg_access) noexcept
83
84 : pc_(pc), op_code_(op_code), instr_decoder_(instr_decoder), reg_access_(reg_access),
85 spec_reg_access_(spec_reg_access) {}
86
90 inline me_adr_t GetPc() const noexcept { return pc_; }
91
95 inline IRegAccessor &GetRegisterAccessor() noexcept { return reg_access_; }
96
100 inline ISpecialRegAccessor &GetSpecialRegisterAccessor() noexcept { return spec_reg_access_; }
101
105 inline const OpCode &GetOpCode() const noexcept { return op_code_; }
106
114 inline void BuildMnemonic(char *buf, std::size_t buf_len) const noexcept {
115 instr_decoder_.Build(buf, buf_len);
116 }
117
118private:
119 const me_adr_t &pc_;
120 const OpCode &op_code_;
121 const IInstrToMnemonic &instr_decoder_;
122
123 IRegAccessor &reg_access_;
124 ISpecialRegAccessor &spec_reg_access_;
125};
126
127} // namespace libmicroemu
void BuildMnemonic(char *buf, std::size_t buf_len) const noexcept
Builds the mnemonic of the current instruction This takes the current instruction and decodes it into...
Definition emu_context.h:114
IRegAccessor & GetRegisterAccessor() noexcept
Gets the register accessor.
Definition emu_context.h:95
ISpecialRegAccessor & GetSpecialRegisterAccessor() noexcept
Gets the special register accessor.
Definition emu_context.h:100
const OpCode & GetOpCode() const noexcept
Gets the opcode of the current instruction.
Definition emu_context.h:105
me_adr_t GetPc() const noexcept
Gets the program counter of the current instruction.
Definition emu_context.h:90
Definition emu_context.h:17
Interface for accessing general-purpose registers.
Definition emu_context.h:25
virtual u32 ReadRegister(const RegisterId &reg_id) const =0
Reads the value of the specified register.
virtual std::string_view GetRegisterName(const RegisterId &reg_id) const =0
Gets the name of the specified register.
virtual void WriteRegister(const RegisterId &reg_id, u32 value)=0
Writes the value to the specified register.
Interface for accessing special registers.
Definition emu_context.h:52
virtual u32 ReadRegister(const SpecialRegisterId &reg_id) const =0
Reads the value of the specified special register.
virtual void WriteRegister(const SpecialRegisterId &reg_id, u32 value)=0
Writes the value to the specified special register.
virtual std::string_view GetRegisterName(const SpecialRegisterId &reg_id) const =0
Gets the name of the specified special register.
The libmicroemu namespace contains all classes and functions of the libmicroemu which are public.
Definition bkpt_flags.h:6
SpecialRegisterId
Enumeration of special register IDs.
Definition special_register_id.h:18
RegisterId
Enumeration of register IDs.
Definition register_id.h:13
This file contains the declaration of the SpecialRegisterId enumeration and related functions.
Definition emu_context.h:11