Skip to content

Draft: AML: allow field in ToInteger #209

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

rw-vanc
Copy link
Contributor

@rw-vanc rw-vanc commented Mar 8, 2024

Seen in the wild, Field is used as argument to ToInteger, even though the spec says it is not an option.

@rw-vanc rw-vanc changed the title allow field in ToInteger AML: allow field in ToInteger Mar 8, 2024
@IsaacWoods
Copy link
Member

Hm, yeah the spec seems pretty explicit here, and none of the other open-source interpreters seem to allow this (e.g. ACPICA. Could you share the AML snippet and what machine it comes from? I wonder if we can see how e.g. Linux is parsing it? Depending on the context, it might be that we're missing some weird implicit conversion semantic elsewhere in the pipeline.

Also slightly possible that the AML is just completely broken if it's in a method that doesn't ever get executed or whatever, and ACPICA would throw an error if it tried to execute it?

@rw-vanc
Copy link
Contributor Author

rw-vanc commented Mar 9, 2024

USTP is a field in GNVS. It is used in an If expression at the top level in the DSDT. The error is occurring at position 36E3F, which is the beginning of the If. This is from a bottom-of-the-barrel HP laptop, Model 14-dq3007. The disassembled code is coming from iasl.

    Field (GNVS, AnyAcc, Lock, Preserve)
    {
...
        USTP,   8, 
...
    1410: 5B 81 8B BB 01 47 4E 56 53 10 4F 53 59 53 10 53  // [....GNVS.OSYS.S
    1420: 4D 49 46 08 50 52 4D 30 08 50 52 4D 31 08 53 43  // MIF.PRM0.PRM1.SC
...
    1B10: 41 08 53 44 4D 42 08 00 08 55 53 54 50 08 00 48  // A.SDMB...USTP..H
    If (USTP)
    {

   36E3F: A0 4C 48 55 53 54 50                             // .LHUSTP

        Scope (_SB.PC00.I2C0)
        {

   36E46: 10 40 09 2F 03 5F 53 42 5F 50 43 30 30 49 32 43  // .@./._SB_PC00I2C
   36E56: 30                                               // 0

            Method (SSCN, 0, NotSerialized)
            {

   36E57: 14 17 53 53 43 4E 00                             // ..SSCN.

                Return (PKG3 (SSH0, SSL0, SSD0))
            }


   36E5E: A4 50 4B 47 33 53 53 48 30 53 53 4C 30 53 53 44  // .PKG3SSH0SSL0SSD
   36E6E: 30                                               // 0

@IsaacWoods
Copy link
Member

IsaacWoods commented Mar 9, 2024

I'm struggling to manually parse that AML a little - there doesn't seem to be a ToInteger opcode (0x99) in the If at all? The 0xa0 is the DefIfOp, and then there's obviously the USTP later, but surely the interspersed HU would also form part of a name, since they're just ASCII chars too? Not sure how it's decompiling to If(USTP), but could be missing something.

Admittedly I haven't had any coffee yet, but I can't see how we'd ever end up in ToInteger at all. What's the error from our parser?

@rw-vanc
Copy link
Contributor Author

rw-vanc commented Mar 9, 2024

My bad, I got this mixed up with my other change, If (field). I will give you the correct code block.

@rw-vanc
Copy link
Contributor Author

rw-vanc commented Mar 9, 2024

It's the Switch value where the problem occurs.

            Method (WIST, 0, Serialized)
            {

   173CD: 14 4A 14 57 49 53 54 08                          // .J.WIST.


   173D5: 08 5F 54 5F 30 00                                // ._T_0.

                If (CondRefOf (VDID))
                {

   173DB: A0 48 13 5B 12 56 44 49 44 00                    // .H.[.VDID.

                    Switch (ToInteger (VDID))
                    {

   173E5: A2 4E 12 01 70 99 56 44 49 44 00 5F 54 5F 30     // .N..p.VDID._T_0

                        Case (0x095A8086)
                        {

   173F4: A0 0D 93 5F 54 5F 30 0C 86 80 5A 09              // ..._T_0...Z.

                            Return (One)
                        }

@rw-vanc
Copy link
Contributor Author

rw-vanc commented Mar 9, 2024

This is the declaration.

            OperationRegion (RPXX, SystemMemory, GMIO (^_ADR, _ADR), 0x10)

   1737E: 5B 80 52 50 58 58 00 47 4D 49 4F 5E 5F 41 44 52  // [.RPXX.GMIO^_ADR
   1738E: 5F 41 44 52 0A 10                                // _ADR..

            Field (RPXX, AnyAcc, NoLock, Preserve)
            {
                VDID,   32
            }


   17394: 5B 81 0B 52 50 58 58 00 56 44 49 44 20           // [..RPXX.VDID 

@rw-vanc rw-vanc changed the title AML: allow field in ToInteger Draft: AML: allow field in ToInteger Apr 7, 2024
@rw-vanc rw-vanc closed this Apr 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants