diff options
| -rw-r--r-- | arch/x86_64/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | arch/x86_64/kapi/interrupts.cpp (renamed from arch/x86_64/kapi/cpu/interrupts.cpp) | 23 | ||||
| -rw-r--r-- | arch/x86_64/src/cpu/interrupts.cpp | 3 | ||||
| -rw-r--r-- | kapi/CMakeLists.txt | 3 | ||||
| -rw-r--r-- | kapi/include/kapi/cpu.hpp | 1 | ||||
| -rw-r--r-- | kapi/include/kapi/interrupts.hpp (renamed from kapi/include/kapi/cpu/interrupts.hpp) | 24 | ||||
| -rw-r--r-- | kernel/src/main.cpp | 3 |
7 files changed, 29 insertions, 30 deletions
diff --git a/arch/x86_64/CMakeLists.txt b/arch/x86_64/CMakeLists.txt index 8ff81d8..4427e4c 100644 --- a/arch/x86_64/CMakeLists.txt +++ b/arch/x86_64/CMakeLists.txt @@ -15,7 +15,7 @@ target_sources("x86_64" PRIVATE "kapi/boot_modules.cpp" "kapi/cio.cpp" "kapi/cpu.cpp" - "kapi/cpu/interrupts.cpp" + "kapi/interrupts.cpp" "kapi/memory.cpp" "kapi/system.cpp" diff --git a/arch/x86_64/kapi/cpu/interrupts.cpp b/arch/x86_64/kapi/interrupts.cpp index b98595c..babc926 100644 --- a/arch/x86_64/kapi/cpu/interrupts.cpp +++ b/arch/x86_64/kapi/interrupts.cpp @@ -1,4 +1,5 @@ -#include "kapi/cpu.hpp" +#include "kapi/interrupts.hpp" + #include "kapi/system.hpp" #include <kstd/print> @@ -7,36 +8,36 @@ #include <array> #include <cstdint> -namespace kapi::cpu +namespace kapi::interrupts { namespace { constexpr auto irq_offset = 32uz; - auto constinit interrupt_handlers = std::array<kstd::vector<interrupt_handler *>, 256 - irq_offset>{}; + auto constinit handlers = std::array<kstd::vector<handler *>, 256 - irq_offset>{}; } // namespace - auto enable_interrupts() -> void + auto enable() -> void { asm volatile("sti"); } - auto disable_interrupts() -> void + auto disable() -> void { asm volatile("cli"); } - auto register_interrupt_handler(std::uint32_t irq_number, interrupt_handler & handler) -> void + auto register_handler(std::uint32_t irq_number, 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); + handlers[irq_number - irq_offset].push_back(&handler); } - auto unregister_interrupt_handler(std::uint32_t irq_number, [[maybe_unused]] interrupt_handler & handler) -> void + auto unregister_handler(std::uint32_t irq_number, [[maybe_unused]] handler & handler) -> void { if (irq_number < irq_offset) { @@ -46,14 +47,14 @@ namespace kapi::cpu kstd::println("[x86_64:CPU] TODO: support erasure from vector."); } - auto dispatch_interrupt(std::uint32_t irq_number) -> status + auto dispatch(std::uint32_t irq_number) -> status { if (irq_number < irq_offset) { return status::unhandled; } - for (auto handler : interrupt_handlers[irq_number - irq_offset]) + for (auto handler : handlers[irq_number - irq_offset]) { if (handler && handler->handle_interrupt(irq_number) == status::handled) { @@ -64,4 +65,4 @@ namespace kapi::cpu return status::unhandled; } -} // namespace kapi::cpu
\ No newline at end of file +} // namespace kapi::interrupts
\ No newline at end of file diff --git a/arch/x86_64/src/cpu/interrupts.cpp b/arch/x86_64/src/cpu/interrupts.cpp index 9ee3ce8..2f23f07 100644 --- a/arch/x86_64/src/cpu/interrupts.cpp +++ b/arch/x86_64/src/cpu/interrupts.cpp @@ -1,6 +1,7 @@ #include "arch/cpu/interrupts.hpp" #include "kapi/cpu.hpp" +#include "kapi/interrupts.hpp" #include "kapi/memory.hpp" #include "arch/cpu/legacy_pic.hpp" @@ -146,7 +147,7 @@ namespace arch::cpu } } else if (number >= number_of_exception_vectors && - kapi::cpu::dispatch_interrupt(number) == kapi::cpu::status::unhandled) + kapi::interrupts::dispatch(number) == kapi::interrupts::status::unhandled) { kstd::println(kstd::print_sink::stderr, "[x86_64:CPU] Unhandled interrupt {:#04x}", number); } diff --git a/kapi/CMakeLists.txt b/kapi/CMakeLists.txt index 4c94829..99b737c 100644 --- a/kapi/CMakeLists.txt +++ b/kapi/CMakeLists.txt @@ -9,8 +9,7 @@ target_sources("kapi" PUBLIC "include/kapi/boot.hpp" "include/kapi/cio.hpp" "include/kapi/cpu.hpp" - "include/kapi/cpu/interrupts.hpp" - "include/kapi/cpu/exception.hpp" + "include/kapi/interrupts.hpp" "include/kapi/boot_module/boot_module.hpp" "include/kapi/boot_module/boot_module_registry.hpp" "include/kapi/memory.hpp" diff --git a/kapi/include/kapi/cpu.hpp b/kapi/include/kapi/cpu.hpp index 041a5db..c6aa6ff 100644 --- a/kapi/include/kapi/cpu.hpp +++ b/kapi/include/kapi/cpu.hpp @@ -1,7 +1,6 @@ #ifndef TEACHOS_KAPI_CPU_HPP #define TEACHOS_KAPI_CPU_HPP -#include "kapi/cpu/interrupts.hpp" // IWYU pragma: export #include "kapi/memory.hpp" #include <kstd/format> diff --git a/kapi/include/kapi/cpu/interrupts.hpp b/kapi/include/kapi/interrupts.hpp index 328e4a7..fa4bc95 100644 --- a/kapi/include/kapi/cpu/interrupts.hpp +++ b/kapi/include/kapi/interrupts.hpp @@ -1,11 +1,9 @@ -#ifndef TEACHOS_KAPI_CPU_INTERRUPTS_HPP -#define TEACHOS_KAPI_CPU_INTERRUPTS_HPP - -// IWYU pragma: private, include "kapi/cpu.hpp" +#ifndef TEACHOS_KAPI_INTERRUPTS_HPP +#define TEACHOS_KAPI_INTERRUPTS_HPP #include <cstdint> -namespace kapi::cpu +namespace kapi::interrupts { enum class status : bool @@ -15,9 +13,9 @@ namespace kapi::cpu }; //! The interface for all interrupt handlers. - struct interrupt_handler + struct handler { - virtual ~interrupt_handler() = default; + virtual ~handler() = default; //! Handle an interrupt with the given IRQ number. // @@ -31,33 +29,33 @@ namespace kapi::cpu //! @qualifier platform-defined //! Enable external interrupts. - auto enable_interrupts() -> void; + auto enable() -> void; //! @qualifier platform-defined //! Disable external interrupts. - auto disable_interrupts() -> void; + auto disable() -> 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; + auto register_handler(std::uint32_t irq_number, 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; + auto unregister_handler(std::uint32_t irq_number, 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; + auto dispatch(std::uint32_t irq_number) -> status; -} // namespace kapi::cpu +} // namespace kapi::interrupts #endif
\ No newline at end of file diff --git a/kernel/src/main.cpp b/kernel/src/main.cpp index 45a4aae..6434045 100644 --- a/kernel/src/main.cpp +++ b/kernel/src/main.cpp @@ -1,6 +1,7 @@ #include "kapi/boot_modules.hpp" #include "kapi/cio.hpp" #include "kapi/cpu.hpp" +#include "kapi/interrupts.hpp" #include "kapi/memory.hpp" #include "kapi/system.hpp" @@ -92,7 +93,7 @@ auto main() -> int kstd::println("[OS] IO subsystem initialized."); kapi::cpu::init(); - kapi::cpu::enable_interrupts(); + kapi::interrupts::enable(); kapi::memory::init(); kernel::memory::init_heap(kapi::memory::heap_base); |
