Compare commits

...

6 Commits

Author SHA1 Message Date
Bananymous cb07142832 Kernel: ACPI allow more calling or \_S5
Spec says that \_Sx must have 4 fields, but virtual box seems to only
have the two defined once. This patch allows shutodown on virtual box
2024-06-25 23:25:10 +03:00
Bananymous 60a05412c9 Kernel: ACPI implement SizeOf 2024-06-25 23:24:51 +03:00
Bananymous 0179f5ea09 Kernel: ACPI add \_OS string 2024-06-25 23:24:19 +03:00
Bananymous f671ed7e3f Kernel: ACPI implement integer stores to registers as copies
Before storing const integer and then modifying the register it would
error.
2024-06-25 23:23:52 +03:00
Bananymous 2fccff5a35 Kernel: Implement ACPI IndexOp into Strings 2024-06-25 23:23:00 +03:00
Bananymous cd41d5f6dd ports: DOOM install now downloads and installs doom1.wad 2024-06-25 19:57:15 +03:00
11 changed files with 123 additions and 25 deletions

View File

@ -5,6 +5,7 @@
#include <kernel/ACPI/AML/Node.h>
#include <kernel/ACPI/AML/ParseContext.h>
#include <kernel/ACPI/AML/Pkg.h>
#include <kernel/ACPI/AML/String.h>
namespace Kernel::ACPI::AML
{
@ -67,11 +68,12 @@ namespace Kernel::ACPI::AML
struct BufferField : AML::NamedObject
{
BAN::RefPtr<Buffer> buffer;
BAN::RefPtr<AML::Node> buffer;
size_t field_bit_offset;
size_t field_bit_size;
BufferField(AML::NameSeg name, BAN::RefPtr<Buffer> buffer, size_t field_bit_offset, size_t field_bit_size)
template<typename T> requires BAN::is_same_v<T, AML::Buffer> || BAN::is_same_v<T, AML::String>
BufferField(AML::NameSeg name, BAN::RefPtr<T> buffer, size_t field_bit_offset, size_t field_bit_size)
: AML::NamedObject(Node::Type::BufferField, name)
, buffer(buffer)
, field_bit_offset(field_bit_offset)
@ -81,7 +83,11 @@ namespace Kernel::ACPI::AML
BAN::RefPtr<AML::Node> evaluate() override
{
ASSERT(buffer);
ASSERT(field_bit_offset + field_bit_size <= buffer->buffer.size() * 8);
ASSERT(buffer->type == AML::Node::Type::Buffer || buffer->type == AML::Node::Type::String);
const auto& buffer = (this->buffer->type == AML::Node::Type::Buffer)
? static_cast<AML::Buffer*>(this->buffer.ptr())->buffer
: static_cast<AML::String*>(this->buffer.ptr())->string;
ASSERT(field_bit_offset + field_bit_size <= buffer.size() * 8);
uint64_t value = 0;
@ -89,13 +95,13 @@ namespace Kernel::ACPI::AML
const size_t bit_offset = field_bit_offset % 8;
if (field_bit_size == 1)
{
value = (buffer->buffer[byte_offset] >> bit_offset) & 1;
value = (buffer[byte_offset] >> bit_offset) & 1;
}
else
{
ASSERT(bit_offset == 0);
for (size_t byte = 0; byte < field_bit_size / 8; byte++)
value |= buffer->buffer[byte_offset + byte] << byte;
value |= buffer[byte_offset + byte] << byte;
}
return MUST(BAN::RefPtr<AML::Integer>::create(value));
@ -104,7 +110,11 @@ namespace Kernel::ACPI::AML
bool store(BAN::RefPtr<AML::Node> node) override
{
ASSERT(buffer);
ASSERT(field_bit_offset + field_bit_size <= buffer->buffer.size() * 8);
ASSERT(buffer->type == AML::Node::Type::Buffer || buffer->type == AML::Node::Type::String);
auto& buffer = (this->buffer->type == AML::Node::Type::Buffer)
? static_cast<AML::Buffer*>(this->buffer.ptr())->buffer
: static_cast<AML::String*>(this->buffer.ptr())->string;
ASSERT(field_bit_offset + field_bit_size <= buffer.size() * 8);
auto value = node->as_integer();
if (!value.has_value())
@ -114,14 +124,14 @@ namespace Kernel::ACPI::AML
const size_t bit_offset = field_bit_offset % 8;
if (field_bit_size == 1)
{
buffer->buffer[byte_offset] &= ~(1 << bit_offset);
buffer->buffer[byte_offset] |= (value.value() & 1) << bit_offset;
buffer[byte_offset] &= ~(1 << bit_offset);
buffer[byte_offset] |= (value.value() & 1) << bit_offset;
}
else
{
ASSERT(bit_offset == 0);
for (size_t byte = 0; byte < field_bit_size / 8; byte++)
buffer->buffer[byte_offset + byte] = (value.value() >> (byte * 8)) & 0xFF;
buffer[byte_offset + byte] = (value.value() >> (byte * 8)) & 0xFF;
}
return true;
@ -163,7 +173,7 @@ namespace Kernel::ACPI::AML
AML_ERROR("Buffer source does not evaluate to a Buffer");
return ParseResult::Failure;
}
auto buffer = static_cast<Buffer*>(buffer_node.ptr());
auto buffer = BAN::RefPtr<AML::Buffer>(static_cast<AML::Buffer*>(buffer_node.ptr()));
auto index_result = AML::parse_object(context);
if (!index_result.success())

View File

@ -42,7 +42,7 @@ namespace Kernel::ACPI::AML
{
case AML::Node::Type::Buffer:
{
auto buffer = static_cast<AML::Buffer*>(source.ptr());
auto buffer = BAN::RefPtr<AML::Buffer>(static_cast<AML::Buffer*>(source.ptr()));
if (index.value() >= buffer->buffer.size())
{
AML_ERROR("IndexOp index is out of buffer bounds");
@ -65,8 +65,17 @@ namespace Kernel::ACPI::AML
break;
}
case AML::Node::Type::String:
AML_TODO("IndexOp source String");
{
auto string = BAN::RefPtr<AML::String>(static_cast<AML::String*>(source.ptr()));
if (index.value() >= string->string.size())
{
AML_ERROR("IndexOp index is out of string bounds");
return ParseResult::Failure;
}
auto buffer_field = MUST(BAN::RefPtr<BufferField>::create(NameSeg(""_sv), string, index.value() * 8, 8));
result = MUST(BAN::RefPtr<AML::Reference>::create(buffer_field));
break;
}
default:
AML_ERROR("IndexOp source is not a Buffer, Package, or String");
return ParseResult::Failure;

View File

@ -30,6 +30,8 @@ namespace Kernel::ACPI::AML
, constant(constant)
{}
BAN::RefPtr<Node> copy() override { return MUST(BAN::RefPtr<Integer>::create(value)); }
BAN::RefPtr<AML::Node> evaluate() override
{
return this;

View File

@ -43,6 +43,8 @@ namespace Kernel::ACPI::AML
virtual bool is_scope() const { return false; }
virtual BAN::RefPtr<Node> copy() { return this; }
[[nodiscard]] BAN::Optional<uint64_t> as_integer();
[[nodiscard]] virtual BAN::RefPtr<AML::Node> evaluate() { AML_TODO("evaluate, type {}", static_cast<uint8_t>(type)); return nullptr; }
[[nodiscard]] virtual bool store(BAN::RefPtr<AML::Node>) { AML_TODO("store, type {}", static_cast<uint8_t>(type)); return false; }

View File

@ -32,7 +32,7 @@ namespace Kernel::ACPI::AML
AML_ERROR("Failed to evaluate source for store");
return false;
}
value = evaluated;
value = evaluated->copy();
return true;
}

View File

@ -0,0 +1,54 @@
#pragma once
#include <kernel/ACPI/AML/Buffer.h>
#include <kernel/ACPI/AML/Names.h>
#include <kernel/ACPI/AML/Package.h>
#include <kernel/ACPI/AML/ParseContext.h>
#include <kernel/ACPI/AML/Reference.h>
namespace Kernel::ACPI::AML
{
struct SizeOf
{
static ParseResult parse(ParseContext& context)
{
ASSERT(context.aml_data.size() >= 1);
ASSERT(static_cast<Byte>(context.aml_data[0]) == Byte::SizeOfOp);
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()->evaluate();
if (object && object->type == AML::Node::Type::Reference)
object = static_cast<AML::Reference*>(object.ptr())->node->evaluate();
if (!object)
{
AML_ERROR("SizeOf object is null");
return ParseResult::Failure;
}
uint64_t size = 0;
switch (object->type)
{
case AML::Node::Type::Buffer:
size = static_cast<AML::Buffer*>(object.ptr())->buffer.size();
break;
case AML::Node::Type::String:
size = static_cast<AML::String*>(object.ptr())->string.size();
break;
case AML::Node::Type::Package:
size = static_cast<AML::Package*>(object.ptr())->elements.size();
break;
default:
AML_ERROR("SizeOf object is not a buffer, string or package ({})", static_cast<uint8_t>(object->type));
return ParseResult::Failure;
}
return ParseResult(MUST(BAN::RefPtr<Integer>::create(size)));
}
};
}

View File

@ -9,28 +9,40 @@ namespace Kernel::ACPI::AML
struct String : public AML::Node
{
BAN::String string;
BAN::Vector<uint8_t> string;
String() : Node(Node::Type::String) {}
String(BAN::StringView string)
: Node(Node::Type::String)
{
MUST(this->string.resize(string.size()));
for (size_t i = 0; i < string.size(); i++)
this->string[i] = string[i];
}
BAN::RefPtr<AML::Node> evaluate() override
{
return this;
}
BAN::StringView string_view() const
{
return BAN::StringView(reinterpret_cast<const char*>(string.data()), string.size());
}
static ParseResult parse(ParseContext& context)
{
ASSERT(context.aml_data.size() >= 1);
ASSERT(static_cast<AML::Byte>(context.aml_data[0]) == AML::Byte::StringPrefix);
context.aml_data = context.aml_data.slice(1);
BAN::String string;
BAN::Vector<uint8_t> string;
while (context.aml_data.size() > 0)
{
if (context.aml_data[0] == 0x00)
break;
MUST(string.push_back(static_cast<char>(context.aml_data[0])));
MUST(string.push_back(context.aml_data[0]));
context.aml_data = context.aml_data.slice(1);
}
@ -49,7 +61,7 @@ namespace Kernel::ACPI::AML
virtual void debug_print(int indent) const override
{
AML_DEBUG_PRINT_INDENT(indent);
AML_DEBUG_PRINT("String \"{}\"", string);
AML_DEBUG_PRINT("String \"{}\"", string_view());
}
};

View File

@ -506,9 +506,9 @@ acpi_release_global_lock:
return;
}
auto* s5_package = static_cast<AML::Package*>(s5_evaluated.ptr());
if (s5_package->elements.size() != 4)
if (s5_package->elements.size() < 2)
{
dwarnln("\\_S5 package has {} elements, expected 4", s5_package->elements.size());
dwarnln("\\_S5 package has {} elements, expected atleast 2", s5_package->elements.size());
return;
}

View File

@ -222,10 +222,14 @@ namespace Kernel::ACPI
return {};
}
auto string = static_cast<AML::String*>(arg.ptr());
return string->string == "Linux" ? AML::Integer::Constants::Ones : AML::Integer::Constants::Zero;
return string->string_view() == "Linux"_sv ? AML::Integer::Constants::Ones : AML::Integer::Constants::Zero;
};
ASSERT(s_root_namespace->add_named_object(context, AML::NameString("\\_OSI"), osi));
auto os_string = MUST(BAN::RefPtr<AML::String>::create("banan-os"_sv));
auto os = MUST(BAN::RefPtr<AML::Name>::create("_OS"_sv, os_string));
ASSERT(s_root_namespace->add_named_object(context, AML::NameString("\\_OS"), os));
return s_root_namespace;
}

View File

@ -17,6 +17,7 @@
#include <kernel/ACPI/AML/Processor.h>
#include <kernel/ACPI/AML/Reference.h>
#include <kernel/ACPI/AML/Region.h>
#include <kernel/ACPI/AML/SizeOf.h>
#include <kernel/ACPI/AML/Sleep.h>
#include <kernel/ACPI/AML/Store.h>
#include <kernel/ACPI/AML/String.h>
@ -176,6 +177,8 @@ namespace Kernel::ACPI
return AML::Index::parse(context);
case AML::Byte::NotifyOp:
return AML::Notify::parse(context);
case AML::Byte::SizeOfOp:
return AML::SizeOf::parse(context);
case AML::Byte::NoopOp:
context.aml_data = context.aml_data.slice(1);
return ParseResult::Success;

View File

@ -10,8 +10,7 @@ if [ -z $BANAN_SYSROOT ]; then
exit 1
fi
CURRENT_DIR=$(dirname $(realpath $0))
pushd $CURRENT_DIR >/dev/null
cd $(dirname $(realpath $0))
if [ ! -d "doomgeneric" ]; then
git clone https://github.com/ozkl/doomgeneric.git
@ -25,7 +24,10 @@ if [ ! -d "doomgeneric" ]; then
grep -qxF doom ../installed || echo doom >> ../installed
fi
if [ ! -f doom1.wad ]; then
wget https://distro.ibiblio.org/slitaz/sources/packages/d/doom1.wad
fi
make --directory doomgeneric/doomgeneric --file Makefile.banan_os
cp "doomgeneric/doomgeneric/build-${BANAN_ARCH}/doomgeneric" "${BANAN_SYSROOT}/bin/doom"
popd >/dev/null
cp doom1.wad $BANAN_SYSROOT/home/user/