IgrOS-Kernel 0.1.34.545
Simple C++20 Kernel for i386/x86_64
Loading...
Searching...
No Matches
exceptions.hpp
Go to the documentation of this file.
1
11
12
13#pragma once
14
15
16// C++
17#include <array>
18// IgrOS-Kernel arch
19#include <arch/types.hpp>
20// IgrOS-Kernel arch x86
21#include <arch/x86/isr.hpp>
22
23
24#ifdef __cplusplus
25
26extern "C" {
27
28#endif // __cplusplus
29
30
32 extern const std::add_pointer_t<void() noexcept> exHandlerTable[32];
33
34
35#ifdef __cplusplus
36
37} // extern "C"
38
39#endif // __cplusplus
40
41
42// x86 namespace
43namespace igros::x86 {
44
45
47 class except final {
48
49 public:
50
52 except(const except &other) = delete;
54 auto operator=(const except &other) -> except & = delete;
56 except(except &&other) = delete;
58 auto operator=(except &&other) -> except & = delete;
59
60
62 constexpr static std::array<const char* const, 32_usize> NAME {
63 "DIVIDE BY ZERO", // 0
64 "DEBUG", // 1
65 "NON-MASKABLE INTERRUPT", // 2
66 "BREAKPOINT", // 3
67 "INTO DETECTED OVERFLOW", // 4
68 "BOUND RANGE EXCEEDED", // 5
69 "INVALID OPCODE", // 6
70 "NO COPROCESSOR", // 7
71 "DOUBLE FAULT", // 8
72 "COPROCESSOR SEGMENT OVERRUN", // 9
73 "INVALID TSS", // 10
74 "SEGMENT NOT PPRESENT", // 11
75 "STACK FAULT", // 12
76 "GENERAL PROTECTION FAULT", // 13
77 "PAGE FAULT", // 14
78 "UNKNOWN INTERRUPT", // 15
79 "COPROCESSOR FAULT", // 16
80 "ALIGNMENT CHECK", // 17
81 "MACHINE CHECK", // 18
82 "RESERVED", // 19
83 "RESERVED", // 20
84 "RESERVED", // 21
85 "RESERVED", // 22
86 "RESERVED", // 23
87 "RESERVED", // 24
88 "RESERVED", // 25
89 "RESERVED", // 26
90 "RESERVED", // 27
91 "RESERVED", // 28
92 "RESERVED", // 29
93 "RESERVED", // 30
94 "RESERVED", // 31
95 };
96
98 enum class NUMBER : igros_dword_t {
99 DIVIDE_BY_ZERO = 0_u32,
100 DEBUG = 1_u32,
101 NON_MASKABLE_IRQ = 2_u32,
102 BREAKPOINT = 3_u32,
103 INTO_DETECTED_OVERFLOW = 4_u32,
104 BOUND_RANGE_EXCEEDED = 5_u32,
105 INVALID_OPCODE = 6_u32,
106 NO_COPROCESSOR = 7_u32,
107 DOUBLE_FAULT = 8_u32,
108 COPROCESSOR_SEGMENT_OVERRUN = 9_u32,
109 INVALID_TSS = 10_u32,
110 SEGMENT_NOT_PRESENT = 11_u32,
111 STACK_FAULT = 12_u32,
112 GENERAL_PROTECTION_FAULT = 13_u32,
113 PAGE_FAULT = 14_u32,
114 UNKNOWN_IRQ = 15_u32,
115 COPROCESSOR_FAULT = 16_u32,
116 ALIGNMENT_CHECK = 17_u32,
117 MACHINE_CHECK = 18_u32,
118 };
119
120
122 except() noexcept = default;
124 ~except() noexcept = default;
125
127 static void init() noexcept;
128
130 template<NUMBER N, isr_t HANDLE>
131 constexpr static void install() noexcept;
133 template<NUMBER N>
134 constexpr static void uninstall() noexcept;
135
138 [[noreturn]]
139 static void defaultHandler(const register_t* regs) noexcept;
140 };
141
142
144 template<except::NUMBER N, isr_t HANDLE>
145 constexpr void except::install() noexcept {
146 // Install ISR
147 isrHandlerInstall(static_cast<igros_dword_t>(N), HANDLE);
148 }
149
151 template<except::NUMBER N>
152 constexpr void except::uninstall() noexcept {
153 // Uninstall ISR
154 isrHandlerUninstall(static_cast<igros_dword_t>(N));
155 }
156
157
158} // namespace igros::x86
159
auto operator=(const except &other) -> except &=delete
Copy assignment.
static void defaultHandler(const register_t *regs) noexcept
Default exception handler.
auto operator=(except &&other) -> except &=delete
Move assignment.
except() noexcept=default
Default c-tor.
static constexpr void install() noexcept
Install exceptions handler.
static constexpr void uninstall() noexcept
Uninstall exceptions handler.
NUMBER
Exceptions number enumeration.
static constexpr std::array< const char *const, 32_usize > NAME
Exceptions names.
static void init() noexcept
Init exceptions.
except(except &&other)=delete
Move c-tor.
except(const except &other)=delete
Copy c-tor.
const std::add_pointer_t< void() noexcept > exHandlerTable[32]
Exception handlers addresses, indexed by exception number (exceptions.s).
std::uint32_t igros_dword_t
32-bit unsigned integer
Definition types.hpp:43
Interrupts low-level operations.
Code shared by i386 and x86_64: ports, interrupts, exceptions, paging.
void isrHandlerInstall(const igros_usize_t number, const isr_t handle) noexcept
Install interrupt service routine handler.
Definition isr.cpp:31
void isrHandlerUninstall(const igros_usize_t number) noexcept
Uninstall interrupt service routine handler.
Definition isr.cpp:37
std::add_pointer_t< void(const register_t *const)> isr_t
Interrupt service routine handler type.
Definition isr.hpp:35
Common C++ types redefinition.