Memory handler API

This commit is contained in:
Connor Wood
2017-07-21 14:11:29 +01:00
parent 0365b6f2b7
commit 1938ca0435
2 changed files with 36 additions and 8 deletions

View File

@@ -7,7 +7,7 @@ use collections::btree_map::BTreeMap;
use super::AmlError;
use super::parser::{ AmlParseType, ParseResult, AmlParseTypeGeneric, AmlExecutionContext, ExecutionState };
use super::namespace::{ AmlValue, ObjectReference, FieldSelector, Method, get_namespace_string };
use super::namespace::{ AmlValue, ObjectReference, FieldSelector, Method, get_namespace_string, Accessor };
use super::namestring::{parse_name_string, parse_name_seg};
use super::termlist::{parse_term_arg, parse_term_list, parse_object_list};
use super::pkglength::parse_pkg_length;
@@ -373,7 +373,11 @@ fn parse_def_data_region(data: &[u8],
ctx.add_to_namespace(local_scope_string, AmlValue::OperationRegion {
region: RegionSpace::SystemMemory,
offset: Box::new(AmlValue::IntegerConstant(0)),
len: Box::new(AmlValue::IntegerConstant(0))
len: Box::new(AmlValue::IntegerConstant(0)),
accessor: Accessor {
read: |x| 0 as u64,
write: |x, y| ()
}
});
Ok(AmlParseType {
@@ -469,7 +473,11 @@ fn parse_def_op_region(data: &[u8],
ctx.add_to_namespace(local_scope_string, AmlValue::OperationRegion {
region: region,
offset: Box::new(offset.val),
len: Box::new(len.val)
len: Box::new(len.val),
accessor: Accessor {
read: |x| 0 as u64,
write: |x, y| ()
}
});
Ok(AmlParseType {

View File

@@ -4,13 +4,14 @@ use collections::vec::Vec;
use collections::btree_map::BTreeMap;
use core::str::FromStr;
use core::fmt::{Debug, Formatter, Error};
use super::termlist::parse_term_list;
use super::namedobj::{ RegionSpace, FieldFlags };
use super::parser::{AmlExecutionContext, ExecutionState};
use super::AmlError;
#[derive(Debug, Clone)]
#[derive(Clone)]
pub enum FieldSelector {
Region(String),
Bank {
@@ -23,7 +24,7 @@ pub enum FieldSelector {
}
}
#[derive(Debug, Clone)]
#[derive(Clone)]
pub enum ObjectReference {
ArgObj(u8),
LocalObj(u8),
@@ -32,7 +33,7 @@ pub enum ObjectReference {
Index(Box<AmlValue>, Box<AmlValue>)
}
#[derive(Debug, Clone)]
#[derive(Clone)]
pub struct Method {
pub arg_count: u8,
pub serialized: bool,
@@ -40,7 +41,21 @@ pub struct Method {
pub term_list: Vec<u8>
}
#[derive(Debug, Clone)]
pub struct Accessor {
pub read: fn(usize) -> u64,
pub write: fn(usize, u64)
}
impl Clone for Accessor {
fn clone(&self) -> Accessor {
Accessor {
read: (*self).read,
write: (*self).write
}
}
}
#[derive(Clone)]
pub enum AmlValue {
None,
Uninitialized,
@@ -69,7 +84,8 @@ pub enum AmlValue {
OperationRegion {
region: RegionSpace,
offset: Box<AmlValue>,
len: Box<AmlValue>
len: Box<AmlValue>,
accessor: Accessor
},
Package(Vec<AmlValue>),
String(String),
@@ -87,6 +103,10 @@ pub enum AmlValue {
ThermalZone(Vec<String>)
}
impl Debug for AmlValue {
fn fmt(&self, f: &mut Formatter) -> Result<(), Error> { Ok(()) }
}
impl AmlValue {
pub fn get_as_string(&self) -> Result<String, AmlError> {
match *self {