diff options
| author | Felix Morgner <felix.morgner@ost.ch> | 2025-07-14 16:02:43 +0000 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@ost.ch> | 2025-07-14 16:02:43 +0000 |
| commit | 25483b7af8df6b08d460f807fda04c6d409bd44e (patch) | |
| tree | 2001f9774fe179dd4a67c77f590aa7ee1406fb87 /kern/src | |
| parent | 1b603d1145b9ee10b1b12a0f765bd2bc1ebe2b3c (diff) | |
| download | teachos-25483b7af8df6b08d460f807fda04c6d409bd44e.tar.xz teachos-25483b7af8df6b08d460f807fda04c6d409bd44e.zip | |
ide: start large-scale restructuring
Diffstat (limited to 'kern/src')
| -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 |
4 files changed, 109 insertions, 0 deletions
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 |
