it works:)))
This commit is contained in:
parent
5c2b5f723b
commit
ed03d247c7
3 changed files with 13 additions and 41 deletions
|
|
@ -179,8 +179,8 @@ pub fn regs() -> Result <(), &'static str> {
|
||||||
use x86::registers::control::*;
|
use x86::registers::control::*;
|
||||||
println!("cr0={:#b}", Cr0::read());
|
println!("cr0={:#b}", Cr0::read());
|
||||||
println!("cr3={:?}", Cr3::read());
|
println!("cr3={:?}", Cr3::read());
|
||||||
|
flush!();
|
||||||
// TODO implement cr4 flags in `x86` module
|
// TODO implement cr4 flags in `x86` module
|
||||||
// println!("cr4={:#b}", Cr4::read());
|
// println!("cr4={:#b}", Cr4::read());
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -34,23 +34,12 @@ pub mod memory;
|
||||||
pub extern fn kmain(multiboot_info_addr: usize) -> ! {
|
pub extern fn kmain(multiboot_info_addr: usize) -> ! {
|
||||||
// acpi::init().unwrap();
|
// acpi::init().unwrap();
|
||||||
let boot_info = unsafe { multiboot2::load(multiboot_info_addr) };
|
let boot_info = unsafe { multiboot2::load(multiboot_info_addr) };
|
||||||
|
|
||||||
enable_write_protect_bit();
|
enable_write_protect_bit();
|
||||||
|
|
||||||
memory::init(&boot_info);
|
memory::init(&boot_info);
|
||||||
vga::init();
|
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(); }
|
loop { keyboard::kbd_callback(); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -65,19 +65,7 @@ impl ActivePageTable {
|
||||||
let (p2_frame, cr3_flags) = Cr3::read();
|
let (p2_frame, cr3_flags) = Cr3::read();
|
||||||
let old_table = InactivePageTable { p2_frame };
|
let old_table = InactivePageTable { p2_frame };
|
||||||
|
|
||||||
// unsafe { Cr3::write(new_table.p2_frame, cr3_flags); }
|
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 {}
|
|
||||||
|
|
||||||
old_table
|
old_table
|
||||||
}
|
}
|
||||||
|
|
@ -92,15 +80,15 @@ impl InactivePageTable {
|
||||||
active_table: &mut ActivePageTable,
|
active_table: &mut ActivePageTable,
|
||||||
temporary_page: &mut TemporaryPage)
|
temporary_page: &mut TemporaryPage)
|
||||||
-> InactivePageTable {
|
-> 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();
|
table.zero();
|
||||||
// set up recursive mapping for the table
|
// set up recursive mapping for the table
|
||||||
table[1023].set(frame.clone(), PageTableFlags::PRESENT | PageTableFlags::WRITABLE)
|
table[1023].set(frame.clone(), PageTableFlags::PRESENT | PageTableFlags::WRITABLE)
|
||||||
}
|
}
|
||||||
temporary_page.unmap(active_table);
|
temporary_page.unmap(active_table);
|
||||||
InactivePageTable { p2_frame: frame }
|
InactivePageTable { p2_frame: frame }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -137,7 +125,7 @@ pub fn remap_the_kernel<A>(allocator: &mut A, boot_info: &BootInformation)
|
||||||
PhysAddr::new(section.start_address() as u32));
|
PhysAddr::new(section.start_address() as u32));
|
||||||
let end_frame = PhysFrame::containing_address(
|
let end_frame = PhysFrame::containing_address(
|
||||||
PhysAddr::new(section.end_address() as u32 - 1));
|
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);
|
mapper.identity_map(frame, flags, allocator);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -146,17 +134,13 @@ pub fn remap_the_kernel<A>(allocator: &mut A, boot_info: &BootInformation)
|
||||||
PhysAddr::new(boot_info.start_address() as u32));
|
PhysAddr::new(boot_info.start_address() as u32));
|
||||||
let multiboot_end = PhysFrame::containing_address(
|
let multiboot_end = PhysFrame::containing_address(
|
||||||
PhysAddr::new(boot_info.end_address() as u32 - 1));
|
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);
|
mapper.identity_map(frame, PageTableFlags::PRESENT, allocator);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
let old_table = active_table.switch(new_table);
|
let old_table = active_table.switch(new_table);
|
||||||
|
|
||||||
println!("check!");
|
|
||||||
flush!();
|
|
||||||
loop {}
|
|
||||||
|
|
||||||
let old_p2_page = Page::containing_address(
|
let old_p2_page = Page::containing_address(
|
||||||
VirtAddr::new(old_table.p2_frame.start_address().as_u32()));
|
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) {
|
if elf_flags.contains(ElfSectionFlags::WRITABLE) {
|
||||||
flags = flags | PageTableFlags::WRITABLE;
|
flags = flags | PageTableFlags::WRITABLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// LONG MODE STUFF
|
// LONG MODE STUFF
|
||||||
// if !elf_flags.contains(ELF_SECTION_EXECUTABLE) {
|
// if !elf_flags.contains(ELF_SECTION_EXECUTABLE) {
|
||||||
// flags = flags | PageTableFlags::NO_EXECUTE;
|
// flags = flags | PageTableFlags::NO_EXECUTE;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue