Selaa lähdekoodia

Add minimal CondRefOf support - only handles checking for source, does not assign to target

Ron Williams 2 vuotta sitten
vanhempi
commit
7d3c85253c
3 muutettua tiedostoa jossa 32 lisäystä ja 2 poistoa
  1. 2 1
      aml/src/expression.rs
  2. 1 0
      aml/src/opcode.rs
  3. 29 1
      aml/src/term_object.rs

+ 2 - 1
aml/src/expression.rs

@@ -4,7 +4,7 @@ use crate::{
     opcode::{self, opcode},
     parser::{choice, comment_scope, n_of, take, take_to_end_of_pkglength, try_with_context, Parser, Propagate},
     pkg_length::pkg_length,
-    term_object::{data_ref_object, term_arg},
+    term_object::{data_ref_object, term_arg, def_cond_ref_of},
     value::{AmlType, AmlValue, Args},
     AmlError,
     DebugVerbosity,
@@ -58,6 +58,7 @@ where
             def_shift_right(),
             def_store(),
             def_to_integer(),
+            def_cond_ref_of(),
             method_invocation() // XXX: this must always appear last. See how we have to parse it to see why.
         ),
     )

+ 1 - 0
aml/src/opcode.rs

@@ -33,6 +33,7 @@ pub const DEF_CREATE_BYTE_FIELD_OP: u8 = 0x8c;
 pub const DEF_CREATE_BIT_FIELD_OP: u8 = 0x8d;
 pub const DEF_CREATE_QWORD_FIELD_OP: u8 = 0x8f;
 pub const EXT_DEF_MUTEX_OP: u8 = 0x01;
+pub const EXT_DEF_COND_REF_OF_OP: u8 = 0x12;
 pub const EXT_DEF_CREATE_FIELD_OP: u8 = 0x13;
 pub const EXT_REVISION_OP: u8 = 0x30;
 pub const EXT_DEF_FATAL_OP: u8 = 0x32;

+ 29 - 1
aml/src/term_object.rs

@@ -1,7 +1,7 @@
 use crate::{
     expression::{def_buffer, def_package, expression_opcode},
     misc::{arg_obj, local_obj},
-    name_object::{name_seg, name_string},
+    name_object::{name_seg, name_string, target, Target},
     namespace::{AmlName, LevelType},
     opcode::{self, ext_opcode, opcode},
     parser::{
@@ -851,6 +851,34 @@ where
         .discard_result()
 }
 
+pub fn def_cond_ref_of<'a, 'c>() -> impl Parser<'a, 'c, AmlValue>
+where
+    'c: 'a,
+{
+    /*
+     * DefCondRefOf := ExtOpPrefix 0x12 NameString Target => boolean
+     */
+    ext_opcode(opcode::EXT_DEF_COND_REF_OF_OP)
+        .then(comment_scope(
+            DebugVerbosity::Scopes,
+            "DefCondRefOf",
+            name_string().then(target()).map_with_context(|(source, target), context| {
+                let handle = context.namespace.search(&source, &context.current_scope);
+                let result = AmlValue::Boolean(handle.is_ok());
+                log::error!("{:?} was {}found", &source, if handle.is_ok() { "" } else { "not " });
+                if let Ok((_name, _handle)) = handle {
+                    match target {
+                        Target::Null => { /* just return the result of the check */ }
+                        _ => todo!(),
+                    }
+                    
+                }
+                (Ok(result), context)
+            }),
+        ))
+        .map(|((), result)| Ok(result))
+}
+
 pub fn term_arg<'a, 'c>() -> impl Parser<'a, 'c, AmlValue>
 where
     'c: 'a,