diff options
| author | Lukas Oesch <lukasoesch20@gmail.com> | 2026-02-26 11:24:27 +0100 |
|---|---|---|
| committer | Lukas Oesch <lukasoesch20@gmail.com> | 2026-03-17 16:42:10 +0100 |
| commit | 035c8d6e38fd901e6769a81f67b8d9e1e3fcea20 (patch) | |
| tree | 5ca549e23b86529fa65045e2f63cdc8411e165ba /arch | |
| parent | ea8172296fa5b56137f97c01650b8d392bdb897f (diff) | |
| download | teachos-035c8d6e38fd901e6769a81f67b8d9e1e3fcea20.tar.xz teachos-035c8d6e38fd901e6769a81f67b8d9e1e3fcea20.zip | |
implemented boot_modules and boot_module_registry, init boot_modules in kernel main
Diffstat (limited to 'arch')
| -rw-r--r-- | arch/x86_64/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | arch/x86_64/kapi/boot_modules.cpp | 51 |
2 files changed, 52 insertions, 0 deletions
diff --git a/arch/x86_64/CMakeLists.txt b/arch/x86_64/CMakeLists.txt index 41932c9..4ae09ff 100644 --- a/arch/x86_64/CMakeLists.txt +++ b/arch/x86_64/CMakeLists.txt @@ -12,6 +12,7 @@ target_link_libraries("x86_64" PUBLIC target_sources("x86_64" PRIVATE # Platform-dependent KAPI implementation + "kapi/boot_modules.cpp" "kapi/cio.cpp" "kapi/cpu.cpp" "kapi/memory.cpp" diff --git a/arch/x86_64/kapi/boot_modules.cpp b/arch/x86_64/kapi/boot_modules.cpp new file mode 100644 index 0000000..5d06eb5 --- /dev/null +++ b/arch/x86_64/kapi/boot_modules.cpp @@ -0,0 +1,51 @@ +#include "kapi/boot_modules.hpp" + +#include "kapi/boot.hpp" +#include "kapi/boot_module/boot_module.hpp" +#include "kapi/boot_module/boot_module_registry.hpp" +#include "kapi/system.hpp" + +#include "arch/boot/boot.hpp" +#include "arch/boot/ld.hpp" + +#include <kstd/print> + +#include <multiboot2/information.hpp> + +#include <algorithm> +#include <atomic> +#include <bit> +#include <cstdint> +#include <optional> + +namespace kapi::boot_modules +{ + namespace + { + auto constinit registry = std::optional<kapi::boot_modules::boot_module_registry>{}; + } // namespace + + auto init() -> void + { + auto static constinit is_initialized = std::atomic_flag{}; + if (is_initialized.test_and_set()) + { + system::panic("[x86_64] Boot module registry has already been initialized."); + } + + kstd::println("[x86_64:BOOT_MODULES] Initializing boot module registry."); + + registry.emplace(kapi::boot_modules::boot_module_registry{}); + + auto modules = boot::bootstrap_information.mbi->modules(); + std::ranges::for_each(modules, [](auto const & module) { + registry->add_boot_module(kapi::boot_modules::boot_module{ + .name = module.string(), + .start_address = module.start_address + std::bit_cast<std::uintptr_t>(&arch::boot::TEACHOS_VMA), + .size = module.end_address - module.start_address, + }); + }); + + set_boot_module_registry(*registry); + } +} // namespace kapi::boot_modules
\ No newline at end of file |
