mips_mcu/
fmt.rs

1//! Support for the Fixed Mapping Translation (FMT) of the MIPS M4K core
2
3use crate::PhysicalAddress;
4
5/// Convert a virtual to a physical address given as `usize` values
6#[inline(never)]
7fn virt_to_phys_usize(virt: usize) -> usize {
8    if virt >= 0x80000000usize {
9        virt & 0x1fff_ffff
10    } else {
11        virt + 0x4000_0000
12    }
13}
14
15/// Calculate a physical address for a raw pointer
16pub fn virt_to_phys<T>(ptr: *mut T) -> PhysicalAddress {
17    let virt: usize = ptr as usize;
18    PhysicalAddress {
19        addr: virt_to_phys_usize(virt),
20    }
21}