Kernel: Implement AML CopyObjectOp

This commit is contained in:
Bananymous 2024-08-15 20:55:55 +03:00
parent 4dc107f77a
commit d8dabab4fb
2 changed files with 69 additions and 0 deletions

View File

@ -0,0 +1,66 @@
#pragma once
#include <kernel/ACPI/AML/Alias.h>
#include <kernel/ACPI/AML/NamedObject.h>
#include <kernel/ACPI/AML/ParseContext.h>
#include <kernel/ACPI/AML/Register.h>
namespace Kernel::ACPI::AML
{
struct CopyObject
{
static ParseResult parse(ParseContext& context)
{
ASSERT(context.aml_data.size() >= 1);
ASSERT(static_cast<Byte>(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<AML::Alias*>(destination.ptr())->target = source;
return source;
case AML::Node::Type::Name:
static_cast<AML::Name*>(destination.ptr())->object = source;
return source;
case AML::Node::Type::Register:
static_cast<AML::Register*>(destination.ptr())->value = source;
return source;
default:
ASSERT_NOT_REACHED();
}
}
};
}

View File

@ -2,6 +2,7 @@
#include <kernel/ACPI/AML/Buffer.h> #include <kernel/ACPI/AML/Buffer.h>
#include <kernel/ACPI/AML/Bytes.h> #include <kernel/ACPI/AML/Bytes.h>
#include <kernel/ACPI/AML/Conversion.h> #include <kernel/ACPI/AML/Conversion.h>
#include <kernel/ACPI/AML/CopyObject.h>
#include <kernel/ACPI/AML/Device.h> #include <kernel/ACPI/AML/Device.h>
#include <kernel/ACPI/AML/Expression.h> #include <kernel/ACPI/AML/Expression.h>
#include <kernel/ACPI/AML/Event.h> #include <kernel/ACPI/AML/Event.h>
@ -179,6 +180,8 @@ namespace Kernel::ACPI
return AML::While::parse(context); return AML::While::parse(context);
case AML::Byte::StoreOp: case AML::Byte::StoreOp:
return AML::Store::parse(context); return AML::Store::parse(context);
case AML::Byte::CopyObjectOp:
return AML::CopyObject::parse(context);
case AML::Byte::DerefOfOp: case AML::Byte::DerefOfOp:
case AML::Byte::RefOfOp: case AML::Byte::RefOfOp:
return AML::Reference::parse(context); return AML::Reference::parse(context);