aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelix Morgner <felix.morgner@ost.ch>2025-12-04 22:52:35 +0100
committerFelix Morgner <felix.morgner@ost.ch>2025-12-04 22:52:35 +0100
commit36cd516c84cf2edd16defcd39e99e2bee0bca892 (patch)
tree26051179b454fbf95cf045858d685379182eb9eb
parentfc26187d9ace9798d9494341f3513eb0840b006d (diff)
downloadteachos-36cd516c84cf2edd16defcd39e99e2bee0bca892.tar.xz
teachos-36cd516c84cf2edd16defcd39e99e2bee0bca892.zip
x86_64/memory: simplify initialization implementation
-rw-r--r--arch/x86_64/src/kapi/memory.cpp27
1 files changed, 14 insertions, 13 deletions
diff --git a/arch/x86_64/src/kapi/memory.cpp b/arch/x86_64/src/kapi/memory.cpp
index 0e4b78e..d09a4c1 100644
--- a/arch/x86_64/src/kapi/memory.cpp
+++ b/arch/x86_64/src/kapi/memory.cpp
@@ -30,18 +30,7 @@ namespace teachos::memory
constexpr auto static unused_page_address = linear_address{0x0000'7fff'cafe'faceuz};
constexpr auto static recursive_page_map_index = x86_64::page_table::entry_count - 2;
- auto create_memory_information() -> x86_64::region_allocator::memory_information
- {
- auto const & mbi = boot::bootstrap_information.mbi;
- auto mbi_span = std::span{std::bit_cast<std::byte *>(mbi), mbi->size_bytes()};
- auto image_span = std::span{&boot::x86_64::_start_physical, &boot::x86_64::_end_physical};
-
- return {.image_range =
- std::make_pair(physical_address{&image_span.front()}, physical_address{&image_span.back()}),
- .mbi_range = std::make_pair(physical_address{&mbi_span.front()}, physical_address{&mbi_span.back()}),
- .memory_map = mbi->memory_map()};
- };
-
+ //! Instantiate a basic, memory region based, early frame allocator for remapping.
auto create_early_frame_allocator()
{
auto memory_map = boot::bootstrap_information.mbi->maybe_memory_map();
@@ -50,15 +39,27 @@ namespace teachos::memory
system::panic("[x86_64] Failed to create early allocator, no memory map available.");
}
- return x86_64::region_allocator{create_memory_information()};
+ auto const & mbi = boot::bootstrap_information.mbi;
+ auto mbi_span = std::span{std::bit_cast<std::byte *>(mbi), mbi->size_bytes()};
+ auto image_span = std::span{&boot::x86_64::_start_physical, &boot::x86_64::_end_physical};
+
+ return x86_64::region_allocator{
+ {
+ .image_range = std::make_pair(physical_address{&image_span.front()}, physical_address{&image_span.back()}),
+ .mbi_range = std::make_pair(physical_address{&mbi_span.front()}, physical_address{&mbi_span.back()}),
+ .memory_map = *memory_map,
+ }
+ };
}
+ //! Enable additional CPU protection features, required during later stages of the kernel.
auto enable_cpu_protections() -> void
{
cpu::x86_64::cr0::set(cpu::x86_64::cr0::flags::write_protect);
cpu::x86_64::i32_efer::set(cpu::x86_64::i32_efer::flags::execute_disable_bit_enable);
}
+ //! Inject, or graft, a faux recursive PML4 into the active page mapping structure.
auto inject_faux_pml4(frame_allocator & allocator) -> void
{
using namespace x86_64;