pub fn virtual_to_physical(virtual_address: usize) -> usize {
	let mut page_bits: usize = 39;

	// A self-reference enables direct access to all page tables
	safe_global_var!(static SELF: [usize; 4] = {
		[
			0xFFFFFF8000000000usize,
			0xFFFFFFFFC0000000usize,
			0xFFFFFFFFFFE00000usize,
			0xFFFFFFFFFFFFF000usize,
		]
	});

	for i in (0..3).rev() {
		page_bits = page_bits - PAGE_MAP_BITS;

		let vpn = (virtual_address >> page_bits) as isize;
		let ptr = SELF[i] as *const usize;
		let entry = unsafe { *ptr.offset(vpn) };

		if entry & PageTableEntryFlags::HUGE_PAGE.bits() != 0 || i == 0 {
			let off = virtual_address
				& !(((!0usize) << page_bits) & !PageTableEntryFlags::EXECUTE_DISABLE.bits());
			let phys =
				entry & (((!0usize) << page_bits) & !PageTableEntryFlags::EXECUTE_DISABLE.bits() & /* exclude pkey */ !(0xF << 59));

			return off | phys;
		}
	}

	panic!("virtual_to_physical should never reach this point");
}
/// Translate a virtual memory address to a physical one.
Translate a virtual memory address to a physical one.
Translate a virtual memory address to a physical one .
pub fn virtual_to_physical(virtual_address: usize) -> usize {
	let mut page_bits: usize = 39;
	// A self-reference enables direct access to all page tables
	safe_global_var!(static SELF: [usize; 4] = {
		[
			0xFFFFFF8000000000usize,
			0xFFFFFFFFC0000000usize,
			0xFFFFFFFFFFE00000usize,
			0xFFFFFFFFFFFFF000usize,
		]
	});
	for i in (0..3).rev() {
		page_bits = page_bits - PAGE_MAP_BITS;
		let vpn = (virtual_address >> page_bits) as isize;
		let ptr = SELF[i] as *const usize;
		let entry = unsafe { *ptr.offset(vpn) };
		if entry & PageTableEntryFlags::HUGE_PAGE.bits() != 0 || i == 0 {
			let off = virtual_address
				& !(((!0usize) << page_bits) & !PageTableEntryFlags::EXECUTE_DISABLE.bits());
			let phys =
				entry & (((!0usize) << page_bits) & !PageTableEntryFlags::EXECUTE_DISABLE.bits() & /* exclude pkey */ !(0xF << 59));
			return off | phys;
		}
	}
	panic!("virtual_to_physical should never reach this point");
}
pub fn virtual_to_physical ( virtual_address : usize ) -> usize { let mut page_bits : usize = 39 ; // A self-reference enables direct access to all page tables safe_global_var ! ( static SELF [ usize 4 ] { [ 0xFFFFFF8000000000usize 0xFFFFFFFFC0000000usize 0xFFFFFFFFFFE00000usize 0xFFFFFFFFFFFFF000usize ] } ) ; for i in ( 0 .. 3 ) . rev ( ) { page_bits = page_bits - PAGE_MAP_BITS ; let vpn = ( virtual_address >> page_bits ) as isize ; let ptr = SELF [ i ] as * const usize ; let entry = unsafe { * ptr . offset ( vpn ) } ; if entry & PageTableEntryFlags :: HUGE_PAGE . bits ( ) != 0 || i == 0 { let off = virtual_address & ! ( ( ( ! 0usize ) << page_bits ) & ! PageTableEntryFlags :: EXECUTE_DISABLE . bits ( ) ) ; let phys = entry & ( ( ( ! 0usize ) << page_bits ) & ! PageTableEntryFlags :: EXECUTE_DISABLE . bits ( ) & /* exclude pkey */ ! ( 0xF << 59 ) ) ; return off | phys ; } } panic ! ( " " ) ; }
Translate a virtual memory address to a physical one.
Translate a virtual memory address to a physical one .
virtual_address
usize
virtual_address
usize