IgrOS-Kernel 0.1.34.545
Simple C++20 Kernel for i386/x86_64
Loading...
Searching...
No Matches
isr.cpp
Go to the documentation of this file.
1
11
12
13// IgrOS-Kernel library
14#include <arch/x86/io.hpp>
15#include <arch/x86/irq.hpp>
16#include <arch/x86/isr.hpp>
17#include <arch/x86/native.hpp>
18// IgrOS-Kernel library
19#include <klib/kPrint.hpp>
20
21
22// x86 namespace
23namespace igros::x86 {
24
25
27 constinit static auto isrList {std::array<isr_t, ISR_SIZE> {}};
28
29
30 // Install interrupt service routine handler
31 void isrHandlerInstall(const igros_usize_t number, const isr_t handle) noexcept {
32 // Put interrupt service routine handler in ISRs list
33 isrList[number] = handle;
34 }
35
36 // Uninstall interrupt service routine handler
37 void isrHandlerUninstall(const igros_usize_t number) noexcept {
38 // Remove interrupt service routine handler from ISRs list
39 isrList[number] = nullptr;
40 }
41
42
43} // namespace igros::x86
44
45
46#ifdef __cplusplus
47
48extern "C" {
49
50#endif // __cplusplus
51
52
53 // Interrupts handler function
54 void isrHandler(const igros::x86::register_t* regs) noexcept {
55 // Interrupt vector
56 const auto vector {static_cast<igros::igros_usize_t>(regs->number)};
57 // Is it hardware interrupt
58 const auto isIrq {igros::x86::isIrqVector(vector)};
59 // Spurious IRQ has no handler and must not be acknowledged on PIC which raised it
60 if (isIrq && igros::x86::irq::isSpurious(igros::x86::irqFromVector(vector))) [[unlikely]] {
61 // Master PIC still needs EOI for cascaded slave spurious IRQ
64 }
65 return;
66 }
67 // Check if irq/exception handler installed
68 if (const auto isr {igros::x86::isrList[vector]}; nullptr != isr) {
69 // Handle ISR
70 isr(regs);
71 // Acknowledge hardware interrupt
72 if (isIrq) {
74 }
75 } else {
76 // Disable interrupts
78 // Debug
79 igros::klib::kprintf(R"unhandled(
80%s -> [#%d]
81 UNHANDLED! CPU halted!
82)unhandled",
83 (isIrq ? "IRQ" : "EXCEPTION"),
84 static_cast<igros::igros_dword_t>(isIrq ? (vector - igros::x86::IRQ_OFFSET) : vector)
85 );
86 // Dump registres
87 igros::x86::cpu::dumpRegisters(regs);
88 // Hang CPU
89 igros::x86::cpu::halt();
90 }
91 }
92
93
94#ifdef __cplusplus
95
96} // extern "C"
97
98#endif // __cplusplus
99
static void disable() noexcept
Disable interrupts.
Definition irq.cpp:70
static void eoi(const irq_t number) noexcept
Send EOI (IRQ done).
Definition irq.cpp:117
static auto isSpurious(const irq_t number) noexcept -> bool
Check if IRQ is spurious (only lines 7 and 15 can be).
Definition irq.cpp:130
std::size_t igros_usize_t
Unsigned size.
Definition types.hpp:51
std::uint32_t igros_dword_t
32-bit unsigned integer
Definition types.hpp:43
void isrHandler(const igros::x86::register_t *regs) noexcept
Interrupts handler function (called from isr.s).
Definition isr.cpp:54
Interrupts low-level operations.
Kernel text print functions.
void kprintf(const char *const format,...) noexcept
Kernel printf function (arguments are checked against format at compile time).
Definition kPrint.cpp:358
Code shared by i386 and x86_64: ports, interrupts, exceptions, paging.
static constinit auto isrList
Interrupt handlers.
Definition isr.cpp:27
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
constexpr auto irqFromVector(const igros_usize_t vector) noexcept -> irq_t
IRQ line of interrupt vector (vector must be IRQ vector).
Definition irq.hpp:105
constexpr auto isIrqVector(const igros_usize_t vector) noexcept -> bool
Check if interrupt vector belongs to IRQ line.
Definition irq.hpp:97
std::add_pointer_t< void(const register_t *const)> isr_t
Interrupt service routine handler type.
Definition isr.hpp:35
@ ATA_SECONDARY
Slave PIC spurious.
Definition irq.hpp:78
@ CASCADE
Slave PIC.
Definition irq.hpp:65
constexpr auto IRQ_OFFSET
IRQ offset in ISR list.
Definition isr.hpp:30
x86 family current (native) architecture selection
IO low-level port operations.
Interrupts low-level operations.