aboutsummaryrefslogtreecommitdiff
path: root/arch/x86_64/src/memory.cpp
blob: a31627be8ed183e254a75636a2dcefad83737538 (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
44
45
46
47
48
49
50
51
52
53
#include "arch/memory.hpp"

#include "kern/error.hpp"

#include "x86_64/boot/boot.hpp"

#include <multiboot2/information.hpp>

#include <atomic>

// extern "C" teachos::arch::asm_pointer<multiboot2::information_view> multiboot_information_pointer;

namespace teachos::arch::memory
{
  namespace
  {
    auto constinit is_initialized = std::atomic_flag{};

    // auto create_memory_information() -> x86_64::memory::region_allocator::memory_information {

    // };
  }  // namespace

  auto init() -> void
  {
    if (is_initialized.test_and_set())
    {
      teachos::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.");
    }

    // auto mem_info = x86_64::memory::region_allocator::memory_information{};
    // auto allocator = x86_64::memory::region_allocator{mem_info};

    // kernel::cpu::set_cr0_bit(kernel::cpu::cr0_flags::WRITE_PROTECT);
    // kernel::cpu::set_efer_bit(kernel::cpu::efer_flags::NXE);

    // paging::kernel_mapper kernel(allocator, memory_information);
    // kernel.remap_kernel();
    // video::vga::text::write("Kernel remapping successful", video::vga::text::common_attributes::green_on_black);
    // video::vga::text::newline();

    // remap_heap(heap::KERNEL_HEAP_START, heap::KERNEL_HEAP_SIZE);
    // video::vga::text::write("Heap remapping successful", video::vga::text::common_attributes::green_on_black);
    // video::vga::text::newline();
  }

}  // namespace teachos::arch::memory