Kernel: Implement AliasOp for AML interpreter

This commit is contained in:
Bananymous 2024-08-13 22:38:01 +03:00
parent ec4cfdee23
commit f71a29b6c4
3 changed files with 79 additions and 1 deletions

View File

@ -0,0 +1,74 @@
#pragma once
#include <kernel/ACPI/AML/NamedObject.h>
#include <kernel/ACPI/AML/Names.h>
#include <kernel/ACPI/AML/ParseContext.h>
namespace Kernel::ACPI::AML
{
struct Alias : public AML::NamedObject
{
BAN::RefPtr<AML::Node> target;
Alias(NameSeg name, BAN::RefPtr<AML::Node> target)
: NamedObject(Node::Type::Alias, name)
, target(target)
{}
bool is_scope() const override { return target->is_scope(); }
BAN::RefPtr<Node> copy() override { return target->copy(); }
BAN::RefPtr<AML::Buffer> as_buffer() override { return target->as_buffer(); }
BAN::RefPtr<AML::Integer> as_integer() override { return target->as_integer(); }
BAN::RefPtr<AML::String> as_string() override { return target->as_string(); }
BAN::RefPtr<AML::Node> evaluate() override { return target->evaluate(); }
bool store(BAN::RefPtr<AML::Node> node) override { return target->store(node); }
static ParseResult parse(ParseContext& context)
{
ASSERT(context.aml_data.size() >= 1);
ASSERT(static_cast<Byte>(context.aml_data[0]) == Byte::AliasOp);
context.aml_data = context.aml_data.slice(1);
auto source_string = AML::NameString::parse(context.aml_data);
if (!source_string.has_value())
return ParseResult::Failure;
auto source_object = AML::Namespace::root_namespace()->find_object(context.scope, source_string.value(), AML::Namespace::FindMode::Normal);
if (!source_object)
{
AML_ERROR("Alias target could not be found");
return ParseResult::Failure;
}
auto alias_string = AML::NameString::parse(context.aml_data);
if (!alias_string.has_value())
return ParseResult::Failure;
auto alias = MUST(BAN::RefPtr<Alias>::create(alias_string.value().path.back(), source_object));
if (!Namespace::root_namespace()->add_named_object(context, alias_string.value(), alias))
return ParseResult::Success;
#if AML_DEBUG_LEVEL >= 2
alias->debug_print(0);
AML_DEBUG_PRINTLN("");
#endif
return ParseResult::Success;
}
void debug_print(int indent) const override
{
AML_DEBUG_PRINT_INDENT(indent);
AML_DEBUG_PRINTLN("Alias {} { ", name);
target->debug_print(indent + 1);
AML_DEBUG_PRINTLN("");
AML_DEBUG_PRINT_INDENT(indent);
AML_DEBUG_PRINT("}");
}
};
}

View File

@ -19,10 +19,11 @@ namespace Kernel::ACPI::AML
enum class Type enum class Type
{ {
Debug, Alias,
BankFieldElement, BankFieldElement,
Buffer, Buffer,
BufferField, BufferField,
Debug,
Device, Device,
FieldElement, FieldElement,
IndexFieldElement, IndexFieldElement,

View File

@ -1,3 +1,4 @@
#include <kernel/ACPI/AML/Alias.h>
#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/Device.h> #include <kernel/ACPI/AML/Device.h>
@ -165,6 +166,8 @@ namespace Kernel::ACPI
case AML::Byte::CreateDWordFieldOp: case AML::Byte::CreateDWordFieldOp:
case AML::Byte::CreateQWordFieldOp: case AML::Byte::CreateQWordFieldOp:
return AML::BufferField::parse(context); return AML::BufferField::parse(context);
case AML::Byte::AliasOp:
return AML::Alias::parse(context);
case AML::Byte::NameOp: case AML::Byte::NameOp:
return AML::Name::parse(context); return AML::Name::parse(context);
case AML::Byte::PackageOp: case AML::Byte::PackageOp: