From eaf06d239c63781cc0dc81bf49aa8d149ceb7e78 Mon Sep 17 00:00:00 2001 From: Bananymous Date: Thu, 15 Aug 2024 20:54:55 +0300 Subject: [PATCH] Kernel: Cleanup and fix AML Method calls --- kernel/include/kernel/ACPI/AML/Method.h | 16 ++++--- kernel/kernel/ACPI/AML/Node.cpp | 62 ++++++++++++------------- 2 files changed, 38 insertions(+), 40 deletions(-) diff --git a/kernel/include/kernel/ACPI/AML/Method.h b/kernel/include/kernel/ACPI/AML/Method.h index c7e1740c..f5ece4a5 100644 --- a/kernel/include/kernel/ACPI/AML/Method.h +++ b/kernel/include/kernel/ACPI/AML/Method.h @@ -3,8 +3,10 @@ #include #include #include +#include #include #include +#include #include namespace Kernel::ACPI::AML @@ -100,13 +102,13 @@ namespace Kernel::ACPI::AML ParseContext context; context.aml_data = term_list; context.scope = scope; - context.method_args[0] = MUST(BAN::RefPtr::create(arg0 && arg0->type == AML::Node::Type::Register ? static_cast(arg0.ptr())->value : arg0)); - context.method_args[1] = MUST(BAN::RefPtr::create(arg1 && arg1->type == AML::Node::Type::Register ? static_cast(arg1.ptr())->value : arg1)); - context.method_args[2] = MUST(BAN::RefPtr::create(arg2 && arg2->type == AML::Node::Type::Register ? static_cast(arg2.ptr())->value : arg2)); - context.method_args[3] = MUST(BAN::RefPtr::create(arg3 && arg3->type == AML::Node::Type::Register ? static_cast(arg3.ptr())->value : arg3)); - context.method_args[4] = MUST(BAN::RefPtr::create(arg4 && arg4->type == AML::Node::Type::Register ? static_cast(arg4.ptr())->value : arg4)); - context.method_args[5] = MUST(BAN::RefPtr::create(arg5 && arg5->type == AML::Node::Type::Register ? static_cast(arg5.ptr())->value : arg5)); - context.method_args[6] = MUST(BAN::RefPtr::create(arg6 && arg6->type == AML::Node::Type::Register ? static_cast(arg6.ptr())->value : arg6)); + context.method_args[0] = MUST(BAN::RefPtr::create(arg0)); + context.method_args[1] = MUST(BAN::RefPtr::create(arg1)); + context.method_args[2] = MUST(BAN::RefPtr::create(arg2)); + context.method_args[3] = MUST(BAN::RefPtr::create(arg3)); + context.method_args[4] = MUST(BAN::RefPtr::create(arg4)); + context.method_args[5] = MUST(BAN::RefPtr::create(arg5)); + context.method_args[6] = MUST(BAN::RefPtr::create(arg6)); context.sync_stack = BAN::move(current_sync_stack); for (auto& local : context.method_locals) local = MUST(BAN::RefPtr::create()); diff --git a/kernel/kernel/ACPI/AML/Node.cpp b/kernel/kernel/ACPI/AML/Node.cpp index af36b230..8454b101 100644 --- a/kernel/kernel/ACPI/AML/Node.cpp +++ b/kernel/kernel/ACPI/AML/Node.cpp @@ -219,45 +219,41 @@ namespace Kernel::ACPI AML_ERROR("NameString {} not found in namespace", name_string.value()); return ParseResult::Failure; } - if (aml_object->type == AML::Node::Type::Method) + if (aml_object->type != AML::Node::Type::Method) + return ParseResult(aml_object); + + auto* method = static_cast(aml_object.ptr()); + + BAN::Array, 7> args; + for (uint8_t i = 0; i < method->arg_count; i++) { - auto* method = static_cast(aml_object.ptr()); - - BAN::Array, 7> args; - for (uint8_t i = 0; i < method->arg_count; i++) + auto arg_result = AML::parse_object(context); + if (!arg_result.success() || !arg_result.node()) { - auto arg = AML::parse_object(context); - if (!arg.success()) - { - AML_ERROR("Failed to parse argument {} for method {}", i, name_string.value()); - return ParseResult::Failure; - } - args[i] = MUST(BAN::RefPtr::create(arg.node())); - } - - auto result = method->invoke_with_sync_stack( - context.sync_stack, - args[0], - args[1], - args[2], - args[3], - args[4], - args[5], - args[6] - ); - if (!result.has_value()) - { - AML_ERROR("Failed to evaluate {}", name_string.value()); + AML_ERROR("Failed to parse argument {} for method {}", i, name_string.value()); return ParseResult::Failure; } - if (!result.value()) - return ParseResult::Success; - return ParseResult(result.value()); + args[i] = arg_result.node(); } - if (aml_object->type == AML::Node::Type::Name) - return ParseResult(static_cast(aml_object.ptr())->object); - return ParseResult(aml_object); + auto result = method->invoke_with_sync_stack( + context.sync_stack, + args[0], + args[1], + args[2], + args[3], + args[4], + args[5], + args[6] + ); + if (!result.has_value()) + { + AML_ERROR("Failed to evaluate {}", name_string.value()); + return ParseResult::Failure; + } + if (!result.value()) + return ParseResult::Success; + return ParseResult(result.value()); } AML_TODO("{2H}", context.aml_data[0]);