Set ready for KFS-2
This commit is contained in:
parent
2ca356340a
commit
9ba59d5858
7 changed files with 42 additions and 24 deletions
|
|
@ -1 +1 @@
|
|||
Subproject commit d66e8cb0e5b10c2097a9aef985b4181694db9ce8
|
||||
Subproject commit 4d6ad9cde926f2ad5d47041e3f3a2cda18f8e11e
|
||||
|
|
@ -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> {
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ pub fn load(addr: u32) -> Result <bool, &'static str> {
|
|||
let ptr_tmp = addr as *const RSDP20;
|
||||
let revision = unsafe {(*ptr_tmp).rsdp.revision};
|
||||
if (revision == 0 && check_checksum(addr, mem::size_of::<RSDP>())) || (revision == 2 && check_checksum(addr, mem::size_of::<RSDP20>())) {
|
||||
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 <bool, &'static str> {
|
|||
Err("Not a valid RSD ptr")
|
||||
}
|
||||
|
||||
fn memory_finding(bound: u32) -> Result <bool, &'static str> {
|
||||
fn memory_finding() -> Result <bool, &'static str> {
|
||||
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 <u32, &'static str> {
|
|||
/// 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 <bool, &'static str> {
|
||||
memory_finding(16)
|
||||
memory_finding()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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(())
|
||||
|
|
|
|||
|
|
@ -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};
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue