Page 1 of 1

AML, forward references?

Posted: Sun Nov 08, 2020 9:42 am
by Gigasoft
The Bochs emulator provides a DSDT where a name (LNKD) is referenced by a package before it is defined. There is no way to know in advance what the name will refer to, so what am I to make of this? Is this even legal AML?

To illustrate the problem, suppose you have the following definition block. If it is legal, what does it do and what will be stored in \AAAA\DDDD? If not, where is the error?

Code: Select all

Device (AAAA) {
    Name (BBBB, Package(1) {CCCC})
    If (LEqual(ObjectType(Index(BBBB, 0)), 1)) {
        Device(CCCC) {
        }
        Name(DDDD, 0)
    } Else {
        Name(DDDD, 1)
    }
}
Name (CCCC, 1234)

Re: AML, forward references?

Posted: Sun Nov 08, 2020 12:26 pm
by bzt
Gigasoft wrote:Is this even legal AML?
Looks like it. I've found this patch from 2016, which says:
With old support, it appears to be the forward referencing in the arguments of the above opcodes is supported by the ACPICA interpreter, while the investigation result shows that Windows doesn't support the forward referencing even in the arguments.
(Again, this is from 2016)

I guess you'll have to parse the AML code more than once, using a multiple-pass parser. First collect the references (or prototypes), then in the second pass the definitions. That's how all compilers work that support forward-referencing languages.

Cheers,
bzt