diff options
| author | Felix Morgner <felix.morgner@ost.ch> | 2025-10-29 11:58:12 +0100 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@ost.ch> | 2025-10-29 11:58:12 +0100 |
| commit | f5aee1e1ab521d6aeb4c79f6ef276625159e202f (patch) | |
| tree | 34e35f7e8e1db2eafba0794899329feafcd8cb91 | |
| parent | c71d18f32e06fb456bc2829d9dfc5b42b78160b0 (diff) | |
| download | teachos-f5aee1e1ab521d6aeb4c79f6ef276625159e202f.tar.xz teachos-f5aee1e1ab521d6aeb4c79f6ef276625159e202f.zip | |
x86_64: extract early boot steps
| -rw-r--r-- | arch/x86_64/src/kapi/memory.cpp | 33 |
1 files changed, 19 insertions, 14 deletions
diff --git a/arch/x86_64/src/kapi/memory.cpp b/arch/x86_64/src/kapi/memory.cpp index 46686b6..a29a0cd 100644 --- a/arch/x86_64/src/kapi/memory.cpp +++ b/arch/x86_64/src/kapi/memory.cpp @@ -33,6 +33,23 @@ namespace teachos::memory physical_address{std::bit_cast<std::byte *>(&mbi) + mbi->size_bytes()}), map}; }; + + auto create_early_frame_allocator() + { + auto memory_map = boot::x86_64::multiboot_information_pointer->maybe_memory_map(); + if (!memory_map) + { + system::panic("[x86_64] Failed to create early allocator, no memory map available."); + } + + return x86_64::region_allocator{create_memory_information()}; + } + + auto enable_cpu_protections() -> void + { + cpu::x86_64::set_cr0_bit(cpu::x86_64::cr0_flags::WRITE_PROTECT); + // set_efer_bit(efer_flags::NXE); + } } // namespace auto active_allocator() -> frame_allocator & @@ -52,20 +69,8 @@ namespace teachos::memory system::panic("[x86_64] Memory management has already been initialized."); } - auto memory_map = boot::x86_64::multiboot_information_pointer->maybe_memory_map(); - if (!memory_map) - { - system::panic("[x86_64] No memory map available."); - } - - auto mem_info = create_memory_information(); - auto allocator = x86_64::region_allocator{mem_info}; - - static_cast<void>(allocator); - - cpu::x86_64::set_cr0_bit(cpu::x86_64::cr0_flags::WRITE_PROTECT); - - // set_efer_bit(efer_flags::NXE); + [[maybe_unused]] auto allocator = create_early_frame_allocator(); + enable_cpu_protections(); // paging::kernel_mapper kernel(allocator, memory_information); // kernel.remap_kernel(); |
