diff options
| -rw-r--r-- | .clang-format | 7 | ||||
| -rw-r--r-- | CMakeLists.txt | 14 | ||||
| -rw-r--r-- | arch/CMakeLists.txt | 26 | ||||
| -rw-r--r-- | arch/include/arch/io.hpp | 9 | ||||
| -rw-r--r-- | arch/include/arch/memory.hpp | 9 | ||||
| -rw-r--r-- | arch/include/arch/system.hpp | 9 | ||||
| -rw-r--r-- | arch/x86_64/CMakeLists.txt | 3 | ||||
| -rw-r--r-- | arch/x86_64/src/io.cpp | 44 | ||||
| -rw-r--r-- | arch/x86_64/src/memory.cpp | 12 | ||||
| -rw-r--r-- | arch/x86_64/src/system.cpp | 6 | ||||
| -rw-r--r-- | kapi/CMakeLists.txt | 27 | ||||
| -rw-r--r-- | kapi/include/kapi/io.hpp | 17 | ||||
| -rw-r--r-- | kapi/include/kapi/memory.hpp | 9 | ||||
| -rw-r--r-- | kapi/include/kapi/system.hpp | 14 | ||||
| -rw-r--r-- | kapi/src/system.cpp | 18 | ||||
| -rw-r--r-- | kern/CMakeLists.txt | 18 | ||||
| -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/kstd.cpp | 10 | ||||
| -rw-r--r-- | kern/src/main.cpp | 14 | ||||
| -rw-r--r-- | kern/src/print.cpp | 51 | ||||
| -rw-r--r-- | src/abort.cpp | 3 | ||||
| -rw-r--r-- | src/kstd.cpp | 13 | ||||
| -rw-r--r-- | src/main.cpp | 13 |
26 files changed, 162 insertions, 245 deletions
diff --git a/.clang-format b/.clang-format index b32e8c9..714f716 100644 --- a/.clang-format +++ b/.clang-format @@ -40,12 +40,9 @@ DerivePointerAlignment: 'false' FixNamespaceComments: 'true' IncludeBlocks: Regroup IncludeCategories: - # Kernel Headers - - Regex: 'kern/[[:alnum:]._\/]+\.hpp' + # Kernel API Headers + - Regex: 'kapi/[[:alnum:]._\/]+\.hpp' Priority: 100 - # Architecture Interface Headers - - Regex: 'arch/[[:alnum:]._\/]+\.hpp' - Priority: 110 # Architecture Implementation Headers - Regex: 'x86_64/[[:alnum:]._\/]+\.hpp' Priority: 110 diff --git a/CMakeLists.txt b/CMakeLists.txt index aa1f6a9..5dd4044 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -35,15 +35,19 @@ add_compile_options( # Kernel Executable #]============================================================================] -add_executable("kernel") - -add_subdirectory("libs") -add_subdirectory("kern") add_subdirectory("arch") +add_subdirectory("kapi") +add_subdirectory("libs") + +add_executable("kernel" + "src/abort.cpp" + "src/kstd.cpp" + "src/main.cpp" +) target_link_libraries("kernel" PRIVATE "arch::${CMAKE_SYSTEM_PROCESSOR}" - "os::kern" + "api::kapi" ) target_link_options("kernel" PRIVATE diff --git a/arch/CMakeLists.txt b/arch/CMakeLists.txt index 83da439..516bfe9 100644 --- a/arch/CMakeLists.txt +++ b/arch/CMakeLists.txt @@ -1,27 +1,3 @@ -add_library("arch-any" INTERFACE) -add_library("arch::any" ALIAS "arch-any") - -target_sources("arch-any" INTERFACE - FILE_SET HEADERS - BASE_DIRS "include" - FILES - "include/arch/io.hpp" - "include/arch/memory.hpp" - "include/arch/system.hpp" -) - -target_include_directories("arch-any" INTERFACE - "include" -) - -target_link_libraries("arch-any" INTERFACE - "libs::kstd" - - "c" - "gcc" - "stdc++" -) +set(KERNEL_LINKER_SCRIPT "${CMAKE_CURRENT_SOURCE_DIR}/${CMAKE_SYSTEM_PROCESSOR}/scripts/kernel.ld" PARENT_SCOPE) add_subdirectory("${CMAKE_SYSTEM_PROCESSOR}") - -set(KERNEL_LINKER_SCRIPT "${CMAKE_CURRENT_SOURCE_DIR}/${CMAKE_SYSTEM_PROCESSOR}/scripts/kernel.ld" PARENT_SCOPE) diff --git a/arch/include/arch/io.hpp b/arch/include/arch/io.hpp deleted file mode 100644 index 8986b9c..0000000 --- a/arch/include/arch/io.hpp +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef TEACHOS_ARCH_IO_HPP -#define TEACHOS_ARCH_IO_HPP - -namespace teachos::arch::io -{ - auto init() -> void; -} - -#endif diff --git a/arch/include/arch/memory.hpp b/arch/include/arch/memory.hpp deleted file mode 100644 index 33f7fdd..0000000 --- a/arch/include/arch/memory.hpp +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef TEACHOS_ARCH_MEMORY_HPP -#define TEACHOS_ARCH_MEMORY_HPP - -namespace teachos::arch::memory -{ - auto init() -> void; -} - -#endif diff --git a/arch/include/arch/system.hpp b/arch/include/arch/system.hpp deleted file mode 100644 index 73e2463..0000000 --- a/arch/include/arch/system.hpp +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef TEACHOS_ARCH_SYSTEM_HPP -#define TEACHOS_ARCH_SYSTEM_HPP - -namespace teachos::arch::system -{ - [[noreturn]] auto halt() -> void; -} - -#endif diff --git a/arch/x86_64/CMakeLists.txt b/arch/x86_64/CMakeLists.txt index 431520e..4cb20b6 100644 --- a/arch/x86_64/CMakeLists.txt +++ b/arch/x86_64/CMakeLists.txt @@ -6,8 +6,7 @@ target_include_directories("arch-x86_64" PUBLIC ) target_link_libraries("arch-x86_64" PUBLIC - "arch::any" - "os::kern" + "api::kapi" "libs::multiboot2" ) diff --git a/arch/x86_64/src/io.cpp b/arch/x86_64/src/io.cpp index 8e9e411..eab6473 100644 --- a/arch/x86_64/src/io.cpp +++ b/arch/x86_64/src/io.cpp @@ -1,28 +1,36 @@ -#include "kern/print.hpp" +#include "kapi/io.hpp" + #include "x86_64/vga/text.hpp" -namespace teachos::arch::io +namespace teachos::io { auto init() -> void { + x86_64::vga::text::clear(); x86_64::vga::text::cursor(false); + } + + auto print(std::string_view text) -> void + { + x86_64::vga::text::write(text, x86_64::vga::text::common_attributes::green_on_black); + } + + auto println(std::string_view text) -> void + { + x86_64::vga::text::write(text, x86_64::vga::text::common_attributes::green_on_black); + x86_64::vga::text::newline(); + } + + auto print_error(std::string_view text) -> void + { + x86_64::vga::text::write(text, x86_64::vga::text::common_attributes::red_on_black); + } - teachos::set_print_handler( - [](auto text) { return x86_64::vga::text::write(text, x86_64::vga::text::common_attributes::green_on_black); }); - teachos::set_println_handler([](auto text) { - x86_64::vga::text::write(text, x86_64::vga::text::common_attributes::green_on_black); - x86_64::vga::text::newline(); - }); - - teachos::set_print_error_handler( - [](auto text) { return x86_64::vga::text::write(text, x86_64::vga::text::common_attributes::red_on_black); }); - teachos::set_println_error_handler([](auto text) { - x86_64::vga::text::write(text, x86_64::vga::text::common_attributes::red_on_black); - x86_64::vga::text::newline(); - }); - - teachos::println("[x86-64] Basic VGA text output initialized."); + auto println_error(std::string_view text) -> void + { + x86_64::vga::text::write(text, x86_64::vga::text::common_attributes::red_on_black); + x86_64::vga::text::newline(); } -} // namespace teachos::arch::io +} // namespace teachos::io diff --git a/arch/x86_64/src/memory.cpp b/arch/x86_64/src/memory.cpp index b6901a5..d1c1f03 100644 --- a/arch/x86_64/src/memory.cpp +++ b/arch/x86_64/src/memory.cpp @@ -1,6 +1,6 @@ -#include "arch/memory.hpp" +#include "kapi/memory.hpp" -#include "kern/error.hpp" +#include "kapi/system.hpp" #include "x86_64/boot/boot.hpp" #include "x86_64/boot/ld.hpp" @@ -11,7 +11,7 @@ #include <atomic> -namespace teachos::arch::memory +namespace teachos::memory { using namespace x86_64::memory; using namespace x86_64::boot; @@ -36,13 +36,13 @@ namespace teachos::arch::memory { if (is_initialized.test_and_set()) { - teachos::panic("[x86_64] Memory management has already been initialized."); + system::panic("[x86_64] Memory management has already been initialized."); } auto memory_map = multiboot_information_pointer->maybe_memory_map(); if (!memory_map) { - teachos::panic("[x86_64] No memory map available."); + system::panic("[x86_64] No memory map available."); } auto mem_info = create_memory_information(); @@ -63,4 +63,4 @@ namespace teachos::arch::memory // video::vga::text::newline(); } -} // namespace teachos::arch::memory +} // namespace teachos::memory diff --git a/arch/x86_64/src/system.cpp b/arch/x86_64/src/system.cpp index 60ebf0e..2d4c3fe 100644 --- a/arch/x86_64/src/system.cpp +++ b/arch/x86_64/src/system.cpp @@ -1,6 +1,6 @@ -#include "arch/system.hpp" +#include "kapi/system.hpp" -namespace teachos::arch::system +namespace teachos::system { auto halt() -> void @@ -9,4 +9,4 @@ namespace teachos::arch::system __builtin_unreachable(); } -} // namespace teachos::arch::system +} // namespace teachos::system 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 diff --git a/kern/CMakeLists.txt b/kern/CMakeLists.txt deleted file mode 100644 index 677fdc2..0000000 --- a/kern/CMakeLists.txt +++ /dev/null @@ -1,18 +0,0 @@ -add_library("kern" OBJECT) -add_library("os::kern" ALIAS "kern") - -target_sources("kern" PRIVATE - "src/abort.cpp" - "src/error.cpp" - "src/kstd.cpp" - "src/main.cpp" - "src/print.cpp" -) - -target_include_directories("kern" PUBLIC - "include" -) - -target_link_libraries("kern" PUBLIC - "arch::any" -) diff --git a/kern/include/kern/error.hpp b/kern/include/kern/error.hpp deleted file mode 100644 index e58b9f1..0000000 --- a/kern/include/kern/error.hpp +++ /dev/null @@ -1,13 +0,0 @@ -#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 deleted file mode 100644 index fc9b5d6..0000000 --- a/kern/include/kern/print.hpp +++ /dev/null @@ -1,26 +0,0 @@ - -#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 deleted file mode 100644 index 6db0b74..0000000 --- a/kern/src/abort.cpp +++ /dev/null @@ -1,3 +0,0 @@ -#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 deleted file mode 100644 index a5229fd..0000000 --- a/kern/src/error.cpp +++ /dev/null @@ -1,19 +0,0 @@ -#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/kstd.cpp b/kern/src/kstd.cpp deleted file mode 100644 index 1b7050b..0000000 --- a/kern/src/kstd.cpp +++ /dev/null @@ -1,10 +0,0 @@ -#include "kern/error.hpp" - -#include <kstd/bits/os.hpp> - -namespace kstd::os -{ - - auto panic(std::string_view message, std::source_location location) -> void { teachos::panic(message, location); } - -} // namespace kstd::os
\ No newline at end of file diff --git a/kern/src/main.cpp b/kern/src/main.cpp deleted file mode 100644 index b99fb37..0000000 --- a/kern/src/main.cpp +++ /dev/null @@ -1,14 +0,0 @@ -#include "arch/io.hpp" -#include "arch/memory.hpp" -#include "kern/error.hpp" -#include "kern/print.hpp" - -auto main() -> int -{ - teachos::arch::io::init(); - teachos::println("[OS] IO subsystem initialized."); - - teachos::arch::memory::init(); - - teachos::panic("Architecture specific main returned!"); -} diff --git a/kern/src/print.cpp b/kern/src/print.cpp deleted file mode 100644 index 2c8539b..0000000 --- a/kern/src/print.cpp +++ /dev/null @@ -1,51 +0,0 @@ - -#include "kern/print.hpp" - -#include <string_view> - -namespace teachos -{ - namespace - { - constinit auto noop = [](std::string_view) {}; - - constinit auto current_print_handler = static_cast<print_handler *>(noop); - constinit auto current_println_handler = static_cast<println_handler *>(noop); - constinit auto current_print_error_handler = static_cast<print_handler *>(noop); - constinit auto current_println_error_handler = static_cast<println_handler *>(noop); - } // namespace - - auto print(std::string_view text) -> void { current_print_handler(text); } - auto println(std::string_view text) -> void { current_println_handler(text); } - auto print_error(std::string_view text) -> void { current_print_error_handler(text); } - auto println_error(std::string_view text) -> void { 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 diff --git a/src/abort.cpp b/src/abort.cpp new file mode 100644 index 0000000..6b0070e --- /dev/null +++ b/src/abort.cpp @@ -0,0 +1,3 @@ +#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 new file mode 100644 index 0000000..2149c12 --- /dev/null +++ b/src/kstd.cpp @@ -0,0 +1,13 @@ +#include "kapi/system.hpp" + +#include <kstd/bits/os.hpp> + +namespace kstd::os +{ + + auto panic(std::string_view message, std::source_location location) -> void + { + teachos::system::panic(message, location); + } + +} // namespace kstd::os
\ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..d6199d0 --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,13 @@ +#include "kapi/io.hpp" +#include "kapi/memory.hpp" +#include "kapi/system.hpp" + +auto main() -> int +{ + teachos::io::init(); + teachos::io::println("[OS] IO subsystem initialized."); + + teachos::memory::init(); + + teachos::system::panic("Architecture specific main returned!"); +} |
