diff options
Diffstat (limited to 'kern')
| -rw-r--r-- | kern/CMakeLists.txt | 16 | ||||
| -rw-r--r-- | kern/include/kern/error.hpp | 13 | ||||
| -rw-r--r-- | kern/include/kern/print.hpp | 26 | ||||
| -rw-r--r-- | kern/src/abort.cpp | 3 | ||||
| -rw-r--r-- | kern/src/error.cpp | 19 | ||||
| -rw-r--r-- | kern/src/main.cpp | 11 | ||||
| -rw-r--r-- | kern/src/print.cpp | 76 |
7 files changed, 164 insertions, 0 deletions
diff --git a/kern/CMakeLists.txt b/kern/CMakeLists.txt new file mode 100644 index 0000000..b2c7e2f --- /dev/null +++ b/kern/CMakeLists.txt @@ -0,0 +1,16 @@ +add_library("kern" OBJECT + "src/abort.cpp" + "src/error.cpp" + "src/main.cpp" + "src/print.cpp" +) + +target_include_directories("kern" PUBLIC + "include" +) + +target_link_libraries("kern" PUBLIC + "arch::all" + + "gcc" +) diff --git a/kern/include/kern/error.hpp b/kern/include/kern/error.hpp new file mode 100644 index 0000000..e58b9f1 --- /dev/null +++ b/kern/include/kern/error.hpp @@ -0,0 +1,13 @@ +#ifndef TEACHOS_KERN_ERROR_HPP +#define TEACHOS_KERN_ERROR_HPP + +#include <source_location> +#include <string_view> + +namespace teachos +{ + [[noreturn]] + auto panic(std::string_view message, std::source_location = std::source_location::current()) -> void; +} + +#endif diff --git a/kern/include/kern/print.hpp b/kern/include/kern/print.hpp new file mode 100644 index 0000000..fc9b5d6 --- /dev/null +++ b/kern/include/kern/print.hpp @@ -0,0 +1,26 @@ + +#ifndef TEACHOS_KERN_PRINT_HPP +#define TEACHOS_KERN_PRINT_HPP + +#include <string_view> + +namespace teachos +{ + + using print_handler = auto(std::string_view) -> void; + using println_handler = auto(std::string_view) -> 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; + + auto set_print_handler(print_handler handler) -> print_handler *; + auto set_println_handler(println_handler handler) -> print_handler *; + auto set_print_error_handler(print_handler handler) -> print_handler *; + auto set_println_error_handler(println_handler handler) -> print_handler *; + +} // namespace teachos + +#endif diff --git a/kern/src/abort.cpp b/kern/src/abort.cpp new file mode 100644 index 0000000..6db0b74 --- /dev/null +++ b/kern/src/abort.cpp @@ -0,0 +1,3 @@ +#include "kern/error.hpp" + +extern "C" [[noreturn]] auto abort() -> void { teachos::panic("Abort called"); } diff --git a/kern/src/error.cpp b/kern/src/error.cpp new file mode 100644 index 0000000..a5229fd --- /dev/null +++ b/kern/src/error.cpp @@ -0,0 +1,19 @@ +#include "kern/error.hpp" + +#include "arch/system.hpp" +#include "kern/print.hpp" + +namespace teachos +{ + + auto panic(std::string_view message, std::source_location location) -> void + { + println_error("!!!Kernel Panic!!! "); + println_error(message); + println_error(location.file_name()); + println_error(location.function_name()); + + arch::system::halt(); + } + +} // namespace teachos diff --git a/kern/src/main.cpp b/kern/src/main.cpp new file mode 100644 index 0000000..5e1b6ea --- /dev/null +++ b/kern/src/main.cpp @@ -0,0 +1,11 @@ +#include "arch/io.hpp" +#include "arch/memory.hpp" +#include "kern/error.hpp" + +auto main() -> int +{ + teachos::arch::io::init(); + teachos::arch::memory::init(); + + teachos::panic("Architecture specific main returned!"); +} diff --git a/kern/src/print.cpp b/kern/src/print.cpp new file mode 100644 index 0000000..64e2c65 --- /dev/null +++ b/kern/src/print.cpp @@ -0,0 +1,76 @@ + +#include "kern/print.hpp" + +#include <string_view> + +namespace teachos +{ + namespace + { + print_handler * current_print_handler{}; + println_handler * current_println_handler{}; + print_handler * current_print_error_handler{}; + println_handler * current_println_error_handler{}; + } // namespace + + auto print(std::string_view text) -> void + { + if (current_print_handler) + { + current_print_handler(text); + } + } + + auto println(std::string_view text) -> void + { + if (current_println_handler) + { + current_println_handler(text); + } + } + + auto print_error(std::string_view text) -> void + { + if (current_print_error_handler) + { + current_print_error_handler(text); + } + } + + auto println_error(std::string_view text) -> void + { + if (current_println_error_handler) + { + current_println_error_handler(text); + } + } + + auto set_print_handler(print_handler handler) -> print_handler * + { + auto old = current_print_handler; + current_print_handler = handler; + return old; + } + + auto set_println_handler(println_handler handler) -> print_handler * + { + auto old = current_println_handler; + current_println_handler = handler; + return old; + } + + auto set_print_error_handler(print_handler handler) -> print_handler * + { + auto old = current_print_error_handler; + current_print_error_handler = handler; + return old; + } + + auto set_println_error_handler(println_handler handler) -> print_handler * + { + auto old = current_println_error_handler; + current_println_error_handler = handler; + return old; + } + +} // namespace teachos |
