Browse Source

aml: Implement DefOr opcode

Mark Poliakov 1 year ago
parent
commit
edddb489ec
2 changed files with 28 additions and 0 deletions
  1. 27 0
      aml/src/expression.rs
  2. 1 0
      aml/src/opcode.rs

+ 27 - 0
aml/src/expression.rs

@@ -38,6 +38,7 @@ where
         choice!(
             def_add(),
             def_and(),
+            def_or(),
             def_buffer(),
             def_concat(),
             def_concat_res(),
@@ -117,6 +118,32 @@ where
         .map(|((), result)| Ok(result))
 }
 
+pub fn def_or<'a, 'c>() -> impl Parser<'a, 'c, AmlValue>
+where
+    'c: 'a,
+{
+    /*
+     * DefOr := 0x7d Operand Operand Target
+     * Operand := TermArg => Integer
+     */
+    opcode(opcode::DEF_OR_OP)
+        .then(comment_scope(
+            DebugVerbosity::AllScopes,
+            "DefOr",
+            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));
+                    let result = AmlValue::Integer(left | right);
+
+                    try_with_context!(context, context.store(target, result.clone()));
+                    (Ok(result), context)
+                },
+            ),
+        ))
+        .map(|((), result)| Ok(result))
+}
+
 pub fn def_buffer<'a, 'c>() -> impl Parser<'a, 'c, AmlValue>
 where
     'c: 'a,

+ 1 - 0
aml/src/opcode.rs

@@ -69,6 +69,7 @@ pub const DEF_DECREMENT_OP: u8 = 0x76;
 pub const DEF_SHIFT_LEFT: u8 = 0x79;
 pub const DEF_SHIFT_RIGHT: u8 = 0x7a;
 pub const DEF_AND_OP: u8 = 0x7b;
+pub const DEF_OR_OP: u8 = 0x7d;
 pub const DEF_CONCAT_RES_OP: u8 = 0x84;
 pub const DEF_SIZE_OF_OP: u8 = 0x87;
 pub const DEF_OBJECT_TYPE_OP: u8 = 0x8e;