Skip to content

Commit e2158d6

Browse files
committed
aml: resolve fields at the top-level if required
This also makes the logic clearer about whether we're meant to resolve a top-level name or not, depending on what we're interpreting.
1 parent 12f8a33 commit e2158d6

File tree

1 file changed

+40
-23
lines changed

1 file changed

+40
-23
lines changed

aml/src/lib.rs

Lines changed: 40 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,7 @@ use alloc::{
2020
vec::Vec,
2121
};
2222
use bit_field::BitField;
23-
use core::{
24-
mem,
25-
str::FromStr,
26-
};
23+
use core::{mem, str::FromStr};
2724
use log::{info, trace, warn};
2825
use namespace::{AmlName, Namespace, NamespaceLevelKind};
2926
use object::{FieldFlags, FieldUnit, FieldUnitKind, MethodFlags, Object, ObjectType, ReferenceKind};
@@ -58,13 +55,11 @@ where
5855
namespace: Spinlock::new(Namespace::new()),
5956
context_stack: Spinlock::new(Vec::new()),
6057
dsdt_revision,
61-
ops_interpreted: AtomicUsize::new(0),
6258
region_handlers: Spinlock::new(BTreeMap::new()),
6359
}
6460
}
6561

6662
pub fn load_table(&self, stream: &[u8]) -> Result<(), AmlError> {
67-
// TODO: probs needs to do more stuff
6863
let context = unsafe { MethodContext::new_from_table(stream) };
6964
self.do_execute_method(context)?;
7065
Ok(())
@@ -925,30 +920,52 @@ where
925920
context.current_block.pc -= 1;
926921
let name = context.namestring()?;
927922

928-
match self.namespace.lock().search(&name, &context.current_scope) {
929-
Ok((resolved_name, object)) => {
930-
if let Object::Method { flags, .. } = *object {
931-
context.start_in_flight_op(OpInFlight::new_with(
932-
Opcode::InternalMethodCall,
933-
vec![Argument::Object(object), Argument::Namestring(resolved_name)],
934-
flags.arg_count(),
935-
))
936-
} else {
937-
context.last_op()?.arguments.push(Argument::Object(object));
923+
/*
924+
* The desired behaviour when we encounter a name at the top-level differs
925+
* depending on the context we're in. There are certain places where we want to
926+
* evaluate things like methods and field units, and others where we simply
927+
* want to reference the name (such as inside package definitions). In the
928+
* latter case, we also allow undefined names to be used, and will resolve them
929+
* at the time of use.
930+
*/
931+
let do_not_resolve = context.current_block.kind == BlockKind::Package
932+
|| context.in_flight.last().map(|op| op.op == Opcode::CondRefOf).unwrap_or(false);
933+
if do_not_resolve {
934+
let object = self.namespace.lock().search(&name, &context.current_scope);
935+
match object {
936+
Ok((_, object)) => {
937+
let reference =
938+
Object::Reference { kind: ReferenceKind::RefOf, inner: object.clone() };
939+
context.last_op()?.arguments.push(Argument::Object(Arc::new(reference)));
938940
}
939-
}
940-
Err(AmlError::ObjectDoesNotExist(_)) => {
941-
let allow_unresolved = context.current_block.kind == BlockKind::Package
942-
|| context.in_flight.last().map(|op| op.op == Opcode::CondRefOf).unwrap_or(false);
943-
if allow_unresolved {
941+
Err(AmlError::ObjectDoesNotExist(_)) => {
944942
let reference = Object::Reference {
945943
kind: ReferenceKind::Unresolved,
946944
inner: Arc::new(Object::String(name.to_string())),
947945
};
948946
context.last_op()?.arguments.push(Argument::Object(Arc::new(reference)));
949947
}
948+
Err(other) => Err(other)?,
949+
}
950+
} else {
951+
let object = self.namespace.lock().search(&name, &context.current_scope);
952+
match object {
953+
Ok((resolved_name, object)) => {
954+
if let Object::Method { flags, .. } = *object {
955+
context.start_in_flight_op(OpInFlight::new_with(
956+
Opcode::InternalMethodCall,
957+
vec![Argument::Object(object), Argument::Namestring(resolved_name)],
958+
flags.arg_count(),
959+
))
960+
} else if let Object::FieldUnit(ref field) = *object {
961+
let value = self.do_field_read(field)?;
962+
context.last_op()?.arguments.push(Argument::Object(value));
963+
} else {
964+
context.last_op()?.arguments.push(Argument::Object(object));
965+
}
966+
}
967+
Err(err) => Err(err)?,
950968
}
951-
Err(other) => Err(other)?,
952969
}
953970
}
954971

@@ -973,7 +990,7 @@ where
973990
Opcode::FindSetLeftBit | Opcode::FindSetRightBit => {
974991
context.start_in_flight_op(OpInFlight::new(opcode, 2))
975992
}
976-
Opcode::DerefOf => todo!(),
993+
Opcode::DerefOf => context.start_in_flight_op(OpInFlight::new(opcode, 1)),
977994
Opcode::Notify => todo!(),
978995
Opcode::ConcatRes => context.start_in_flight_op(OpInFlight::new(opcode, 3)),
979996
Opcode::SizeOf => context.start_in_flight_op(OpInFlight::new(opcode, 1)),

0 commit comments

Comments
 (0)