Commit Graph

24 Commits (master)

Author SHA1 Message Date
cinap_lenrek 1a46b6c19e libaml: fix gc bug, need to amltake()/amldrop() temporary buffer
we have to protect the temporary buffer allocated by rwfield()
as rwreg() calls amlmapio() which might cause further aml code
execution causing gc() which frees it under us (as it is not
referenced from the interpreter state).

this fixes a panic on boot of a

Lenovo Thinkpad P17 Gen1 Professional Mobile Workstation
2021-07-14 17:04:40 +00:00
cinap_lenrek e77fa31516 libaml: fix IndexField and BankField implementations (thanks Michael Forney)
IndexField is supposed to increment the index value when an
access is done with a bigger size than the data field.
The index value is always a byte offset.

Now that we always calculate the offset for each field unit
access for IndexField, rename the indexv to bank (the bank
value), as it is only used for that. Also, do not compare
it with nil, as it is a integer constant which can be
encoded as nil to mean zero.

For BankField, the banking field was written using store(),
which does nothing when the destination is a Field*.
Use rwfield() to fix it in the new rwfieldunit().

Resolve all the Name*'s when IndexField, BankField and
Field are created. Now, Field.reg points to eigther
Buffer object, Region or Field (data Field of an IndexField).

PS: initial bug report by Michael Forney follows below:

In /dev/kmesg on my T14, I saw a message

	amlmapio: [0xffffff18-0x100000018] overlaps usable memory
	amlmapio: mapping \_SB.FRTP failed

Here is the relevant snippet from my DSDT:

    Scope (_SB)
    {
        ...

        OperationRegion (ECMC, SystemIO, 0x72, 0x02)
        Field (ECMC, AnyAcc, NoLock, Preserve)
        {
            ECMI,   8,
            ECMD,   8
        }

        IndexField (ECMI, ECMD, ByteAcc, NoLock, Preserve)
        {
            Offset (0x08),
            FRTB,   32
        }

        OperationRegion (FRTP, SystemMemory, FRTB, 0x0100)
        Field (FRTP, AnyAcc, NoLock, Preserve)
        {
		...
        }
    }

With some debugging output:

	amlmapio(\_SB.ECMC): Io       72 - 74
	rwreg(\_SB.ECMC): Io       [72+0]/1 <- 8
	rwreg(\_SB.ECMC): Io       [72+1]/1 -> 18
	amlmapio(\_SB.FRTP): Mem      ffffff18 - 100000018
	amlmapio: [0xffffff18-0x100000018) overlaps usable memory
	amlmapio: mapping \_SB.FRTP failed

It seems that libaml does not handle IndexField correctly and just did
a single read from ECMD after setting ECMI to 8, causing the FRTP
region to be evaluated as 0xffffff18-0x100000018. Instead, it should
be reading 4 bytes [18 c0 22 cc], evaluating it as
0xcc22c018-0xcc22118:

	amlmapio(\_SB.ECMC): Io       72 - 74
	rwreg(\_SB.ECMC): Io       [72+0]/1 <- 8
	rwreg(\_SB.ECMC): Io       [72+1]/1 -> 18
	rwreg(\_SB.ECMC): Io       [72+0]/1 <- 9
	rwreg(\_SB.ECMC): Io       [72+1]/1 -> c0
	rwreg(\_SB.ECMC): Io       [72+0]/1 <- a
	rwreg(\_SB.ECMC): Io       [72+1]/1 -> 22
	rwreg(\_SB.ECMC): Io       [72+0]/1 <- b
	rwreg(\_SB.ECMC): Io       [72+1]/1 -> cc
	amlmapio(\_SB.FRTP): Mem      cc22c018 - cc22c118

I wrote a patch (attached) to fix this, and it seems to work. Though,
it's not clear to me when things should be dereferenced. Previously,
the data field was dereferenced at evalfield, but the region and index
field were not until rwfield. After the patch, the index field is
also dereferenced in evalfield.

For BankField, the index *is* dereferenced in evalfield. I'm pretty
sure that this means that BankField does not work currently, since
store() just returns nil for 'f' objects. The bank selector will
never get set.

Anyway, I don't know if this solves any real problems; it's just
something I noticed and thought I'd try to fix.
2021-02-22 19:27:49 +01:00
Sigrid 797a5ac470 libaml: add (nop) "signal" op 2020-10-21 12:06:25 +02:00
Sigrid b6fde0c7b9 libaml: fix fault when the second operand of comparison cannot be converted 2020-08-20 08:28:24 +02:00
cinap_lenrek ec737b6a2e libaml: implement ToDecimalString and ToHexString operations 2020-05-23 17:44:30 +02:00
cinap_lenrek 93e493f391 libaml: allow amlmapio() to re-enter the interpreter (can happen by pciadd() -> amleval())
- make frame base pointer variable
- in rwreg(), save/restore the interpreter state and allocate a Frame* on the stack
- add overflow checks for frame base pointer to xec() and amleval()
- gc() scans the whole stack from FP to the *real* bottom F0
2018-11-04 19:48:27 +01:00
cinap_lenrek c52251c9b6 libaml: make heap size field int, implement BankField definitions 2017-02-24 01:31:58 +01:00
cinap_lenrek bc2a5d9b1e aml: define amlintmask and set it according to DSDT revision (64bit / 32bit) 2016-06-05 14:57:38 +02:00
cinap_lenrek 3ccc8224be aml: implement ToInteger() and Match() instructions 2016-06-04 21:11:17 +02:00
cinap_lenrek 772afbe98c format pointer subtraction results with %zd instead of %ld (for long -> intptr on amd64) 2016-01-07 04:44:13 +01:00
cinap_lenrek 12596736e9 libaml: fix formating 2013-09-07 16:22:35 +02:00
cinap_lenrek ad1edf7541 libaml: fix uninitialized variable in getle(), make amleval() work with buildin methods 2013-09-07 16:14:08 +02:00
cinap_lenrek 1b32bd5f0f libaml: use FP->env to access method arguments instead of FP->arg in evalosi() 2013-09-07 14:50:17 +02:00
cinap_lenrek cf166c3850 libaml: amldelay(), _OSI(), fix bug in Load() (from plhk's acpi patch)
export amldelay() for microsecond sleeps.

implement _OSI() method.

fix rwreg argument in evalload()
2013-09-07 14:40:24 +02:00
cinap_lenrek 9add5b765f libaml: new io interface, add amlnew()/amltake()/amldrop(), late binding names, FindSetLeftBit/FindSetRightBit
new io interface was added. user defines amlmapio() and amlunmapio() functions
that will fill out Amlio structure with function pointers to read/write
routines for a particular region.

amlnew() function added allowing the creation of aml objects like buffers
or packages. these can be passed to amleval() with b, p or * format.

amltake()/amldrop() exclude an aml object from garbage collection.

on load, names are not always resolvable until the whole table is loaded.
for this, we create n objects that are just name strings. after load, we
recursively traverse the namespace and resolve them (see fixnames()).

the FindSetLeftBit and FindSetRightBit opcodes got implemened.
2013-09-06 16:48:27 +02:00
cinap_lenrek deaa290f85 aml: preserve reference type when indexing into package to prevent implicit type conversion when storing to arg or local
if LocalX or ArgX is a package, the store into
a element should *not* type convert. so when taking
the index reference, we have to carry over the type.
2013-07-12 01:58:47 +02:00
cinap_lenrek 61aeb582ca libaml: add Concatenate instruction, fix type conversions 2013-06-29 11:56:18 +02:00
cinap_lenrek 1bf892cc67 libaml: add Load and Unload instructions
not very usefull at the moment as theres no code to map/unmap
memory regions right now.
2013-06-29 22:14:34 +02:00
cinap_lenrek 8ac67646a2 libaml: pikeshedd style, handle division by zero (thanks erik) 2013-06-18 21:49:19 +02:00
cinap_lenrek 4e81aab690 libaml: create \_GL name object 2013-06-07 18:34:28 +02:00
cinap_lenrek 60fd776d37 libaml: various fixes found by plhk
- fix bogus execution of Else{} blocks
- always allocate Env in amleval()
- add Sleep() and Stall() instructions
- keep package size for packages with empty body
2013-06-04 22:11:01 +02:00
cinap_lenrek b62042cdeb libaml: store *value* instead of name reference in dest for alias op 2012-09-09 09:06:37 +02:00
cinap_lenrek 6aa1ca35c3 libaml: implement Alias and Debug instructions 2012-09-08 17:48:09 +02:00
cinap_lenrek a47521a3ed experimental acpi support for apic irq routing 2012-06-17 23:12:19 +02:00