aml is a pure-Rust AML (ACPI Machine Language) parser, used for parsing the DSDT and
SSDT tables from ACPI. This crate can be used by kernels to gather information about the
hardware, and invoke control methods (this is not yet supported) to query and change the state
of devices in a hardware-independent way.
To use the library, you will mostly interact with the
AmlContext type. You should create an
instance of this type using
AmlContext::new(), and then pass it tables containing AML
(probably from the
acpi crate), which you've mapped into the virtual address space. This will
parse the table, populating the namespace with objects encoded by the AML. After this, you may
unmap the memory the table was mapped into - all the information needed will be extracted and
allocated on the heap.
You can then access specific objects by name like so: e.g.
let my_aml_value = aml_context.lookup(&AmlName::from_str("\\_SB.PCI0.S08._ADR").unwrap());
The parser is written using a set of custom parser combinators - the code can be confusing on first reading, but provides an extensible and type-safe way to write parsers. For an easy introduction to parser combinators and the foundations used for this library, I suggest reading Bodil's fantastic blog post.
The actual combinators can be found in
parser.rs. Various tricks are used to provide a nice
API and work around limitations in the type system, such as the concrete types like
MapWithContext, and the
make_parser_concrete hack macro.
The actual parsers are then grouped into categories based loosely on the AML grammar sections in the ACPI spec. Most are written in terms of combinators, but some have to be written in a more imperitive style, either because they're clearer, or because we haven't yet found good combinator patterns to express the parse.
Takes a number of parsers, and tries to apply each one to the input in order. Returns the result of the first one that succeeds, or fails if all of them fail.
This encapsulates an unfortunate hack we sometimes need to use, where the type checker gets
caught in an infinite loop of parser types. This occurs when an object can indirectly contain
itself, and so the parser type will contain its own type. This works by breaking the cycle of
Helper macro for use within
A handle is used to refer to an AML value without actually borrowing it until you need to access it (this makes borrowing situation much easier as you only have to consider who's borrowing the namespace). They can also be cached to avoid expensive namespace lookups.
AML has a