Skip to content

Commit 159039a

Browse files
ahunter6Ingo Molnar
authored andcommitted
x86/insn: x86/insn: Add support for REX2 prefix to the instruction decoder opcode map
Support for REX2 has been added to the instruction decoder logic and the awk script that generates the attribute tables from the opcode map. Add REX2 prefix byte (0xD5) to the opcode map. Add annotation (!REX2) for map 0/1 opcodes that are reserved under REX2. Add JMPABS to the opcode map and add annotation (REX2) to identify that it has a mandatory REX2 prefix. A separate opcode attribute table is not needed at this time because JMPABS has the same attribute encoding as the MOV instruction that it shares an opcode with i.e. INAT_MOFFSET. Signed-off-by: Adrian Hunter <adrian.hunter@intel.com> Signed-off-by: Ingo Molnar <mingo@kernel.org> Link: https://lore.kernel.org/r/20240502105853.5338-7-adrian.hunter@intel.com
1 parent eada38d commit 159039a

File tree

2 files changed

+152
-144
lines changed

2 files changed

+152
-144
lines changed

arch/x86/lib/x86-opcode-map.txt

Lines changed: 76 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@
3333
# - (F2): the last prefix is 0xF2
3434
# - (!F3) : the last prefix is not 0xF3 (including non-last prefix case)
3535
# - (66&F2): Both 0x66 and 0xF2 prefixes are specified.
36+
#
37+
# REX2 Prefix
38+
# - (!REX2): REX2 is not allowed
39+
# - (REX2): REX2 variant e.g. JMPABS
3640

3741
Table: one byte opcode
3842
Referrer:
@@ -157,22 +161,22 @@ AVXcode:
157161
6e: OUTS/OUTSB DX,Xb
158162
6f: OUTS/OUTSW/OUTSD DX,Xz
159163
# 0x70 - 0x7f
160-
70: JO Jb
161-
71: JNO Jb
162-
72: JB/JNAE/JC Jb
163-
73: JNB/JAE/JNC Jb
164-
74: JZ/JE Jb
165-
75: JNZ/JNE Jb
166-
76: JBE/JNA Jb
167-
77: JNBE/JA Jb
168-
78: JS Jb
169-
79: JNS Jb
170-
7a: JP/JPE Jb
171-
7b: JNP/JPO Jb
172-
7c: JL/JNGE Jb
173-
7d: JNL/JGE Jb
174-
7e: JLE/JNG Jb
175-
7f: JNLE/JG Jb
164+
70: JO Jb (!REX2)
165+
71: JNO Jb (!REX2)
166+
72: JB/JNAE/JC Jb (!REX2)
167+
73: JNB/JAE/JNC Jb (!REX2)
168+
74: JZ/JE Jb (!REX2)
169+
75: JNZ/JNE Jb (!REX2)
170+
76: JBE/JNA Jb (!REX2)
171+
77: JNBE/JA Jb (!REX2)
172+
78: JS Jb (!REX2)
173+
79: JNS Jb (!REX2)
174+
7a: JP/JPE Jb (!REX2)
175+
7b: JNP/JPO Jb (!REX2)
176+
7c: JL/JNGE Jb (!REX2)
177+
7d: JNL/JGE Jb (!REX2)
178+
7e: JLE/JNG Jb (!REX2)
179+
7f: JNLE/JG Jb (!REX2)
176180
# 0x80 - 0x8f
177181
80: Grp1 Eb,Ib (1A)
178182
81: Grp1 Ev,Iz (1A)
@@ -208,24 +212,24 @@ AVXcode:
208212
9e: SAHF
209213
9f: LAHF
210214
# 0xa0 - 0xaf
211-
a0: MOV AL,Ob
212-
a1: MOV rAX,Ov
213-
a2: MOV Ob,AL
214-
a3: MOV Ov,rAX
215-
a4: MOVS/B Yb,Xb
216-
a5: MOVS/W/D/Q Yv,Xv
217-
a6: CMPS/B Xb,Yb
218-
a7: CMPS/W/D Xv,Yv
219-
a8: TEST AL,Ib
220-
a9: TEST rAX,Iz
221-
aa: STOS/B Yb,AL
222-
ab: STOS/W/D/Q Yv,rAX
223-
ac: LODS/B AL,Xb
224-
ad: LODS/W/D/Q rAX,Xv
225-
ae: SCAS/B AL,Yb
215+
a0: MOV AL,Ob (!REX2)
216+
a1: MOV rAX,Ov (!REX2) | JMPABS O (REX2),(o64)
217+
a2: MOV Ob,AL (!REX2)
218+
a3: MOV Ov,rAX (!REX2)
219+
a4: MOVS/B Yb,Xb (!REX2)
220+
a5: MOVS/W/D/Q Yv,Xv (!REX2)
221+
a6: CMPS/B Xb,Yb (!REX2)
222+
a7: CMPS/W/D Xv,Yv (!REX2)
223+
a8: TEST AL,Ib (!REX2)
224+
a9: TEST rAX,Iz (!REX2)
225+
aa: STOS/B Yb,AL (!REX2)
226+
ab: STOS/W/D/Q Yv,rAX (!REX2)
227+
ac: LODS/B AL,Xb (!REX2)
228+
ad: LODS/W/D/Q rAX,Xv (!REX2)
229+
ae: SCAS/B AL,Yb (!REX2)
226230
# Note: The May 2011 Intel manual shows Xv for the second parameter of the
227231
# next instruction but Yv is correct
228-
af: SCAS/W/D/Q rAX,Yv
232+
af: SCAS/W/D/Q rAX,Yv (!REX2)
229233
# 0xb0 - 0xbf
230234
b0: MOV AL/R8L,Ib
231235
b1: MOV CL/R9L,Ib
@@ -266,7 +270,7 @@ d1: Grp2 Ev,1 (1A)
266270
d2: Grp2 Eb,CL (1A)
267271
d3: Grp2 Ev,CL (1A)
268272
d4: AAM Ib (i64)
269-
d5: AAD Ib (i64)
273+
d5: AAD Ib (i64) | REX2 (Prefix),(o64)
270274
d6:
271275
d7: XLAT/XLATB
272276
d8: ESC
@@ -281,26 +285,26 @@ df: ESC
281285
# Note: "forced64" is Intel CPU behavior: they ignore 0x66 prefix
282286
# in 64-bit mode. AMD CPUs accept 0x66 prefix, it causes RIP truncation
283287
# to 16 bits. In 32-bit mode, 0x66 is accepted by both Intel and AMD.
284-
e0: LOOPNE/LOOPNZ Jb (f64)
285-
e1: LOOPE/LOOPZ Jb (f64)
286-
e2: LOOP Jb (f64)
287-
e3: JrCXZ Jb (f64)
288-
e4: IN AL,Ib
289-
e5: IN eAX,Ib
290-
e6: OUT Ib,AL
291-
e7: OUT Ib,eAX
288+
e0: LOOPNE/LOOPNZ Jb (f64) (!REX2)
289+
e1: LOOPE/LOOPZ Jb (f64) (!REX2)
290+
e2: LOOP Jb (f64) (!REX2)
291+
e3: JrCXZ Jb (f64) (!REX2)
292+
e4: IN AL,Ib (!REX2)
293+
e5: IN eAX,Ib (!REX2)
294+
e6: OUT Ib,AL (!REX2)
295+
e7: OUT Ib,eAX (!REX2)
292296
# With 0x66 prefix in 64-bit mode, for AMD CPUs immediate offset
293297
# in "near" jumps and calls is 16-bit. For CALL,
294298
# push of return address is 16-bit wide, RSP is decremented by 2
295299
# but is not truncated to 16 bits, unlike RIP.
296-
e8: CALL Jz (f64)
297-
e9: JMP-near Jz (f64)
298-
ea: JMP-far Ap (i64)
299-
eb: JMP-short Jb (f64)
300-
ec: IN AL,DX
301-
ed: IN eAX,DX
302-
ee: OUT DX,AL
303-
ef: OUT DX,eAX
300+
e8: CALL Jz (f64) (!REX2)
301+
e9: JMP-near Jz (f64) (!REX2)
302+
ea: JMP-far Ap (i64) (!REX2)
303+
eb: JMP-short Jb (f64) (!REX2)
304+
ec: IN AL,DX (!REX2)
305+
ed: IN eAX,DX (!REX2)
306+
ee: OUT DX,AL (!REX2)
307+
ef: OUT DX,eAX (!REX2)
304308
# 0xf0 - 0xff
305309
f0: LOCK (Prefix)
306310
f1:
@@ -386,14 +390,14 @@ AVXcode: 1
386390
2e: vucomiss Vss,Wss (v1) | vucomisd Vsd,Wsd (66),(v1)
387391
2f: vcomiss Vss,Wss (v1) | vcomisd Vsd,Wsd (66),(v1)
388392
# 0x0f 0x30-0x3f
389-
30: WRMSR
390-
31: RDTSC
391-
32: RDMSR
392-
33: RDPMC
393-
34: SYSENTER
394-
35: SYSEXIT
393+
30: WRMSR (!REX2)
394+
31: RDTSC (!REX2)
395+
32: RDMSR (!REX2)
396+
33: RDPMC (!REX2)
397+
34: SYSENTER (!REX2)
398+
35: SYSEXIT (!REX2)
395399
36:
396-
37: GETSEC
400+
37: GETSEC (!REX2)
397401
38: escape # 3-byte escape 1
398402
39:
399403
3a: escape # 3-byte escape 2
@@ -473,22 +477,22 @@ AVXcode: 1
473477
7f: movq Qq,Pq | vmovdqa Wx,Vx (66) | vmovdqa32/64 Wx,Vx (66),(evo) | vmovdqu Wx,Vx (F3) | vmovdqu32/64 Wx,Vx (F3),(evo) | vmovdqu8/16 Wx,Vx (F2),(ev)
474478
# 0x0f 0x80-0x8f
475479
# Note: "forced64" is Intel CPU behavior (see comment about CALL insn).
476-
80: JO Jz (f64)
477-
81: JNO Jz (f64)
478-
82: JB/JC/JNAE Jz (f64)
479-
83: JAE/JNB/JNC Jz (f64)
480-
84: JE/JZ Jz (f64)
481-
85: JNE/JNZ Jz (f64)
482-
86: JBE/JNA Jz (f64)
483-
87: JA/JNBE Jz (f64)
484-
88: JS Jz (f64)
485-
89: JNS Jz (f64)
486-
8a: JP/JPE Jz (f64)
487-
8b: JNP/JPO Jz (f64)
488-
8c: JL/JNGE Jz (f64)
489-
8d: JNL/JGE Jz (f64)
490-
8e: JLE/JNG Jz (f64)
491-
8f: JNLE/JG Jz (f64)
480+
80: JO Jz (f64) (!REX2)
481+
81: JNO Jz (f64) (!REX2)
482+
82: JB/JC/JNAE Jz (f64) (!REX2)
483+
83: JAE/JNB/JNC Jz (f64) (!REX2)
484+
84: JE/JZ Jz (f64) (!REX2)
485+
85: JNE/JNZ Jz (f64) (!REX2)
486+
86: JBE/JNA Jz (f64) (!REX2)
487+
87: JA/JNBE Jz (f64) (!REX2)
488+
88: JS Jz (f64) (!REX2)
489+
89: JNS Jz (f64) (!REX2)
490+
8a: JP/JPE Jz (f64) (!REX2)
491+
8b: JNP/JPO Jz (f64) (!REX2)
492+
8c: JL/JNGE Jz (f64) (!REX2)
493+
8d: JNL/JGE Jz (f64) (!REX2)
494+
8e: JLE/JNG Jz (f64) (!REX2)
495+
8f: JNLE/JG Jz (f64) (!REX2)
492496
# 0x0f 0x90-0x9f
493497
90: SETO Eb | kmovw/q Vk,Wk | kmovb/d Vk,Wk (66)
494498
91: SETNO Eb | kmovw/q Mv,Vk | kmovb/d Mv,Vk (66)

0 commit comments

Comments
 (0)