From 51d1e47bfee4b626eb97b0ad51fce9700eaa5783 Mon Sep 17 00:00:00 2001 From: Bananymous Date: Thu, 15 Aug 2024 19:05:58 +0300 Subject: [PATCH] Kernel: Fix AML CreateFieldOp to take bit index instead of byte index --- kernel/include/kernel/ACPI/AML/Buffer.h | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/kernel/include/kernel/ACPI/AML/Buffer.h b/kernel/include/kernel/ACPI/AML/Buffer.h index efed7471..ffb6cf46 100644 --- a/kernel/include/kernel/ACPI/AML/Buffer.h +++ b/kernel/include/kernel/ACPI/AML/Buffer.h @@ -166,27 +166,35 @@ namespace Kernel::ACPI::AML { ASSERT(context.aml_data.size() >= 1); - size_t field_bit_size = 0; + bool offset_in_bytes; + size_t field_bit_size; switch (static_cast(context.aml_data[0])) { case AML::Byte::CreateBitFieldOp: field_bit_size = 1; + offset_in_bytes = false; break; case AML::Byte::CreateByteFieldOp: field_bit_size = 8; + offset_in_bytes = true; break; case AML::Byte::CreateWordFieldOp: field_bit_size = 16; + offset_in_bytes = true; break; case AML::Byte::CreateDWordFieldOp: field_bit_size = 32; + offset_in_bytes = true; break; case AML::Byte::CreateQWordFieldOp: field_bit_size = 64; + offset_in_bytes = true; break; case AML::Byte::ExtOpPrefix: ASSERT(context.aml_data.size() >= 2); ASSERT(static_cast(context.aml_data[1]) == AML::ExtOp::CreateFieldOp); + field_bit_size = 0; + offset_in_bytes = false; break; default: ASSERT_NOT_REACHED(); @@ -238,7 +246,7 @@ namespace Kernel::ACPI::AML } size_t field_bit_offset = static_cast(index_node.ptr())->value; - if (field_bit_size != 1) + if (offset_in_bytes) field_bit_offset *= 8; auto field = MUST(BAN::RefPtr::create(field_name->path.back(), buffer, field_bit_offset, field_bit_size));