acpi in static not in reference

This commit is contained in:
wescande 2018-03-16 15:03:00 +01:00
parent e73d3e175a
commit 904e7158d8
8 changed files with 33 additions and 33 deletions

View file

@ -12,7 +12,7 @@ static mut DSDT: DSDT = DSDT {
struct DSDT { struct DSDT {
valid: bool, valid: bool,
dsdt: Option<*const ACPISDTHeader>, dsdt: Option<&'static ACPISDTHeader>,
s5_ptr: u32, s5_ptr: u32,
slp_typ_a: u16, slp_typ_a: u16,
slp_typ_b: u16 slp_typ_b: u16
@ -20,7 +20,7 @@ struct DSDT {
impl DSDT { impl DSDT {
fn init(&mut self, addr: u32) -> Result <(), &'static str> { fn init(&mut self, addr: u32) -> Result <(), &'static str> {
self.dsdt = Some(addr as *const ACPISDTHeader); self.dsdt = Some(unsafe{ &(*(addr as *const ACPISDTHeader)) });
self.s5_ptr = self.find_s5(addr)?; self.s5_ptr = self.find_s5(addr)?;
self.parse_s5(); self.parse_s5();
self.valid = true; self.valid = true;
@ -29,7 +29,7 @@ impl DSDT {
fn find_s5(&self, addr: u32) -> Result <u32, &'static str> { fn find_s5(&self, addr: u32) -> Result <u32, &'static str> {
let dsdt_start = addr + mem::size_of::<ACPISDTHeader>() as u32; let dsdt_start = addr + mem::size_of::<ACPISDTHeader>() as u32;
let dsdt_end = dsdt_start + unsafe {(*self.dsdt.unwrap()).length}; let dsdt_end = dsdt_start + self.dsdt.unwrap().length;
for addr in dsdt_start..dsdt_end { for addr in dsdt_start..dsdt_end {
if check_signature(addr, "_S5_") { if check_signature(addr, "_S5_") {
if (check_signature(addr - 1, "\x08") || check_signature(addr - 2, "\x08\\")) && check_signature(addr + 4, "\x12") { if (check_signature(addr - 1, "\x08") || check_signature(addr - 2, "\x08\\")) && check_signature(addr + 4, "\x12") {

View file

@ -83,18 +83,18 @@ struct FADT
} }
static mut FADT: Option<*const FADT> = None; static mut FADT: Option<&'static FADT> = None;
/// ## Initialize Fixed ACPI Description Table (FADT) /// ## Initialize Fixed ACPI Description Table (FADT)
/// input param addr is contain in other ptr of rsdt /// input param addr is contain in other ptr of rsdt
pub fn init(sdt_iter: ACPISDTIter) -> Result <(), &'static str> { pub fn init(sdt_iter: ACPISDTIter) -> Result <(), &'static str> {
for sdt_ptr in sdt_iter { for sdt_ptr in sdt_iter {
if ACPISDTHeader::valid(sdt_ptr, "FACP") { // Where is "FADT"? Shut up is magic if ACPISDTHeader::valid(sdt_ptr, "FACP") { // Where is "FADT"? Shut up is magic
let ptr = sdt_ptr as *const FADT; let ref fadt_tmp: &FADT = unsafe{ &(*(sdt_ptr as *const FADT)) };
unsafe {FADT = Some(ptr)}; unsafe {FADT = Some(fadt_tmp)};
if !is_enable()? { // TODO do i have to check if enabled before init ??? if !is_enable()? { // TODO do i have to check if enabled before init ???
let smi_cmd = unsafe {(*ptr).smi_commandport} as u16; // TODO WHY DO I NEED THIS FUCKING CAST let smi_cmd = fadt_tmp.smi_commandport as u16; // TODO WHY DO I NEED THIS FUCKING CAST
let acpi_enable = unsafe {(*ptr).acpi_enable}; let acpi_enable = fadt_tmp.acpi_enable;
cpuio::outb(smi_cmd, acpi_enable); // send acpi enable command cpuio::outb(smi_cmd, acpi_enable); // send acpi enable command
} }
return Ok(()); return Ok(());
@ -103,9 +103,9 @@ pub fn init(sdt_iter: ACPISDTIter) -> Result <(), &'static str> {
return Err("Can not find Fixed ACPI Description Table (FADT)."); return Err("Can not find Fixed ACPI Description Table (FADT).");
} }
fn is_init() -> Result <*const FADT, &'static str> { fn is_init() -> Result <&'static FADT, &'static str> {
match unsafe {FADT} { match unsafe {FADT} {
Some(ptr) => Ok(ptr), Some(fadt) => Ok(fadt),
None => Err("Fixed ACPI Description Table (FADT) is not initialized") None => Err("Fixed ACPI Description Table (FADT) is not initialized")
} }
} }
@ -113,18 +113,18 @@ fn is_init() -> Result <*const FADT, &'static str> {
/// Return Dsdt address /// Return Dsdt address
/// FADT must have been initialized first /// FADT must have been initialized first
pub fn dsdtaddr() -> Result <u32, &'static str> { pub fn dsdtaddr() -> Result <u32, &'static str> {
let ptr = is_init()?; let fadt = is_init()?;
return Ok(unsafe {(*ptr).dsdt}); return Ok(fadt.dsdt);
} }
fn get_cnt(ptr: *const FADT) -> [u16; 2] { fn get_cnt(fadt: &'static FADT) -> [u16; 2] {
[unsafe {(*ptr).pm1acontrolblock} as u16, unsafe {(*ptr).pm1bcontrolblock} as u16] // TODO WHY DO I NEED THIS FUCKING CAST [fadt.pm1acontrolblock as u16, fadt.pm1bcontrolblock as u16] // TODO WHY DO I NEED THIS FUCKING CAST
} }
/// Return true/false depending of acpi is enable /// Return true/false depending of acpi is enable
pub fn is_enable() -> Result <bool, &'static str> { pub fn is_enable() -> Result <bool, &'static str> {
let ptr = is_init()?; let fadt = is_init()?;
let pm1_cnt = get_cnt(ptr); let pm1_cnt = get_cnt(fadt);
if pm1_cnt[1] == 0 { if pm1_cnt[1] == 0 {
Ok(cpuio::inw(pm1_cnt[0]) & 0x1 == 0x1) Ok(cpuio::inw(pm1_cnt[0]) & 0x1 == 0x1)
} else { } else {

View file

@ -6,6 +6,7 @@ mod dsdt;
use core; use core;
use core::mem; use core::mem;
// use cpuio;
#[repr(C)] #[repr(C)]
#[derive(Debug, Clone, Copy)] #[derive(Debug, Clone, Copy)]

View file

@ -19,7 +19,7 @@ pub struct RSDP20 {
reserved: [u8; 3], reserved: [u8; 3],
} }
static mut RSDPTR: Option<*const RSDP20> = None; static mut RSDPTR: Option<&'static RSDP20> = None;
/// RSDP load will check is RSDP is present at the addr sent. /// RSDP load will check is RSDP is present at the addr sent.
/// Return a bool /// Return a bool
@ -27,10 +27,11 @@ static mut RSDPTR: Option<*const RSDP20> = None;
/// false => RSDP is V1 /// false => RSDP is V1
pub fn load(addr: u32) -> Result <bool, &'static str> { pub fn load(addr: u32) -> Result <bool, &'static str> {
if check_signature(addr, "RSD PTR ") { if check_signature(addr, "RSD PTR ") {
let ptr_tmp = addr as *const RSDP20; let ref rsdp_tmp: &RSDP20 = unsafe{ &(*(addr as *const RSDP20)) };
let revision = unsafe {(*ptr_tmp).rsdp.revision}; let revision = rsdp_tmp.rsdp.revision;
if (revision == 0 && check_checksum(addr, mem::size_of::<RSDP>())) || (revision == 2 && check_checksum(addr, mem::size_of::<RSDP20>())) { if (revision == 0 && check_checksum(addr, mem::size_of::<RSDP>())) || (revision == 2 && check_checksum(addr, mem::size_of::<RSDP20>())) {
unsafe {RSDPTR = Some(ptr_tmp)}; unsafe {RSDPTR = Some(rsdp_tmp)};
println!("Found rsdptr at {:#x}", addr);
return Ok(revision == 2); return Ok(revision == 2);
} }
} }
@ -52,33 +53,29 @@ fn memory_finding(bound: u32) -> Result <bool, &'static str> {
Err("Can not find Root System Description Pointer (RSDP).") Err("Can not find Root System Description Pointer (RSDP).")
} }
fn is_init() -> Result <*const RSDP20, &'static str> { fn is_init() -> Result <&'static RSDP20, &'static str> {
match unsafe {RSDPTR} { match unsafe {RSDPTR} {
Some(ptr) => Ok(ptr), Some(rsdptr) => Ok(rsdptr),
None => Err("Root System Description Pointer (RSDP) is not initialized") 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)
} }
} }
/// Return a ptr on xsdt /// Return a ptr on xsdt
/// RSDP must have been initialized first /// RSDP must have been initialized first
pub fn xsdtaddr() -> Result <u64, &'static str> { pub fn xsdtaddr() -> Result <u64, &'static str> {
let ptr = is_init()?; let rsdptr = is_init()?;
let revision = unsafe {(*ptr).rsdp.revision}; let revision = rsdptr.rsdp.revision;
if revision != 2 { if revision != 2 {
return Err("Wrong RSDP version asked"); return Err("Wrong RSDP version asked");
} }
return Ok(unsafe {(*ptr).xsdtaddress}); return Ok(rsdptr.xsdtaddress);
} }
/// Return a ptr on rsdt /// Return a ptr on rsdt
/// RSDP must have been initialized first /// RSDP must have been initialized first
pub fn rsdtaddr() -> Result <u32, &'static str> { pub fn rsdtaddr() -> Result <u32, &'static str> {
let ptr = is_init()?; let rsdptr = is_init()?;
return Ok(unsafe {(*ptr).rsdp.rsdtaddr}); return Ok(rsdptr.rsdp.rsdtaddr);
} }
/// RSDP init will iter on addr in [0x0 - 0x1000000] to find "RSDP PTR " /// RSDP init will iter on addr in [0x0 - 0x1000000] to find "RSDP PTR "

View file

@ -1,5 +1,6 @@
use super::{ACPISDTHeader,ACPISDTIter}; use super::{ACPISDTHeader,ACPISDTIter};
//TODO this can work only if pagging is disabled
static mut RSDT: Option<*const ACPISDTHeader> = None; static mut RSDT: Option<*const ACPISDTHeader> = None;
/// ## Initialize Root System Description Table (RSDT) /// ## Initialize Root System Description Table (RSDT)

View file

@ -1,5 +1,6 @@
use super::{ACPISDTHeader,ACPISDTIter}; use super::{ACPISDTHeader,ACPISDTIter};
//TODO this can work only if pagging is disabled
static mut XSDT: Option<*const ACPISDTHeader> = None; static mut XSDT: Option<*const ACPISDTHeader> = None;
/// ## Initialize Root System Description Table (XSDT) /// ## Initialize Root System Description Table (XSDT)

View file

@ -13,7 +13,7 @@ start:
call set_up_page_tables call set_up_page_tables
call enable_pse call enable_pse
call enable_paging ; call enable_paging
; load the new gdt ; load the new gdt
lgdt [GDTR.ptr] lgdt [GDTR.ptr]

View file

@ -31,7 +31,7 @@ pub mod x86;
#[no_mangle] #[no_mangle]
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();