Expand description
s9vm : minimal x86-64 instruction decoder for exit emulation.
When a guest exit is a fault that must be emulated (MMIO, EPT violation, port I/O), the kernel needs three pieces of information: the access width, the direction (read/write), and : for MMIO : the effective address and the destination/source general-purpose register. This module decodes just enough x86-64 to answer those questions for the forms a device model actually sees:
mov r8, r/m8,mov r16/r32/r64, r/m8/16/32/64,mov r/m8, r8,mov r/m16/32/64, r(opcodes0x8A/0x8B/0x88/0x89);mov r8, imm8andmov r16/32/64, imm16/32/64(opcodes0xB0..0xBF);mov r/m8, imm8,mov r/m16/32/64, imm16/32/64(0xC6/0xC7,/0);mov AL/AX/EAX/RAX, moffsandmov moffs, AL/AX/EAX/RAX(0xA0..0xA3), with a 64-bit offset, or a 32-bit offset under0x67;movzx/movsxregister from memory (0x0F 0xB6/0xB7/0xBE/0xBF);in/outwith an immediate port (0xE4..0xE7) orDX(0xEC..0xEF);rdmsr/wrmsr(0x0F 0x30/0x32).
Prefix handling: 0x66 selects a 16-bit operand, 0x67 selects 32-bit
addressing (the effective address is zero-extended), segment prefixes are
consumed and ignored, and LOCK/REP/REPNE are rejected with
DecodeError::Unsupported because none of the supported forms uses them.
REX.W/R/X/B is honoured where architectural.
ModRM addressing supports mod = 00/01/10, SIB with scale/base/index,
absolute disp32 (SIB base 5 or rm = 5 in 32-bit addressing),
RIP-relative disp32 (mod = 00, rm = 101 in 64-bit addressing), signed
disp8, and disp32 with the correct sign. mod = 11 forms that are not
plain register moves are reported as unsupported rather than mis-decoded.
It is deliberately pure: no memory access, no hardware. The caller supplies
a register reader and the instruction bytes; the decoder returns the
effective address and the next RIP, or a typed error. Decoding never
panics: every read is bounds-checked through slice::get and a truncated
instruction yields DecodeError::Truncated. Every result is testable on
the host, which is why this logic lives apart from the virtual-machine
monitor.
Re-exportsยง
use alloc::string::String;๐
Structsยง
- Memory
Access - A guest memory access decoded from an instruction.
- MsrAccess
- An MSR access decoded from an instruction.
- Port
Access - A guest port access decoded from an instruction.
- Prefixes ๐
- Prefixes decoded before the opcode.
- Register
Access - A register-only move decoded from an instruction.
Enumsยง
- Decode
Error - Reason a sequence could not be decoded.
- Decoded
- Result of decoding one instruction.
- Extension
- How a memory operand narrower than the destination register is widened.
- ModRm
Operand ๐ - Addresses of a ModRM operand, resolved before the instruction length is known.
Constantsยง
- MAX_
INSTRUCTION - Longest possible x86 instruction.
Functionsยง
- decode
- Decodes one instruction.
- decode_
immediate_ ๐move - Builds a
mov r/m, immresult once the ModRM operand and immediate are known. - decode_
modrm ๐ - Decodes the ModRM byte (and optional SIB/displacement) of an instruction.
- decode_
read_ ๐only_ memory - Builds a read-only memory probe (
test/cmpwith a memory operand). - error_
name - Human-readable name of a decode error (diagnostics).
- operand_
size ๐ - Operand width in bytes for a general instruction.
- parse_
prefixes ๐ - Parses legacy and
REXprefixes. - read_i8 ๐
- read_
i32 ๐ - read_
immediate ๐ - Reads an immediate of
sizebytes, zero-extended tou64. - read_
moffs ๐ - Reads the address of a
moffsoperand. - read_u8 ๐
- read_
u16 ๐ - read_
u32 ๐ - read_
u64 ๐ - register_
move ๐ - Builds a register-only move result.