diff --git a/src/arch/x86_64/memory/paging/entry.rs b/src/arch/x86_64/memory/paging/entry.rs index 35b6c21..dd12856 100644 --- a/src/arch/x86_64/memory/paging/entry.rs +++ b/src/arch/x86_64/memory/paging/entry.rs @@ -1,5 +1,6 @@ //! Page table entry (meta)data +use multiboot2::ElfSection; use arch::x86_64::memory::Frame; pub struct Entry(u64); @@ -50,3 +51,24 @@ bitflags! { const NO_EXECUTE = 1 << 63; } } + +impl EntryFlags { + pub fn from_elf_section_flags(section: &ElfSection) -> EntryFlags { + use multiboot2::{ELF_SECTION_ALLOCATED, ELF_SECTION_WRITABLE, + ELF_SECTION_EXECUTABLE}; + + let mut flags = EntryFlags::empty(); + + if section.flags().contains(ELF_SECTION_ALLOCATED) { + flags = flags | PRESENT; + } + if section.flags().contains(ELF_SECTION_WRITABLE) { + flags = flags | WRITABLE; + } + if !section.flags().contains(ELF_SECTION_EXECUTABLE) { + flags = flags | NO_EXECUTE; + } + + flags + } +}