@@ -20,10 +20,7 @@ use alloc::{
20
20
vec:: Vec ,
21
21
} ;
22
22
use bit_field:: BitField ;
23
- use core:: {
24
- mem,
25
- str:: FromStr ,
26
- } ;
23
+ use core:: { mem, str:: FromStr } ;
27
24
use log:: { info, trace, warn} ;
28
25
use namespace:: { AmlName , Namespace , NamespaceLevelKind } ;
29
26
use object:: { FieldFlags , FieldUnit , FieldUnitKind , MethodFlags , Object , ObjectType , ReferenceKind } ;
@@ -58,13 +55,11 @@ where
58
55
namespace : Spinlock :: new ( Namespace :: new ( ) ) ,
59
56
context_stack : Spinlock :: new ( Vec :: new ( ) ) ,
60
57
dsdt_revision,
61
- ops_interpreted : AtomicUsize :: new ( 0 ) ,
62
58
region_handlers : Spinlock :: new ( BTreeMap :: new ( ) ) ,
63
59
}
64
60
}
65
61
66
62
pub fn load_table ( & self , stream : & [ u8 ] ) -> Result < ( ) , AmlError > {
67
- // TODO: probs needs to do more stuff
68
63
let context = unsafe { MethodContext :: new_from_table ( stream) } ;
69
64
self . do_execute_method ( context) ?;
70
65
Ok ( ( ) )
@@ -925,30 +920,52 @@ where
925
920
context. current_block. pc -= 1 ;
926
921
let name = context. namestring( ) ?;
927
922
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) ) ) ;
938
940
}
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 ( _) ) => {
944
942
let reference = Object :: Reference {
945
943
kind : ReferenceKind :: Unresolved ,
946
944
inner : Arc :: new( Object :: String ( name. to_string( ) ) ) ,
947
945
} ;
948
946
context. last_op( ) ?. arguments. push( Argument :: Object ( Arc :: new( reference) ) ) ;
949
947
}
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) ?,
950
968
}
951
- Err ( other) => Err ( other) ?,
952
969
}
953
970
}
954
971
@@ -973,7 +990,7 @@ where
973
990
Opcode :: FindSetLeftBit | Opcode :: FindSetRightBit => {
974
991
context. start_in_flight_op( OpInFlight :: new( opcode, 2 ) )
975
992
}
976
- Opcode :: DerefOf => todo ! ( ) ,
993
+ Opcode :: DerefOf => context . start_in_flight_op ( OpInFlight :: new ( opcode , 1 ) ) ,
977
994
Opcode :: Notify => todo ! ( ) ,
978
995
Opcode :: ConcatRes => context. start_in_flight_op( OpInFlight :: new( opcode, 3 ) ) ,
979
996
Opcode :: SizeOf => context. start_in_flight_op( OpInFlight :: new( opcode, 1 ) ) ,
0 commit comments