aboutsummaryrefslogtreecommitdiff
path: root/kapi
diff options
context:
space:
mode:
Diffstat (limited to 'kapi')
-rw-r--r--kapi/include/kapi/cpu.hpp7
-rw-r--r--kapi/include/kapi/cpu/exception.hpp60
2 files changed, 67 insertions, 0 deletions
diff --git a/kapi/include/kapi/cpu.hpp b/kapi/include/kapi/cpu.hpp
index 05b84b7..1dd7cfe 100644
--- a/kapi/include/kapi/cpu.hpp
+++ b/kapi/include/kapi/cpu.hpp
@@ -1,6 +1,8 @@
#ifndef TEACHOS_KAPI_CPU_HPP
#define TEACHOS_KAPI_CPU_HPP
+#include "kapi/cpu/exception.hpp"
+
namespace kapi::cpu
{
//! @qualifier platform-defined
@@ -8,6 +10,11 @@ namespace kapi::cpu
//!
//! This function terminates execution of the kernel.
[[noreturn]] auto halt() -> void;
+
+ //! @qualifier platform-defined
+ //! Perform early CPU initialization.
+ auto init() -> void;
+
} // namespace kapi::cpu
#endif
diff --git a/kapi/include/kapi/cpu/exception.hpp b/kapi/include/kapi/cpu/exception.hpp
new file mode 100644
index 0000000..09e15a7
--- /dev/null
+++ b/kapi/include/kapi/cpu/exception.hpp
@@ -0,0 +1,60 @@
+#ifndef TEACHOS_KAPI_CPU_EXCEPTION_HPP
+#define TEACHOS_KAPI_CPU_EXCEPTION_HPP
+
+// IWYU pragma: private, include "kapi/cpu.hpp"
+
+#include "kapi/memory.hpp"
+
+#include <cstdint>
+
+namespace kapi::cpu
+{
+
+ struct exception
+ {
+ enum class type : std::uint8_t
+ {
+ unknown,
+ page_fault,
+ alignment_fault,
+ memory_access_fault,
+ illegal_instruction,
+ privilege_violation,
+ arithmetic_error,
+ breakpoint,
+ single_step,
+ };
+
+ //! The type of exception.
+ type type{};
+
+ //! The instruction pointer at the time of the exception.
+ kapi::memory::linear_address instruction_pointer{};
+
+ //! The memory address that caused the exception.
+ kapi::memory::linear_address access_address{};
+
+ //! Whether the page was present at the time of the exception.
+ bool is_present{};
+
+ //! Whether the exception was caused by a write access.
+ bool is_write_access{};
+
+ //! Whether the exception was caused by a user mode access.
+ bool is_user_mode{};
+ };
+
+ struct exception_handler
+ {
+ virtual ~exception_handler() = default;
+
+ virtual auto handle(exception const & context) -> bool = 0;
+ };
+
+ auto get_exception_handler() -> exception_handler &;
+
+ auto set_exception_handler(exception_handler & handler) -> void;
+
+} // namespace kapi::cpu
+
+#endif \ No newline at end of file