diff --git a/kernel/include/kernel/ACPI/AML/CopyObject.h b/kernel/include/kernel/ACPI/AML/CopyObject.h new file mode 100644 index 00000000..bd102e3a --- /dev/null +++ b/kernel/include/kernel/ACPI/AML/CopyObject.h @@ -0,0 +1,66 @@ +#pragma once + +#include +#include +#include +#include + +namespace Kernel::ACPI::AML +{ + + struct CopyObject + { + static ParseResult parse(ParseContext& context) + { + ASSERT(context.aml_data.size() >= 1); + ASSERT(static_cast(context.aml_data[0]) == Byte::CopyObjectOp); + context.aml_data = context.aml_data.slice(1); + + auto source_result = AML::parse_object(context); + if (!source_result.success()) + return ParseResult::Failure; + auto source = source_result.node(); + if (!source) + { + AML_ERROR("CopyObject source is null"); + return ParseResult::Failure; + } + + auto destination_result = AML::parse_object(context); + if (!destination_result.success()) + return ParseResult::Failure; + auto destination = destination_result.node(); + if (!destination) + { + AML_ERROR("CopyObject destination is null"); + return ParseResult::Failure; + } + +#if AML_DEBUG_LEVEL >= 2 + AML_DEBUG_PRINTLN("CopyObject {"); + source->debug_print(1); + AML_DEBUG_PRINTLN(""); + AML_DEBUG_PRINTLN("} to {"); + destination->debug_print(1); + AML_DEBUG_PRINTLN(""); + AML_DEBUG_PRINTLN("}"); +#endif + + switch (destination->type) + { + case AML::Node::Type::Alias: + static_cast(destination.ptr())->target = source; + return source; + case AML::Node::Type::Name: + static_cast(destination.ptr())->object = source; + return source; + case AML::Node::Type::Register: + static_cast(destination.ptr())->value = source; + return source; + default: + ASSERT_NOT_REACHED(); + } + } + }; + +} diff --git a/kernel/kernel/ACPI/AML/Node.cpp b/kernel/kernel/ACPI/AML/Node.cpp index 8454b101..59b6948d 100644 --- a/kernel/kernel/ACPI/AML/Node.cpp +++ b/kernel/kernel/ACPI/AML/Node.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include #include #include @@ -179,6 +180,8 @@ namespace Kernel::ACPI return AML::While::parse(context); case AML::Byte::StoreOp: return AML::Store::parse(context); + case AML::Byte::CopyObjectOp: + return AML::CopyObject::parse(context); case AML::Byte::DerefOfOp: case AML::Byte::RefOfOp: return AML::Reference::parse(context);