Debian Codegraph @

x86/bytecode.txt

raw
1 Bytecode specification
2 ----------------------
3
4 These are the bytecodes generated by x86/insn.pl into x86/insnsb.c
5 and consumed by asm/assemble.c and disasm/disasm.c.
6
7 Values prefixed with \ are in octal, values prefixed with \x are in
8 hexadecimal.
9
10 The mnemonics are the ones used in x86/insns.dat, where applicable.
11
12 In x86/insns.dat, the encoding slot of each operand is encoded as:
13
14 - implicit operand (no encoding)
15 x+y multiple encoding slots for one operand
16 r "r" position in modr/m, or base register with "+r"
17 m "m" position in modr/m
18 n immediate encoded in the "m" position in modr/m
19 b register encoded in the "m" position in modr/m
20 x register encoded in the "x" position in modr/m + sib (MIB)
21 v "v" register position in vex/evex
22 s "s" registe rposition in /is4
23 w immediate encoded in the "v" position in vex/evex
24 i first immediate or mem_offs
25 j second immediate or mem_offs
26
27 Codes Mnemonic Explanation
28
29 \0 terminates the code. (Unless it's a literal of course.)
30 \1..\4 that many literal bytes follow in the code stream
31 \5 add 4 to the primary operand number (b, low octdigit)
32 \6 add 4 to the secondary operand number (a, middle octdigit)
33 \7 add 4 to both the primary and the secondary operand number
34 \10..\13 a literal byte follows in the code stream, to be added
35 to the register value of operand 0..3
36 \14..\17 the position of index register operand in MIB (BND insns)
37 \20..\23 ib a byte immediate operand, from operand 0..3
38 \24..\27 ib,u a zero-extended byte immediate operand, from operand 0..3
39 \30..\33 iw a word immediate operand, from operand 0..3
40 \34..\37 iwd select between \3[0-3] and \4[0-3]
41 depending on the *operand* size of the instruction.
42 \40..\43 id a long immediate operand, from operand 0..3
43 \44..\47 iwdq select between \3[0-3], \4[0-3] and \5[4-7]
44 depending on the *address* size of the instruction.
45 \50..\53 rel8 a byte relative operand, from operand 0..3
46 \54..\57 iq a qword immediate operand, from operand 0..3
47 \60..\63 rel16 a word relative operand, from operand 0..3
48 \64..\67 rel select between \6[0-3] and \7[0-3] depending on 16/32 bit
49 assembly mode or the operand-size override on the operand
50 \70..\73 rel32 a long relative operand, from operand 0..3
51 \74..\77 seg a word constant, from the _segment_ part of operand 0..3
52 \1ab /r a ModRM, calculated on EA in operand a, with the reg
53 field the register value of operand b.
54 \171\mab /mrb (e.g /3r0) a ModRM, with the reg field taken from operand a, and the m
55 and b fields set to the specified values.
56 \172\ab /is4 the register number from operand a in bits 7..4, with
57 the 4-bit immediate from operand b in bits 3..0.
58 \173\xab the register number from operand a in bits 7..4, with
59 the value b in bits 3..0.
60 \174..\177 the register number from operand 0..3 in bits 7..4, and
61 an arbitrary value in bits 3..0 (assembled as zero.)
62 \2ab /b a ModRM, calculated on EA in operand a, with the reg
63 field equal to digit b.
64 \240..\243 this instruction uses EVEX rather than REX or VEX/XOP, with the
65 V register number taken from operand "b" (0..3) (which may
66 be an immediate, as is used for DFV.)
67 \250 this instruction uses EVEX rather than REX or VEX/XOP, with the
68 V register number set to 0 (subject to the XOR as defined
69 below)
70
71 EVEX prefixes are followed by the sequence:
72
73 \p1\p2\p3\3tt
74
75 ... which are XOR'd into the EVEX payload bytes. These are used to encode the
76 map and other fixed fields. Note that the inverted register bits should be
77 set to 1.
78
79 These are used in conjunction with the following instruction flags:
80
81 IF_LIG hint to the disassembler: ignore EVEX.L
82 IF_WIG hint to the disassembler: ignore EVEX.W
83 IF_WW W is used as REX_W
84 IF_NF the {nf} prefix is permitted for this instruction
85 IF_DFV this instruction uses the V field as DFV
86
87 tt is tuple type for Disp8*N from %tuple_codes in insns.pl
88 (compressed displacement encoding)
89
90 \254..\257 id,s a signed 32-bit operand to be extended to 64 bits.
91 \260..\263 this instruction uses VEX/XOP rather than REX, with the
92 V register taken from operand "b" 0..3.
93 \264..\267 id,u an unsigned 32-bit operand to be extended to 64 bits.
94 \270 this instruction uses VEX/XOP rather than REX, with the
95 V register set to 0.
96 VEX/XOP prefixes are followed by the sequence:
97 \tmm\wlp tmm format: tt 0mm mmm
98 [vex] tt = 0
99 [xop] tt = 1
100
101 mmmmm = M field
102
103 wlp format: w0 00l lpp
104 [l0] ll = 0 for L = 0 (.128, .lz)
105 [l1] ll = 1 for L = 1 (.256)
106 [lig] ll = 0 for L don't care (always assembled as 0) with IF_LIG
107
108 [w0] w = 0 for W = 0
109 [w1 ] w = 1 for W = 1
110 [wig] w = 0 for W don't care (always assembled as 0) with IF_WIG
111 [ww] w = 0 for W used as REX.W with IF_WW
112
113 t = 0 for VEX (C4/C5), t = 1 for XOP (8F).
114
115 \271 hlex instruction takes XRELEASE (F3) with or without lock
116 \272 hlenl instruction takes XACQUIRE/XRELEASE with or without lock
117 \273 hle instruction takes XACQUIRE/XRELEASE with lock only
118 \274..\277 ib,s a byte immediate operand, from operand 0..3, sign-extended
119 to the operand size (if o16/o32/o64 present) or the bit size
120 \300..\303 ibn a valid 0F NOP opcode.
121 \304..\307
122 \0\xNN ib^NN intermediate byte XOR 0xNN
123 \1\xNN ib,s^NN signed intermediate byte XOR 0xNN
124 \2\xNN ib,u^NN unsigned intermediate byte XOR 0xNN
125 \310 a16 indicates fixed 16-bit address size, i.e. optional 0x67.
126 \311 a32 indicates fixed 32-bit address size, i.e. optional 0x67.
127 \312 adf, asz (disassembler only) invalid with non-default address size.
128 \313 a64 indicates fixed 64-bit address size, 0x67 invalid.
129 \314 norexb (disassembler only) invalid with REX.B
130 \315 norexx (disassembler only) invalid with REX.X
131 \316 norexr (disassembler only) invalid with REX.R
132 \317 norexw (disassembler only) invalid with REX.W
133 - o8 generates no byte code; for orthogonality.
134 \320 o16* indicates fixed 16-bit operand size, i.e. optional 0x66.
135 \321 o32* indicates fixed 32-bit operand size, i.e. optional 0x66.
136 \322 odf indicates that this instruction is only valid when the
137 operand size is the default (instruction to disassembler,
138 generates no code in the assembler)
139 \323 o64nw indicates fixed 64-bit operand size (equivalent to nw o64)
140 \324 o64 indicates 64-bit operand size requiring REX.W.
141 \325 nohi instruction which always uses spl/bpl/sil/dil
142 \326 nof3 (disassembler only) not valid with 0xF3 REP prefix.
143 \327 nw indicates that the operand size defaults to 64 in 64-bit mode;
144 REX.W is not required. As a side effect, 32-bit operand size is
145 not available. If followed by an oxx code, this has the
146 following effects:
147 o16 - 66 prefix generated in 32- or 64-bit mode.
148 o32 - 66 prefix generated in 16-bit mode; treated as o64 in 64-bit mode.
149 o64 - only permitted in 64-bit mode, does not set REX.W unless combined
150 with code rex.w (\347).
151 \330 osz default or user-specified operand size
152 \331 norep not valid with 0xF2 or 0xF3 REP prefixes.
153 \332 f2 REP prefix (0xF2 byte) used as opcode extension.
154 \333 f3 REP prefix (0xF3 byte) used as opcode extension.
155 \334 rex.l LOCK prefix used as REX.R in 16/32-bit mode.
156 \335 repe disassemble a rep (0xF3 byte) prefix as repe not rep.
157 \336 optw 16-, 32- and 64-bit operation identical; allow optimization.
158 \337 optd 32- and 64-bit operation identical; allow optimization.
159 \340 resb reserve <operand 0> bytes of uninitialized storage.
160 Operand 0 had better be a segmentless constant.
161 \341 wait this instruction needs a WAIT "prefix"
162 \342 osm o16, o32 or o64 matching bit mode
163 \343 osd o16, o32 or o32 matching bit mode
164 \344 rex.b REX[2].B used as an opcode extension.
165 \345 rex.x REX[2].X used as an opcode extension.
166 \346 rex.r REX[2].R used as an opcode extension.
167 \347 rex.w REX[2].W used as an opcode extension.
168 \350..\351 rex2[.w] obligatory REX2 prefix, rex2.w = rex.w rex2
169 \355..\357 m[1-3] 0f 0f38 0f3a Set the legacy map number. Unless a REX2, VEX, or EVEX prefix
170 is also generated, these are emitted as legacy prefix bytes.
171 - m0 Generates no byte code, but can be used to indicate that
172 following bytes are literal and not part of a prefix.
173 \360 np no SSE prefix (== \364\331)
174 \361 66 66 SSE prefix (== \366\331)
175 \364 !osp operand-size prefix (0x66) not permitted
176 \365 !asp address-size prefix (0x67) not permitted
177 \366 osp operand-size prefix (0x66) used as opcode extension
178 \367 67 address-size prefix (0x67) used as opcode extension
179 \370,\371 jcc8 match only if operand 0 meets byte jump criteria.
180 jmp8 370 is used for Jcc, 371 is used for JMP.
181 \373 jlen assemble 0x03 if bits==16, 0x05 if bits==32;
182 used for conditional jump over longer jump
183 \374 vsibx|vm32x|vm64x this instruction takes an XMM VSIB memory EA
184 \375 vsiby|vm32y|vm64y this instruction takes an YMM VSIB memory EA
185 \376 vsibz|vm32z|vm64z this instruction takes an ZMM VSIB memory EA
186
187 * No 66 prefix is emitted if combined with VEX/EVEX, np, 66, osp or !osp.