fn init_kernel_page_table() -> PagingResult<PageTable> {
    extern "C" {
        fn stext();
        fn etext();
        fn srodata();
        fn erodata();
        fn sdata();
        fn edata();
        fn sbss();
        fn ebss();

        fn bootstack();
        fn bootstacktop();

        fn end();
    }

    let mut pt = PageTable::new();
    let mut map_range = |start: VirtAddr, end: VirtAddr, flags: MMUFlags| -> PagingResult {
        pt.map_cont(
            start,
            crate::addr::align_up(end - start),
            start - KCONFIG.phys_to_virt_offset,
            flags | MMUFlags::HUGE_PAGE,
        )
    };

    map_range(
        stext as usize,
        etext as usize,
        MMUFlags::READ | MMUFlags::EXECUTE,
    )?;
    map_range(srodata as usize, erodata as usize, MMUFlags::READ)?;
    map_range(
        sdata as usize,
        edata as usize,
        MMUFlags::READ | MMUFlags::WRITE,
    )?;
    map_range(
        sbss as usize,
        ebss as usize,
        MMUFlags::READ | MMUFlags::WRITE,
    )?;
    // stack
    map_range(
        bootstack as usize,
        bootstacktop as usize,
        MMUFlags::READ | MMUFlags::WRITE,
    )?;
    // physical frames
    map_range(
        align_up(end as usize + PAGE_SIZE),
        phys_to_virt(align_down(KCONFIG.phys_mem_end)),
        MMUFlags::READ | MMUFlags::WRITE,
    )?;

    info!("initialized kernel page table @ {:#x}", pt.table_phys());
    Ok(pt)
}
/// remap kernel ELF segments with 4K page
remap kernel ELF segments with 4K page
remap kernel ELF segments with 4K page
fn init_kernel_page_table() -> PagingResult<PageTable> {
    extern "C" {
        fn stext();
        fn etext();
        fn srodata();
        fn erodata();
        fn sdata();
        fn edata();
        fn sbss();
        fn ebss();
        fn bootstack();
        fn bootstacktop();
        fn end();
    }
    let mut pt = PageTable::new();
    let mut map_range = |start: VirtAddr, end: VirtAddr, flags: MMUFlags| -> PagingResult {
        pt.map_cont(
            start,
            crate::addr::align_up(end - start),
            start - KCONFIG.phys_to_virt_offset,
            flags | MMUFlags::HUGE_PAGE,
        )
    };
    map_range(
        stext as usize,
        etext as usize,
        MMUFlags::READ | MMUFlags::EXECUTE,
    )?;
    map_range(srodata as usize, erodata as usize, MMUFlags::READ)?;
    map_range(
        sdata as usize,
        edata as usize,
        MMUFlags::READ | MMUFlags::WRITE,
    )?;
    map_range(
        sbss as usize,
        ebss as usize,
        MMUFlags::READ | MMUFlags::WRITE,
    )?;
    // stack
    map_range(
        bootstack as usize,
        bootstacktop as usize,
        MMUFlags::READ | MMUFlags::WRITE,
    )?;
    // physical frames
    map_range(
        align_up(end as usize + PAGE_SIZE),
        phys_to_virt(align_down(KCONFIG.phys_mem_end)),
        MMUFlags::READ | MMUFlags::WRITE,
    )?;
    info!("initialized kernel page table @ {:#x}", pt.table_phys());
    Ok(pt)
}
fn init_kernel_page_table ( ) -> PagingResult < PageTable > { extern " " { fn stext ( ) ; fn etext ( ) ; fn srodata ( ) ; fn erodata ( ) ; fn sdata ( ) ; fn edata ( ) ; fn sbss ( ) ; fn ebss ( ) ; fn bootstack ( ) ; fn bootstacktop ( ) ; fn end ( ) ; } let mut pt = PageTable :: new ( ) ; let mut map_range = | start : VirtAddr , end : VirtAddr , flags : MMUFlags | -> PagingResult { pt . map_cont ( start , crate :: addr :: align_up ( end - start ) , start - KCONFIG . phys_to_virt_offset , flags | MMUFlags :: HUGE_PAGE , ) } ; map_range ( stext as usize , etext as usize , MMUFlags :: READ | MMUFlags :: EXECUTE , ) ? ; map_range ( srodata as usize , erodata as usize , MMUFlags :: READ ) ? ; map_range ( sdata as usize , edata as usize , MMUFlags :: READ | MMUFlags :: WRITE , ) ? ; map_range ( sbss as usize , ebss as usize , MMUFlags :: READ | MMUFlags :: WRITE , ) ? ; // stack map_range ( bootstack as usize , bootstacktop as usize , MMUFlags :: READ | MMUFlags :: WRITE , ) ? ; // physical frames map_range ( align_up ( end as usize + PAGE_SIZE ) , phys_to_virt ( align_down ( KCONFIG . phys_mem_end ) ) , MMUFlags :: READ | MMUFlags :: WRITE , ) ? ; info ! ( " " pt table_phys ( ) ) ; Ok ( pt ) }
remap kernel ELF segments with 4K page
remap kernel ELF segments with 4K page