aboutsummaryrefslogtreecommitdiff
path: root/arch/x86_64/kapi
diff options
context:
space:
mode:
authorFelix Morgner <felix.morgner@ost.ch>2026-03-25 16:39:13 +0100
committerFelix Morgner <felix.morgner@ost.ch>2026-03-27 07:02:35 +0100
commita82416648d148152338dc612c25bf8dff428e773 (patch)
treeb4953e734ce8d28babd4c3905fcd988b09d52d1b /arch/x86_64/kapi
parentfd1c5a50bb35f772b8e37125188640447d4b3b2a (diff)
downloadteachos-a82416648d148152338dc612c25bf8dff428e773.tar.xz
teachos-a82416648d148152338dc612c25bf8dff428e773.zip
kapi: introduce cpu::interrupt_handler
Diffstat (limited to 'arch/x86_64/kapi')
-rw-r--r--arch/x86_64/kapi/cpu.cpp49
1 files changed, 49 insertions, 0 deletions
diff --git a/arch/x86_64/kapi/cpu.cpp b/arch/x86_64/kapi/cpu.cpp
index 8ca3847..b19ba21 100644
--- a/arch/x86_64/kapi/cpu.cpp
+++ b/arch/x86_64/kapi/cpu.cpp
@@ -4,11 +4,22 @@
#include "arch/cpu/initialization.hpp"
+#include <kstd/print>
+#include <kstd/vector>
+
+#include <array>
#include <atomic>
+#include <cstdint>
namespace kapi::cpu
{
+ namespace
+ {
+ constexpr auto irq_offset = 32uz;
+ auto constinit interrupt_handlers = std::array<kstd::vector<interrupt_handler *>, 256 - irq_offset>{};
+ } // namespace
+
auto init() -> void
{
auto static constinit is_initialized = std::atomic_flag{};
@@ -38,4 +49,42 @@ namespace kapi::cpu
asm volatile("cli");
}
+ auto register_interrupt_handler(std::uint32_t irq_number, interrupt_handler & handler) -> void
+ {
+ if (irq_number < irq_offset)
+ {
+ system::panic("[x86_64:CPU] IRQ number must be in range [32, 255].");
+ }
+
+ interrupt_handlers[irq_number - irq_offset].push_back(&handler);
+ }
+
+ auto unregister_interrupt_handler(std::uint32_t irq_number, [[maybe_unused]] interrupt_handler & handler) -> void
+ {
+ if (irq_number < irq_offset)
+ {
+ system::panic("[x86_64:CPU] IRQ number must be in range [32, 255].");
+ }
+
+ kstd::println("[x86_64:CPU] TODO: support erasure from vector.");
+ }
+
+ auto dispatch_interrupt(std::uint32_t irq_number) -> status
+ {
+ if (irq_number < irq_offset)
+ {
+ return status::unhandled;
+ }
+
+ for (auto handler : interrupt_handlers[irq_number - irq_offset])
+ {
+ if (handler && handler->handle_interrupt(irq_number) == status::handled)
+ {
+ return status::handled;
+ }
+ }
+
+ return status::unhandled;
+ }
+
} // namespace kapi::cpu