aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelix Morgner <felix.morgner@ost.ch>2026-03-25 13:24:03 +0100
committerFelix Morgner <felix.morgner@ost.ch>2026-03-27 07:02:35 +0100
commitfd1c5a50bb35f772b8e37125188640447d4b3b2a (patch)
treeed1ac0b99fccb52e627338915490ba035655c774
parent363a6d701d4998137fcc123059f9749098ac7d75 (diff)
downloadteachos-fd1c5a50bb35f772b8e37125188640447d4b3b2a.tar.xz
teachos-fd1c5a50bb35f772b8e37125188640447d4b3b2a.zip
kapi/cpu: enable formatting of exception types
-rw-r--r--kapi/include/kapi/cpu/exception.hpp36
-rw-r--r--kernel/src/cpu.cpp3
2 files changed, 37 insertions, 2 deletions
diff --git a/kapi/include/kapi/cpu/exception.hpp b/kapi/include/kapi/cpu/exception.hpp
index 9fc697a..00b02e7 100644
--- a/kapi/include/kapi/cpu/exception.hpp
+++ b/kapi/include/kapi/cpu/exception.hpp
@@ -5,6 +5,8 @@
#include "kapi/memory.hpp"
+#include <kstd/format>
+
#include <cstdint>
namespace kapi::cpu
@@ -82,4 +84,38 @@ namespace kapi::cpu
} // namespace kapi::cpu
+template<>
+struct kstd::formatter<enum kapi::cpu::exception::type>
+{
+ constexpr auto parse(kstd::format_parse_context & ctx) -> decltype(ctx.begin())
+ {
+ return ctx.begin();
+ }
+
+ constexpr auto format(enum kapi::cpu::exception::type type, kstd::format_context & ctx) const -> void
+ {
+ switch (type)
+ {
+ case kapi::cpu::exception::type::unknown:
+ return ctx.push("unknown");
+ case kapi::cpu::exception::type::page_fault:
+ return ctx.push("page fault");
+ case kapi::cpu::exception::type::alignment_fault:
+ return ctx.push("alignment fault");
+ case kapi::cpu::exception::type::memory_access_fault:
+ return ctx.push("memory access fault");
+ case kapi::cpu::exception::type::illegal_instruction:
+ return ctx.push("illegal instruction");
+ case kapi::cpu::exception::type::privilege_violation:
+ return ctx.push("privilege violation");
+ case kapi::cpu::exception::type::arithmetic_error:
+ return ctx.push("arithmetic error");
+ case kapi::cpu::exception::type::breakpoint:
+ return ctx.push("breakpoint");
+ case kapi::cpu::exception::type::single_step:
+ return ctx.push("single step");
+ }
+ }
+};
+
#endif \ No newline at end of file
diff --git a/kernel/src/cpu.cpp b/kernel/src/cpu.cpp
index fc460c9..11b6551 100644
--- a/kernel/src/cpu.cpp
+++ b/kernel/src/cpu.cpp
@@ -14,6 +14,7 @@ namespace kernel::cpu
{
auto handle(kapi::cpu::exception const & context) -> bool override
{
+ kstd::println(kstd::print_sink::stderr, "[OS:CPU] {} @ {:#018x}", context.type, context.instruction_pointer);
switch (context.type)
{
case kapi::cpu::exception::type::page_fault:
@@ -26,12 +27,10 @@ namespace kernel::cpu
private:
auto handle_page_fault(kapi::cpu::exception const & context) -> bool
{
- kstd::println(kstd::print_sink::stderr, "[OS:CPU] PAGE FAULT!");
kstd::println(kstd::print_sink::stderr, "\tFault address: {:#018x}", context.access_address);
kstd::println(kstd::print_sink::stderr, "\tPresent: {}", context.is_present);
kstd::println(kstd::print_sink::stderr, "\tWrite: {}", context.is_write_access);
kstd::println(kstd::print_sink::stderr, "\tUser: {}", context.is_user_mode);
- kstd::println(kstd::print_sink::stderr, "\tRIP: {:#018x}", context.instruction_pointer);
kapi::system::panic("Halting the system due to an unrecoverable page fault.");
}