Create a new mapping and write through it to the screen

This commit is contained in:
Philipp Oppermann
2019-03-13 14:31:45 +01:00
parent 3e59283c19
commit 770af27d75

View File

@@ -12,7 +12,7 @@ entry_point!(kernel_main);
fn kernel_main(boot_info: &'static BootInfo) -> ! { fn kernel_main(boot_info: &'static BootInfo) -> ! {
use blog_os::interrupts::PICS; use blog_os::interrupts::PICS;
use blog_os::memory; use blog_os::memory;
use x86_64::{structures::paging::MapperAllSizes, VirtAddr}; use x86_64::{structures::paging::Page, VirtAddr};
println!("Hello World{}", "!"); println!("Hello World{}", "!");
@@ -21,24 +21,16 @@ fn kernel_main(boot_info: &'static BootInfo) -> ! {
unsafe { PICS.lock().initialize() }; unsafe { PICS.lock().initialize() };
x86_64::instructions::interrupts::enable(); 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 = [ // map a previously unmapped page
// the identity-mapped vga buffer page let page = Page::containing_address(VirtAddr::new(0x1000));
0xb8000, memory::create_example_mapping(page, &mut mapper, &mut frame_allocator);
// some code page
0x20010a,
// some stack page
0x57ac_001f_fe48,
// virtual address mapped to physical address 0
boot_info.physical_memory_offset,
];
for &address in &addresses { // write the string `New!` to the screen through the new mapping
let virt = VirtAddr::new(address); let page_ptr: *mut u64 = page.start_address().as_mut_ptr();
let phys = mapper.translate_addr(virt); unsafe { page_ptr.offset(400).write_volatile(0x_f021_f077_f065_f04e) };
println!("{:?} -> {:?}", virt, phys);
}
println!("It did not crash!"); println!("It did not crash!");
blog_os::hlt_loop(); blog_os::hlt_loop();