Skip to content

target/i386: Decode group 3 /1 instructions as TEST - #2353

Open
unknown-1-0 wants to merge 1 commit into
unicorn-engine:devfrom
unknown-1-0:i386-decode-modrm-reg-1-in-group-3-as-test
Open

target/i386: Decode group 3 /1 instructions as TEST#2353
unknown-1-0 wants to merge 1 commit into
unicorn-engine:devfrom
unknown-1-0:i386-decode-modrm-reg-1-in-group-3-as-test

Conversation

@unknown-1-0

Copy link
Copy Markdown

According to table A-6 in Volume 3 of AMD64 Architecture Programmer's Manual, group 3 instructions that have ModRM.reg field value of either 0 or 1 are decoded as TEST instruction.

Although Volume 2 of Intel 64 and IA-32 Architectures Software Developer's Manual leaves the cell for ModRM.reg == 1 in group 3 in table A-6 blank, group 3 instructions with ModRM.reg == 1 seem to behave like TEST on Intel CPUs.

Currently, Unicorn does not recognize group 3 instruction with ModRM.reg == 1. As a result, it raises an #UD exception. This behavior does not match that of a real hardware.

Fix this issue by adding a missing case 1: to the group 3 decoder.

Upstream QEMU issue: https://gitlab.com/qemu-project/qemu/-/work_items/3580

@unknown-1-0 unknown-1-0 changed the title I386 decode modrm reg 1 in group 3 as test target/i386: Decode group 3 /1 instructions as TEST Jul 4, 2026
According to table A-6 in Volume 3 of AMD64 Architecture Programmer's Manual,
group 3 instructions that have ModRM.reg field value of either 0 or 1 are
decoded as TEST instruction.

Although Volume 2 of Intel 64 and IA-32 Architectures Software Developer's
Manual leaves the cell for ModRM.reg == 1 in group 3 in table A-6 blank,
group 3 instructions with ModRM.reg == 1 seem to behave like TEST on
Intel CPUs.

Currently, Unicorn does not recognize group 3 instruction with ModRM.reg == 1.
As a result, it raises an #UD exception. This behavior does not match that
of a real hardware.

Fix this issue by adding a missing `case 1:` to the group 3 decoder.

Upstream QEMU issue: https://gitlab.com/qemu-project/qemu/-/work_items/3580

Signed-off-by: Andrey Polivoda <apolivodaa433@gmail.com>
@unknown-1-0
unknown-1-0 force-pushed the i386-decode-modrm-reg-1-in-group-3-as-test branch from fc5ebd1 to e71f504 Compare August 12, 2026 13:39
@unknown-1-0

Copy link
Copy Markdown
Author

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