From ab37e359ac3998a651acc33c2270df60269ef987 Mon Sep 17 00:00:00 2001 From: WangRunji Date: Fri, 13 Apr 2018 22:57:41 +0800 Subject: [PATCH] Temporarily map pages and run pass APIC init. --- src/arch/x86_64/boot/linker.ld | 18 ++++++++++-------- src/arch/x86_64/driver/acpi/mod.rs | 3 +-- src/arch/x86_64/driver/apic/lapic.rs | 2 -- src/lib.rs | 13 ++++++++++--- src/memory/mod.rs | 11 +++++++++-- 5 files changed, 30 insertions(+), 17 deletions(-) diff --git a/src/arch/x86_64/boot/linker.ld b/src/arch/x86_64/boot/linker.ld index 5b58518..2e2560a 100644 --- a/src/arch/x86_64/boot/linker.ld +++ b/src/arch/x86_64/boot/linker.ld @@ -3,7 +3,7 @@ ENTRY(start) SECTIONS { . = 1M; - .rodata : + .rodata : ALIGN(4K) { /* ensure that the multiboot header is at the beginning */ KEEP(*(.multiboot_header)) @@ -11,42 +11,44 @@ SECTIONS { . = ALIGN(4K); } - .text : + .text : ALIGN(4K) { *(.text .text.*) . = ALIGN(4K); } - .data : + .data : ALIGN(4K) { *(.data .data.*) . = ALIGN(4K); } - .bss : + .bss : ALIGN(4K) { *(.bss .bss.*) . = ALIGN(4K); } - .got : + .got : ALIGN(4K) { *(.got) . = ALIGN(4K); } - .got.plt : + .got.plt : ALIGN(4K) { *(.got.plt) . = ALIGN(4K); } - .data.rel.ro : ALIGN(4K) { + .data.rel.ro : ALIGN(4K) + { *(.data.rel.ro.local*) *(.data.rel.ro .data.rel.ro.*) . = ALIGN(4K); } - .gcc_except_table : ALIGN(4K) { + .gcc_except_table : ALIGN(4K) + { *(.gcc_except_table) . = ALIGN(4K); } diff --git a/src/arch/x86_64/driver/acpi/mod.rs b/src/arch/x86_64/driver/acpi/mod.rs index 2567aba..a68a2be 100644 --- a/src/arch/x86_64/driver/acpi/mod.rs +++ b/src/arch/x86_64/driver/acpi/mod.rs @@ -5,12 +5,11 @@ use self::structs::*; use consts::*; pub fn init() -> Result { - use core::mem::size_of; - use util::Checkable; let rsdp = find_rsdp().expect("acpi: rsdp not found."); if rsdp.RsdtPhysicalAddress > PHYSICAL_MEMORY_LIMIT { return Err(ACPI_Error::NotMapped); } + debug!("RSDT at {:#x}", rsdp.RsdtPhysicalAddress); let rsdt = unsafe{ &*(rsdp.RsdtPhysicalAddress as *const rsdt) }; let mut madt: Option<&'static madt> = None; for i in 0 .. rsdt.entry_count() { diff --git a/src/arch/x86_64/driver/apic/lapic.rs b/src/arch/x86_64/driver/apic/lapic.rs index 1d9a538..8c2a609 100644 --- a/src/arch/x86_64/driver/apic/lapic.rs +++ b/src/arch/x86_64/driver/apic/lapic.rs @@ -7,8 +7,6 @@ pub fn init(lapic_addr: *const ()) { debug!("WARNING: lapic::init use C lib"); unsafe { lapic = lapic_addr; - debug!("lapic = {:?}", lapic); - unimplemented!(); lapicinit(); } } \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index ca17c65..fa95282 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -65,12 +65,19 @@ pub extern "C" fn rust_main(multiboot_information_address: usize) { test!(guard_page); test!(find_mp); - // TODO Build temp page map. Now page fault. + // TODO Handle this temp page map. + memory_controller.map_page_identity(0); // EBDA + for addr in (0xE0000 .. 0x100000).step_by(0x1000) { + memory_controller.map_page_identity(addr); + } + memory_controller.map_page_identity(0x7fe1000); // RSDT + memory_controller.print_page_table(); let acpi = arch::driver::acpi::init().expect("Failed to init ACPI"); debug!("{:?}", acpi); - unimplemented!(); - + + memory_controller.map_page_identity(acpi.lapic_addr as usize); // LAPIC arch::driver::apic::init(acpi.lapic_addr); + io::init(); test_end!(); diff --git a/src/memory/mod.rs b/src/memory/mod.rs index 83df09e..67c35ea 100644 --- a/src/memory/mod.rs +++ b/src/memory/mod.rs @@ -40,8 +40,6 @@ pub fn init(boot_info: &BootInformation) -> MemoryController { let mut active_table = paging::remap_the_kernel(&mut frame_allocator, boot_info); - println!("{:?}", active_table); - use self::paging::Page; use {HEAP_START, HEAP_SIZE}; @@ -131,4 +129,13 @@ impl MemoryController { stack_allocator.alloc_stack(active_table, frame_allocator, size_in_pages) } + pub fn map_page_identity(&mut self, addr: usize) { + use self::paging::{WRITABLE}; + let frame = Frame::containing_address(addr); + let flags = WRITABLE; + self.active_table.identity_map(frame, flags, &mut self.frame_allocator); + } + pub fn print_page_table(&self) { + debug!("{:?}", self.active_table); + } }