1*7a29d4fcSLoGin use system_error::SystemError; 2666cffedSLoGin 3*7a29d4fcSLoGin use crate::{ 4*7a29d4fcSLoGin arch::{ 5*7a29d4fcSLoGin mm::{KERNEL_BEGIN_PA, KERNEL_BEGIN_VA, KERNEL_END_PA, KERNEL_END_VA}, 6*7a29d4fcSLoGin MMArch, 7*7a29d4fcSLoGin }, 8*7a29d4fcSLoGin kdebug, 9*7a29d4fcSLoGin mm::{ 10*7a29d4fcSLoGin allocator::page_frame::PageFrameCount, 11*7a29d4fcSLoGin no_init::{pseudo_map_phys, EARLY_IOREMAP_PAGES}, 12*7a29d4fcSLoGin page::{PageEntry, PageMapper, PageTable}, 13*7a29d4fcSLoGin MemoryManagementArch, PageTableKind, PhysAddr, VirtAddr, 14*7a29d4fcSLoGin }, 15*7a29d4fcSLoGin }; 16*7a29d4fcSLoGin 17*7a29d4fcSLoGin #[inline(never)] 18*7a29d4fcSLoGin pub fn mm_early_init() { 19*7a29d4fcSLoGin unsafe { init_kernel_addr() }; 20*7a29d4fcSLoGin // unsafe { map_initial_page_table_linearly() }; 21*7a29d4fcSLoGin } 22*7a29d4fcSLoGin 23*7a29d4fcSLoGin unsafe fn init_kernel_addr() { 24*7a29d4fcSLoGin extern "C" { 25*7a29d4fcSLoGin /// 内核起始label 26*7a29d4fcSLoGin fn boot_text_start_pa(); 27*7a29d4fcSLoGin /// 内核结束位置的label 28*7a29d4fcSLoGin fn _end(); 29*7a29d4fcSLoGin 30*7a29d4fcSLoGin fn _start(); 31*7a29d4fcSLoGin 32*7a29d4fcSLoGin /// 内核start标签被加载到的物理地址 33*7a29d4fcSLoGin fn __initial_start_load_paddr(); 34*7a29d4fcSLoGin } 35*7a29d4fcSLoGin let initial_start_load_pa = *(__initial_start_load_paddr as usize as *const usize); 36*7a29d4fcSLoGin let offset = _start as usize - boot_text_start_pa as usize; 37*7a29d4fcSLoGin let start_pa = initial_start_load_pa - offset; 38*7a29d4fcSLoGin 39*7a29d4fcSLoGin let offset2 = _end as usize - boot_text_start_pa as usize; 40*7a29d4fcSLoGin let end_pa = start_pa + offset2; 41*7a29d4fcSLoGin 42*7a29d4fcSLoGin KERNEL_BEGIN_PA = PhysAddr::new(start_pa); 43*7a29d4fcSLoGin KERNEL_END_PA = PhysAddr::new(end_pa); 44*7a29d4fcSLoGin 45*7a29d4fcSLoGin KERNEL_BEGIN_VA = VirtAddr::new(boot_text_start_pa as usize); 46*7a29d4fcSLoGin KERNEL_END_VA = VirtAddr::new(_end as usize); 47*7a29d4fcSLoGin 48*7a29d4fcSLoGin kdebug!( 49*7a29d4fcSLoGin "init_kernel_addr: \n\tKERNEL_BEGIN_PA: {KERNEL_BEGIN_PA:?} 50*7a29d4fcSLoGin \tKERNEL_END_PA: {KERNEL_END_PA:?} 51*7a29d4fcSLoGin \tKERNEL_BEGIN_VA: {KERNEL_BEGIN_VA:?} 52*7a29d4fcSLoGin \tKERNEL_END_VA: {KERNEL_END_VA:?} 53*7a29d4fcSLoGin " 54*7a29d4fcSLoGin ); 55*7a29d4fcSLoGin } 56