From 4dc107f77a04bda92b0f49e4ecbb93125a70b3a5 Mon Sep 17 00:00:00 2001 From: Bananymous Date: Thu, 15 Aug 2024 20:55:18 +0300 Subject: [PATCH] Kernel: Fix AML Register/Reference accesses --- kernel/include/kernel/ACPI/AML/Reference.h | 7 +++++-- kernel/include/kernel/ACPI/AML/SizeOf.h | 2 ++ kernel/include/kernel/ACPI/AML/Store.h | 6 +++--- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/kernel/include/kernel/ACPI/AML/Reference.h b/kernel/include/kernel/ACPI/AML/Reference.h index dfe2b4be..56a32a18 100644 --- a/kernel/include/kernel/ACPI/AML/Reference.h +++ b/kernel/include/kernel/ACPI/AML/Reference.h @@ -69,10 +69,13 @@ namespace Kernel::ACPI::AML if (!parse_result.success()) return ParseResult::Failure; object = parse_result.node(); - if (object && object->type == AML::Node::Type::Register) - object = static_cast(object.ptr())->value; } + if (object && object->type == AML::Node::Type::Reference) + object = static_cast(object.ptr())->node; + if (object && object->type == AML::Node::Type::Register) + object = static_cast(object.ptr())->value; + if (!conditional) { if (!object) diff --git a/kernel/include/kernel/ACPI/AML/SizeOf.h b/kernel/include/kernel/ACPI/AML/SizeOf.h index 828fad96..d81bb099 100644 --- a/kernel/include/kernel/ACPI/AML/SizeOf.h +++ b/kernel/include/kernel/ACPI/AML/SizeOf.h @@ -22,6 +22,8 @@ namespace Kernel::ACPI::AML if (!object_result.success()) return ParseResult::Failure; auto object_node = object_result.node(); + if (object_node && object_node->type == AML::Node::Type::Register) + object_node = static_cast(object_node.ptr())->value; if (!object_node) { AML_ERROR("SizeOf object is null"); diff --git a/kernel/include/kernel/ACPI/AML/Store.h b/kernel/include/kernel/ACPI/AML/Store.h index 62fa30ac..c691f757 100644 --- a/kernel/include/kernel/ACPI/AML/Store.h +++ b/kernel/include/kernel/ACPI/AML/Store.h @@ -44,9 +44,9 @@ namespace Kernel::ACPI::AML AML_DEBUG_PRINTLN("}"); #endif - if (!destination->store(source)) - return ParseResult::Failure; - return ParseResult(destination); + if (auto stored = destination->store(source)) + return ParseResult(stored); + return ParseResult::Failure; } };