Skip to content

Commit 0e15346

Browse files
alnyanIsaacWoods
authored andcommitted
aml: DefSizeOf implementation
1 parent 301302e commit 0e15346

File tree

4 files changed

+39
-1
lines changed

4 files changed

+39
-1
lines changed

aml/src/expression.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::{
44
opcode::{self, opcode},
55
parser::{choice, comment_scope, n_of, take, take_to_end_of_pkglength, try_with_context, Parser, Propagate},
66
pkg_length::pkg_length,
7-
term_object::{data_ref_object, term_arg, def_cond_ref_of},
7+
term_object::{data_ref_object, def_cond_ref_of, term_arg},
88
value::{AmlType, AmlValue, Args},
99
AmlError,
1010
DebugVerbosity,
@@ -59,6 +59,7 @@ where
5959
def_store(),
6060
def_to_integer(),
6161
def_cond_ref_of(),
62+
def_size_of(),
6263
method_invocation() // XXX: this must always appear last. See how we have to parse it to see why.
6364
),
6465
)
@@ -758,6 +759,26 @@ where
758759
})
759760
}
760761

762+
fn def_size_of<'a, 'c>() -> impl Parser<'a, 'c, AmlValue>
763+
where
764+
'c: 'a,
765+
{
766+
/*
767+
* SizeOf := 0x87 SuperName
768+
*/
769+
opcode(opcode::DEF_SIZE_OF_OP)
770+
.then(comment_scope(
771+
DebugVerbosity::AllScopes,
772+
"DefSizeOf",
773+
super_name().map_with_context(|target, context| {
774+
let value = try_with_context!(context, context.read_target(&target));
775+
let size_of = try_with_context!(context, value.size_of());
776+
(Ok(AmlValue::Integer(size_of)), context)
777+
}),
778+
))
779+
.map(|((), value)| Ok(value))
780+
}
781+
761782
fn method_invocation<'a, 'c>() -> impl Parser<'a, 'c, AmlValue>
762783
where
763784
'c: 'a,

aml/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -796,6 +796,7 @@ pub enum AmlError {
796796
TypeCannotBeSliced(AmlType),
797797
TypeCannotBeWrittenToBufferField(AmlType),
798798
BufferFieldIndexesOutOfBounds,
799+
InvalidSizeOfApplication(AmlType),
799800

800801
/// Unimplemented functionality - return error rather than abort
801802
Unimplemented,

aml/src/opcode.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ pub const DEF_SHIFT_LEFT: u8 = 0x79;
6868
pub const DEF_SHIFT_RIGHT: u8 = 0x7a;
6969
pub const DEF_AND_OP: u8 = 0x7b;
7070
pub const DEF_CONCAT_RES_OP: u8 = 0x84;
71+
pub const DEF_SIZE_OF_OP: u8 = 0x87;
7172
pub const DEF_OBJECT_TYPE_OP: u8 = 0x8e;
7273
pub const DEF_L_AND_OP: u8 = 0x90;
7374
pub const DEF_L_OR_OP: u8 = 0x91;

aml/src/value.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,21 @@ impl AmlValue {
263263
}
264264
}
265265

266+
/// Returns the `SizeOf (x)` application result as specified in ACPI 6.2 §19.6.125
267+
pub fn size_of(&self) -> Result<u64, AmlError> {
268+
match self {
269+
// For a buffer, returns the size in bytes of the data
270+
AmlValue::Buffer(value) => Ok(value.lock().len() as u64),
271+
// For a string, returns the size in bytes (without NULL)
272+
AmlValue::String(value) => Ok(value.len() as u64),
273+
// For a package, returns the number of elements
274+
AmlValue::Package(value) => Ok(value.len() as u64),
275+
// TODO: For an Object Reference, the size of the object is returned
276+
// Other data types cause a fatal run-time error
277+
_ => Err(AmlError::InvalidSizeOfApplication(self.type_of())),
278+
}
279+
}
280+
266281
pub fn as_bool(&self) -> Result<bool, AmlError> {
267282
match self {
268283
AmlValue::Boolean(value) => Ok(*value),

0 commit comments

Comments
 (0)