From: "Jan Beulich" Subject: [PATCH 4/4] x86/emulator: cleanup Date: Wed, 30 Nov 2011 16:07:25 +0000 Message-ID: <4ED662CD020000780006468F@nat28.tlf.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__Part09269CAD.0__=" Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: "xen-devel@lists.xensource.com" 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. --=__Part09269CAD.0__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Utilize some of the additions in the prior patches to clean up other code: - keep track of REP prefixes in only one variable - use REX_W in a few more places (instead of a literal number) Signed-off-by: Jan Beulich --- a/xen/arch/x86/x86_emulate/x86_emulate.c +++ b/xen/arch/x86/x86_emulate/x86_emulate.c @@ -304,6 +304,10 @@ union vex { ptr[1] =3D rex | REX_PREFIX; \ } while (0) =20 +#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) + /* Type, address-of, and value of an instruction's operand. */ struct operand { enum { OP_REG, OP_MEM, OP_IMM, OP_NONE } type; @@ -734,7 +738,7 @@ static unsigned long __get_rep_prefix( =20 #define get_rep_prefix() ({ \ unsigned long max_reps =3D 1; = \ - if ( rep_prefix ) \ + if ( rep_prefix() ) \ max_reps =3D __get_rep_prefix(&_regs, ctxt->regs, ad_bytes); = \ if ( max_reps =3D=3D 0 ) = \ goto done; \ @@ -765,7 +769,7 @@ static void __put_rep_prefix( } =20 #define put_rep_prefix(reps_completed) ({ \ - if ( rep_prefix ) \ + if ( rep_prefix() ) \ __put_rep_prefix(&_regs, ctxt->regs, ad_bytes, reps_completed); \ }) =20 @@ -1328,9 +1332,7 @@ x86_emulate( uint8_t modrm =3D 0, modrm_mod =3D 0, modrm_reg =3D 0, modrm_rm =3D = 0; union vex vex =3D {}; unsigned int op_bytes, def_op_bytes, ad_bytes, def_ad_bytes; -#define REPE_PREFIX 1 -#define REPNE_PREFIX 2 - unsigned int lock_prefix =3D 0, rep_prefix =3D 0; + bool_t lock_prefix =3D 0; int override_seg =3D -1, rc =3D X86EMUL_OKAY; struct operand src, dst; DECLARE_ALIGNED(mmval_t, mmval); @@ -1359,7 +1361,8 @@ x86_emulate( { case 0x66: /* operand-size override */ op_bytes =3D def_op_bytes ^ 6; - vex.pfx =3D vex_66; + if ( !vex.pfx ) + vex.pfx =3D vex_66; break; case 0x67: /* address-size override */ ad_bytes =3D def_ad_bytes ^ (mode_64bit() ? 12 : 6); @@ -1386,11 +1389,9 @@ x86_emulate( lock_prefix =3D 1; break; case 0xf2: /* REPNE/REPNZ */ - rep_prefix =3D REPNE_PREFIX; vex.pfx =3D vex_f2; break; case 0xf3: /* REP/REPE/REPZ */ - rep_prefix =3D REPE_PREFIX; vex.pfx =3D vex_f3; break; case 0x40 ... 0x4f: /* REX */ @@ -1407,7 +1408,7 @@ x86_emulate( } done_prefixes: =20 - if ( rex_prefix & 8 ) /* REX.W */ + if ( rex_prefix & REX_W ) op_bytes =3D 8; =20 /* Opcode byte(s). */ @@ -2418,8 +2419,8 @@ x86_emulate( put_rep_prefix(1); /* cmp: dst - src =3D=3D> src=3D*%%edi,dst=3D*%%esi =3D=3D> = *%%esi - *%%edi */ emulate_2op_SrcV("cmp", src, dst, _regs.eflags); - if ( ((rep_prefix =3D=3D REPE_PREFIX) && !(_regs.eflags & = EFLG_ZF)) || - ((rep_prefix =3D=3D REPNE_PREFIX) && (_regs.eflags & = EFLG_ZF)) ) + if ( (repe_prefix() && !(_regs.eflags & EFLG_ZF)) || + (repne_prefix() && (_regs.eflags & EFLG_ZF)) ) _regs.eip =3D next_eip; break; } @@ -2464,8 +2465,8 @@ x86_emulate( put_rep_prefix(1); /* cmp: dst - src =3D=3D> src=3D*%%edi,dst=3D%%eax =3D=3D> %%eax = - *%%edi */ emulate_2op_SrcV("cmp", src, dst, _regs.eflags); - if ( ((rep_prefix =3D=3D REPE_PREFIX) && !(_regs.eflags & = EFLG_ZF)) || - ((rep_prefix =3D=3D REPNE_PREFIX) && (_regs.eflags & = EFLG_ZF)) ) + if ( (repe_prefix() && !(_regs.eflags & EFLG_ZF)) || + (repne_prefix() && (_regs.eflags & EFLG_ZF)) ) _regs.eip =3D next_eip; break; } @@ -4076,7 +4077,7 @@ x86_emulate( case 0x35: /* sysexit */ { uint64_t msr_content; struct segment_register cs, ss; - int user64 =3D !!(rex_prefix & 8); /* REX.W */ + bool_t user64 =3D !!(rex_prefix & REX_W); int rc; =20 generate_exception_if(!mode_ring0(), EXC_GP, 0); @@ -4366,7 +4367,7 @@ x86_emulate( : "=3Dr" (dst.val), "=3Dq" (zf) : "r" (src.val) ); _regs.eflags &=3D ~EFLG_ZF; - if ( (rep_prefix =3D=3D REPE_PREFIX) && vcpu_has_bmi1() ) + if ( (vex.pfx =3D=3D vex_f3) && vcpu_has_bmi1() ) { _regs.eflags &=3D ~EFLG_CF; if ( zf ) @@ -4391,7 +4392,7 @@ x86_emulate( : "=3Dr" (dst.val), "=3Dq" (zf) : "r" (src.val) ); _regs.eflags &=3D ~EFLG_ZF; - if ( (rep_prefix =3D=3D REPE_PREFIX) && vcpu_has_lzcnt() ) + if ( (vex.pfx =3D=3D vex_f3) && vcpu_has_lzcnt() ) { _regs.eflags &=3D ~EFLG_CF; if ( zf ) --=__Part09269CAD.0__= Content-Type: text/plain; name="x86-emul-cleanup.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="x86-emul-cleanup.patch" x86/emulator: cleanup=0A=0AUtilize some of the additions in the prior = patches to clean up other=0Acode:=0A- keep track of REP prefixes in only = one variable=0A- use REX_W in a few more places (instead of a literal = number)=0A=0ASigned-off-by: Jan Beulich =0A=0A--- = a/xen/arch/x86/x86_emulate/x86_emulate.c=0A+++ b/xen/arch/x86/x86_emulate/x= 86_emulate.c=0A@@ -304,6 +304,10 @@ union vex {=0A ptr[1] =3D rex = | REX_PREFIX; \=0A } while (0)=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+=0A /* Type, address-of, and = value of an instruction's operand. */=0A struct operand {=0A enum { = OP_REG, OP_MEM, OP_IMM, OP_NONE } type;=0A@@ -734,7 +738,7 @@ static = unsigned long __get_rep_prefix(=0A =0A #define get_rep_prefix() ({ = \=0A unsigned long max_reps =3D 1; = \=0A- if ( rep_prefix ) = \=0A+ if ( rep_prefix() ) = \=0A max_reps =3D = __get_rep_prefix(&_regs, ctxt->regs, ad_bytes); \=0A if ( = max_reps =3D=3D 0 ) \=0A = goto done; = \=0A@@ -765,7 +769,7 @@ static void __put_rep_prefix(=0A }=0A =0A #define = put_rep_prefix(reps_completed) ({ \=0A- = if ( rep_prefix ) \=0A+ = if ( rep_prefix() ) \=0A = __put_rep_prefix(&_regs, ctxt->regs, ad_bytes, reps_completed); = \=0A })=0A =0A@@ -1328,9 +1332,7 @@ x86_emulate(=0A uint8_t modrm =3D = 0, modrm_mod =3D 0, modrm_reg =3D 0, modrm_rm =3D 0;=0A union vex vex = =3D {};=0A unsigned int op_bytes, def_op_bytes, ad_bytes, def_ad_bytes;= =0A-#define REPE_PREFIX 1=0A-#define REPNE_PREFIX 2=0A- unsigned int = lock_prefix =3D 0, rep_prefix =3D 0;=0A+ bool_t lock_prefix =3D 0;=0A = int override_seg =3D -1, rc =3D X86EMUL_OKAY;=0A struct operand src, = dst;=0A DECLARE_ALIGNED(mmval_t, mmval);=0A@@ -1359,7 +1361,8 @@ = x86_emulate(=0A {=0A case 0x66: /* operand-size override = */=0A op_bytes =3D def_op_bytes ^ 6;=0A- vex.pfx = =3D vex_66;=0A+ if ( !vex.pfx )=0A+ vex.pfx =3D = vex_66;=0A break;=0A case 0x67: /* address-size = override */=0A ad_bytes =3D def_ad_bytes ^ (mode_64bit() ? 12 = : 6);=0A@@ -1386,11 +1389,9 @@ x86_emulate(=0A lock_prefix =3D = 1;=0A break;=0A case 0xf2: /* REPNE/REPNZ */=0A- = rep_prefix =3D REPNE_PREFIX;=0A vex.pfx =3D vex_f2;=0A = break;=0A case 0xf3: /* REP/REPE/REPZ */=0A- = rep_prefix =3D REPE_PREFIX;=0A vex.pfx =3D vex_f3;=0A = break;=0A case 0x40 ... 0x4f: /* REX */=0A@@ -1407,7 +1408,7 @@ = x86_emulate(=0A }=0A done_prefixes:=0A =0A- if ( rex_prefix & 8 ) = /* REX.W */=0A+ if ( rex_prefix & REX_W )=0A op_bytes =3D 8;=0A = =0A /* Opcode byte(s). */=0A@@ -2418,8 +2419,8 @@ x86_emulate(=0A = put_rep_prefix(1);=0A /* cmp: dst - src =3D=3D> src=3D*%%edi,dst= =3D*%%esi =3D=3D> *%%esi - *%%edi */=0A emulate_2op_SrcV("cmp", = src, dst, _regs.eflags);=0A- if ( ((rep_prefix =3D=3D REPE_PREFIX) = && !(_regs.eflags & EFLG_ZF)) ||=0A- ((rep_prefix =3D=3D = REPNE_PREFIX) && (_regs.eflags & EFLG_ZF)) )=0A+ if ( (repe_prefix()= && !(_regs.eflags & EFLG_ZF)) ||=0A+ (repne_prefix() && = (_regs.eflags & EFLG_ZF)) )=0A _regs.eip =3D next_eip;=0A = break;=0A }=0A@@ -2464,8 +2465,8 @@ x86_emulate(=0A = put_rep_prefix(1);=0A /* cmp: dst - src =3D=3D> src=3D*%%edi,dst=3D= %%eax =3D=3D> %%eax - *%%edi */=0A emulate_2op_SrcV("cmp", src, = dst, _regs.eflags);=0A- if ( ((rep_prefix =3D=3D REPE_PREFIX) && = !(_regs.eflags & EFLG_ZF)) ||=0A- ((rep_prefix =3D=3D = REPNE_PREFIX) && (_regs.eflags & EFLG_ZF)) )=0A+ if ( (repe_prefix()= && !(_regs.eflags & EFLG_ZF)) ||=0A+ (repne_prefix() && = (_regs.eflags & EFLG_ZF)) )=0A _regs.eip =3D next_eip;=0A = break;=0A }=0A@@ -4076,7 +4077,7 @@ x86_emulate(=0A case 0x35: = /* sysexit */ {=0A uint64_t msr_content;=0A struct = segment_register cs, ss;=0A- int user64 =3D !!(rex_prefix & 8); /* = REX.W */=0A+ bool_t user64 =3D !!(rex_prefix & REX_W);=0A = int rc;=0A =0A generate_exception_if(!mode_ring0(), EXC_GP, = 0);=0A@@ -4366,7 +4367,7 @@ x86_emulate(=0A : "=3Dr" = (dst.val), "=3Dq" (zf)=0A : "r" (src.val) );=0A = _regs.eflags &=3D ~EFLG_ZF;=0A- if ( (rep_prefix =3D=3D REPE_PREFIX)= && vcpu_has_bmi1() )=0A+ if ( (vex.pfx =3D=3D vex_f3) && vcpu_has_b= mi1() )=0A {=0A _regs.eflags &=3D ~EFLG_CF;=0A = if ( zf )=0A@@ -4391,7 +4392,7 @@ x86_emulate(=0A : = "=3Dr" (dst.val), "=3Dq" (zf)=0A : "r" (src.val) );=0A = _regs.eflags &=3D ~EFLG_ZF;=0A- if ( (rep_prefix =3D=3D REPE_PREFI= X) && vcpu_has_lzcnt() )=0A+ if ( (vex.pfx =3D=3D vex_f3) && = vcpu_has_lzcnt() )=0A {=0A _regs.eflags &=3D = ~EFLG_CF;=0A if ( zf )=0A --=__Part09269CAD.0__= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --=__Part09269CAD.0__=--