Compare commits

..

No commits in common. "cb07142832481aa7aea9424a8b768073e3cc3df7" and "66905fcc081bb34335bb3e6430d7739aff0b21fe" have entirely different histories.

11 changed files with 25 additions and 123 deletions

View File

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

View File

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

View File

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

View File

@ -43,8 +43,6 @@ namespace Kernel::ACPI::AML
virtual bool is_scope() const { return false; } virtual bool is_scope() const { return false; }
virtual BAN::RefPtr<Node> copy() { return this; }
[[nodiscard]] BAN::Optional<uint64_t> as_integer(); [[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 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; } [[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"); AML_ERROR("Failed to evaluate source for store");
return false; return false;
} }
value = evaluated->copy(); value = evaluated;
return true; return true;
} }

View File

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

View File

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

View File

@ -222,14 +222,10 @@ namespace Kernel::ACPI
return {}; return {};
} }
auto string = static_cast<AML::String*>(arg.ptr()); auto string = static_cast<AML::String*>(arg.ptr());
return string->string_view() == "Linux"_sv ? AML::Integer::Constants::Ones : AML::Integer::Constants::Zero; return string->string == "Linux" ? AML::Integer::Constants::Ones : AML::Integer::Constants::Zero;
}; };
ASSERT(s_root_namespace->add_named_object(context, AML::NameString("\\_OSI"), osi)); 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; return s_root_namespace;
} }

View File

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

View File

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