diff options
| -rw-r--r-- | CMakeLists.txt | 1 | ||||
| -rw-r--r-- | kapi/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | libs/kstd/CMakeLists.txt | 8 | ||||
| -rw-r--r-- | libs/kstd/include/kstd/bits/os.hpp | 2 | ||||
| -rw-r--r-- | libs/kstd/src/bits/os.cpp | 10 | ||||
| -rw-r--r-- | libs/kstd/src/cstdlib.cpp | 18 | ||||
| -rw-r--r-- | libs/kstd/src/cstring.cpp | 10 | ||||
| -rw-r--r-- | src/abort.cpp | 3 | ||||
| -rw-r--r-- | src/kstd.cpp | 6 |
9 files changed, 54 insertions, 5 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 3251847..ed4b16c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -40,7 +40,6 @@ add_subdirectory("kapi") add_subdirectory("libs") add_executable("kernel" - "src/abort.cpp" "src/kstd.cpp" "src/main.cpp" ) diff --git a/kapi/CMakeLists.txt b/kapi/CMakeLists.txt index 14244bc..86b0fb6 100644 --- a/kapi/CMakeLists.txt +++ b/kapi/CMakeLists.txt @@ -22,7 +22,6 @@ target_include_directories("kapi" PUBLIC target_link_libraries("kapi" PUBLIC "libs::kstd" - "c" "gcc" "stdc++" ) diff --git a/libs/kstd/CMakeLists.txt b/libs/kstd/CMakeLists.txt index ac9e78f..666a5d7 100644 --- a/libs/kstd/CMakeLists.txt +++ b/libs/kstd/CMakeLists.txt @@ -2,6 +2,9 @@ add_library("kstd" STATIC) add_library("libs::kstd" ALIAS "kstd") target_sources("kstd" PRIVATE + "src/bits/os.cpp" + "src/cstdlib.cpp" + "src/cstring.cpp" "src/mutex.cpp" ) @@ -23,3 +26,8 @@ target_sources("kstd" PUBLIC target_include_directories("kstd" PUBLIC "include" ) + +target_link_options("kstd" INTERFACE + "-Wl,--undefined=abort" + "-Wl,--undefined=strlen" +)
\ No newline at end of file diff --git a/libs/kstd/include/kstd/bits/os.hpp b/libs/kstd/include/kstd/bits/os.hpp index 0425b88..7f5fcc8 100644 --- a/libs/kstd/include/kstd/bits/os.hpp +++ b/libs/kstd/include/kstd/bits/os.hpp @@ -6,6 +6,8 @@ namespace kstd::os { + auto abort() -> bool; + [[noreturn]] auto panic(std::string_view message, std::source_location = std::source_location::current()) -> void; } diff --git a/libs/kstd/src/bits/os.cpp b/libs/kstd/src/bits/os.cpp new file mode 100644 index 0000000..fb64202 --- /dev/null +++ b/libs/kstd/src/bits/os.cpp @@ -0,0 +1,10 @@ +#include "kstd/bits/os.hpp" + +namespace kstd::os +{ + [[gnu::weak]] + auto abort() -> bool + { + return false; + } +} // namespace kstd::os
\ No newline at end of file diff --git a/libs/kstd/src/cstdlib.cpp b/libs/kstd/src/cstdlib.cpp new file mode 100644 index 0000000..8fb5f63 --- /dev/null +++ b/libs/kstd/src/cstdlib.cpp @@ -0,0 +1,18 @@ +#include "kstd/bits/os.hpp" + +namespace kstd +{ + + extern "C" + { + [[noreturn]] auto abort() -> void + { + if (!kstd::os::abort()) + { + os::panic("System abort handler returned."); + } + __builtin_trap(); + } + } + +} // namespace kstd
\ No newline at end of file diff --git a/libs/kstd/src/cstring.cpp b/libs/kstd/src/cstring.cpp new file mode 100644 index 0000000..5419b7d --- /dev/null +++ b/libs/kstd/src/cstring.cpp @@ -0,0 +1,10 @@ +#include <algorithm> +#include <cstddef> + +extern "C" +{ + auto strlen(const char * string) -> std::size_t + { + return std::distance(string, std::ranges::find(string, nullptr, '\0')); + } +} diff --git a/src/abort.cpp b/src/abort.cpp deleted file mode 100644 index 6b0070e..0000000 --- a/src/abort.cpp +++ /dev/null @@ -1,3 +0,0 @@ -#include "kapi/system.hpp" - -extern "C" [[noreturn]] auto abort() -> void { teachos::system::panic("Abort called"); } diff --git a/src/kstd.cpp b/src/kstd.cpp index 2149c12..77155af 100644 --- a/src/kstd.cpp +++ b/src/kstd.cpp @@ -5,6 +5,12 @@ namespace kstd::os { + auto abort() -> bool + { + panic("Abort called."); + return true; + } + auto panic(std::string_view message, std::source_location location) -> void { teachos::system::panic(message, location); |
