From 1938ca043522bc9b5776edff624806fac8de2531 Mon Sep 17 00:00:00 2001 From: Connor Wood Date: Fri, 21 Jul 2017 14:11:29 +0100 Subject: [PATCH] Memory handler API --- src/acpi/aml/namedobj.rs | 14 +++++++++++--- src/acpi/aml/namespace.rs | 30 +++++++++++++++++++++++++----- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/src/acpi/aml/namedobj.rs b/src/acpi/aml/namedobj.rs index a99c82f..1d16d2b 100644 --- a/src/acpi/aml/namedobj.rs +++ b/src/acpi/aml/namedobj.rs @@ -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 { diff --git a/src/acpi/aml/namespace.rs b/src/acpi/aml/namespace.rs index 1c84f81..ac3f585 100644 --- a/src/acpi/aml/namespace.rs +++ b/src/acpi/aml/namespace.rs @@ -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, Box) } -#[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 } -#[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, - len: Box + len: Box, + accessor: Accessor }, Package(Vec), String(String), @@ -87,6 +103,10 @@ pub enum AmlValue { ThermalZone(Vec) } +impl Debug for AmlValue { + fn fmt(&self, f: &mut Formatter) -> Result<(), Error> { Ok(()) } +} + impl AmlValue { pub fn get_as_string(&self) -> Result { match *self {