aboutsummaryrefslogtreecommitdiff
path: root/kapi
diff options
context:
space:
mode:
authorFelix Morgner <felix.morgner@ost.ch>2025-07-24 20:51:55 +0000
committerFelix Morgner <felix.morgner@ost.ch>2025-07-24 20:51:55 +0000
commitdd04850c27e8bc273506f4a64bb28b7ddf111dc5 (patch)
treea00212f5c903e80e4e729c87ce34ece2c40e4ee6 /kapi
parentfeac668578a35aac280b59d478a57b6937bb68da (diff)
downloadteachos-dd04850c27e8bc273506f4a64bb28b7ddf111dc5.tar.xz
teachos-dd04850c27e8bc273506f4a64bb28b7ddf111dc5.zip
kapi: rework text device interface
Diffstat (limited to 'kapi')
-rw-r--r--kapi/CMakeLists.txt3
-rw-r--r--kapi/include/kapi/cio.hpp29
-rw-r--r--kapi/include/kapi/io.hpp17
-rw-r--r--kapi/src/cio.cpp29
-rw-r--r--kapi/src/system.cpp10
5 files changed, 65 insertions, 23 deletions
diff --git a/kapi/CMakeLists.txt b/kapi/CMakeLists.txt
index 3a15fee..14244bc 100644
--- a/kapi/CMakeLists.txt
+++ b/kapi/CMakeLists.txt
@@ -5,12 +5,13 @@ target_sources("kapi" PUBLIC
FILE_SET HEADERS
BASE_DIRS "include"
FILES
- "include/kapi/io.hpp"
+ "include/kapi/cio.hpp"
"include/kapi/memory.hpp"
"include/kapi/system.hpp"
)
target_sources("kapi" PRIVATE
+ "src/cio.cpp"
"src/system.cpp"
)
diff --git a/kapi/include/kapi/cio.hpp b/kapi/include/kapi/cio.hpp
new file mode 100644
index 0000000..6b93638
--- /dev/null
+++ b/kapi/include/kapi/cio.hpp
@@ -0,0 +1,29 @@
+#ifndef TEACHOS_KAPI_IO_HPP
+#define TEACHOS_KAPI_IO_HPP
+
+#include <optional>
+#include <string_view>
+
+namespace teachos::cio
+{
+ struct output_device
+ {
+ auto virtual write(std::string_view text [[maybe_unused]]) -> void {}
+ auto virtual writeln(std::string_view text [[maybe_unused]]) -> void {}
+
+ auto virtual write_error(std::string_view text [[maybe_unused]]) -> void {}
+ auto virtual writeln_error(std::string_view text [[maybe_unused]]) -> void {}
+ };
+
+ auto init() -> void;
+
+ auto set_output_device(output_device & device) -> std::optional<output_device *>;
+
+ auto print(std::string_view text) -> void;
+ auto println(std::string_view text) -> void;
+
+ auto print_error(std::string_view text) -> void;
+ auto println_error(std::string_view text) -> void;
+} // namespace teachos::cio
+
+#endif
diff --git a/kapi/include/kapi/io.hpp b/kapi/include/kapi/io.hpp
deleted file mode 100644
index 764738f..0000000
--- a/kapi/include/kapi/io.hpp
+++ /dev/null
@@ -1,17 +0,0 @@
-#ifndef TEACHOS_KAPI_IO_HPP
-#define TEACHOS_KAPI_IO_HPP
-
-#include <string_view>
-
-namespace teachos::io
-{
- auto init() -> void;
-
- auto print(std::string_view text) -> void;
- auto println(std::string_view text) -> void;
-
- auto print_error(std::string_view text) -> void;
- auto println_error(std::string_view text) -> void;
-} // namespace teachos::io
-
-#endif
diff --git a/kapi/src/cio.cpp b/kapi/src/cio.cpp
new file mode 100644
index 0000000..aa26d49
--- /dev/null
+++ b/kapi/src/cio.cpp
@@ -0,0 +1,29 @@
+#include "kapi/cio.hpp"
+
+#include <optional>
+#include <utility>
+
+namespace teachos::cio
+{
+ auto constinit null_device = output_device{};
+
+ auto constinit active_device = &null_device;
+
+ 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/kapi/src/system.cpp b/kapi/src/system.cpp
index c3b1c5e..041404e 100644
--- a/kapi/src/system.cpp
+++ b/kapi/src/system.cpp
@@ -1,16 +1,16 @@
#include "kapi/system.hpp"
-#include "kapi/io.hpp"
+#include "kapi/cio.hpp"
namespace teachos::system
{
auto panic(std::string_view message, std::source_location location) -> void
{
- io::println_error("!!!Kernel Panic!!! ");
- io::println_error(message);
- io::println_error(location.file_name());
- io::println_error(location.function_name());
+ cio::println_error("!!!Kernel Panic!!! ");
+ cio::println_error(message);
+ cio::println_error(location.file_name());
+ cio::println_error(location.function_name());
halt();
}