aboutsummaryrefslogtreecommitdiff
path: root/arch/x86_64/kapi/boot_modules.cpp
blob: 136eb30d4411676867864b3f158e7cffda4ff77e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <kapi/boot_modules.hpp>

#include <arch/boot/boot.hpp>
#include <arch/boot/ld.hpp>

#include <kapi/boot.hpp>
#include <kapi/boot_modules/module.hpp>
#include <kapi/boot_modules/registry.hpp>
#include <kapi/memory.hpp>

#include <kstd/print.hpp>

#include <multiboot2/information.hpp>

#include <algorithm>
#include <bit>
#include <cstdint>

namespace kapi::boot_modules
{

  auto init() -> void
  {
    registry::init();

    kstd::println("[x86_64:BOOT_MODULES] Registering boot modules.");

    auto modules = boot::bootstrap_information.mbi->modules();
    std::ranges::for_each(modules, [](auto const & module) {
      registry::get().add(kapi::boot_modules::module{
        .name = module.string(),
        .start_address =
            memory::linear_address{module.start_address + std::bit_cast<std::uintptr_t>(&arch::boot::TEACHOS_VMA)},
        .size = module.end_address - module.start_address,
      });
    });
  }
}  // namespace kapi::boot_modules