aboutsummaryrefslogtreecommitdiff
path: root/arch/x86_64/include
diff options
context:
space:
mode:
Diffstat (limited to 'arch/x86_64/include')
-rw-r--r--arch/x86_64/include/arch/memory/allocator/tiny_frame_allocator.hpp19
-rw-r--r--arch/x86_64/include/arch/memory/paging/active_page_table.hpp2
-rw-r--r--arch/x86_64/include/arch/memory/paging/kernel_mapper.hpp30
-rw-r--r--arch/x86_64/include/arch/memory/paging/temporary_page.hpp7
4 files changed, 36 insertions, 22 deletions
diff --git a/arch/x86_64/include/arch/memory/allocator/tiny_frame_allocator.hpp b/arch/x86_64/include/arch/memory/allocator/tiny_frame_allocator.hpp
index e55b376..b8ed506 100644
--- a/arch/x86_64/include/arch/memory/allocator/tiny_frame_allocator.hpp
+++ b/arch/x86_64/include/arch/memory/allocator/tiny_frame_allocator.hpp
@@ -9,6 +9,11 @@
namespace teachos::arch::memory::allocator
{
+ namespace
+ {
+ uint8_t constexpr TINY_ALLOCATOR_FRAMES_COUNT = 3U;
+ }
+
/**
* @brief Allocates memory using memory areas read from the multiboot2 information pointer.
*/
@@ -23,9 +28,16 @@ namespace teachos::arch::memory::allocator
* entries *when a new page table is required.
*/
tiny_frame_allocator(area_frame_allocator & allocator)
- : frames{allocator.allocate_frame(), allocator.allocate_frame(), allocator.allocate_frame()}
+ : frames{}
{
- // Nothing to do
+ for (auto & frame : frames)
+ {
+ auto allocated = allocator.allocate_frame();
+ if (allocated.has_value())
+ {
+ frame.emplace(allocated.value());
+ }
+ }
}
/**
@@ -47,7 +59,8 @@ namespace teachos::arch::memory::allocator
auto deallocate_frame(physical_frame physical_frame) -> void;
private:
- std::array<std::optional<physical_frame>, 3U> frames = {};
+ std::array<std::optional<physical_frame>, TINY_ALLOCATOR_FRAMES_COUNT> frames =
+ {}; ///< Container that holds the frames allocated by another allocator.
};
} // namespace teachos::arch::memory::allocator
diff --git a/arch/x86_64/include/arch/memory/paging/active_page_table.hpp b/arch/x86_64/include/arch/memory/paging/active_page_table.hpp
index 71f70b5..5140c3d 100644
--- a/arch/x86_64/include/arch/memory/paging/active_page_table.hpp
+++ b/arch/x86_64/include/arch/memory/paging/active_page_table.hpp
@@ -128,7 +128,7 @@ namespace teachos::arch::memory::paging
"[Page Mapper] Attempted to unmap page, which has not been mapped previously");
auto current_handle = active_handle;
- std::array<page_table_handle, 4U> handles{current_handle, current_handle, current_handle, current_handle};
+ std::array<page_table_handle, 3U> handles{current_handle, current_handle, current_handle};
for (auto level = page_table_handle::LEVEL4; level != page_table_handle::LEVEL1; --level)
{
diff --git a/arch/x86_64/include/arch/memory/paging/kernel_mapper.hpp b/arch/x86_64/include/arch/memory/paging/kernel_mapper.hpp
index 5ee4ea8..a7ae3aa 100644
--- a/arch/x86_64/include/arch/memory/paging/kernel_mapper.hpp
+++ b/arch/x86_64/include/arch/memory/paging/kernel_mapper.hpp
@@ -16,21 +16,16 @@ namespace teachos::arch::memory::paging
/**
* @brief Kernel mapper that allows to remap the kernel elf sections in C++.
- *
- * @tparam T Contract the allocator that should be used to allocate frames for the remapping process has to fulfill.
*/
- template<allocator::FrameAllocator T>
struct kernel_mapper
{
/**
* @brief Constructor.
*
- * @param allocator Allocator that should be used to allocate frames for the remapping process.
* @param mem_info Information about elf kernel sections required for remapping process.
*/
- kernel_mapper(T & allocator, multiboot::memory_information const & mem_info)
- : allocator(allocator)
- , mem_info(mem_info)
+ kernel_mapper(multiboot::memory_information const & mem_info)
+ : mem_info(mem_info)
{
// Nothing to do
}
@@ -42,16 +37,22 @@ namespace teachos::arch::memory::paging
* @note We have to use a workaround with an
* inactive page table, that is not used by the CPU to ensure we are not changign memory that we are using. Because
* remapping active kernel memory in the kernel wouldn't work.
+ *
+ * @tparam T Contract the allocator that should be used to allocate frames for the remapping process has to fulfill.
+ *
+ * @param allocator Allocator that should be used to allocate frames for the remapping process.
*/
- auto remap_kernel() -> void
+ template<allocator::FrameAllocator T>
+ auto remap_kernel(T & allocator) -> void
{
- temporary_page temp_page{virtual_page{UNUSED_VIRTUAL_ADDRESS}, allocator};
+ virtual_page temporary_address{UNUSED_VIRTUAL_ADDRESS};
+ temporary_page temporary_page{temporary_address, allocator};
auto & active_table = active_page_table::create_or_get();
auto const frame = allocator.allocate_frame();
exception_handling::assert(frame.has_value(),
"[Kernel Mapper] Frame could not be allocated and therefore kernel not mapped");
- auto const inactive_table = inactive_page_table{frame.value(), active_table, temp_page};
- remap_elf_kernel_sections(inactive_table, temp_page, active_table);
+ inactive_page_table inactive_table{frame.value(), active_table, temporary_page};
+ remap_elf_kernel_sections(inactive_table, temporary_page, active_table);
}
private:
@@ -79,7 +80,7 @@ namespace teachos::arch::memory::paging
active_table.active_handle[511].set_entry(inactive_table.page_table_level_4_frame,
entry::PRESENT | entry::WRITABLE);
tlb_flush_all();
- map_elf_kernel_sections(active_table);
+ map_elf_kernel_sections(temporary_page, active_table);
page_table_level4[511].set_entry(backup, entry::PRESENT | entry::WRITABLE);
tlb_flush_all();
@@ -93,7 +94,7 @@ namespace teachos::arch::memory::paging
* @param active_table Active level 4 page table that should be used to map the required elf sections into entries.
* Has had its recursive mapping temporarily replaced and points to unmapped place in memory.
*/
- auto map_elf_kernel_sections(active_page_table & active_table) -> void
+ auto map_elf_kernel_sections(temporary_page & temporary_page, active_page_table & active_table) -> void
{
for (auto const & section : mem_info.sections)
{
@@ -114,12 +115,11 @@ namespace teachos::arch::memory::paging
for (auto const & frame : frames)
{
// TODO: Use actual elf section flags, convert from one to the other flag type.
- active_table.identity_map(allocator, frame, entry::WRITABLE);
+ active_table.identity_map(temporary_page.allocator, frame, entry::WRITABLE);
}
}
}
- T & allocator; ///< Allocator that should be used to allocate frames for the mapping process.
multiboot::memory_information const &
mem_info; ///< Information about elf kernel sections required for remapping process.
};
diff --git a/arch/x86_64/include/arch/memory/paging/temporary_page.hpp b/arch/x86_64/include/arch/memory/paging/temporary_page.hpp
index 0cadc29..6b3bcb6 100644
--- a/arch/x86_64/include/arch/memory/paging/temporary_page.hpp
+++ b/arch/x86_64/include/arch/memory/paging/temporary_page.hpp
@@ -51,6 +51,10 @@ namespace teachos::arch::memory::paging
*/
auto map_table_frame(allocator::physical_frame frame, active_page_table & active_table) -> page_table_handle;
+ // TODO: Better way to do this?
+ virtual_page page;
+ allocator::tiny_frame_allocator allocator;
+
private:
/**
* @brief Map the temporary page to a frame.
@@ -60,9 +64,6 @@ namespace teachos::arch::memory::paging
* @return The virtual address of the page.
*/
auto map_to_frame(allocator::physical_frame frame, active_page_table & active_table) -> virtual_address;
-
- virtual_page page;
- allocator::tiny_frame_allocator allocator;
};
} // namespace teachos::arch::memory::paging