aboutsummaryrefslogtreecommitdiff
path: root/arch/x86_64
diff options
context:
space:
mode:
Diffstat (limited to 'arch/x86_64')
-rw-r--r--arch/x86_64/include/arch/memory/page_table.hpp10
-rw-r--r--arch/x86_64/include/arch/memory/recursive_page_mapper.hpp5
-rw-r--r--arch/x86_64/kapi/memory.cpp10
-rw-r--r--arch/x86_64/src/memory/recursive_page_mapper.cpp18
4 files changed, 25 insertions, 18 deletions
diff --git a/arch/x86_64/include/arch/memory/page_table.hpp b/arch/x86_64/include/arch/memory/page_table.hpp
index a82d9e0..003dbf3 100644
--- a/arch/x86_64/include/arch/memory/page_table.hpp
+++ b/arch/x86_64/include/arch/memory/page_table.hpp
@@ -304,6 +304,11 @@ namespace arch::memory
result |= mapper_flags::supervisor_only;
}
+ if ((flags & table_flags::global) != table_flags::empty)
+ {
+ result |= mapper_flags::global;
+ }
+
return result;
}
@@ -334,6 +339,11 @@ namespace arch::memory
result |= table_flags::user_accessible;
}
+ if ((flags & mapper_flags::global) != mapper_flags::empty)
+ {
+ result |= table_flags::global;
+ }
+
return result;
}
diff --git a/arch/x86_64/include/arch/memory/recursive_page_mapper.hpp b/arch/x86_64/include/arch/memory/recursive_page_mapper.hpp
index e278a6d..a0c290a 100644
--- a/arch/x86_64/include/arch/memory/recursive_page_mapper.hpp
+++ b/arch/x86_64/include/arch/memory/recursive_page_mapper.hpp
@@ -10,14 +10,11 @@ namespace arch::memory
struct recursive_page_mapper : kapi::memory::page_mapper
{
- explicit recursive_page_mapper(kapi::memory::frame_allocator & allocator);
+ explicit recursive_page_mapper();
auto map(kapi::memory::page page, kapi::memory::frame frame, flags flags) -> std::byte * override;
auto unmap(kapi::memory::page page) -> void override;
auto try_unmap(kapi::memory::page page) noexcept -> bool override;
-
- private:
- kapi::memory::frame_allocator * m_allocator;
};
} // namespace arch::memory
diff --git a/arch/x86_64/kapi/memory.cpp b/arch/x86_64/kapi/memory.cpp
index 48aab9f..e704408 100644
--- a/arch/x86_64/kapi/memory.cpp
+++ b/arch/x86_64/kapi/memory.cpp
@@ -189,7 +189,7 @@ namespace kapi::memory
auto mbi_size = boot::bootstrap_information.mbi->size_bytes();
auto mbi_address = physical_address{mbi_base & ~std::bit_cast<std::uintptr_t>(&arch::boot::TEACHOS_VMA)};
auto mbi_start = frame::containing(mbi_address);
- auto mbi_end = frame::containing(physical_address{mbi_address.raw() + mbi_size}) + 1;
+ auto mbi_end = frame::containing(mbi_address + mbi_size) + 1;
std::ranges::for_each(std::views::iota(mbi_start, mbi_end), [&](auto frame) { new_allocator.mark_used(frame); });
}
@@ -211,7 +211,10 @@ namespace kapi::memory
region_based_allocator.emplace(collect_memory_information());
allocation_buffer.emplace(&*region_based_allocator);
- recursive_page_mapper.emplace(*allocation_buffer);
+ set_frame_allocator(*allocation_buffer);
+
+ recursive_page_mapper.emplace();
+ set_page_mapper(*recursive_page_mapper);
kstd::println("[x86_64:MEM] Preparing new paging hierarchy.");
@@ -227,9 +230,6 @@ namespace kapi::memory
cr3.frame(new_pml4_frame);
arch::cpu::cr3::write(cr3);
- set_frame_allocator(*allocation_buffer);
- set_page_mapper(*recursive_page_mapper);
-
auto memory_map = boot::bootstrap_information.mbi->memory_map();
auto highest_byte = std::ranges::max(std::views::transform(
std::views::filter(memory_map.regions(),
diff --git a/arch/x86_64/src/memory/recursive_page_mapper.cpp b/arch/x86_64/src/memory/recursive_page_mapper.cpp
index d8273e1..c7c5341 100644
--- a/arch/x86_64/src/memory/recursive_page_mapper.cpp
+++ b/arch/x86_64/src/memory/recursive_page_mapper.cpp
@@ -56,18 +56,17 @@ namespace arch::memory
} // namespace
- recursive_page_mapper::recursive_page_mapper(kapi::memory::frame_allocator & allocator)
- : m_allocator{&allocator}
- {}
+ recursive_page_mapper::recursive_page_mapper() {}
auto recursive_page_mapper::map(kapi::memory::page page, kapi::memory::frame frame, flags flags) -> std::byte *
{
auto pml4 = static_cast<recursive_page_table<4> *>((paging_root::get()));
+ auto & allocator = kapi::memory::get_frame_allocator();
return std::optional{pml4}
- .and_then([&](auto pml) -> auto { return do_map(pml, page, *m_allocator, flags); })
- .and_then([&](auto pml) -> auto { return do_map(pml, page, *m_allocator, flags); })
- .and_then([&](auto pml) -> auto { return do_map(pml, page, *m_allocator, flags); })
+ .and_then([&](auto pml) -> auto { return do_map(pml, page, allocator, flags); })
+ .and_then([&](auto pml) -> auto { return do_map(pml, page, allocator, flags); })
+ .and_then([&](auto pml) -> auto { return do_map(pml, page, allocator, flags); })
.and_then([&](auto pml) -> auto { return do_map(pml, page, frame, flags); })
.value_or(nullptr);
}
@@ -91,27 +90,28 @@ namespace arch::memory
auto pml3 = pml4->next(pml_index<4>(page)).value();
auto pml2 = pml3->next(pml_index<3>(page)).value();
auto pml1 = pml2->next(pml_index<2>(page)).value();
+ auto & allocator = kapi::memory::get_frame_allocator();
(*pml1)[pml_index<1>(page)].clear();
if (pml1->empty())
{
auto pml1_frame = (*pml2)[pml_index<2>(page)].frame().value();
- m_allocator->release(pml1_frame);
+ allocator.release(pml1_frame);
(*pml2)[pml_index<2>(page)].clear();
}
if (pml2->empty())
{
auto pml2_frame = (*pml3)[pml_index<3>(page)].frame().value();
- m_allocator->release(pml2_frame);
+ allocator.release(pml2_frame);
(*pml3)[pml_index<3>(page)].clear();
}
if (pml3->empty())
{
auto pml3_frame = (*pml4)[pml_index<4>(page)].frame().value();
- m_allocator->release(pml3_frame);
+ allocator.release(pml3_frame);
(*pml4)[pml_index<4>(page)].clear();
}