From d23241d8007f4571d67dc6b2255a8a92621d51f3 Mon Sep 17 00:00:00 2001
From: Connor Wood <connorwood71@gmail.com>
Date: Tue, 29 Aug 2017 12:25:41 +0100
Subject: [PATCH] Implemented copy

---
 src/acpi/aml/parser.rs      | 27 +++++++++++++++++++++++++++
 src/acpi/aml/type2opcode.rs |  4 +++-
 2 files changed, 30 insertions(+), 1 deletion(-)

diff --git a/src/acpi/aml/parser.rs b/src/acpi/aml/parser.rs
index e956c02a..13c51a93 100644
--- a/src/acpi/aml/parser.rs
+++ b/src/acpi/aml/parser.rs
@@ -423,6 +423,33 @@ impl AmlExecutionContext {
         }
     }
 
+    fn copy_local_obj(&mut self, local: usize, value: AmlValue) -> Result<(), AmlError> {
+        self.local_vars[local] = value;
+        Ok(())
+    }
+
+    fn copy_object(&mut self, name: String, value: AmlValue) -> Result<(), AmlError> {
+        if let Some(ref mut namespace) = *ACPI_TABLE.namespace.write() {
+            namespace.insert(name, value);
+            Ok(())
+        } else {
+            Err(AmlError::AmlHardFatal)
+        }
+    }
+
+    pub fn copy(&mut self, name: AmlValue, value: AmlValue) -> Result<(), AmlError> {
+        match name {
+            AmlValue::ObjectReference(r) => match r {
+                ObjectReference::ArgObj(_) => Err(AmlError::AmlValueError),
+                ObjectReference::LocalObj(i) => self.copy_local_obj(i as usize, value),
+                ObjectReference::Object(s) => self.copy_object(s, value),
+                ObjectReference::Index(c, v) => self.modify_index(*c, value, vec!(v.get_as_integer()?))
+            },
+            AmlValue::String(s) => self.copy_object(s, value),
+            _ => Err(AmlError::AmlValueError)
+        }
+    }
+
     fn get_index_final(&self, name: String, indices: Vec<u64>) -> Result<AmlValue, AmlError> {
         if let Some(ref namespace) = *ACPI_TABLE.namespace.read() {
             let obj = if let Some(s) = namespace.get(&name) {
diff --git a/src/acpi/aml/type2opcode.rs b/src/acpi/aml/type2opcode.rs
index 09c3b93e..f193575f 100644
--- a/src/acpi/aml/type2opcode.rs
+++ b/src/acpi/aml/type2opcode.rs
@@ -1118,8 +1118,10 @@ fn parse_def_copy_object(data: &[u8],
     let source = parse_term_arg(&data[1..], ctx)?;
     let destination = parse_simple_name(&data[1 + source.len..], ctx)?;
 
+    ctx.copy(destination.val, source.val.clone())?;
+
     Ok(AmlParseType {
-        val: AmlValue::Uninitialized,
+        val: source.val,
         len: 1 + source.len + destination.len
     })
 }
-- 
GitLab