All conversions to BufferField, dependent on the conversion to Buffer

This commit is contained in:
Connor Wood
2017-07-24 16:15:18 +01:00
parent 9408e71dcd
commit e7edaceec0
2 changed files with 44 additions and 22 deletions

View File

@@ -3,7 +3,8 @@ 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 };
use super::namespace::{AmlValue, ObjectReference, FieldSelector, Method, get_namespace_string,
Accessor, BufferField};
use super::namestring::{parse_name_string, parse_name_seg};
use super::termlist::{parse_term_arg, parse_object_list};
use super::pkglength::parse_pkg_length;
@@ -182,11 +183,11 @@ fn parse_def_create_bit_field(data: &[u8],
let local_scope_string = get_namespace_string(ctx.scope.clone(), name.val)?;
ctx.add_to_namespace(local_scope_string, AmlValue::BufferField {
ctx.add_to_namespace(local_scope_string, AmlValue::BufferField(BufferField {
source_buf: Box::new(source_buf.val),
index: Box::new(bit_index.val),
length: Box::new(AmlValue::IntegerConstant(1))
})?;
}))?;
Ok(AmlParseType {
val: AmlValue::None,
@@ -212,11 +213,11 @@ fn parse_def_create_byte_field(data: &[u8],
let local_scope_string = get_namespace_string(ctx.scope.clone(), name.val)?;
ctx.add_to_namespace(local_scope_string, AmlValue::BufferField {
ctx.add_to_namespace(local_scope_string, AmlValue::BufferField(BufferField {
source_buf: Box::new(source_buf.val),
index: Box::new(bit_index.val),
length: Box::new(AmlValue::IntegerConstant(8))
})?;
}))?;
Ok(AmlParseType {
val: AmlValue::None,
@@ -242,11 +243,11 @@ fn parse_def_create_word_field(data: &[u8],
let local_scope_string = get_namespace_string(ctx.scope.clone(), name.val)?;
ctx.add_to_namespace(local_scope_string, AmlValue::BufferField {
ctx.add_to_namespace(local_scope_string, AmlValue::BufferField(BufferField {
source_buf: Box::new(source_buf.val),
index: Box::new(bit_index.val),
length: Box::new(AmlValue::IntegerConstant(16))
})?;
}))?;
Ok(AmlParseType {
val: AmlValue::None,
@@ -272,11 +273,11 @@ fn parse_def_create_dword_field(data: &[u8],
let local_scope_string = get_namespace_string(ctx.scope.clone(), name.val)?;
ctx.add_to_namespace(local_scope_string, AmlValue::BufferField {
ctx.add_to_namespace(local_scope_string, AmlValue::BufferField(BufferField {
source_buf: Box::new(source_buf.val),
index: Box::new(bit_index.val),
length: Box::new(AmlValue::IntegerConstant(32))
});
}));
Ok(AmlParseType {
val: AmlValue::None,
@@ -302,11 +303,11 @@ fn parse_def_create_qword_field(data: &[u8],
let local_scope_string = get_namespace_string(ctx.scope.clone(), name.val)?;
ctx.add_to_namespace(local_scope_string, AmlValue::BufferField {
ctx.add_to_namespace(local_scope_string, AmlValue::BufferField(BufferField {
source_buf: Box::new(source_buf.val),
index: Box::new(bit_index.val),
length: Box::new(AmlValue::IntegerConstant(64))
})?;
}))?;
Ok(AmlParseType {
val: AmlValue::None,
@@ -333,11 +334,11 @@ fn parse_def_create_field(data: &[u8],
let local_scope_string = get_namespace_string(ctx.scope.clone(), name.val)?;
ctx.add_to_namespace(local_scope_string, AmlValue::BufferField {
ctx.add_to_namespace(local_scope_string, AmlValue::BufferField(BufferField {
source_buf: Box::new(source_buf.val),
index: Box::new(bit_index.val),
length: Box::new(num_bits.val)
})?;
}))?;
Ok(AmlParseType {
val: AmlValue::None,

View File

@@ -40,6 +40,13 @@ pub struct Method {
pub term_list: Vec<u8>
}
#[derive(Clone)]
pub struct BufferField {
pub source_buf: Box<AmlValue>,
pub index: Box<AmlValue>,
pub length: Box<AmlValue>
}
pub struct Accessor {
pub read: fn(usize) -> u64,
pub write: fn(usize, u64)
@@ -59,11 +66,7 @@ pub enum AmlValue {
None,
Uninitialized,
Buffer(Vec<u8>),
BufferField {
source_buf: Box<AmlValue>,
index: Box<AmlValue>,
length: Box<AmlValue>
},
BufferField(BufferField),
DDBHandle(Vec<String>),
DebugObject,
Device(Vec<String>),
@@ -129,6 +132,24 @@ impl AmlValue {
}
}
pub fn get_as_buffer_field(&self) -> Result<BufferField, AmlError> {
match *self {
AmlValue::BufferField(ref b) => Ok(b.clone()),
_ => {
let raw_buf = self.get_as_buffer()?;
let buf = Box::new(AmlValue::Buffer(raw_buf.clone()));
let idx = Box::new(AmlValue::IntegerConstant(0));
let len = Box::new(AmlValue::Integer(raw_buf.len() as u64));
Ok(BufferField {
source_buf: buf,
index: idx,
length: len
})
}
}
}
pub fn get_as_buffer(&self) -> Result<Vec<u8>, AmlError> {
match *self {
AmlValue::Buffer(ref b) => Ok(b.clone()),
@@ -150,10 +171,10 @@ impl AmlValue {
AmlValue::String(ref s) => {
Ok(s.clone().into_bytes())
},
AmlValue::BufferField { ref source_buf, ref index, ref length } => {
let buf = source_buf.get_as_buffer()?;
let idx = index.get_as_integer()? as usize;
let len = length.get_as_integer()? as usize;
AmlValue::BufferField(ref b) => {
let buf = b.source_buf.get_as_buffer()?;
let idx = b.index.get_as_integer()? as usize;
let len = b.length.get_as_integer()? as usize;
if idx + len > buf.len() {
return Err(AmlError::AmlValueError);