From 40c698937429cb721c17d369fa65c4c47861ff35 Mon Sep 17 00:00:00 2001 From: Bananymous Date: Sun, 18 Aug 2024 20:49:35 +0300 Subject: [PATCH] Kernel: Implement AML ObjectTypeOp --- kernel/include/kernel/ACPI/AML/ObjectType.h | 108 ++++++++++++++++++++ kernel/kernel/ACPI/AML/Node.cpp | 3 + 2 files changed, 111 insertions(+) create mode 100644 kernel/include/kernel/ACPI/AML/ObjectType.h diff --git a/kernel/include/kernel/ACPI/AML/ObjectType.h b/kernel/include/kernel/ACPI/AML/ObjectType.h new file mode 100644 index 00000000..37864d5f --- /dev/null +++ b/kernel/include/kernel/ACPI/AML/ObjectType.h @@ -0,0 +1,108 @@ +#pragma once + +#include +#include +#include + +namespace Kernel::ACPI::AML +{ + + struct ObjectType + { + static ParseResult parse(ParseContext& context) + { + ASSERT(context.aml_data.size() >= 1); + ASSERT(static_cast(context.aml_data[0]) == Byte::ObjectTypeOp); + context.aml_data = context.aml_data.slice(1); + + auto object_result = AML::parse_object(context); + if (!object_result.success()) + return ParseResult::Failure; + auto object = object_result.node() + ? object_result.node()->to_underlying() + : BAN::RefPtr(); + + if (object && object->type == AML::Node::Type::Reference) + object = static_cast(object.ptr())->node->to_underlying(); + + uint64_t value = 0; + if (object) + { + switch (object->type) + { + case AML::Node::Type::None: + case AML::Node::Type::Alias: + case AML::Node::Type::Name: + case AML::Node::Type::PackageElement: + case AML::Node::Type::Reference: + case AML::Node::Type::Register: + ASSERT_NOT_REACHED(); + case AML::Node::Type::Namespace: + value = 0; + break; + case AML::Node::Type::Integer: + value = 1; + break; + case AML::Node::Type::String: + value = 2; + break; + case AML::Node::Type::Buffer: + value = 3; + break; + case AML::Node::Type::Package: + value = 4; + break; + case AML::Node::Type::FieldElement: + case AML::Node::Type::BankFieldElement: + case AML::Node::Type::IndexFieldElement: + value = 5; + break; + case AML::Node::Type::Device: + value = 6; + break; + case AML::Node::Type::Event: + value = 7; + break; + case AML::Node::Type::Method: + value = 8; + break; + case AML::Node::Type::Mutex: + value = 9; + break; + case AML::Node::Type::OpRegion: + value = 10; + break; + case AML::Node::Type::PowerResource: + value = 11; + break; + case AML::Node::Type::Processor: + value = 12; + break; + case AML::Node::Type::ThermalZone: + value = 13; + break; + case AML::Node::Type::BufferField: + value = 14; + break; + case AML::Node::Type::Debug: + value = 16; + break; + } + } + +#if AML_DEBUG_LEVEL >= 2 + if (!object) + AML_DEBUG_PRINTLN("ObjectType { null }"); + else + { + AML_DEBUG_PRINTLN("ObjectType {"); + object->debug_print(1); + AML_DEBUG_PRINTLN(""); + } +#endif + + return ParseResult(MUST(BAN::RefPtr::create(value))); + } + }; + +} diff --git a/kernel/kernel/ACPI/AML/Node.cpp b/kernel/kernel/ACPI/AML/Node.cpp index 1c0609bd..d2134a79 100644 --- a/kernel/kernel/ACPI/AML/Node.cpp +++ b/kernel/kernel/ACPI/AML/Node.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -191,6 +192,8 @@ namespace Kernel::ACPI return AML::Notify::parse(context); case AML::Byte::SizeOfOp: return AML::SizeOf::parse(context); + case AML::Byte::ObjectTypeOp: + return AML::ObjectType::parse(context); case AML::Byte::BreakPointOp: // TODO: support breakpoints? case AML::Byte::NoopOp: context.aml_data = context.aml_data.slice(1);