The native DBT translator implements the four extension opcodes MOVZX r32/r64,
r/m8 (0F B6), MOVZX r32/r64, r/m16 (0F B7), MOVSX r32/r64, r/m8 (0F BE) and
MOVSX r32/r64, r/m16 (0F BF), with both register and memory source operands.
The interpreter implemented none of them: its 0x0F handler covered only SYSCALL
(0F 05) and BSWAP (0F C8..CF), so any of the four opcodes exited with
IllegalInstruction and the two execution paths accepted different instruction
sets for the same bytes.
Implement them in the interpreter:
- The source width follows the opcode, so 0F B6 and 0F BE read one byte and
0F B7 and 0F BF read one word.
- The destination width follows REX.W. Without REX.W the destination is 32
bits and its upper half is cleared; with REX.W it is 64 bits.
- MOVZX zero-extends, so both destination widths hold the same value.
- MOVSX sign-extends to the destination width, so a 32-bit destination keeps
the sign in bits 31:0 with the upper half cleared, while a 64-bit
destination keeps the sign extension across all 64 bits.
The effective-address computation shared by the memory forms of MOV,
MOVZX and MOVSX is extracted into an `effective_address` method so both
instruction families use one implementation. That is a pure refactor: the
address computation itself is unchanged.
Add six regression tests in crates/loader/tests/bootstrap.rs covering the
register and the memory source forms independently, both destination widths,
and the sign-extension boundary values. Every encoding was produced by LLVM
23.1.6 llvm-mc -show-encoding and the expected values follow the Intel SDM
rules for MOVZX and MOVSX.
All six tests fail against the unmodified interpreter and pass with this
change.
A related defect in the native DBT translator was found while writing these
tests: its MOVSX paths sign-extend to 64 bits unconditionally, so a 32-bit
destination keeps the sign extension in bits 63:32 instead of having them
cleared. That belongs to #65, which permits the translator files, and is
reported there rather than fixed here.
Closes#66
Signed-off-by: Swastick Chowdhury <28708247+Swastickc@users.noreply.github.com>
The interpreter used REX.R to extend the SIB index field and ignored REX.X
entirely, so the two paths disagreed with the native DBT translator, which
already extends the index with REX.X.
Two defects are fixed in the SIB branch of the MOV r/m effective-address
computation:
- The index register is now extended by REX.X. REX.R extends the ModRM reg
field and must not affect the index.
- A SIB index field of 100b selects r12 when REX.X is set, and means "no
index register" only when REX.X is clear.
REX.X is decoded from the REX prefix into the typed Prefixes struct.
Add regression tests covering an extended index register including r12, an
independent REX.R and REX.X combination, both prefix bits set together, and
the no-index case. Every encoding was produced by LLVM 23.1.6 llvm-mc and the
expected addresses were derived from the Intel SDM SIB rules.
The three REX.X tests fail against the unfixed interpreter and pass with the
fix; the no-index test passes in both cases.
Closes#63
Signed-off-by: Swastick Chowdhury <28708247+Swastickc@users.noreply.github.com>