aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFelix Morgner <felix.morgner@ost.ch>2025-12-12 14:26:16 +0100
committerFelix Morgner <felix.morgner@ost.ch>2025-12-12 14:26:16 +0100
commit4bf9eded3a5d6b007ba79a5716143fa8b3a5aaf6 (patch)
tree5ffcfb9b12afd58627a52498f232c798b273a351 /src
parent5f695cd3519d8a09a53485c08971f49ed92969ff (diff)
downloadteachos-4bf9eded3a5d6b007ba79a5716143fa8b3a5aaf6.tar.xz
teachos-4bf9eded3a5d6b007ba79a5716143fa8b3a5aaf6.zip
kapi: move platform independent implementation
Diffstat (limited to 'src')
-rw-r--r--src/kapi/cio.cpp57
-rw-r--r--src/kapi/system.cpp20
2 files changed, 77 insertions, 0 deletions
diff --git a/src/kapi/cio.cpp b/src/kapi/cio.cpp
new file mode 100644
index 0000000..66493b6
--- /dev/null
+++ b/src/kapi/cio.cpp
@@ -0,0 +1,57 @@
+#include "kapi/cio.hpp"
+
+#include <optional>
+#include <string_view>
+#include <utility>
+
+namespace teachos::cio
+{
+ namespace
+ {
+ struct null_device final : public output_device
+ {
+ null_device static instance;
+
+ auto write(std::string_view) -> void override {}
+ auto writeln(std::string_view) -> void override {}
+
+ auto write_error(std::string_view) -> void override {}
+ auto writeln_error(std::string_view) -> void override {}
+ };
+
+ constinit null_device null_device::instance;
+ } // namespace
+
+ // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
+ constinit auto active_device = static_cast<output_device *>(&null_device::instance);
+
+ auto set_output_device(output_device & device) -> std::optional<output_device *>
+ {
+ if (&device == active_device)
+ {
+ return {};
+ }
+ return std::exchange(active_device, &device);
+ }
+
+ auto print(std::string_view text) -> void
+ {
+ active_device->write(text);
+ }
+
+ auto println(std::string_view text) -> void
+ {
+ active_device->writeln(text);
+ }
+
+ auto print_error(std::string_view text) -> void
+ {
+ active_device->write_error(text);
+ }
+
+ auto println_error(std::string_view text) -> void
+ {
+ active_device->writeln_error(text);
+ }
+
+} // namespace teachos::cio \ No newline at end of file
diff --git a/src/kapi/system.cpp b/src/kapi/system.cpp
new file mode 100644
index 0000000..3ae3f29
--- /dev/null
+++ b/src/kapi/system.cpp
@@ -0,0 +1,20 @@
+#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!!! ");
+ cio::println_error(message);
+ cio::println_error(location.file_name());
+ cio::println_error(location.function_name());
+
+ cpu::halt();
+ }
+
+} // namespace teachos::system