Initialize a new OffsetPageTable. This function must be only called once to avoid aliasing `&mut` references (which is undefined behavior).
(boot_info: &'static BootInfo)
| 44 | /// This function must be only called once to avoid aliasing `&mut` |
| 45 | /// references (which is undefined behavior). |
| 46 | pub fn init(boot_info: &'static BootInfo) { |
| 47 | use x86_64::instructions::interrupts; |
| 48 | |
| 49 | interrupts::without_interrupts(|| { |
| 50 | let mut memory_size = 0; |
| 51 | for region in boot_info.memory_map.iter() { |
| 52 | let start_addr = region.range.start_addr(); |
| 53 | let end_addr = region.range.end_addr(); |
| 54 | memory_size += end_addr - start_addr; |
| 55 | println!("MEM [{:#016X}-{:#016X}] {:?}", start_addr, end_addr, region.region_type); |
| 56 | } |
| 57 | println!("Memory size: {} KB\n", memory_size >> 10); |
| 58 | |
| 59 | let physical_memory_offset = VirtAddr::new(boot_info.physical_memory_offset); |
| 60 | |
| 61 | println!("Physical memory offset: {:#016X}", physical_memory_offset.as_u64()); |
| 62 | |
| 63 | let level_4_table = unsafe {active_level_4_table(physical_memory_offset)}; |
| 64 | |
| 65 | // Initialise the memory mapper |
| 66 | let mut mapper = unsafe {OffsetPageTable::new(level_4_table, physical_memory_offset)}; |
| 67 | let mut frame_allocator = unsafe { |
| 68 | MultilevelBitmapFrameAllocator::init(&boot_info.memory_map, |
| 69 | physical_memory_offset) |
| 70 | }; |
| 71 | |
| 72 | allocator::init_heap(&mut mapper, &mut frame_allocator) |
| 73 | .expect("heap initialization failed"); |
| 74 | |
| 75 | kernel_info::init(&mut frame_allocator, physical_memory_offset) |
| 76 | .expect("KernelInfo initialization failed"); |
| 77 | |
| 78 | // Store boot_info for later calls |
| 79 | unsafe { MEMORY_INFO = Some(MemoryInfo { |
| 80 | boot_info, |
| 81 | physical_memory_offset, |
| 82 | frame_allocator, |
| 83 | kernel_l4_table: level_4_table |
| 84 | }) }; |
| 85 | }); |
| 86 | } |
| 87 | |
| 88 | /// This should only be called from the init function |
| 89 | /// because each call will result in a mutable reference |
nothing calls this directly
no test coverage detected