mirror of
https://github.com/phil-opp/blog_os.git
synced 2025-12-16 14:27:49 +00:00
Create a new mapping and write through it to the screen
This commit is contained in:
26
src/main.rs
26
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();
|
||||
|
||||
Reference in New Issue
Block a user