aboutsummaryrefslogtreecommitdiff
path: root/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 /kapi
parentfd1c5a50bb35f772b8e37125188640447d4b3b2a (diff)
downloadteachos-a82416648d148152338dc612c25bf8dff428e773.tar.xz
teachos-a82416648d148152338dc612c25bf8dff428e773.zip
kapi: introduce cpu::interrupt_handler
Diffstat (limited to 'kapi')
-rw-r--r--kapi/include/kapi/cpu/interrupts.hpp44
1 files changed, 44 insertions, 0 deletions
diff --git a/kapi/include/kapi/cpu/interrupts.hpp b/kapi/include/kapi/cpu/interrupts.hpp
index 26a215e..328e4a7 100644
--- a/kapi/include/kapi/cpu/interrupts.hpp
+++ b/kapi/include/kapi/cpu/interrupts.hpp
@@ -3,9 +3,32 @@
// IWYU pragma: private, include "kapi/cpu.hpp"
+#include <cstdint>
+
namespace kapi::cpu
{
+ enum class status : bool
+ {
+ unhandled,
+ handled,
+ };
+
+ //! The interface for all interrupt handlers.
+ struct interrupt_handler
+ {
+ virtual ~interrupt_handler() = default;
+
+ //! Handle an interrupt with the given IRQ number.
+ //
+ //! This function will be called by the kernel in an interrupt context. As such, the function should complete its
+ //! task quickly and must take care when acquiring globally shared locks.
+ //!
+ //! @param irq_number The identifier of the interrupt request that triggered the handler.
+ //! @return status::handled if the handler successfully handled the interrupt, status::unhandled otherwise.
+ virtual auto handle_interrupt(std::uint32_t irq_number) -> status = 0;
+ };
+
//! @qualifier platform-defined
//! Enable external interrupts.
auto enable_interrupts() -> void;
@@ -14,6 +37,27 @@ namespace kapi::cpu
//! Disable external interrupts.
auto disable_interrupts() -> void;
+ //! @qualifier platform-defined
+ //! Register an interrupt handler for the given IRQ number.
+ //!
+ //! @param irq_number The IRQ number to register the handler for.
+ //! @param handler The interrupt handler to register.
+ auto register_interrupt_handler(std::uint32_t irq_number, interrupt_handler & handler) -> void;
+
+ //! @qualifier platform-defined
+ //! Unregister a previously registered interrupt handler.
+ //!
+ //! @param irq_number The IRQ number to unregister the handler for.
+ //! @param handler The interrupt handler to unregister.
+ auto unregister_interrupt_handler(std::uint32_t irq_number, interrupt_handler & handler) -> void;
+
+ //! @qualifier platform-defined
+ //! Dispatch an interrupt to all registered handlers.
+ //!
+ //! @param irq_number The IRQ number to dispatch.
+ //! @return status::handled if the interrupt was handled by at least one handler, status::unhandled otherwise.
+ auto dispatch_interrupt(std::uint32_t irq_number) -> status;
+
} // namespace kapi::cpu
#endif \ No newline at end of file