Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

x86/asm/decoder: Explain CALLW discrepancy between Intel and AMD

In 64-bit mode, AMD and Intel CPUs treat 0x66 prefix before
branch insns differently. For near branches, it affects decode
too since immediate offset's width is different.

See these empirical tests:

http://marc.info/?l=linux-kernel&m=139714939728946&w=2

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Cc: Oleg Nesterov <oleg@redhat.com>
Link: http://lkml.kernel.org/r/1423768017-31766-1-git-send-email-dvlasenk@redhat.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>

authored by

Denys Vlasenko and committed by
Ingo Molnar
cbb53b96 8a764a87

+9
+9
arch/x86/lib/x86-opcode-map.txt
··· 273 273 de: ESC 274 274 df: ESC 275 275 # 0xe0 - 0xef 276 + # Note: "forced64" is Intel CPU behavior: they ignore 0x66 prefix 277 + # in 64-bit mode. AMD CPUs accept 0x66 prefix, it causes RIP truncation 278 + # to 16 bits. In 32-bit mode, 0x66 is accepted by both Intel and AMD. 276 279 e0: LOOPNE/LOOPNZ Jb (f64) 277 280 e1: LOOPE/LOOPZ Jb (f64) 278 281 e2: LOOP Jb (f64) ··· 284 281 e5: IN eAX,Ib 285 282 e6: OUT Ib,AL 286 283 e7: OUT Ib,eAX 284 + # With 0x66 prefix in 64-bit mode, for AMD CPUs immediate offset 285 + # in "near" jumps and calls is 16-bit. For CALL, 286 + # push of return address is 16-bit wide, RSP is decremented by 2 287 + # but is not truncated to 16 bits, unlike RIP. 287 288 e8: CALL Jz (f64) 288 289 e9: JMP-near Jz (f64) 289 290 ea: JMP-far Ap (i64) ··· 463 456 7e: movd/q Ey,Pd | vmovd/q Ey,Vy (66),(v1) | vmovq Vq,Wq (F3),(v1) 464 457 7f: movq Qq,Pq | vmovdqa Wx,Vx (66) | vmovdqu Wx,Vx (F3) 465 458 # 0x0f 0x80-0x8f 459 + # Note: "forced64" is Intel CPU behavior (see comment about CALL insn). 466 460 80: JO Jz (f64) 467 461 81: JNO Jz (f64) 468 462 82: JB/JC/JNAE Jz (f64) ··· 850 842 GrpTable: Grp5 851 843 0: INC Ev 852 844 1: DEC Ev 845 + # Note: "forced64" is Intel CPU behavior (see comment about CALL insn). 853 846 2: CALLN Ev (f64) 854 847 3: CALLF Ep 855 848 4: JMPN Ev (f64)