aboutsummaryrefslogtreecommitdiff
path: root/kapi
diff options
context:
space:
mode:
authorFelix Morgner <felix.morgner@ost.ch>2025-07-24 15:31:31 +0000
committerFelix Morgner <felix.morgner@ost.ch>2025-07-24 15:31:31 +0000
commit4edbe94ce1266c9acc6a695fedf1d2edd4ce11cd (patch)
tree6738e5ab071075c15beccc59b3f79f53477f477d /kapi
parent2b8fafa2bddc48ddec047de517115c8e65ee61e8 (diff)
downloadteachos-4edbe94ce1266c9acc6a695fedf1d2edd4ce11cd.tar.xz
teachos-4edbe94ce1266c9acc6a695fedf1d2edd4ce11cd.zip
build: factor out kernel API
Diffstat (limited to 'kapi')
-rw-r--r--kapi/CMakeLists.txt27
-rw-r--r--kapi/include/kapi/io.hpp17
-rw-r--r--kapi/include/kapi/memory.hpp9
-rw-r--r--kapi/include/kapi/system.hpp14
-rw-r--r--kapi/src/system.cpp18
5 files changed, 85 insertions, 0 deletions
diff --git a/kapi/CMakeLists.txt b/kapi/CMakeLists.txt
new file mode 100644
index 0000000..a3cd040
--- /dev/null
+++ b/kapi/CMakeLists.txt
@@ -0,0 +1,27 @@
+add_library("kapi" OBJECT)
+add_library("api::kapi" ALIAS "kapi")
+
+target_sources("kapi" PUBLIC
+ FILE_SET HEADERS
+ BASE_DIRS "include"
+ FILES
+ "include/kapi/io.hpp"
+ "include/kapi/memory.hpp"
+ "include/kapi/system.hpp"
+)
+
+target_sources("kapi" PRIVATE
+ "src/system.cpp"
+)
+
+target_include_directories("kapi" PUBLIC
+ "include"
+)
+
+target_link_libraries("kapi" PUBLIC
+ "libs::kstd"
+
+ "c"
+ "gcc"
+ "stdc++"
+)
diff --git a/kapi/include/kapi/io.hpp b/kapi/include/kapi/io.hpp
new file mode 100644
index 0000000..764738f
--- /dev/null
+++ b/kapi/include/kapi/io.hpp
@@ -0,0 +1,17 @@
+#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/include/kapi/memory.hpp b/kapi/include/kapi/memory.hpp
new file mode 100644
index 0000000..842a2fa
--- /dev/null
+++ b/kapi/include/kapi/memory.hpp
@@ -0,0 +1,9 @@
+#ifndef TEACHOS_KAPI_MEMORY_HPP
+#define TEACHOS_KAPI_MEMORY_HPP
+
+namespace teachos::memory
+{
+ auto init() -> void;
+}
+
+#endif
diff --git a/kapi/include/kapi/system.hpp b/kapi/include/kapi/system.hpp
new file mode 100644
index 0000000..0d4f2c9
--- /dev/null
+++ b/kapi/include/kapi/system.hpp
@@ -0,0 +1,14 @@
+#ifndef TEACHOS_KAPI_SYSTEM_HPP
+#define TEACHOS_KAPI_SYSTEM_HPP
+
+#include <source_location>
+#include <string_view>
+
+namespace teachos::system
+{
+ [[noreturn]] auto halt() -> void;
+
+ [[noreturn]] auto panic(std::string_view message, std::source_location = std::source_location::current()) -> void;
+} // namespace teachos::system
+
+#endif
diff --git a/kapi/src/system.cpp b/kapi/src/system.cpp
new file mode 100644
index 0000000..c3b1c5e
--- /dev/null
+++ b/kapi/src/system.cpp
@@ -0,0 +1,18 @@
+#include "kapi/system.hpp"
+
+#include "kapi/io.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());
+
+ halt();
+ }
+
+} // namespace teachos::system