From 770af27d75e080edd6f15e3c943a599618058d61 Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Wed, 13 Mar 2019 14:31:45 +0100 Subject: [PATCH] Create a new mapping and write through it to the screen --- src/main.rs | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/src/main.rs b/src/main.rs index 6a1fea0f..f883906b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,7 +12,7 @@ entry_point!(kernel_main); fn kernel_main(boot_info: &'static BootInfo) -> ! { use blog_os::interrupts::PICS; use blog_os::memory; - use x86_64::{structures::paging::MapperAllSizes, VirtAddr}; + use x86_64::{structures::paging::Page, VirtAddr}; println!("Hello World{}", "!"); @@ -21,24 +21,16 @@ fn kernel_main(boot_info: &'static BootInfo) -> ! { unsafe { PICS.lock().initialize() }; x86_64::instructions::interrupts::enable(); - let mapper = unsafe { memory::init(boot_info.physical_memory_offset) }; + let mut mapper = unsafe { memory::init(boot_info.physical_memory_offset) }; + let mut frame_allocator = memory::EmptyFrameAllocator; - let addresses = [ - // the identity-mapped vga buffer page - 0xb8000, - // some code page - 0x20010a, - // some stack page - 0x57ac_001f_fe48, - // virtual address mapped to physical address 0 - boot_info.physical_memory_offset, - ]; + // map a previously unmapped page + let page = Page::containing_address(VirtAddr::new(0x1000)); + memory::create_example_mapping(page, &mut mapper, &mut frame_allocator); - for &address in &addresses { - let virt = VirtAddr::new(address); - let phys = mapper.translate_addr(virt); - println!("{:?} -> {:?}", virt, phys); - } + // write the string `New!` to the screen through the new mapping + let page_ptr: *mut u64 = page.start_address().as_mut_ptr(); + unsafe { page_ptr.offset(400).write_volatile(0x_f021_f077_f065_f04e) }; println!("It did not crash!"); blog_os::hlt_loop();