libmicroemu 0.2.0
ARM Microcontroller Emulator Library
Loading...
Searching...
No Matches
exception_states.h
1#pragma once
2
3#include "libmicroemu/exception_type.h"
4#include "libmicroemu/types.h"
5#include <array>
6
7namespace libmicroemu {
8
9using ExceptionFlagsSet = u8;
10
11enum class ExceptionFlags : ExceptionFlagsSet {
12 kPending = 1U << 0U,
13 kActive = 1U << 1U,
14};
15
16static constexpr i16 kLowestExceptionPriority = 255U;
17
20struct SingleExceptionState {
21 explicit constexpr SingleExceptionState(u8 number) : number_{number}, priority_{0}, flags_{0U} {}
22
25 inline void ClearFlags() noexcept { flags_ = 0U; }
26
31 inline bool IsPending() const noexcept {
32 return (flags_ & static_cast<ExceptionFlagsSet>(ExceptionFlags::kPending)) != 0U;
33 }
34
37 inline void ClearPending() noexcept {
38 flags_ &= ~static_cast<ExceptionFlagsSet>(ExceptionFlags::kPending);
39 }
40
43 inline void SetPending() noexcept {
44 flags_ |= static_cast<ExceptionFlagsSet>(ExceptionFlags::kPending);
45 }
46
51 inline bool IsActive() const noexcept {
52 return (flags_ & static_cast<ExceptionFlagsSet>(ExceptionFlags::kActive)) != 0U;
53 }
54
57 inline void ClearActive() noexcept {
58 flags_ &= ~static_cast<ExceptionFlagsSet>(ExceptionFlags::kActive);
59 }
60
63 inline void SetActive() noexcept {
64 flags_ |= static_cast<ExceptionFlagsSet>(ExceptionFlags::kActive);
65 }
66
71 inline i16 GetPriority() const noexcept { return priority_; }
72
77 inline void SetPriority(i16 priority) noexcept { priority_ = priority; }
78
83 inline u8 GetNumber() const noexcept { return number_; }
84
85private:
86 const u8 number_;
87 i16 priority_;
88 ExceptionFlagsSet flags_;
89};
90
91template <std::size_t... Indices>
92constexpr auto MakeExceptionArray(std::index_sequence<Indices...>) {
93 return std::array<SingleExceptionState, sizeof...(Indices)>{
94 SingleExceptionState(static_cast<u8>(Indices))...};
95}
96
97struct ExceptionStates {
98 ExceptionStates()
99 : exception{MakeExceptionArray(std::make_index_sequence<CountExceptions()>())} {}
100
101 u32 pending_exceptions{0U};
102 std::array<SingleExceptionState, CountExceptions()> exception;
103};
104
105} // namespace libmicroemu
The libmicroemu namespace contains all classes and functions of the libmicroemu which are public.
Definition bkpt_flags.h:6
Represents the state of a single exception.
Definition exception_states.h:20
i16 GetPriority() const noexcept
Gets the priority of the exception.
Definition exception_states.h:71
u8 GetNumber() const noexcept
Gets the number of the exception.
Definition exception_states.h:83
void SetActive() noexcept
Sets the active flag of the exception.
Definition exception_states.h:63
void SetPriority(i16 priority) noexcept
Sets the priority of the exception.
Definition exception_states.h:77
void ClearFlags() noexcept
Clears all flags of the exception.
Definition exception_states.h:25
bool IsActive() const noexcept
Checks if the exception is active.
Definition exception_states.h:51
void ClearPending() noexcept
Clears the pending flag of the exception.
Definition exception_states.h:37
void SetPending() noexcept
Sets the pending flag of the exception.
Definition exception_states.h:43
bool IsPending() const noexcept
Checks if the exception is pending.
Definition exception_states.h:31
void ClearActive() noexcept
Clears the active flag of the exception.
Definition exception_states.h:57