浏览代码

Parse DefCreateDWordField

Isaac Woods 3 年之前
父节点
当前提交
ead2a0ad1c
共有 2 个文件被更改,包括 36 次插入0 次删除
  1. 1 0
      aml/src/opcode.rs
  2. 35 0
      aml/src/term_object.rs

+ 1 - 0
aml/src/opcode.rs

@@ -26,6 +26,7 @@ pub const DEF_BUFFER_OP: u8 = 0x11;
 pub const DEF_PACKAGE_OP: u8 = 0x12;
 pub const DEF_METHOD_OP: u8 = 0x14;
 pub const DEF_EXTERNAL_OP: u8 = 0x15;
+pub const DEF_CREATE_DWORD_FIELD_OP: u8 = 0x8a;
 pub const DEF_CREATE_WORD_FIELD_OP: u8 = 0x8b;
 pub const DEF_CREATE_BYTE_FIELD_OP: u8 = 0x8c;
 pub const DEF_CREATE_BIT_FIELD_OP: u8 = 0x8d;

+ 35 - 0
aml/src/term_object.rs

@@ -101,6 +101,7 @@ where
             def_create_bit_field(),
             def_create_byte_field(),
             def_create_word_field(),
+            def_create_dword_field(),
             def_op_region(),
             def_field(),
             def_method(),
@@ -277,6 +278,40 @@ where
         ))
         .discard_result()
 }
+
+pub fn def_create_dword_field<'a, 'c>() -> impl Parser<'a, 'c, ()>
+where
+    'c: 'a,
+{
+    /*
+     * DefCreateDWordField := 0x8a SourceBuf ByteIndex NameString
+     * SourceBuf := TermArg => Buffer
+     * ByteIndex := TermArg => Integer
+     */
+    opcode(opcode::DEF_CREATE_DWORD_FIELD_OP)
+        .then(comment_scope(
+            DebugVerbosity::AllScopes,
+            "DefCreateDWordField",
+            term_arg().then(term_arg()).then(name_string()).map_with_context(
+                |((source, index), name), context| {
+                    let source_data: Arc<Vec<u8>> = try_with_context!(context, source.as_buffer(context)).clone();
+                    let index = try_with_context!(context, index.as_integer(context));
+
+                    try_with_context!(
+                        context,
+                        context.namespace.add_value_at_resolved_path(
+                            name,
+                            &context.current_scope,
+                            AmlValue::BufferField { buffer_data: source_data, offset: index * 8, length: 32 }
+                        )
+                    );
+
+                    (Ok(()), context)
+                },
+            ),
+        ))
+        .discard_result()
+}
 pub fn def_op_region<'a, 'c>() -> impl Parser<'a, 'c, ()>
 where
     'c: 'a,