aboutsummaryrefslogtreecommitdiff
path: root/arch/x86_64/kapi/boot_modules.cpp
blob: c86b9cf7141a914dcfcdd6df081c3eab17a2465c (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
39
40
41
42
43
#include <kapi/boot_modules.hpp>

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

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

#include <kstd/memory.hpp>
#include <kstd/print.hpp>

#include <multiboot2/information.hpp>

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

namespace kapi::boot_modules
{

  auto init(kapi::devices::bus & bus) -> void
  {
    kstd::println("[x86_64:BOOT_MODULES] Attaching boot modules.");

    auto modules = boot::bootstrap_information.mbi->modules();

    std::ranges::for_each(std::views::enumerate(modules), [&bus](auto entry) {
      auto [index, module] = entry;
      auto boot_module = 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};
      auto device = kstd::make_shared<kapi::boot_modules::device>(index, boot_module);
      bus.add_child(device);
    });
  }

}  // namespace kapi::boot_modules