From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Jan Beulich" Subject: [PATCH 06/17] x86emul: add EVEX decoding Date: Thu, 08 Sep 2016 07:12:09 -0600 Message-ID: <57D17FC9020000780010D17A@prv-mh.provo.novell.com> References: <57D17C78020000780010D127@prv-mh.provo.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__Part3402BFB9.1__=" Return-path: Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bhz7l-0000eF-Iz for xen-devel@lists.xenproject.org; Thu, 08 Sep 2016 13:12:13 +0000 In-Reply-To: <57D17C78020000780010D127@prv-mh.provo.novell.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" To: xen-devel Cc: Andrew Cooper List-Id: xen-devel@lists.xenproject.org This is a MIME message. If you are reading this text, you may want to consider changing to a mail reader or gateway that understands how to properly handle MIME multipart messages. --=__Part3402BFB9.1__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline This way we can at least size (and e.g. skip) them if needed, and we also won't raise the wrong fault due to not having read all relevant bytes. Signed-off-by: Jan Beulich --- TBD: I'm kind of undecided whether to right away propagate evex.R into modrm_reg (and then also deal with the new meaning of evex.x for modrm_rm). Since that doesn't affect GPRs (and the extra bits would need masking off when accessing GPRs) I've left this out for now. --- a/xen/arch/x86/x86_emulate/x86_emulate.c +++ b/xen/arch/x86/x86_emulate/x86_emulate.c @@ -336,6 +336,27 @@ union vex { ptr[1] =3D rex | REX_PREFIX; \ } while (0) =20 +union evex { + uint8_t raw[3]; + struct { + uint8_t opcx:2; + uint8_t :2; + uint8_t R:1; + uint8_t b:1; + uint8_t x:1; + uint8_t r:1; + uint8_t pfx:2; + uint8_t evex:1; + uint8_t reg:4; + uint8_t w:1; + uint8_t opmsk:3; + uint8_t RX:1; + uint8_t bcst:1; + uint8_t lr:2; + uint8_t z:1; + }; +}; + #define rep_prefix() (vex.pfx >=3D vex_f3) #define repe_prefix() (vex.pfx =3D=3D vex_f3) #define repne_prefix() (vex.pfx =3D=3D vex_f2) @@ -1596,6 +1617,7 @@ struct x86_emulate_state { bool lock_prefix; opcode_desc_t desc; union vex vex; + union evex evex; int override_seg; =20 /* @@ -1623,6 +1645,7 @@ struct x86_emulate_state { #define rex_prefix (state->rex_prefix) #define lock_prefix (state->lock_prefix) #define vex (state->vex) +#define evex (state->evex) #define override_seg (state->override_seg) #define ea (state->ea) =20 @@ -1811,7 +1834,8 @@ x86_decode( modrm =3D insn_fetch_type(uint8_t); modrm_mod =3D (modrm & 0xc0) >> 6; =20 - if ( !ext && ((b & ~1) =3D=3D 0xc4 || (b =3D=3D 0x8f && (modrm & = 0x18))) ) + if ( !ext && ((b & ~1) =3D=3D 0xc4 || (b =3D=3D 0x8f && (modrm & = 0x18)) || + b =3D=3D 0x62) ) switch ( def_ad_bytes ) { default: @@ -1825,7 +1849,7 @@ x86_decode( break; /* fall through */ case 8: - /* VEX / XOP */ + /* VEX / XOP / EVEX */ generate_exception_if(rex_prefix || vex.pfx, EXC_UD, -1); =20 vex.raw[0] =3D modrm; @@ -1852,6 +1876,14 @@ x86_decode( op_bytes =3D 8; } } + if ( b =3D=3D 0x62 ) + { + evex.raw[0] =3D vex.raw[0]; + evex.raw[1] =3D vex.raw[1]; + evex.raw[2] =3D insn_fetch_type(uint8_t); + + vex.opcx =3D evex.opcx; + } } if ( mode_64bit() && !vex.r ) rex_prefix |=3D REX_R; --=__Part3402BFB9.1__= Content-Type: text/plain; name="x86emul-decode-EVEX.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="x86emul-decode-EVEX.patch" x86emul: add EVEX decoding=0A=0AThis way we can at least size (and e.g. = skip) them if needed, and we=0Aalso won't raise the wrong fault due to not = having read all relevant=0Abytes.=0A=0ASigned-off-by: Jan Beulich = =0A---=0ATBD: I'm kind of undecided whether to right = away propagate evex.R into=0A modrm_reg (and then also deal with the = new meaning of evex.x for=0A modrm_rm). Since that doesn't affect GPRs = (and the extra bits=0A would need masking off when accessing GPRs) = I've left this out for=0A now.=0A=0A--- a/xen/arch/x86/x86_emulate/x86_= emulate.c=0A+++ b/xen/arch/x86/x86_emulate/x86_emulate.c=0A@@ -336,6 = +336,27 @@ union vex {=0A ptr[1] =3D rex | REX_PREFIX; \=0A } = while (0)=0A =0A+union evex {=0A+ uint8_t raw[3];=0A+ struct {=0A+ = uint8_t opcx:2;=0A+ uint8_t :2;=0A+ uint8_t R:1;=0A+ = uint8_t b:1;=0A+ uint8_t x:1;=0A+ uint8_t r:1;=0A+ = uint8_t pfx:2;=0A+ uint8_t evex:1;=0A+ uint8_t reg:4;=0A+ = uint8_t w:1;=0A+ uint8_t opmsk:3;=0A+ uint8_t RX:1;=0A+ = uint8_t bcst:1;=0A+ uint8_t lr:2;=0A+ uint8_t = z:1;=0A+ };=0A+};=0A+=0A #define rep_prefix() (vex.pfx >=3D vex_f3)=0A= #define repe_prefix() (vex.pfx =3D=3D vex_f3)=0A #define repne_prefix() = (vex.pfx =3D=3D vex_f2)=0A@@ -1596,6 +1617,7 @@ struct x86_emulate_state = {=0A bool lock_prefix;=0A opcode_desc_t desc;=0A union vex = vex;=0A+ union evex evex;=0A int override_seg;=0A =0A /*=0A@@ = -1623,6 +1645,7 @@ struct x86_emulate_state {=0A #define rex_prefix = (state->rex_prefix)=0A #define lock_prefix (state->lock_prefix)=0A #define = vex (state->vex)=0A+#define evex (state->evex)=0A #define override_seg = (state->override_seg)=0A #define ea (state->ea)=0A =0A@@ -1811,7 +1834,8 = @@ x86_decode(=0A modrm =3D insn_fetch_type(uint8_t);=0A = modrm_mod =3D (modrm & 0xc0) >> 6;=0A =0A- if ( !ext && ((b & ~1) = =3D=3D 0xc4 || (b =3D=3D 0x8f && (modrm & 0x18))) )=0A+ if ( !ext = && ((b & ~1) =3D=3D 0xc4 || (b =3D=3D 0x8f && (modrm & 0x18)) ||=0A+ = b =3D=3D 0x62) )=0A switch ( def_ad_bytes )=0A = {=0A default:=0A@@ -1825,7 +1849,7 @@ x86_decode(=0A= break;=0A /* fall through */=0A = case 8:=0A- /* VEX / XOP */=0A+ /* VEX = / XOP / EVEX */=0A generate_exception_if(rex_prefix || = vex.pfx, EXC_UD, -1);=0A =0A vex.raw[0] =3D modrm;=0A@@ = -1852,6 +1876,14 @@ x86_decode(=0A op_bytes = =3D 8;=0A }=0A }=0A+ = if ( b =3D=3D 0x62 )=0A+ {=0A+ = evex.raw[0] =3D vex.raw[0];=0A+ evex.raw[1] = =3D vex.raw[1];=0A+ evex.raw[2] =3D insn_fetch_type(= uint8_t);=0A+=0A+ vex.opcx =3D evex.opcx;=0A+ = }=0A }=0A if ( mode_64bit() = && !vex.r )=0A rex_prefix |=3D REX_R;=0A --=__Part3402BFB9.1__= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Disposition: inline X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18KWGVuLWRldmVs IG1haWxpbmcgbGlzdApYZW4tZGV2ZWxAbGlzdHMueGVuLm9yZwpodHRwczovL2xpc3RzLnhlbi5v cmcveGVuLWRldmVsCg== --=__Part3402BFB9.1__=--