LibACPI: Add support for reading methods

For now just create a node, but don't actually do anything with the
body as it's not needed for now.

Co-authored-by: RatcheT2497 <[email protected]>
This commit is contained in:
UndefineandRatcheT2497 authored and Sönke Holz committed 2026-11-01 15:08:28 +01:00
1 parent c9e5fa6ada
commit 70f7715bca
5 files changed
+62 -3

No files matched your search

+14 -2
View File
@@ -205,7 +205,7 @@ ErrorOr<Object> Interpreter::finalize_value_opcode(OpcodeFrame& frame)
VERIFY_NOT_REACHED();
}
ErrorOr<void> Interpreter::finalize_term_opcode(OpcodeFrame& frame)
ErrorOr<void> Interpreter::finalize_term_opcode(OpcodeFrame& frame, TableStream& stream)
{
switch (frame.opcode()) {
case Opcode::ScopeOp: {
@@ -227,6 +227,18 @@ ErrorOr<void> Interpreter::finalize_term_opcode(OpcodeFrame& frame)
return {};
}
case Opcode::MethodOp: {
auto length = TRY(frame.operand(0).as<u64>());
auto path = TRY(frame.operand(1).as<NameString>());
auto flags = TRY(frame.operand(2).as<u64>());
auto node = TRY(try_make_ref_counted<MethodNode>(frame.start(), frame.start() + length, m_loaded_tables.size() - 1, flags));
TRY(m_scope_frames.last().insert_node(path, node));
TRY(stream.seek(frame.start() + length));
return {};
}
case Opcode::OpRegionOp: {
auto path = TRY(frame.operand(0).as<NameString>());
auto region_space = TRY(frame.operand(1).as<u64>());
@@ -428,7 +440,7 @@ ErrorOr<IterationDecision> Interpreter::cycle(TableStream& stream)
} else {
DEBUG_LOG("Finalizing term {}", top_frame_value.opcode());
TRY(finalize_term_opcode(top_frame_value));
TRY(finalize_term_opcode(top_frame_value, stream));
m_state = State::ReadingOpcode;
}
+1 -1
View File
@@ -77,7 +77,7 @@ private:
ErrorOr<IterationDecision> read_operand(TableStream& stream, OperandType operand);
ErrorOr<Object> finalize_value_opcode(OpcodeFrame& frame);
ErrorOr<void> finalize_term_opcode(OpcodeFrame& frame);
ErrorOr<void> finalize_term_opcode(OpcodeFrame& frame, TableStream& stream);
void debug_print_header(TableStream& stream, size_t operand_index = 0);
+6
View File
@@ -65,6 +65,12 @@ ErrorOr<void> NameNode::write_description(StringBuilder& builder)
return {};
}
ErrorOr<void> MethodNode::write_description(StringBuilder& builder)
{
TRY(builder.try_appendff("Method(Table: {}, Arguments: {}, Start: {}, End: {}, Flags: {})", m_table_index, argument_count(), m_start, m_end, m_flags));
return {};
}
ErrorOr<void> OperationRegionNode::write_description(StringBuilder& builder)
{
TRY(builder.try_appendff("OperationRegion(Space: {}, Offset: {}, Length: {})", m_space_raw, m_offset, m_length));
+32
View File
@@ -24,6 +24,7 @@ enum class NodeType : u8 {
Untyped,
Scope,
Name,
Method,
OperationRegion,
Field,
};
@@ -79,6 +80,37 @@ protected:
Object m_data;
};
class MethodNode : public Node {
public:
MethodNode(size_t start, size_t end, size_t table_index, u8 flags)
: m_start(start)
, m_end(end)
, m_table_index(table_index)
, m_flags(flags)
{
}
virtual ErrorOr<void> write_description(StringBuilder& builder) override;
virtual NodeType type() const override { return NodeType::Method; }
virtual StringView kind() const override { return "Method"sv; }
size_t table_index() const { return m_table_index; }
size_t start() const { return m_start; }
size_t end() const { return m_end; }
u8 flags() const { return m_flags; }
u8 argument_count() const { return m_flags & 7; }
private:
size_t m_start { 0 };
size_t m_end { 0 };
size_t m_table_index { 0 };
u8 m_flags { 0 };
};
class OperationRegionNode : public Node {
public:
OperationRegionNode(u8 region_space, u64 region_offset, u64 region_length)
@@ -26,6 +26,13 @@ constexpr static Array<OperandType, 2> WORD_CONST_OPERANDS = { OperandType::Word
constexpr static Array<OperandType, 2> DWORD_CONST_OPERANDS = { OperandType::DWordData, OperandType::End };
constexpr static Array<OperandType, 2> QWORD_CONST_OPERANDS = { OperandType::QWordData, OperandType::End };
constexpr static Array<OperandType, 4> METHOD_OPERANDS = {
OperandType::PackageLength,
OperandType::NameString,
OperandType::ByteData,
OperandType::End,
};
constexpr static Array<OperandType, 5> OP_REGION_OPERANDS = {
OperandType::NameString,
OperandType::ByteData,
@@ -60,6 +67,8 @@ static ErrorOr<ReadonlySpan<OperandType>> get_opcode_operand_template(Opcode opc
return SCOPE_OPERANDS.span();
case Opcode::NameOp:
return NAME_OPERANDS.span();
case Opcode::MethodOp:
return METHOD_OPERANDS.span();
case Opcode::OpRegionOp:
return OP_REGION_OPERANDS.span();
case Opcode::FieldOp: