From 30ceaa6bef4d0b721f2df97aae10ae9e85ec6272 Mon Sep 17 00:00:00 2001 From: Bananymous Date: Fri, 22 Nov 2024 22:22:27 +0200 Subject: [PATCH] Kernel: Implement AML ToHexStringOp --- kernel/include/kernel/ACPI/AML/Conversion.h | 36 +++++++++++++++++++-- kernel/kernel/ACPI/AML/Node.cpp | 1 + 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/kernel/include/kernel/ACPI/AML/Conversion.h b/kernel/include/kernel/ACPI/AML/Conversion.h index e89d9393..d896ac5b 100644 --- a/kernel/include/kernel/ACPI/AML/Conversion.h +++ b/kernel/include/kernel/ACPI/AML/Conversion.h @@ -17,8 +17,9 @@ namespace Kernel::ACPI::AML switch (opcode) { - case AML::Byte::ToIntegerOp: case AML::Byte::ToBufferOp: + case AML::Byte::ToHexStringOp: + case AML::Byte::ToIntegerOp: case AML::Byte::ToStringOp: break; default: @@ -28,7 +29,7 @@ namespace Kernel::ACPI::AML auto data_result = AML::parse_object(context); if (!data_result.success()) return ParseResult::Failure; - auto data_node = data_result.node(); + auto data_node = data_result.node() ? data_result.node()->to_underlying() : BAN::RefPtr(); if (!data_node) { AML_ERROR("Conversion {2H} data could not be evaluated", static_cast(opcode)); @@ -69,6 +70,37 @@ namespace Kernel::ACPI::AML case AML::Byte::ToStringOp: converted = data_node->convert(AML::Node::ConvString); break; + case AML::Byte::ToHexStringOp: + { + switch (data_node->type) + { + case AML::Node::Type::Integer: + converted = MUST(BAN::RefPtr::create( + MUST(BAN::String::formatted("0x{H}", static_cast(data_node.ptr())->value)) + )); + break; + case AML::Node::Type::String: + converted = data_node->copy(); + break; + case AML::Node::Type::Buffer: + { + const auto& buffer = static_cast(data_node.ptr())->buffer; + + BAN::String temp; + for (size_t i = 0; i < buffer.size(); i++) + { + const char* format = (i == 0) ? "0x{H}" : ", 0x{H}"; + MUST(temp.append(MUST(BAN::String::formatted(format, buffer[i])))); + } + + converted = MUST(BAN::RefPtr::create(temp)); + break; + } + default: + break; + } + break; + } default: ASSERT_NOT_REACHED(); } diff --git a/kernel/kernel/ACPI/AML/Node.cpp b/kernel/kernel/ACPI/AML/Node.cpp index d2134a79..a1c52a50 100644 --- a/kernel/kernel/ACPI/AML/Node.cpp +++ b/kernel/kernel/ACPI/AML/Node.cpp @@ -152,6 +152,7 @@ namespace Kernel::ACPI case AML::Byte::XorOp: return AML::Expression::parse(context); case AML::Byte::ToBufferOp: + case AML::Byte::ToHexStringOp: case AML::Byte::ToIntegerOp: case AML::Byte::ToStringOp: return AML::Conversion::parse(context);