use ax_memory_addr::{PAGE_SIZE_4K, PhysAddr, VirtAddr};
use ax_page_table_multiarch::PagingHandler;
use crate::host::{HostMemory, default_host};
pub struct HostPagingHandler;
impl PagingHandler for HostPagingHandler {
fn alloc_frames(num: usize, align: usize) -> Option<PhysAddr> {
if !align.is_multiple_of(PAGE_SIZE_4K) {
panic!("align must be multiple of PAGE_SIZE_4K")
}
if !align.is_power_of_two() {
panic!("align must be a power of 2")
}
default_host().alloc_contiguous_frames(num, align)
}
fn dealloc_frames(paddr: PhysAddr, num: usize) {
default_host().dealloc_contiguous_frames(paddr, num);
}
fn alloc_frame() -> Option<PhysAddr> {
default_host().alloc_frame()
}
fn dealloc_frame(paddr: PhysAddr) {
default_host().dealloc_frame(paddr)
}
fn phys_to_virt(paddr: PhysAddr) -> VirtAddr {
default_host().phys_to_virt(paddr)
}
}
pub(crate) fn virt_to_phys(vaddr: VirtAddr) -> PhysAddr {
default_host().virt_to_phys(vaddr)
}