//! 页表定义

cfg_if::cfg_if! {
    if #[cfg(aarch64_moana)] {
        mod aarch64;
        use aarch64::{ARCH_PA_BITS, ARCH_PAGE_SIZE, ARCH_PAGE_SHIFT, ARCH_PAGE_PTRS, ARCH_PMD_SIZE, ARCH_PMD_SHIFT, ARCH_PMD_PTRS, ARCH_PUD_SIZE, ARCH_PUD_SHIFT, ARCH_PUD_PTRS, ARCH_PGD_SIZE, ARCH_PGD_SHIFT, ARCH_PGD_PTRS, ARCH_PGD_TYPE_TABLE, ARCH_PUD_TYPE_TABLE, ARCH_PMD_TYPE_TABLE, ARCH_PTE_TYPE_PAGE, ARCH_PMD_TYPE_SECT, ARCH_PAGE_NONE, ARCH_PAGE_READWRITE, ARCH_PAGE_READWRITE_EXEC, ARCH_PAGE_RDONLY, ARCH_PAGE_RDONLY_EXEC, ARCH_PAGE_EXECONLY, ARCH_DEVICE_NONE, ARCH_DEVICE_READWRITE, ARCH_DEVICE_RDONLY, ARCH_SECTION_PAGE_NONE, ARCH_SECTION_PAGE_READWRITE, ARCH_SECTION_PAGE_READWRITE_EXEC, ARCH_SECTION_PAGE_RDONLY, ARCH_SECTION_PAGE_RDONLY_EXEC, ARCH_SECTION_PAGE_EXECONLY, ARCH_SECTION_DEVICE_NONE, ARCH_SECTION_DEVICE_READWRITE, ARCH_SECTION_DEVICE_RDONLY};
    } else {
        mod dummy;
        use dummy::{ARCH_PA_BITS, ARCH_PAGE_SIZE, ARCH_PAGE_SHIFT, ARCH_PAGE_PTRS, ARCH_PMD_SIZE, ARCH_PMD_SHIFT, ARCH_PMD_PTRS, ARCH_PUD_SIZE, ARCH_PUD_SHIFT, ARCH_PUD_PTRS, ARCH_PGD_SIZE, ARCH_PGD_SHIFT, ARCH_PGD_PTRS, ARCH_PGD_TYPE_TABLE, ARCH_PUD_TYPE_TABLE, ARCH_PMD_TYPE_TABLE, ARCH_PTE_TYPE_PAGE, ARCH_PMD_TYPE_SECT, ARCH_PAGE_NONE, ARCH_PAGE_READWRITE, ARCH_PAGE_READWRITE_EXEC, ARCH_PAGE_RDONLY, ARCH_PAGE_RDONLY_EXEC, ARCH_PAGE_EXECONLY, ARCH_DEVICE_NONE, ARCH_DEVICE_READWRITE, ARCH_DEVICE_RDONLY, ARCH_SECTION_PAGE_NONE, ARCH_SECTION_PAGE_READWRITE, ARCH_SECTION_PAGE_READWRITE_EXEC, ARCH_SECTION_PAGE_RDONLY, ARCH_SECTION_PAGE_RDONLY_EXEC, ARCH_SECTION_PAGE_EXECONLY, ARCH_SECTION_DEVICE_NONE, ARCH_SECTION_DEVICE_READWRITE, ARCH_SECTION_DEVICE_RDONLY};
    }
}

const PA_BITS: usize = ARCH_PA_BITS;

// 页表物理地址掩码
pub(crate) const PGTABLE_ADDR_MASK: usize = ((1 << (PA_BITS - PAGE_SHIFT)) - 1) << PAGE_SHIFT;
// 大页物理地址掩码
pub(crate) const SECTION_ADDR_MASK: usize = ((1 << (PA_BITS - PMD_SHIFT)) - 1) << PMD_SHIFT;

/// 大页大小
pub const SECTION_SIZE: usize = PMD_SIZE;

/// 页大小
pub const PAGE_SIZE: usize = ARCH_PAGE_SIZE;
/// 页偏移
pub const PAGE_SHIFT: usize = ARCH_PAGE_SHIFT;
/// 页掩码
pub const PAGE_MASK: usize = !(PAGE_SIZE - 1);
/// 页表条目数量
pub const PAGE_PTRS: usize = ARCH_PAGE_PTRS;

/// 二级页目录大小
pub const PMD_SIZE: usize = ARCH_PMD_SIZE;
/// 二级页目录便宜
pub const PMD_SHIFT: usize = ARCH_PMD_SHIFT;
/// 二级页目录掩码
pub const PMD_MASK: usize = !(PMD_SIZE - 1);
/// 二级页目录条目数量
pub const PMD_PTRS: usize = ARCH_PMD_PTRS;

/// 三级页目录大小
pub const PUD_SIZE: usize = ARCH_PUD_SIZE;
/// 三级页目录便宜
pub const PUD_SHIFT: usize = ARCH_PUD_SHIFT;
/// 三级页目录掩码
pub const PUD_MASK: usize = !(PUD_SIZE - 1);
/// 三级页目录条目数量
pub const PUD_PTRS: usize = ARCH_PUD_PTRS;

/// 四级页目录大小
pub const PGD_SIZE: usize = ARCH_PGD_SIZE;
/// 四级页目录便宜
pub const PGD_SHIFT: usize = ARCH_PGD_SHIFT;
/// 四级页目录掩码
pub const PGD_MASK: usize = !(PGD_SIZE - 1);
/// 四级页目录条目数量
pub const PGD_PTRS: usize = ARCH_PGD_PTRS;

// 四级页表类型
pub(crate) const PGD_TYPE_TABLE: usize = ARCH_PGD_TYPE_TABLE;
// 三级页表类型
pub(crate) const PUD_TYPE_TABLE: usize = ARCH_PUD_TYPE_TABLE;
// 二级页表类型
pub(crate) const PMD_TYPE_TABLE: usize = ARCH_PMD_TYPE_TABLE;

// 小页类型
pub(crate) const PAGE_TYPE_VALID: usize = ARCH_PTE_TYPE_PAGE;
// 大页类型
pub(crate) const SECT_TYPE_VALID: usize = ARCH_PMD_TYPE_SECT;

// 普通小页无效
pub(crate) const PAGE_NONE: usize = ARCH_PAGE_NONE;
// 普通小页用户可读可写不可执行
pub(crate) const PAGE_READWRITE: usize = ARCH_PAGE_READWRITE;
// 普通小页用户可读可写可执行
pub(crate) const PAGE_READWRITE_EXEC: usize = ARCH_PAGE_READWRITE_EXEC;
// 普通小页用户仅可读不可写不可执行
pub(crate) const PAGE_RDONLY: usize = ARCH_PAGE_RDONLY;
// 普通小页用户仅可读可执行不可写
pub(crate) const PAGE_RDONLY_EXEC: usize = ARCH_PAGE_RDONLY_EXEC;
// 普通小页用户仅可执行不可读可写
pub(crate) const PAGE_EXECONLY: usize = ARCH_PAGE_EXECONLY;

// 设备小页无效
pub(crate) const DEVICE_NONE: usize = ARCH_DEVICE_NONE;
// 设备小页用户可读可写不可执行
pub(crate) const DEVICE_READWRITE: usize = ARCH_DEVICE_READWRITE;
// 设备小页用户仅可读不可写不可执行
pub(crate) const DEVICE_RDONLY: usize = ARCH_DEVICE_RDONLY;

// 普通大页无效
pub(crate) const SECTION_PAGE_NONE: usize = ARCH_SECTION_PAGE_NONE;
// 普通大页用户可读可写不可执行
pub(crate) const SECTION_PAGE_READWRITE: usize = ARCH_SECTION_PAGE_READWRITE;
// 普通大页用户可读可写可执行
pub(crate) const SECTION_PAGE_READWRITE_EXEC: usize = ARCH_SECTION_PAGE_READWRITE_EXEC;
// 普通大页用户仅可读不可写不可执行
pub(crate) const SECTION_PAGE_RDONLY: usize = ARCH_SECTION_PAGE_RDONLY;
// 普通大页仅可读可执行不可写
pub(crate) const SECTION_PAGE_RDONLY_EXEC: usize = ARCH_SECTION_PAGE_RDONLY_EXEC;
// 普通大页仅可执行不可读可写
pub(crate) const SECTION_PAGE_EXECONLY: usize = ARCH_SECTION_PAGE_EXECONLY;

// 设备大页无效
pub(crate) const SECTION_DEVICE_NONE: usize = ARCH_SECTION_DEVICE_NONE;
// 设备大页用户可读可写不可执行
pub(crate) const SECTION_DEVICE_READWRITE: usize = ARCH_SECTION_DEVICE_READWRITE;
// 设备大页用户仅可读不可写不可执行
pub(crate) const SECTION_DEVICE_RDONLY: usize = ARCH_SECTION_DEVICE_RDONLY;
