Browse Source

Parse DefAnd

Isaac Woods 4 years ago
parent
commit
d5a3899a04
2 changed files with 25 additions and 1 deletions
  1. 1 0
      aml/src/opcode.rs
  2. 24 1
      aml/src/type2.rs

+ 1 - 0
aml/src/opcode.rs

@@ -45,6 +45,7 @@ pub const DEF_RETURN_OP: u8 = 0xa4;
 pub const DEF_STORE_OP: u8 = 0x70;
 pub const DEF_SHIFT_LEFT: u8 = 0x79;
 pub const DEF_SHIFT_RIGHT: u8 = 0x7a;
+pub const DEF_AND_OP: u8 = 0x7b;
 pub const DEF_L_OR_OP: u8 = 0x91;
 pub const DEF_L_EQUAL_OP: u8 = 0x93;
 

+ 24 - 1
aml/src/type2.rs

@@ -4,7 +4,6 @@ use crate::{
     parser::{
         choice,
         comment_scope,
-        id,
         make_parser_concrete,
         n_of,
         take,
@@ -43,6 +42,7 @@ where
         DebugVerbosity::AllScopes,
         "Type2Opcode",
         choice!(
+            def_and(),
             def_buffer(),
             def_l_equal(),
             def_l_or(),
@@ -55,6 +55,29 @@ where
     ))
 }
 
+pub fn def_and<'a, 'c>() -> impl Parser<'a, 'c, AmlValue>
+where
+    'c: 'a,
+{
+    /*
+     * DefAnd := 0x7b Operand Operand Target
+     * Operand := TermArg => Integer
+     */
+    opcode(opcode::DEF_AND_OP)
+        .then(comment_scope(
+            DebugVerbosity::AllScopes,
+            "DefAnd",
+            term_arg().then(term_arg()).then(target()).map_with_context(
+                |((left_arg, right_arg), target), context| {
+                    let left = try_with_context!(context, left_arg.as_integer(context));
+                    let right = try_with_context!(context, right_arg.as_integer(context));
+                    (Ok(AmlValue::Integer(left & right)), context)
+                },
+            ),
+        ))
+        .map(|((), result)| Ok(result))
+}
+
 pub fn def_buffer<'a, 'c>() -> impl Parser<'a, 'c, AmlValue>
 where
     'c: 'a,