From ed03d247c715bb3111b45532eef9f91fb89c0bc2 Mon Sep 17 00:00:00 2001 From: Jack Halford Date: Mon, 19 Mar 2018 12:14:30 +0100 Subject: [PATCH] it works:))) --- kernel-rs/src/console.rs | 2 +- kernel-rs/src/lib.rs | 13 +--------- kernel-rs/src/memory/paging/mod.rs | 39 +++++++++--------------------- 3 files changed, 13 insertions(+), 41 deletions(-) diff --git a/kernel-rs/src/console.rs b/kernel-rs/src/console.rs index 6ababe05..4ffcdd54 100644 --- a/kernel-rs/src/console.rs +++ b/kernel-rs/src/console.rs @@ -179,8 +179,8 @@ pub fn regs() -> Result <(), &'static str> { use x86::registers::control::*; println!("cr0={:#b}", Cr0::read()); println!("cr3={:?}", Cr3::read()); + flush!(); // TODO implement cr4 flags in `x86` module // println!("cr4={:#b}", Cr4::read()); Ok(()) } - diff --git a/kernel-rs/src/lib.rs b/kernel-rs/src/lib.rs index 1303e417..8cf31d6e 100644 --- a/kernel-rs/src/lib.rs +++ b/kernel-rs/src/lib.rs @@ -34,23 +34,12 @@ pub mod memory; pub extern fn kmain(multiboot_info_addr: usize) -> ! { // acpi::init().unwrap(); let boot_info = unsafe { multiboot2::load(multiboot_info_addr) }; + enable_write_protect_bit(); memory::init(&boot_info); vga::init(); - use alloc::boxed::Box; - let mut heap_test = Box::new(42); - *heap_test -= 15; - let heap_test2 = Box::new("Hello"); - println!("{:?} {:?}", heap_test, heap_test2); - - let mut vec_test = vec![1,2,3,4,5,6,7]; - vec_test[3] = 42; - for i in &vec_test { - print!("{} ", i); - } - loop { keyboard::kbd_callback(); } } diff --git a/kernel-rs/src/memory/paging/mod.rs b/kernel-rs/src/memory/paging/mod.rs index ce5a9bee..5b3fbd67 100644 --- a/kernel-rs/src/memory/paging/mod.rs +++ b/kernel-rs/src/memory/paging/mod.rs @@ -65,19 +65,7 @@ impl ActivePageTable { let (p2_frame, cr3_flags) = Cr3::read(); let old_table = InactivePageTable { p2_frame }; - // unsafe { Cr3::write(new_table.p2_frame, cr3_flags); } - - ::console::regs(); - flush!(); - loop {} - - unsafe { asm!("mov $0, %cr3" :: "r" (4096) : "memory"); } - - // let addr = new_table.p2_frame.start_address(); - // let value = addr.as_u32() | cr3_flags.bits(); - // println!("value = {}", 0); - // flush!(); - // loop {} + unsafe { Cr3::write(new_table.p2_frame, cr3_flags); } old_table } @@ -92,15 +80,15 @@ impl InactivePageTable { active_table: &mut ActivePageTable, temporary_page: &mut TemporaryPage) -> InactivePageTable { - { - let table = temporary_page.map_table_frame(frame.clone(), active_table); + { + let table = temporary_page.map_table_frame(frame.clone(), active_table); - table.zero(); - // set up recursive mapping for the table - table[1023].set(frame.clone(), PageTableFlags::PRESENT | PageTableFlags::WRITABLE) - } - temporary_page.unmap(active_table); - InactivePageTable { p2_frame: frame } + table.zero(); + // set up recursive mapping for the table + table[1023].set(frame.clone(), PageTableFlags::PRESENT | PageTableFlags::WRITABLE) + } + temporary_page.unmap(active_table); + InactivePageTable { p2_frame: frame } } } @@ -137,7 +125,7 @@ pub fn remap_the_kernel(allocator: &mut A, boot_info: &BootInformation) PhysAddr::new(section.start_address() as u32)); let end_frame = PhysFrame::containing_address( PhysAddr::new(section.end_address() as u32 - 1)); - for frame in start_frame..end_frame { + for frame in start_frame..end_frame + 1 { mapper.identity_map(frame, flags, allocator); } } @@ -146,17 +134,13 @@ pub fn remap_the_kernel(allocator: &mut A, boot_info: &BootInformation) PhysAddr::new(boot_info.start_address() as u32)); let multiboot_end = PhysFrame::containing_address( PhysAddr::new(boot_info.end_address() as u32 - 1)); - for frame in multiboot_start..multiboot_end { + for frame in multiboot_start..multiboot_end + 1 { mapper.identity_map(frame, PageTableFlags::PRESENT, allocator); } }); let old_table = active_table.switch(new_table); - println!("check!"); - flush!(); - loop {} - let old_p2_page = Page::containing_address( VirtAddr::new(old_table.p2_frame.start_address().as_u32())); @@ -179,7 +163,6 @@ fn elf_to_pagetable_flags(elf_flags: &multiboot2::ElfSectionFlags) if elf_flags.contains(ElfSectionFlags::WRITABLE) { flags = flags | PageTableFlags::WRITABLE; } - // LONG MODE STUFF // if !elf_flags.contains(ELF_SECTION_EXECUTABLE) { // flags = flags | PageTableFlags::NO_EXECUTE;