Browse Source

Parse DefLEqual, allow Type2Opcodes in TermArgs

Isaac Woods 5 years ago
parent
commit
7b25aafff7
4 changed files with 34 additions and 3 deletions
  1. 5 0
      aml_parser/src/opcode.rs
  2. 2 2
      aml_parser/src/term_object.rs
  3. 19 1
      aml_parser/src/type2.rs
  4. 8 0
      aml_parser/src/value.rs

+ 5 - 0
aml_parser/src/opcode.rs

@@ -32,6 +32,11 @@ pub const EXT_DEF_FIELD_OP: u8 = 0x81;
 pub const EXT_DEF_DEVICE_OP: u8 = 0x82;
 pub const EXT_DEF_PROCESSOR_OP: u8 = 0x83;
 
+/*
+ * Type 2 opcodes
+ */
+pub const DEF_L_EQUAL: u8 = 0x93;
+
 pub const EXT_OPCODE_PREFIX: u8 = 0x5b;
 
 pub(crate) fn opcode<'a, 'c>(opcode: u8) -> impl Parser<'a, 'c, ()>

+ 2 - 2
aml_parser/src/term_object.rs

@@ -466,8 +466,8 @@ where
     /*
      * TermArg := Type2Opcode | DataObject | ArgObj | LocalObj
      */
-    // TODO: this doesn't yet parse Term2Opcode, ArgObj, or LocalObj
-    comment_scope_verbose("TermArg", choice!(data_object()))
+    // TODO: this doesn't yet parse ArgObj, or LocalObj
+    comment_scope_verbose("TermArg", choice!(data_object(), make_parser_concrete!(type2_opcode())))
 }
 
 pub fn data_ref_object<'a, 'c>() -> impl Parser<'a, 'c, AmlValue>

+ 19 - 1
aml_parser/src/type2.rs

@@ -24,7 +24,25 @@ where
      *                DefSubtract | DefTimer | DefToBCD | DefToBuffer | DefToDecimalString |
      *                DefToHexString | DefToInteger | DefToString | DefWait | DefXOr | MethodInvocation
      */
-    comment_scope_verbose("Type2Opcode", choice!(method_invocation()))
+    comment_scope_verbose("Type2Opcode", choice!(def_l_equal(), method_invocation()))
+}
+
+fn def_l_equal<'a, 'c>() -> impl Parser<'a, 'c, AmlValue>
+where
+    'c: 'a,
+{
+    /*
+     * DefLEqual := 0x93 Operand Operand
+     * Operand := TermArg => Integer
+     */
+    opcode(opcode::DEF_L_EQUAL)
+        .then(comment_scope_verbose(
+            "DefLEqual",
+            term_arg().then(term_arg()).map(|(left_arg, right_arg)| {
+                Ok(AmlValue::Boolean(left_arg.as_integer()? == right_arg.as_integer()?))
+            }),
+        ))
+        .map(|((), result)| Ok(result))
 }
 
 fn method_invocation<'a, 'c>() -> impl Parser<'a, 'c, AmlValue>

+ 8 - 0
aml_parser/src/value.rs

@@ -101,6 +101,7 @@ impl MethodFlags {
 
 #[derive(Clone, PartialEq, Eq, Debug)]
 pub enum AmlValue {
+    Boolean(bool),
     Integer(u64),
     String(String),
     Name(Box<AmlValue>),
@@ -115,6 +116,13 @@ pub enum AmlValue {
 }
 
 impl AmlValue {
+    pub fn as_bool(&self) -> Result<bool, AmlError> {
+        match self {
+            AmlValue::Boolean(value) => Ok(*value),
+            _ => Err(AmlError::IncompatibleValueConversion),
+        }
+    }
+
     pub fn as_integer(&self) -> Result<u64, AmlError> {
         match self {
             AmlValue::Integer(value) => Ok(*value),