pub fn is_page_fault(addr: usize) -> bool {
    if !is_s1p9_mstatus_sv39_mode() {
        return false;
    }
    if !check_sext_sv39(addr) {
        return true;
    }
    let base_ppn = read_sptbr_ppn();
    let level_2_ppn = unsafe {
        let vpn2 = (addr >> 30) & 0x1FF;
        let ptr = ((base_ppn << 12) as *const usize).add(vpn2);
        let level_2_pte = if let Ok(ans) = try_read_address(ptr) {
            ans
        } else { // level 2 ppn read failed
            return true;
        };
        if (level_2_pte & 0b1) == 0 { // level 2 pte is not valid
            return true;
        }
        if (level_2_pte & 0b1110) != 0b0000 && (level_2_pte >> 10) & 0x3FFFF != 0 { // 大页对齐出错，返回页异常
            // level 2 huge page align not satisfied
            return true;
        }
        (level_2_pte >> 10) & 0x3F_FFFF_FFFF
    };
    let level_1_ppn = unsafe {
        let vpn1 = (addr >> 21) & 0x1FF;
        let ptr = ((level_2_ppn << 12) as *const usize).add(vpn1);
        let level_1_pte = if let Ok(ans) = try_read_address(ptr) {
            ans
        } else { // level 1 ppn read failed
            return true;
        };
        if (level_1_pte & 0b1) == 0 { // level 1 pte is not valid
            return true;
        }
        if (level_1_pte & 0b1110) != 0b0000 && (level_1_pte >> 10) & 0x1FF != 0 { // 大页对齐出错，返回页异常
            // level 1 huge page align not satisfied
            return true;
        }
        (level_1_pte >> 10) & 0x3F_FFFF_FFFF
    };
    let _ppn = unsafe {
        let vpn0 = (addr >> 12) & 0x1FF;
        let ptr = ((level_1_ppn << 12) as *const usize).add(vpn0);
        let final_pte = if let Ok(ans) = try_read_address(ptr) {
            ans
        } else { // level 0 ppn read failed
            return true;
        };
        if (final_pte & 0b1) == 0 { // level 0 pte is not valid
            return true;
        }
        if (final_pte & 0b1110) == 0b0000 { // level 0 page cannot have leaves
            return true;
        }
        (final_pte >> 10) & 0x3F_FFFF_FFFF
    }; 
    // 到这一步都没有错误，说明查找是成功的，并非页异常
    false
}
// This function will lookup virtual memory module and page table system
// if memory fault from address `addr` is a page fault, return true
// otherwise when not a page fault, or when paging is disabled, return false
This function will lookup virtual memory module and page table system
if memory fault from address `addr` is a page fault, return true
otherwise when not a page fault, or when paging is disabled, return false
This function will lookup virtual memory module and page table system if memory fault from address ` addr ` is a page fault return true otherwise when not a page fault or when paging is disabled return false
pub fn is_page_fault(addr: usize) -> bool {
    if !is_s1p9_mstatus_sv39_mode() {
        return false;
    }
    if !check_sext_sv39(addr) {
        return true;
    }
    let base_ppn = read_sptbr_ppn();
    let level_2_ppn = unsafe {
        let vpn2 = (addr >> 30) & 0x1FF;
        let ptr = ((base_ppn << 12) as *const usize).add(vpn2);
        let level_2_pte = if let Ok(ans) = try_read_address(ptr) {
            ans
        } else { // level 2 ppn read failed
            return true;
        };
        if (level_2_pte & 0b1) == 0 { // level 2 pte is not valid
            return true;
        }
        if (level_2_pte & 0b1110) != 0b0000 && (level_2_pte >> 10) & 0x3FFFF != 0 { // 大页对齐出错，返回页异常
            // level 2 huge page align not satisfied
            return true;
        }
        (level_2_pte >> 10) & 0x3F_FFFF_FFFF
    };
    let level_1_ppn = unsafe {
        let vpn1 = (addr >> 21) & 0x1FF;
        let ptr = ((level_2_ppn << 12) as *const usize).add(vpn1);
        let level_1_pte = if let Ok(ans) = try_read_address(ptr) {
            ans
        } else { // level 1 ppn read failed
            return true;
        };
        if (level_1_pte & 0b1) == 0 { // level 1 pte is not valid
            return true;
        }
        if (level_1_pte & 0b1110) != 0b0000 && (level_1_pte >> 10) & 0x1FF != 0 { // 大页对齐出错，返回页异常
            // level 1 huge page align not satisfied
            return true;
        }
        (level_1_pte >> 10) & 0x3F_FFFF_FFFF
    };
    let _ppn = unsafe {
        let vpn0 = (addr >> 12) & 0x1FF;
        let ptr = ((level_1_ppn << 12) as *const usize).add(vpn0);
        let final_pte = if let Ok(ans) = try_read_address(ptr) {
            ans
        } else { // level 0 ppn read failed
            return true;
        };
        if (final_pte & 0b1) == 0 { // level 0 pte is not valid
            return true;
        }
        if (final_pte & 0b1110) == 0b0000 { // level 0 page cannot have leaves
            return true;
        }
        (final_pte >> 10) & 0x3F_FFFF_FFFF
    }; 
    // 到这一步都没有错误，说明查找是成功的，并非页异常
    false
}
pub fn is_page_fault ( addr : usize ) -> bool { if ! is_s1p9_mstatus_sv39_mode ( ) { return false ; } if ! check_sext_sv39 ( addr ) { return true ; } let base_ppn = read_sptbr_ppn ( ) ; let level_2_ppn = unsafe { let vpn2 = ( addr >> 30 ) & 0x1FF ; let ptr = ( ( base_ppn << 12 ) as * const usize ) . add ( vpn2 ) ; let level_2_pte = if let Ok ( ans ) = try_read_address ( ptr ) { ans } else { // level 2 ppn read failed return true ; } ; if ( level_2_pte & 0b1 ) == 0 { // level 2 pte is not valid return true ; } if ( level_2_pte & 0b1110 ) != 0b0000 && ( level_2_pte >> 10 ) & 0x3FFFF != 0 { // 大页对齐出错，返回页异常 // level 2 huge page align not satisfied return true ; } ( level_2_pte >> 10 ) & 0x3F_FFFF_FFFF } ; let level_1_ppn = unsafe { let vpn1 = ( addr >> 21 ) & 0x1FF ; let ptr = ( ( level_2_ppn << 12 ) as * const usize ) . add ( vpn1 ) ; let level_1_pte = if let Ok ( ans ) = try_read_address ( ptr ) { ans } else { // level 1 ppn read failed return true ; } ; if ( level_1_pte & 0b1 ) == 0 { // level 1 pte is not valid return true ; } if ( level_1_pte & 0b1110 ) != 0b0000 && ( level_1_pte >> 10 ) & 0x1FF != 0 { // 大页对齐出错，返回页异常 // level 1 huge page align not satisfied return true ; } ( level_1_pte >> 10 ) & 0x3F_FFFF_FFFF } ; let _ppn = unsafe { let vpn0 = ( addr >> 12 ) & 0x1FF ; let ptr = ( ( level_1_ppn << 12 ) as * const usize ) . add ( vpn0 ) ; let final_pte = if let Ok ( ans ) = try_read_address ( ptr ) { ans } else { // level 0 ppn read failed return true ; } ; if ( final_pte & 0b1 ) == 0 { // level 0 pte is not valid return true ; } if ( final_pte & 0b1110 ) == 0b0000 { // level 0 page cannot have leaves return true ; } ( final_pte >> 10 ) & 0x3F_FFFF_FFFF } ; // 到这一步都没有错误，说明查找是成功的，并非页异常 false }
This function will lookup virtual memory module and page table system
if memory fault from address `addr` is a page fault, return true
otherwise when not a page fault, or when paging is disabled, return false
This function will lookup virtual memory module and page table system if memory fault from address ` addr ` is a page fault return true otherwise when not a page fault or when paging is disabled return false
addr
usize
addr
usize