From 9ba59d585811d8c0d2124c33cf0c718a6fea211f Mon Sep 17 00:00:00 2001 From: wescande Date: Thu, 8 Mar 2018 14:50:25 +0100 Subject: [PATCH] Set ready for KFS-2 --- kernel-rs/multiboot2-elf64 | 2 +- kernel-rs/src/acpi/mod.rs | 20 ++++++++++++++++++-- kernel-rs/src/acpi/rsdp.rs | 15 ++++----------- kernel-rs/src/arch/x86/boot.asm | 8 ++++---- kernel-rs/src/console.rs | 8 ++++---- kernel-rs/src/lib.rs | 12 +++++++++++- kernel-rs/src/vga/mod.rs | 1 - 7 files changed, 42 insertions(+), 24 deletions(-) diff --git a/kernel-rs/multiboot2-elf64 b/kernel-rs/multiboot2-elf64 index d66e8cb0..4d6ad9cd 160000 --- a/kernel-rs/multiboot2-elf64 +++ b/kernel-rs/multiboot2-elf64 @@ -1 +1 @@ -Subproject commit d66e8cb0e5b10c2097a9aef985b4181694db9ce8 +Subproject commit 4d6ad9cde926f2ad5d47041e3f3a2cda18f8e11e diff --git a/kernel-rs/src/acpi/mod.rs b/kernel-rs/src/acpi/mod.rs index 702e6f9c..5256d1ae 100644 --- a/kernel-rs/src/acpi/mod.rs +++ b/kernel-rs/src/acpi/mod.rs @@ -44,8 +44,7 @@ struct Acpi { } impl Acpi { - fn init(&mut self) -> Result <(), &'static str> { - self.v2 = rsdp::init()?; + fn common_init(&mut self) -> Result <(), &'static str> { if self.v2 { // Xsdt Address: // 64-bit physical address of the XSDT table. If you detect ACPI Version 2.0 you should use this table instead of RSDT even on x86, casting the address to uint32_t. @@ -58,6 +57,15 @@ impl Acpi { dsdt::init(fadt::dsdtaddr()?)?; self.valid = true; Ok(()) + + } + fn init(&mut self) -> Result <(), &'static str> { + self.v2 = rsdp::init()?; + self.common_init() + } + fn load(&mut self, rsdp_addr: u32) -> Result <(), &'static str> { + self.v2 = rsdp::load(rsdp_addr)?; + self.common_init() } } @@ -130,6 +138,14 @@ pub fn init() -> Result <(), &'static str> { unsafe {ACPI.init()} } +/// Load the ACPI module, addr given is a ptr to RSDP +pub fn load(rsdp_addr: u32) -> Result <(), &'static str> { + if let Ok(()) = is_init() { + return Ok(()); + } + unsafe {ACPI.load(rsdp_addr)} +} + /// Proceed to ACPI shutdown /// This function doesn't work with Virtual Box yet pub fn shutdown() -> Result <(), &'static str> { diff --git a/kernel-rs/src/acpi/rsdp.rs b/kernel-rs/src/acpi/rsdp.rs index b5b6967b..d1ec9d52 100644 --- a/kernel-rs/src/acpi/rsdp.rs +++ b/kernel-rs/src/acpi/rsdp.rs @@ -30,6 +30,7 @@ pub fn load(addr: u32) -> Result { let ptr_tmp = addr as *const RSDP20; let revision = unsafe {(*ptr_tmp).rsdp.revision}; if (revision == 0 && check_checksum(addr, mem::size_of::())) || (revision == 2 && check_checksum(addr, mem::size_of::())) { + println!("REAL FOUND AT {:x}", addr); unsafe {RSDPTR = Some(ptr_tmp)}; return Ok(revision == 2); } @@ -37,18 +38,14 @@ pub fn load(addr: u32) -> Result { Err("Not a valid RSD ptr") } -fn memory_finding(bound: u32) -> Result { +fn memory_finding() -> Result { let mut i = 0; while i < 0x1000000 { - i += bound; + i += 8; if let Ok(result) = load(i) { return Ok(result) } } - // HACK because RSDP is not always aligned on 16 bytes boundary with QEMU - if bound > 1 { - return memory_finding(bound / 2); - } Err("Can not find Root System Description Pointer (RSDP).") } @@ -56,10 +53,6 @@ fn is_init() -> Result <*const RSDP20, &'static str> { match unsafe {RSDPTR} { Some(ptr) => Ok(ptr), None => Err("Root System Description Pointer (RSDP) is not initialized") - // if ptr == 0 as *const RSDP20 - // => Err("Root System Description Pointer (RSDP) is not initialized"), - // ptr - // => Ok(ptr) } } @@ -85,5 +78,5 @@ pub fn rsdtaddr() -> Result { /// if you already know the location, you should prefer to use load function /// return an Error if there is no RSDP in memory, or return the value of load function pub fn init() -> Result { - memory_finding(16) + memory_finding() } diff --git a/kernel-rs/src/arch/x86/boot.asm b/kernel-rs/src/arch/x86/boot.asm index 2b8b5995..ed470888 100644 --- a/kernel-rs/src/arch/x86/boot.asm +++ b/kernel-rs/src/arch/x86/boot.asm @@ -62,7 +62,7 @@ GDTR: DW 0xffff ; Limit ( bits 0 -15 ) DW 0x0 ; Base ( bits 0 -15 ) DB 0x0 ; Base ( bits 16 -23 ) - DB 0xFE ; [ Access Flags: 0x9A=11111110b = (present)|(Privilege Ring 3=11b)|(1)|(code => 1)|(expand up => 1)|(readable)|(0) ] + DB 0xFE ; [ Access Flags: 0xFE=11111110b = (present)|(Privilege Ring 3=11b)|(1)|(code => 1)|(expand up => 1)|(readable)|(0) ] DB 0xCF ; [ Flags: C=1100b = (granularity)|(32bit)|(!64bit)|(0) ] / [ Limits: (bits 16-19): F=1111b ] DB 0x0 ; Base ( bits 24 -31 ) @@ -70,7 +70,7 @@ GDTR: DW 0xffff ; Limit ( bits 0 -15 ) DW 0x0 ; Base ( bits 0 -15 ) DB 0x0 ; Base ( bits 16 -23 ) - DB 0xF2 ; [ Access Flags: 0x9A=11110010b = (present)|(Privilege Ring 3=11b)|(1)|(data => 0)|(expand down => 0)|(readable)|(0) ] + DB 0xF2 ; [ Access Flags: 0xF2=11110010b = (present)|(Privilege Ring 3=11b)|(1)|(data => 0)|(expand down => 0)|(readable)|(0) ] DB 0xCF ; [ Flags: C=1100b = (granularity)|(32bit)|(!64bit)|(0) ] / [ Limits: (bits 16-19): F=1111b ] DB 0x0 ; Base ( bits 24 -31 ) @@ -78,8 +78,8 @@ GDTR: DW 0x0 ; Limit ( bits 0 -15 ) DW 0x0 ; Base ( bits 0 -15 ) DB 0x0 ; Base ( bits 16 -23 ) - DB 0x00 ; [ Access Flags: 0x9A=11110110b = (present)|(Privilege Ring 3=11b)|(1)|(data => 0)|(expand up => 1)|(readable)|(0) ] - DB 0x00 ; [ Flags: C=1100b = (granularity)|(32bit)|(!64bit)|(0) ] / [ Limits: (bits 16-19): F=1111b ] + DB 0xF6 ; [ Access Flags: 0xF2=11110110b = (present)|(Privilege Ring 3=11b)|(1)|(data => 0)|(expand up => 1)|(readable)|(0) ] + DB 0xCF ; [ Flags: C=1100b = (granularity)|(32bit)|(!64bit)|(0) ] / [ Limits: (bits 16-19): F=1111b ] DB 0x0 ; Base ( bits 24 -31 ) .gdt_bottom: diff --git a/kernel-rs/src/console.rs b/kernel-rs/src/console.rs index b43620e8..aba02cc6 100644 --- a/kernel-rs/src/console.rs +++ b/kernel-rs/src/console.rs @@ -35,10 +35,10 @@ fn help() -> Result <(), &'static str> { print!("{}\n{}\n{}\n{}\n{}\n{}\n{}\n{}\n", "acpi => Return acpi state (ENABLED|DISABLE)", "help | h => Print this help", - "memory => lolilol", // TODO - "multiboot => lolilol", // TODO - "reboot => reboot", - "sections => lolilol", // TODO + "memory => Print memory areas", + "multiboot => Print multiboot information", + "reboot => Reboot", + "sections => Print elf sections", "shutdown | halt | q => Kill a kitten, then shutdown", "stack => Print kernel stack in a fancy way"); Ok(()) diff --git a/kernel-rs/src/lib.rs b/kernel-rs/src/lib.rs index 0c0170cd..8ff0e619 100644 --- a/kernel-rs/src/lib.rs +++ b/kernel-rs/src/lib.rs @@ -26,7 +26,17 @@ use context::CONTEXT; fn init_kernel(multiboot_information_address: usize) -> Result <(), &'static str> { unsafe { CONTEXT.boot_info_addr = multiboot_information_address }; - acpi::init()?; + let mtboot = unsafe { multiboot2::load(multiboot_information_address)}; + if let Some(rsdp) = mtboot.rsdp_v2_tag() { + println!("rsdp at {:x}", rsdp); + acpi::load(rsdp)?; + } else if let Some(rsdp) = mtboot.rsdp_tag() { + println!("rsdp2 at {:x}", rsdp); + acpi::load(rsdp)?; + } + else { + acpi::init()?; + } Ok(()) } use vga::{Color, ColorCode}; diff --git a/kernel-rs/src/vga/mod.rs b/kernel-rs/src/vga/mod.rs index c448f91c..130da283 100644 --- a/kernel-rs/src/vga/mod.rs +++ b/kernel-rs/src/vga/mod.rs @@ -123,7 +123,6 @@ impl Writer { self.buffer[i] = b' '; self.buffer[i + 1] = 0; self.flush(); - // flush!(); } pub fn write_byte(&mut self, byte: u8) {