From e7b04ef7f5da8e014e8b85fcf65448b317cca8ff Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Wed, 29 Oct 2025 11:15:50 +0100 Subject: kapi: move halt to cpu namespace --- arch/x86_64/CMakeLists.txt | 2 +- arch/x86_64/src/kapi/cpu.cpp | 12 ++++++++++++ arch/x86_64/src/kapi/system.cpp | 12 ------------ kapi/include/kapi/cpu.hpp | 13 +++++++++++++ kapi/include/kapi/system.hpp | 2 -- kapi/src/system.cpp | 4 +++- 6 files changed, 29 insertions(+), 16 deletions(-) create mode 100644 arch/x86_64/src/kapi/cpu.cpp delete mode 100644 arch/x86_64/src/kapi/system.cpp create mode 100644 kapi/include/kapi/cpu.hpp diff --git a/arch/x86_64/CMakeLists.txt b/arch/x86_64/CMakeLists.txt index 9be7b04..a681347 100644 --- a/arch/x86_64/CMakeLists.txt +++ b/arch/x86_64/CMakeLists.txt @@ -22,8 +22,8 @@ target_sources("x86_64" PRIVATE # api::kapi implementation "src/kapi/cio.cpp" + "src/kapi/cpu.cpp" "src/kapi/memory.cpp" - "src/kapi/system.cpp" # Memory management "src/memory/mmu.cpp" diff --git a/arch/x86_64/src/kapi/cpu.cpp b/arch/x86_64/src/kapi/cpu.cpp new file mode 100644 index 0000000..22543ee --- /dev/null +++ b/arch/x86_64/src/kapi/cpu.cpp @@ -0,0 +1,12 @@ +#include "kapi/cpu.hpp" + +namespace teachos::cpu +{ + + auto halt() -> void + { + asm volatile("1: hlt\njmp 1b"); + __builtin_unreachable(); + } + +} // namespace teachos::cpu diff --git a/arch/x86_64/src/kapi/system.cpp b/arch/x86_64/src/kapi/system.cpp deleted file mode 100644 index 2d4c3fe..0000000 --- a/arch/x86_64/src/kapi/system.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include "kapi/system.hpp" - -namespace teachos::system -{ - - auto halt() -> void - { - asm volatile("1: hlt\njmp 1b"); - __builtin_unreachable(); - } - -} // namespace teachos::system diff --git a/kapi/include/kapi/cpu.hpp b/kapi/include/kapi/cpu.hpp new file mode 100644 index 0000000..673deab --- /dev/null +++ b/kapi/include/kapi/cpu.hpp @@ -0,0 +1,13 @@ +#ifndef TEACHOS_KAPI_CPU_HPP +#define TEACHOS_KAPI_CPU_HPP + +namespace teachos::cpu +{ + /** + * @brief Halt the CPU, effectively terminating kernel execution. + * + */ + [[noreturn]] auto halt() -> void; +} // namespace teachos::cpu + +#endif diff --git a/kapi/include/kapi/system.hpp b/kapi/include/kapi/system.hpp index 0d4f2c9..b0b0e28 100644 --- a/kapi/include/kapi/system.hpp +++ b/kapi/include/kapi/system.hpp @@ -6,8 +6,6 @@ namespace teachos::system { - [[noreturn]] auto halt() -> void; - [[noreturn]] auto panic(std::string_view message, std::source_location = std::source_location::current()) -> void; } // namespace teachos::system diff --git a/kapi/src/system.cpp b/kapi/src/system.cpp index 041404e..3ae3f29 100644 --- a/kapi/src/system.cpp +++ b/kapi/src/system.cpp @@ -1,10 +1,12 @@ #include "kapi/system.hpp" #include "kapi/cio.hpp" +#include "kapi/cpu.hpp" namespace teachos::system { + [[gnu::weak]] auto panic(std::string_view message, std::source_location location) -> void { cio::println_error("!!!Kernel Panic!!! "); @@ -12,7 +14,7 @@ namespace teachos::system cio::println_error(location.file_name()); cio::println_error(location.function_name()); - halt(); + cpu::halt(); } } // namespace teachos::system -- cgit v1.2.3