Skip to content

aml: Fix Divide argument order, and report error in division by zero - #375

Merged
martin-hughes merged 1 commit into
rust-osdev:mainfrom
ogoffart:olivier/divide-targets
Nov 8, 2026
Merged

martin-hughes merged 1 commit into
rust-osdev:mainfrom
ogoffart:olivier/divide-targets

Conversation

@ogoffart

@ogoffart ogoffart commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

Divide swaps its two targets

I ran into this while using acpi to read a laptop's battery state: we run the firmware's own AML (_BST / _BIX on the battery devices). The result were nonsense.
Tracing it down, the firmware's methods do things like Local0 = Local1 / Local2, and we were getting the remainder back instead of the quotient.

DefOpDivide is Divide (Dividend, Divisor, Remainder, Result): the third operand is the remainder's target and the fourth the quotient's. They were swapped, so Divide (17, 5, Local0, Local1) or X = A / B stored the remainder where the quotient was expected.

Divide has its own function now, as it has two targets: do_binary_maths is back to (left, right, target). Dividing by zero (Divide or Mod) is a new AmlError::DivideByZero (ACPICA's AE_AML_DIVIDE_BY_ZERO) instead of a panic.

DefOpDivide is Divide (Dividend, Divisor, Remainder, Result): the third
operand is the remainder's target and the fourth the quotient's. They
were swapped, so `Divide (17, 5, Local0, Local1)` or `X = A / B` stored
the remainder where the quotient was expected.

Divide has its own function now, as it has two targets: do_binary_maths
is back to (left, right, target). Dividing by zero (Divide or Mod) is a
new AmlError::DivideByZero (ACPICA's AE_AML_DIVIDE_BY_ZERO) instead of a
panic.
@martin-hughes

Copy link
Copy Markdown
Contributor

Good find @ogoffart and thank you for the fix!

Looks good to me with no particular comments. I appreciate the tests, thanks again.

@martin-hughes
martin-hughes merged commit 0f7ba37 into rust-osdev:main Nov 8, 2026
6 checks passed
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