init.rs 1.5 KB

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