kernel/arch/x86_64/mm/vmm/paging/
helpers.rs1use super::super::page_type::PageType;
7use crate::lib::panic_codes::PanicCode;
8use crate::lib::panic::kernel_panic;
9use crate::state::kstate::KSTATE;
10use x86_64::structures::paging::page_table::PageTableEntry;
11use x86_64::structures::paging::{PageTable, PageTableFlags};
12
13pub fn misaligned_address_panic(align: PageType) -> ! {
15 kernel_panic(
16 PanicCode::InvalidPageOperation,
17 match align {
18 PageType::Normal => "Physical and/or virtual address is not aligned to 4 KiB",
19 PageType::HugePage2MiB => "Physical and/or virtual address is not aligned to 2 MiB",
20 PageType::HugePage1GiB => "Physical and/or virtual address is not aligned to 1 GiB"
21 }
22 );
23}
24
25pub fn is_present(entry: &PageTableEntry) -> bool {
27 entry.flags().contains(PageTableFlags::PRESENT)
28}
29
30pub fn is_huge_page(entry: &PageTableEntry) -> bool {
32 entry.flags().contains(PageTableFlags::HUGE_PAGE)
33}
34
35pub fn advance_current_pagetable(entry: &PageTableEntry) -> *mut PageTable {
37 (entry.frame().unwrap().start_address().as_u64() + KSTATE.mm.hhdm_offset()) as *mut PageTable
38}