Converted DDB handle to integer and vice versa

This commit is contained in:
Connor Wood
2017-08-31 11:25:08 +01:00
parent 1cce42b691
commit 7145e2390c
2 changed files with 38 additions and 2 deletions

View File

@@ -12,7 +12,7 @@ use super::namedobj::{ RegionSpace, FieldFlags };
use super::parser::{AmlExecutionContext, ExecutionState};
use super::AmlError;
use acpi::SdtSignature;
use acpi::{SdtSignature, get_signature_from_index, get_index_from_signature};
#[derive(Clone)]
pub enum FieldSelector {
@@ -255,9 +255,13 @@ impl AmlValue {
}
pub fn get_as_ddb_handle(&self) -> Result<(Vec<String>, SdtSignature), AmlError> {
// TODO: Integer conversion
match *self {
AmlValue::DDBHandle(ref v) => Ok(v.clone()),
AmlValue::Integer(i) => if let Some(sig) = get_signature_from_index(i as usize) {
Ok((vec!(), sig))
} else {
Err(AmlError::AmlValueError)
},
_ => Err(AmlError::AmlValueError)
}
}
@@ -317,6 +321,11 @@ impl AmlValue {
Ok(i)
},
AmlValue::DDBHandle(ref v) => if let Some(idx) = get_index_from_signature(v.1.clone()) {
Ok(idx as u64)
} else {
Err(AmlError::AmlValueError)
},
AmlValue::String(ref s) => {
let mut s = s.clone()[0..8].to_string().to_uppercase();
let mut i: u64 = 0;

View File

@@ -227,6 +227,33 @@ pub fn load_table(signature: SdtSignature) {
}
}
pub fn get_signature_from_index(index: usize) -> Option<SdtSignature> {
if let Some(ref order) = *(SDT_ORDER.read()) {
if index < order.len() {
Some(order[index].clone())
} else {
None
}
} else {
None
}
}
pub fn get_index_from_signature(signature: SdtSignature) -> Option<usize> {
if let Some(ref order) = *(SDT_ORDER.read()) {
let mut i = order.len();
while i > 0 {
i -= 1;
if order[i] == signature {
return Some(i);
}
}
}
None
}
pub struct Acpi {
pub fadt: RwLock<Option<Fadt>>,
pub namespace: RwLock<Option<BTreeMap<String, AmlValue>>>,