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/x86_64/memory/kernel_mapper.hpp5
-rw-r--r--arch/x86_64/include/x86_64/memory/page_table.hpp65
-rw-r--r--arch/x86_64/include/x86_64/memory/paging_root.hpp9
-rw-r--r--arch/x86_64/include/x86_64/memory/recursive_page_mapper.hpp23
-rw-r--r--arch/x86_64/include/x86_64/memory/scoped_mapping.hpp9
5 files changed, 98 insertions, 13 deletions
diff --git a/arch/x86_64/include/x86_64/memory/kernel_mapper.hpp b/arch/x86_64/include/x86_64/memory/kernel_mapper.hpp
index 4b681ae..1f217ae 100644
--- a/arch/x86_64/include/x86_64/memory/kernel_mapper.hpp
+++ b/arch/x86_64/include/x86_64/memory/kernel_mapper.hpp
@@ -1,8 +1,6 @@
#ifndef TEACHOS_X86_64_KERNEL_MAPPER_HPP
#define TEACHOS_X86_64_KERNEL_MAPPER_HPP
-#include "kapi/memory.hpp"
-
#include <elf/format.hpp>
#include <elf/section_header.hpp>
#include <multiboot2/information.hpp>
@@ -16,14 +14,13 @@ namespace teachos::memory::x86_64
{
using section_header_type = elf::section_header<elf::format::elf64>;
- kernel_mapper(frame_allocator & allocator, multiboot2::information_view const * mbi);
+ explicit kernel_mapper(multiboot2::information_view const * mbi);
auto remap_kernel() -> void;
private:
auto map_section(section_header_type const & section, std::string_view name) -> void;
- frame_allocator * m_allocator;
multiboot2::information_view const * m_mbi;
std::uintptr_t m_kernel_load_base;
};
diff --git a/arch/x86_64/include/x86_64/memory/page_table.hpp b/arch/x86_64/include/x86_64/memory/page_table.hpp
index 22616e8..6a9c045 100644
--- a/arch/x86_64/include/x86_64/memory/page_table.hpp
+++ b/arch/x86_64/include/x86_64/memory/page_table.hpp
@@ -146,4 +146,69 @@ namespace kstd::ext
};
} // namespace kstd::ext
+namespace teachos::memory::x86_64
+{
+
+ constexpr auto to_mapper_flags(page_table::entry::flags flags) -> page_mapper::flags
+ {
+ using table_flags = page_table::entry::flags;
+ using mapper_flags = page_mapper::flags;
+
+ auto result = mapper_flags{};
+
+ if ((flags & table_flags::no_execute) == table_flags::empty)
+ {
+ result |= mapper_flags::executable;
+ }
+
+ if ((flags & table_flags::writable) != table_flags::empty)
+ {
+ result |= mapper_flags::writable;
+ }
+
+ if ((flags & table_flags::disable_cache) != table_flags::empty)
+ {
+ result |= mapper_flags::uncached;
+ }
+
+ if ((flags & table_flags::user_accessible) == table_flags::empty)
+ {
+ result |= mapper_flags::supervisor;
+ }
+
+ return result;
+ }
+
+ constexpr auto to_table_flags(page_mapper::flags flags) -> page_table::entry::flags
+ {
+ using table_flags = page_table::entry::flags;
+ using mapper_flags = page_mapper::flags;
+
+ auto result = table_flags{};
+
+ if ((flags & mapper_flags::executable) == mapper_flags::empty)
+ {
+ result |= table_flags::no_execute;
+ }
+
+ if ((flags & mapper_flags::writable) != mapper_flags::empty)
+ {
+ result |= table_flags::writable;
+ }
+
+ if ((flags & mapper_flags::uncached) != mapper_flags::empty)
+ {
+ result |= table_flags::disable_cache;
+ }
+
+ if ((flags & mapper_flags::supervisor) != mapper_flags::empty)
+ {
+ result |= table_flags::user_accessible;
+ }
+
+ return result;
+ }
+
+} // namespace teachos::memory::x86_64
+
#endif \ No newline at end of file
diff --git a/arch/x86_64/include/x86_64/memory/paging_root.hpp b/arch/x86_64/include/x86_64/memory/paging_root.hpp
index d4aa023..ed95106 100644
--- a/arch/x86_64/include/x86_64/memory/paging_root.hpp
+++ b/arch/x86_64/include/x86_64/memory/paging_root.hpp
@@ -30,8 +30,13 @@ namespace teachos::memory::x86_64
//! @param page A page to map.
//! @param frame The frame into which to map the page.
//! @param flags The flags to apply to the mapping.
- //! @param allocator The frame allocator used to allocate any required page tables.
- auto map(page page, frame frame, entry::flags flags, frame_allocator & allocator) -> std::optional<std::byte *>;
+ auto map(page page, frame frame, entry::flags flags) -> std::optional<std::byte *>;
+
+ //! Unmap the given page from virtual memory.
+ //!
+ //! @warning If the page has not previously been mapped, this function will panic.
+ //! @param page The page to unmap
+ auto unmap(page) -> void;
private:
paging_root() = default;
diff --git a/arch/x86_64/include/x86_64/memory/recursive_page_mapper.hpp b/arch/x86_64/include/x86_64/memory/recursive_page_mapper.hpp
new file mode 100644
index 0000000..a66c8d1
--- /dev/null
+++ b/arch/x86_64/include/x86_64/memory/recursive_page_mapper.hpp
@@ -0,0 +1,23 @@
+#ifndef TEACHOS_X86_64_RECURSIVE_PAGE_MAPPER_HPP
+#define TEACHOS_X86_64_RECURSIVE_PAGE_MAPPER_HPP
+
+#include "kapi/memory.hpp"
+
+namespace teachos::memory::x86_64
+{
+
+ struct recursive_page_mapper : page_mapper
+ {
+ explicit recursive_page_mapper(frame_allocator & allocator);
+
+ auto map(page page, frame frame, flags flags) -> std::byte * override;
+ auto unmap(page page) -> void override;
+ auto try_unmap(page page) -> bool override;
+
+ private:
+ frame_allocator * m_allocator;
+ };
+
+} // namespace teachos::memory::x86_64
+
+#endif \ No newline at end of file
diff --git a/arch/x86_64/include/x86_64/memory/scoped_mapping.hpp b/arch/x86_64/include/x86_64/memory/scoped_mapping.hpp
index d4844fb..415ea8e 100644
--- a/arch/x86_64/include/x86_64/memory/scoped_mapping.hpp
+++ b/arch/x86_64/include/x86_64/memory/scoped_mapping.hpp
@@ -22,8 +22,7 @@ namespace teachos::memory::x86_64
//! Construct a new scoped mapping, which can be used to map a frame to the given unused page.
//! @param page An unused page. If the page is already mapped, this constructor will panic.
- //! @param allocator An allocator to be used to allocate any page maps required to map the frame.
- scoped_mapping(page page, frame_allocator & allocator);
+ explicit scoped_mapping(page page);
//! Unmap the mapped frame if one was mapped.
//! @note Any page tables that were allocated to support the mapping will be released.
@@ -53,17 +52,13 @@ namespace teachos::memory::x86_64
//! @note If no frame was ever mapped, this function will panic.
auto unmap() -> void;
- auto swap(scoped_mapping & other) -> void;
+ friend auto swap(scoped_mapping & lhs, scoped_mapping & rhs) -> void;
private:
page m_page;
- frame_allocator * m_allocator;
bool m_mapped;
- std::uint8_t m_allocated;
};
- auto swap(scoped_mapping & lhs, scoped_mapping & rhs) -> void;
-
} // namespace teachos::memory::x86_64
#endif \ No newline at end of file