Skip to content

Align more of the interpreter with NT & fix a few more bugs - #169

Merged
d-tatianin merged 19 commits into
masterfrom
nt-reference-semantics
Oct 16, 2026
Merged

d-tatianin merged 19 commits into
masterfrom
nt-reference-semantics

Conversation

@d-tatianin

Copy link
Copy Markdown
Contributor

No description provided.

NT never replaces a field unit or a buffer field: a store or a CopyObject
to one writes to it with implicit conversion, also when it's reached via
an ArgX that holds a reference. Increment and Decrement work on fields
behind any number of references as well.

Firmware relies on this, e.g. EC helpers that take RefOf (Field) and do
Arg1 = Arg0. Until now the field got replaced by the value instead, so
the write never reached the EC, and an EC command loop waiting for the
field to clear could hang.

A field that is being accessed can't be overwritten anymore, so drop the
cases that did that from field-io-vs-copy-object.asl.

Signed-off-by: Daniil Tatianin <99danilt@gmail.com>
Signed-off-by: Daniil Tatianin <99danilt@gmail.com>
NT treats an Index() as a reference to where it points, wherever it's
kept:

- A store, CopyObject or Increment via an ArgX or a LocalX that holds an
  Index() of a buffer writes the byte, instead of replacing the ArgX or
  the LocalX.
- An Index() of a package keeps referring to the slot that the element
  is stored in, also once it's passed to a method or stored to a LocalX.
  Until now those got a copy that only referred to the element, so a
  store via such an ArgX was lost, and a later replacement of the element
  wasn't seen.

Signed-off-by: Daniil Tatianin <99danilt@gmail.com>
Signed-off-by: Daniil Tatianin <99danilt@gmail.com>
A store through an ArgX reference only overwrites data on NT, it's an
error for a Device, Event, Method, Mutex, OperationRegion, PowerResource,
Processor or ThermalZone. CopyObject is still allowed to overwrite them.

Signed-off-by: Daniil Tatianin <99danilt@gmail.com>
Signed-off-by: Daniil Tatianin <99danilt@gmail.com>
A name can end up holding a reference, via CopyObject (RefOf (X), N) or
a store of a RefOf() through an ArgX that refers to N. NT treats such a
name as an alias of what it refers to: reading N reads X, and a
CopyObject to N overwrites X, unless N holds an Index() of a package.

Until now reading N produced the reference itself, which most operators
then rejected.

Signed-off-by: Daniil Tatianin <99danilt@gmail.com>
Signed-off-by: Daniil Tatianin <99danilt@gmail.com>
Concatenating two empty buffers allocated 0 bytes, and so did converting
an empty buffer to a string for Concatenate, as buffer_to_string()
counted one comma less than there are values. Give both a byte like
make_null_buffer() does and have buffer_to_string() write the null
terminator itself, so that ToHexString() and ToDecimalString() don't
need a special case for empty buffers anymore.

Signed-off-by: Daniil Tatianin <99danilt@gmail.com>
Signed-off-by: Daniil Tatianin <99danilt@gmail.com>
Commit 7f4c9ce forbade Buffer (0) {} on the grounds that NT and ACPICA
do too, but both actually create an empty buffer for it. Do the same,
giving it a byte of storage like the empty buffers that make_null_buffer()
makes. More initializers than the size is still an error, as on NT.

Signed-off-by: Daniil Tatianin <99danilt@gmail.com>
Signed-off-by: Daniil Tatianin <99danilt@gmail.com>
NT accepts a length of 0, the result is a buffer field that writes don't
change anything through. Do the same instead of aborting the method, and
make sure nothing tries to read from or write to such a field.

Signed-off-by: Daniil Tatianin <99danilt@gmail.com>
Signed-off-by: Daniil Tatianin <99danilt@gmail.com>
The AML can declare a field with a length of 0. NT never accesses one,
reading it returns 0 without touching the region, writing it does nothing,
and it doesn't even write the index register of an index field. Do the
same.

Signed-off-by: Daniil Tatianin <99danilt@gmail.com>
Signed-off-by: Daniil Tatianin <99danilt@gmail.com>
NT doesn't truncate a String or a Buffer that's stored to a smaller
field. It writes it one field-sized chunk at a time, every chunk being a
complete write of the field, the last one zero-extended. An 8-bit field
over a debug port prints the whole string that way, and anything that's
backed by memory is left with the last chunk. An empty String or Buffer
isn't written at all. Integers are still written in one go.

Buffer fields and buffer indices work the same way, so only their last
chunk is written, as that's all that can be observed. GenericSerialBus
and the other fields that take a buffer as a whole aren't affected.

The answers of the generated buffer field write test come from acpiexec,
which truncates, so only give it the last chunk.

Signed-off-by: Daniil Tatianin <99danilt@gmail.com>
Signed-off-by: Daniil Tatianin <99danilt@gmail.com>
NT does exactly that for every AnyAcc field, whatever its size and
alignment, in SystemIO, PCI_Config and SystemMemory alike. Replace the
TODO that suggested picking a wider access with a comment saying so.

Signed-off-by: Daniil Tatianin <99danilt@gmail.com>
@d-tatianin
d-tatianin merged commit 72f6fdc into master Oct 16, 2026
4 checks passed
@d-tatianin
d-tatianin deleted the nt-reference-semantics branch October 16, 2026 08:14
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.

1 participant