(boot_info: &'static mut BootInfo)
| 202 | entry_point!(kernel_main, config = &BOOTLOADER_CONFIG); |
| 203 | |
| 204 | fn kernel_main(boot_info: &'static mut BootInfo) -> ! { |
| 205 | gdt::init(); |
| 206 | interrupts::init_idt(); |
| 207 | |
| 208 | let framebuffer = boot_info.framebuffer.as_mut().unwrap(); |
| 209 | let fbinfo = framebuffer.info(); |
| 210 | |
| 211 | let fbm = framebuffer.buffer_mut(); |
| 212 | let fbm2 = unsafe { |
| 213 | let p = fbm.as_mut_ptr(); |
| 214 | slice::from_raw_parts_mut(p, fbinfo.byte_len) |
| 215 | }; |
| 216 | init_logger(fbm, fbinfo.clone(), LevelFilter::Trace, true, true); |
| 217 | |
| 218 | // x86_64::instructions::interrupts::int3(); |
| 219 | let virtual_full_mapping_offset = VirtAddr::new( |
| 220 | boot_info |
| 221 | .physical_memory_offset |
| 222 | .into_option() |
| 223 | .expect("no physical_memory_offset"), |
| 224 | ); |
| 225 | log::info!("physical_memory_offset {:x}", virtual_full_mapping_offset); |
| 226 | unsafe { |
| 227 | VIRTUAL_MAPPING_OFFSET = virtual_full_mapping_offset; |
| 228 | } |
| 229 | let mapper = unsafe { memory::init(virtual_full_mapping_offset) }; |
| 230 | let frame_allocator = unsafe { BootInfoFrameAllocator::init(&boot_info.memory_regions) }; |
| 231 | MAPPER.init_once(|| Mutex::new(mapper)); |
| 232 | FRAME_ALLOCATOR.init_once(|| Mutex::new(frame_allocator)); |
| 233 | { |
| 234 | log::info!("Complete Bootloader Map physical memory"); |
| 235 | type VirtualMappingPageSize = Size2MiB; // Size2MiB;Size1GiB Size4KiB |
| 236 | |
| 237 | let start_frame: PhysFrame<VirtualMappingPageSize> = |
| 238 | PhysFrame::containing_address(PhysAddr::new(0)); |
| 239 | let max_phys = PhysAddr::new(virtual_full_mapping_offset.as_u64() - 1u64); |
| 240 | let max_phys = PhysAddr::new(Size1GiB::SIZE * 64 - 1); |
| 241 | |
| 242 | let end_frame: PhysFrame<VirtualMappingPageSize> = PhysFrame::containing_address(max_phys); |
| 243 | |
| 244 | use x86_64::structures::paging::PageSize; |
| 245 | let mut news = 0; |
| 246 | let mut olds = 0; |
| 247 | for frame in PhysFrame::range_inclusive(start_frame, end_frame) { |
| 248 | let page: Page<VirtualMappingPageSize> = Page::containing_address( |
| 249 | virtual_full_mapping_offset + frame.start_address().as_u64(), |
| 250 | ); |
| 251 | let flags = PageTableFlags::PRESENT | PageTableFlags::WRITABLE; |
| 252 | match unsafe { |
| 253 | MAPPER.get_unchecked().lock().map_to( |
| 254 | page, |
| 255 | frame, |
| 256 | flags, |
| 257 | &mut *FRAME_ALLOCATOR.get_unchecked().lock(), |
| 258 | ) |
| 259 | } { |
| 260 | Ok(tlb) => { |
| 261 | tlb.flush(); |
nothing calls this directly
no test coverage detected