From 490a28ee7a9a95ef68c624acd15574d1fe9de3ea Mon Sep 17 00:00:00 2001 From: Bananymous Date: Thu, 15 Aug 2024 23:14:13 +0300 Subject: [PATCH] Kernel/AML: General cleanup and compliance improvements --- kernel/include/kernel/ACPI/AML/Buffer.h | 2 +- kernel/include/kernel/ACPI/AML/CopyObject.h | 6 +++--- kernel/include/kernel/ACPI/AML/Index.h | 16 ++++++---------- kernel/include/kernel/ACPI/AML/Package.h | 9 ++++++--- kernel/kernel/ACPI/AML/Register.cpp | 2 +- 5 files changed, 17 insertions(+), 18 deletions(-) diff --git a/kernel/include/kernel/ACPI/AML/Buffer.h b/kernel/include/kernel/ACPI/AML/Buffer.h index a48f3385..57a3ae39 100644 --- a/kernel/include/kernel/ACPI/AML/Buffer.h +++ b/kernel/include/kernel/ACPI/AML/Buffer.h @@ -171,7 +171,7 @@ namespace Kernel::ACPI::AML // TODO: optimize for whole byte accesses for (size_t i = 0; i < field_bit_size; i++) { - const size_t bit = field_bit_offset + 1; + const size_t bit = field_bit_offset + i; buffer[bit / 8] &= ~(1 << (bit % 8)); buffer[bit / 8] |= ((value >> i) & 1) << (bit % 8); } diff --git a/kernel/include/kernel/ACPI/AML/CopyObject.h b/kernel/include/kernel/ACPI/AML/CopyObject.h index ad83092a..d6c35ef9 100644 --- a/kernel/include/kernel/ACPI/AML/CopyObject.h +++ b/kernel/include/kernel/ACPI/AML/CopyObject.h @@ -51,13 +51,13 @@ namespace Kernel::ACPI::AML switch (destination->type) { case AML::Node::Type::Alias: - static_cast(destination.ptr())->target = source; + static_cast(destination.ptr())->target = source->copy(); return source; case AML::Node::Type::Name: - static_cast(destination.ptr())->object = source; + static_cast(destination.ptr())->object = source->copy(); return source; case AML::Node::Type::Register: - static_cast(destination.ptr())->value = source; + static_cast(destination.ptr())->value = source->copy(); return source; default: ASSERT_NOT_REACHED(); diff --git a/kernel/include/kernel/ACPI/AML/Index.h b/kernel/include/kernel/ACPI/AML/Index.h index d92a90ca..c7fd1692 100644 --- a/kernel/include/kernel/ACPI/AML/Index.h +++ b/kernel/include/kernel/ACPI/AML/Index.h @@ -5,6 +5,7 @@ #include #include #include +#include namespace Kernel::ACPI::AML { @@ -20,25 +21,20 @@ namespace Kernel::ACPI::AML auto source_result = AML::parse_object(context); if (!source_result.success()) return ParseResult::Failure; - auto source = source_result.node() - ? source_result.node()->convert(AML::Node::ConvBuffer | AML::Node::ConvInteger | AML::Node::ConvString) - : BAN::RefPtr(); + auto source = source_result.node() ? source_result.node()->to_underlying() : BAN::RefPtr(); + if (source && source->type != AML::Node::Type::Package) + source = source->convert(AML::Node::ConvBuffer | AML::Node::ConvInteger | AML::Node::ConvString); if (!source) { AML_ERROR("IndexOp source could not be converted"); - if (source) - { - source->debug_print(0); - AML_DEBUG_PRINTLN(""); - } return ParseResult::Failure; } auto index_result = AML::parse_object(context); if (!index_result.success()) return ParseResult::Failure; - auto index_node = source_result.node() - ? source_result.node()->convert(AML::Node::ConvInteger) + auto index_node = index_result.node() + ? index_result.node()->convert(AML::Node::ConvInteger) : BAN::RefPtr(); if (!index_node) { diff --git a/kernel/include/kernel/ACPI/AML/Package.h b/kernel/include/kernel/ACPI/AML/Package.h index 9991d778..0dd6ca29 100644 --- a/kernel/include/kernel/ACPI/AML/Package.h +++ b/kernel/include/kernel/ACPI/AML/Package.h @@ -5,6 +5,7 @@ #include #include #include +#include namespace Kernel::ACPI::AML { @@ -100,9 +101,11 @@ namespace Kernel::ACPI::AML } if (!resolved && !resolve()) return {}; - if (element->type == AML::Node::Type::Reference) - return element->store(node); - element = node->copy(); + ASSERT(element->type != AML::Node::Type::Reference); + if (node->type == AML::Node::Type::Reference) + element = static_cast(element.ptr())->node; + else + element = element->copy(); return element; } diff --git a/kernel/kernel/ACPI/AML/Register.cpp b/kernel/kernel/ACPI/AML/Register.cpp index 9027a222..7ca9a689 100644 --- a/kernel/kernel/ACPI/AML/Register.cpp +++ b/kernel/kernel/ACPI/AML/Register.cpp @@ -20,7 +20,7 @@ namespace Kernel::ACPI { if (node->type == AML::Node::Type::Reference) node = static_cast(node.ptr())->node; - else if (node) + else if (node->type != AML::Node::Type::Buffer && node->type != AML::Node::Type::Package) node = node->copy(); if (node->type == AML::Node::Type::Register) {