aboutsummaryrefslogtreecommitdiff
path: root/arch
diff options
context:
space:
mode:
Diffstat (limited to 'arch')
-rw-r--r--arch/x86_64/include/arch/memory/paging/kernel_mapper.hpp4
-rw-r--r--arch/x86_64/include/arch/memory/paging/page_entry.hpp20
-rw-r--r--arch/x86_64/src/memory/paging/page_entry.cpp22
3 files changed, 43 insertions, 3 deletions
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 f30ca24..54ec682 100644
--- a/arch/x86_64/include/arch/memory/paging/kernel_mapper.hpp
+++ b/arch/x86_64/include/arch/memory/paging/kernel_mapper.hpp
@@ -116,11 +116,11 @@ namespace teachos::arch::memory::paging
allocator::physical_frame_iterator const begin{start_frame};
allocator::physical_frame_iterator const end{end_frame};
frame_container frames{begin, end};
+ entry entry{section.flags};
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(allocator, frame, entry.get_flags());
}
}
}
diff --git a/arch/x86_64/include/arch/memory/paging/page_entry.hpp b/arch/x86_64/include/arch/memory/paging/page_entry.hpp
index 5959801..ab9659d 100644
--- a/arch/x86_64/include/arch/memory/paging/page_entry.hpp
+++ b/arch/x86_64/include/arch/memory/paging/page_entry.hpp
@@ -2,6 +2,7 @@
#define TEACHOS_ARCH_X86_64_MEMORY_PAGING_PAGE_ENTRY_HPP
#include "arch/memory/allocator/physical_frame.hpp"
+#include "arch/memory/multiboot/elf_symbols_section.hpp"
#include <bitset>
#include <optional>
@@ -48,6 +49,18 @@ namespace teachos::arch::memory::paging
explicit entry(uint64_t flags);
/**
+ * @brief Converts the given elf section flags into the corresponding correct entry flags.
+ *
+ * @note Enables us to set the correct flags on a entry depending on which elf section it is contained in. For
+ * example entries of .text sections should be executable and read only or entries of .data sections should be
+ * writable but not executable.
+ *
+ * @param elf_flags Elf section flags we want to convert into entry flags.
+ * @return Entry that has the corresponding bit flags set.
+ */
+ explicit entry(multiboot::elf_section_flags elf_flags);
+
+ /**
* @brief Whether the current page is unused, meaning the underlying std::bitset is 0.
*
* @return Current page is in memory.
@@ -86,6 +99,13 @@ namespace teachos::arch::memory::paging
*/
auto contains_flags(std::bitset<64U> other) const -> bool;
+ /**
+ * @brief Extracts only the flags from the underlying entry and ignores all bits that contain the physical address.
+ *
+ * @return Extracted entry flags, without the physical address.
+ */
+ auto get_flags() -> std::bitset<64U>;
+
private:
std::bitset<64U> flags; ///< Underlying bitset used to read the flags from. Bits 9 - 11 and 52 - 62 can be
///< freely used for additional flags by the operating system.
diff --git a/arch/x86_64/src/memory/paging/page_entry.cpp b/arch/x86_64/src/memory/paging/page_entry.cpp
index 23c700f..5c4bc67 100644
--- a/arch/x86_64/src/memory/paging/page_entry.cpp
+++ b/arch/x86_64/src/memory/paging/page_entry.cpp
@@ -7,7 +7,8 @@ namespace teachos::arch::memory::paging
namespace
{
std::size_t constexpr PHYSICAL_ADDRESS_MASK = 0x000fffff'fffff000;
- }
+ std::size_t constexpr ENTRY_FLAGS_MASK = 0xfff00000'00000fff;
+ } // namespace
entry::entry(uint64_t flags)
: flags(flags)
@@ -15,6 +16,23 @@ namespace teachos::arch::memory::paging
// Nothing to do.
}
+ entry::entry(multiboot::elf_section_flags elf_flags)
+ {
+ if (elf_flags.contains_flags(multiboot::elf_section_flags::OCCUPIES_MEMORY))
+ {
+ flags = flags.to_ulong() | entry::PRESENT;
+ }
+ if (elf_flags.contains_flags(multiboot::elf_section_flags::WRITABLE))
+ {
+ flags = flags.to_ulong() | entry::WRITABLE;
+ }
+ if (!elf_flags.contains_flags(multiboot::elf_section_flags::EXECUTABLE_CODE))
+ {
+ // TODO: Ensure to set the NXE bit, if we don't using this entry flag causes crashes
+ // flags = flags.to_ulong() | entry::EXECUTING_CODE_FORBIDDEN;
+ }
+ }
+
auto entry::is_unused() const -> bool { return flags == 0U; }
auto entry::set_unused() -> void { flags = 0U; }
@@ -37,4 +55,6 @@ namespace teachos::arch::memory::paging
"[Paging Entry] Start address is not aligned with page");
flags = frame.start_address() | additional_flags.to_ulong();
}
+
+ auto entry::get_flags() -> std::bitset<64U> { return flags.to_ulong() & ENTRY_FLAGS_MASK; }
} // namespace teachos::arch::memory::paging