aboutsummaryrefslogtreecommitdiff
path: root/kapi
diff options
context:
space:
mode:
Diffstat (limited to 'kapi')
-rw-r--r--kapi/kapi/system.hpp44
1 files changed, 44 insertions, 0 deletions
diff --git a/kapi/kapi/system.hpp b/kapi/kapi/system.hpp
index 8a20af94..f7dd4d7c 100644
--- a/kapi/kapi/system.hpp
+++ b/kapi/kapi/system.hpp
@@ -1,8 +1,15 @@
#ifndef TEACHOS_KAPI_SYSTEM_HPP
#define TEACHOS_KAPI_SYSTEM_HPP
+#include <kstd/format.hpp>
+#include <kstd/system_error.hpp>
+
+#include <array>
+#include <cstddef>
#include <source_location>
+#include <span>
#include <string_view>
+#include <type_traits>
namespace kapi::system
{
@@ -10,6 +17,26 @@ namespace kapi::system
//! @addtogroup kapi-system-kernel-defined
//! @{
+ template<typename... FormatArguments>
+ struct panic_format_string
+ {
+ kstd::format_string<FormatArguments...> format;
+ std::source_location location;
+
+ template<std::size_t Size>
+ consteval panic_format_string(char const (&format)[Size], // NOLINT
+ std::source_location location = std::source_location::current())
+ : format{format}
+ , location{location}
+ {}
+
+ consteval panic_format_string(std::string_view const & format,
+ std::source_location location = std::source_location::current())
+ : format{format}
+ , location{location}
+ {}
+ };
+
//! Terminate kernel execution with the given error message.
//!
//! This function terminates the execution of the kernel and attempts to issue the given error message to the user.
@@ -17,6 +44,14 @@ namespace kapi::system
//! @param message The message associated with the panic
[[noreturn]] auto panic(std::string_view message, std::source_location = std::source_location::current()) -> void;
+ //! Termite kernel execution with the given error message and error code.
+ //!
+ //! This function terminates the execution of the kernel and attempts to issue the given error message to the user.
+ //! @param message The message associated with the panic.
+ //! @param error The erro code associated with the panic.
+ [[noreturn]] auto panic(std::string_view message, kstd::error_code error,
+ std::source_location = std::source_location::current()) -> void;
+
//! @} // end group kernel-defined
//! @addtogroup kapi-system-platform-defined
@@ -26,6 +61,15 @@ namespace kapi::system
auto memory_initialized() -> void;
//! @} // end group platform-defined
+ //
+ template<typename... FormatArguments>
+ [[noreturn]] auto panic(panic_format_string<std::type_identity_t<FormatArguments>...> format,
+ FormatArguments &&... arguments)
+ {
+ auto buffer = std::array<char, 512uz>{};
+ auto [_, length] = kstd::format_to(std::span{buffer}, format.format, std::forward<FormatArguments>(arguments)...);
+ panic(std::string_view{buffer.data(), length}, format.location);
+ }
} // namespace kapi::system