Completed simple type conversions

This commit is contained in:
Connor Wood
2017-07-24 17:50:41 +01:00
parent fdcacd7d18
commit d7229d7132
4 changed files with 106 additions and 46 deletions

View File

@@ -4,7 +4,7 @@ use collections::string::String;
use super::AmlError;
use super::parser::{ AmlParseType, ParseResult, AmlParseTypeGeneric, AmlExecutionContext, ExecutionState };
use super::namespace::{AmlValue, ObjectReference, FieldSelector, Method, get_namespace_string,
Accessor, BufferField, FieldUnit};
Accessor, BufferField, FieldUnit, Processor, PowerResource, OperationRegion};
use super::namestring::{parse_name_string, parse_name_seg};
use super::termlist::{parse_term_arg, parse_object_list};
use super::pkglength::parse_pkg_length;
@@ -366,7 +366,7 @@ fn parse_def_data_region(data: &[u8],
let local_scope_string = get_namespace_string(ctx.scope.clone(), name.val)?;
ctx.add_to_namespace(local_scope_string, AmlValue::OperationRegion {
ctx.add_to_namespace(local_scope_string, AmlValue::OperationRegion(OperationRegion {
region: RegionSpace::SystemMemory,
offset: Box::new(AmlValue::IntegerConstant(0)),
len: Box::new(AmlValue::IntegerConstant(0)),
@@ -375,7 +375,7 @@ fn parse_def_data_region(data: &[u8],
write: |x, y| ()
},
accessed_by: None
})?;
}))?;
Ok(AmlParseType {
val: AmlValue::None,
@@ -467,7 +467,7 @@ fn parse_def_op_region(data: &[u8],
let len = parse_term_arg(&data[3 + name.len + offset.len..], ctx)?;
let local_scope_string = get_namespace_string(ctx.scope.clone(), name.val)?;
ctx.add_to_namespace(local_scope_string, AmlValue::OperationRegion {
ctx.add_to_namespace(local_scope_string, AmlValue::OperationRegion(OperationRegion {
region: region,
offset: Box::new(offset.val),
len: Box::new(len.val),
@@ -476,7 +476,7 @@ fn parse_def_op_region(data: &[u8],
write: |x, y| ()
},
accessed_by: None
})?;
}))?;
Ok(AmlParseType {
val: AmlValue::None,
@@ -850,11 +850,11 @@ fn parse_def_power_res(data: &[u8],
let mut local_ctx = AmlExecutionContext::new(local_scope_string.clone());
parse_object_list(&data[5 + pkg_len_len + name.len .. 2 + pkg_len], &mut local_ctx)?;
ctx.add_to_namespace(local_scope_string, AmlValue::PowerResource {
ctx.add_to_namespace(local_scope_string, AmlValue::PowerResource(PowerResource {
system_level,
resource_order,
obj_list: local_ctx.namespace_delta.clone()
})?;
}))?;
Ok(AmlParseType {
val: AmlValue::None,
@@ -889,11 +889,11 @@ fn parse_def_processor(data: &[u8],
let mut local_ctx = AmlExecutionContext::new(local_scope_string.clone());
parse_object_list(&data[8 + pkg_len_len + name.len .. 2 + pkg_len], &mut local_ctx)?;
ctx.add_to_namespace(local_scope_string, AmlValue::Processor {
ctx.add_to_namespace(local_scope_string, AmlValue::Processor(Processor {
proc_id: proc_id,
p_blk: if p_blk_len > 0 { Some(p_blk_addr) } else { None },
obj_list: local_ctx.namespace_delta.clone()
})?;
}))?;
Ok(AmlParseType {
val: AmlValue::None,

View File

@@ -56,6 +56,29 @@ pub struct FieldUnit {
pub length: usize
}
#[derive(Clone)]
pub struct Processor {
pub proc_id: u8,
pub p_blk: Option<u32>,
pub obj_list: Vec<String>
}
#[derive(Clone)]
pub struct OperationRegion {
pub region: RegionSpace,
pub offset: Box<AmlValue>,
pub len: Box<AmlValue>,
pub accessor: Accessor,
pub accessed_by: Option<u64>
}
#[derive(Clone)]
pub struct PowerResource {
pub system_level: u8,
pub resource_order: u16,
pub obj_list: Vec<String>
}
pub struct Accessor {
pub read: fn(usize) -> u64,
pub write: fn(usize, u64)
@@ -86,25 +109,11 @@ pub enum AmlValue {
Method(Method),
Mutex((u8, Option<u64>)),
ObjectReference(ObjectReference),
OperationRegion {
region: RegionSpace,
offset: Box<AmlValue>,
len: Box<AmlValue>,
accessor: Accessor,
accessed_by: Option<u64>
},
OperationRegion(OperationRegion),
Package(Vec<AmlValue>),
String(String),
PowerResource {
system_level: u8,
resource_order: u16,
obj_list: Vec<String>
},
Processor {
proc_id: u8,
p_blk: Option<u32>,
obj_list: Vec<String>
},
PowerResource(PowerResource),
Processor(Processor),
RawDataBuffer(Vec<u8>),
ThermalZone(Vec<String>)
}
@@ -198,6 +207,14 @@ impl AmlValue {
}
pub fn get_as_integer(&self) -> Result<u64, AmlError> {
match *self {
AmlValue::IntegerConstant(ref i) => Ok(i.clone()),
AmlValue::Integer(ref i) => Ok(i.clone()),
_ => Err(AmlError::AmlValueError)
}
}
pub fn get_as_integer_constant(&self) -> Result<u64, AmlError> {
match *self {
AmlValue::IntegerConstant(ref i) => Ok(i.clone()),
_ => Err(AmlError::AmlValueError)
@@ -210,6 +227,27 @@ impl AmlValue {
_ => Err(AmlError::AmlValueError)
}
}
pub fn get_as_mutex(&self) -> Result<(u8, Option<u64>), AmlError> {
match *self {
AmlValue::Mutex(ref m) => Ok(m.clone()),
_ => Err(AmlError::AmlValueError)
}
}
pub fn get_as_object_reference(&self) -> Result<ObjectReference, AmlError> {
match *self {
AmlValue::ObjectReference(ref m) => Ok(m.clone()),
_ => Err(AmlError::AmlValueError)
}
}
pub fn get_as_operation_region(&self) -> Result<OperationRegion, AmlError> {
match *self {
AmlValue::OperationRegion(ref p) => Ok(p.clone()),
_ => Err(AmlError::AmlValueError)
}
}
pub fn get_as_package(&self) -> Result<Vec<AmlValue>, AmlError> {
match *self {
@@ -224,6 +262,34 @@ impl AmlValue {
_ => Err(AmlError::AmlValueError)
}
}
pub fn get_as_power_resource(&self) -> Result<PowerResource, AmlError> {
match *self {
AmlValue::PowerResource(ref p) => Ok(p.clone()),
_ => Err(AmlError::AmlValueError)
}
}
pub fn get_as_processor(&self) -> Result<Processor, AmlError> {
match *self {
AmlValue::Processor(ref p) => Ok(p.clone()),
_ => Err(AmlError::AmlValueError)
}
}
pub fn get_as_raw_data_buffer(&self) -> Result<Vec<u8>, AmlError> {
match *self {
AmlValue::RawDataBuffer(ref p) => Ok(p.clone()),
_ => Err(AmlError::AmlValueError)
}
}
pub fn get_as_thermal_zone(&self) -> Result<Vec<String>, AmlError> {
match *self {
AmlValue::ThermalZone(ref p) => Ok(p.clone()),
_ => Err(AmlError::AmlValueError)
}
}
}
impl Method {

View File

@@ -1,6 +1,6 @@
use super::AmlError;
use super::parser::{AmlParseType, ParseResult, AmlExecutionContext, ExecutionState};
use super::namespace::{AmlValue, ObjectReference};
use super::namespace::{AmlValue, ObjectReference, OperationRegion};
use super::pkglength::parse_pkg_length;
use super::termlist::{parse_term_arg, parse_term_list};
use super::namestring::{parse_name_string, parse_super_name};
@@ -216,16 +216,13 @@ fn parse_def_release(data: &[u8],
}
}
},
AmlValue::OperationRegion { region, offset, len, accessor, accessed_by } => {
if let Some(o) = accessed_by {
AmlValue::OperationRegion(ref region) => {
if let Some(o) = region.accessed_by {
if o == ctx.ctx_id {
ctx.modify(obj.val.clone(), AmlValue::OperationRegion {
region,
offset,
len,
accessor,
accessed_by: None
});
let mut new_region = region.clone();
new_region.accessed_by = None;
ctx.modify(obj.val.clone(), AmlValue::OperationRegion(new_region));
} else {
return Err(AmlError::AmlHardFatal);
}

View File

@@ -4,7 +4,7 @@ use collections::vec::Vec;
use super::{AmlError, parse_aml_with_scope};
use super::parser::{AmlParseType, ParseResult, AmlExecutionContext, ExecutionState};
use super::namespace::{AmlValue, ObjectReference};
use super::namespace::{AmlValue, ObjectReference, OperationRegion};
use super::pkglength::parse_pkg_length;
use super::termlist::{parse_term_arg, parse_method_invocation};
use super::namestring::{parse_super_name, parse_target, parse_name_string, parse_simple_name};
@@ -332,15 +332,12 @@ fn parse_def_acquire(data: &[u8],
});
}
},
AmlValue::OperationRegion { region, offset, len, accessor, accessed_by } => {
if accessed_by == None {
ctx.modify(obj.val.clone(), AmlValue::OperationRegion {
region,
offset,
len,
accessor,
accessed_by: Some(id)
});
AmlValue::OperationRegion(ref o) => {
if o.accessed_by == None {
let mut new_region = o.clone();
new_region.accessed_by = Some(id);
ctx.modify(obj.val.clone(), AmlValue::OperationRegion(new_region));
return Ok(AmlParseType {
val: AmlValue::Integer(0),
len: 4 + obj.len