diff options
Diffstat (limited to 'arch')
| -rw-r--r-- | arch/x86_64/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | arch/x86_64/kapi/cpu.cpp | 59 | ||||
| -rw-r--r-- | arch/x86_64/kapi/cpu/interrupts.cpp | 67 |
3 files changed, 68 insertions, 59 deletions
diff --git a/arch/x86_64/CMakeLists.txt b/arch/x86_64/CMakeLists.txt index 89d9bc0..8ff81d8 100644 --- a/arch/x86_64/CMakeLists.txt +++ b/arch/x86_64/CMakeLists.txt @@ -15,6 +15,7 @@ target_sources("x86_64" PRIVATE "kapi/boot_modules.cpp" "kapi/cio.cpp" "kapi/cpu.cpp" + "kapi/cpu/interrupts.cpp" "kapi/memory.cpp" "kapi/system.cpp" diff --git a/arch/x86_64/kapi/cpu.cpp b/arch/x86_64/kapi/cpu.cpp index b19ba21..12edb0f 100644 --- a/arch/x86_64/kapi/cpu.cpp +++ b/arch/x86_64/kapi/cpu.cpp @@ -4,22 +4,11 @@ #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{}; @@ -39,52 +28,4 @@ namespace kapi::cpu __builtin_unreachable(); } - auto enable_interrupts() -> void - { - asm volatile("sti"); - } - - auto disable_interrupts() -> void - { - 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 diff --git a/arch/x86_64/kapi/cpu/interrupts.cpp b/arch/x86_64/kapi/cpu/interrupts.cpp new file mode 100644 index 0000000..b98595c --- /dev/null +++ b/arch/x86_64/kapi/cpu/interrupts.cpp @@ -0,0 +1,67 @@ +#include "kapi/cpu.hpp" +#include "kapi/system.hpp" + +#include <kstd/print> +#include <kstd/vector> + +#include <array> +#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 enable_interrupts() -> void + { + asm volatile("sti"); + } + + auto disable_interrupts() -> void + { + 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
\ No newline at end of file |
