aboutsummaryrefslogtreecommitdiffstats
path: root/arch
diff options
context:
space:
mode:
authorAvi Kivity <avi@redhat.com>2011-09-07 09:41:40 -0400
committerAvi Kivity <avi@redhat.com>2011-09-25 12:52:37 -0400
commite8f2b1d621e7b73c16aaae2ccf4a64d09a0f56d8 (patch)
treef6b16a317c45843153f17dd8a2b9298990ece537 /arch
parent9fef72ce10dc8263fec9350a8e2a1c505ebedaae (diff)
KVM: x86 emulator: simplify emulate_1op_rax_rdx()
emulate_1op_rax_rdx() is always called with the same parameters. Simplify by passing just the emulation context. Signed-off-by: Avi Kivity <avi@redhat.com> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
Diffstat (limited to 'arch')
-rw-r--r--arch/x86/kvm/emulate.c42
1 files changed, 17 insertions, 25 deletions
diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
index 6f2e4197fe74..e10fd3732d10 100644
--- a/arch/x86/kvm/emulate.c
+++ b/arch/x86/kvm/emulate.c
@@ -322,9 +322,11 @@ struct gprefix {
322 } \ 322 } \
323 } while (0) 323 } while (0)
324 324
325#define __emulate_1op_rax_rdx(_op, _src, _rax, _rdx, _eflags, _suffix, _ex) \ 325#define __emulate_1op_rax_rdx(ctxt, _op, _suffix, _ex) \
326 do { \ 326 do { \
327 unsigned long _tmp; \ 327 unsigned long _tmp; \
328 ulong *rax = &(ctxt)->regs[VCPU_REGS_RAX]; \
329 ulong *rdx = &(ctxt)->regs[VCPU_REGS_RDX]; \
328 \ 330 \
329 __asm__ __volatile__ ( \ 331 __asm__ __volatile__ ( \
330 _PRE_EFLAGS("0", "5", "1") \ 332 _PRE_EFLAGS("0", "5", "1") \
@@ -337,31 +339,27 @@ struct gprefix {
337 "jmp 2b \n\t" \ 339 "jmp 2b \n\t" \
338 ".popsection \n\t" \ 340 ".popsection \n\t" \
339 _ASM_EXTABLE(1b, 3b) \ 341 _ASM_EXTABLE(1b, 3b) \
340 : "=m" (_eflags), "=&r" (_tmp), \ 342 : "=m" ((ctxt)->eflags), "=&r" (_tmp), \
341 "+a" (_rax), "+d" (_rdx), "+qm"(_ex) \ 343 "+a" (*rax), "+d" (*rdx), "+qm"(_ex) \
342 : "i" (EFLAGS_MASK), "m" ((_src).val), \ 344 : "i" (EFLAGS_MASK), "m" ((ctxt)->src.val), \
343 "a" (_rax), "d" (_rdx)); \ 345 "a" (*rax), "d" (*rdx)); \
344 } while (0) 346 } while (0)
345 347
346/* instruction has only one source operand, destination is implicit (e.g. mul, div, imul, idiv) */ 348/* instruction has only one source operand, destination is implicit (e.g. mul, div, imul, idiv) */
347#define emulate_1op_rax_rdx(_op, _src, _rax, _rdx, _eflags, _ex) \ 349#define emulate_1op_rax_rdx(ctxt, _op, _ex) \
348 do { \ 350 do { \
349 switch((_src).bytes) { \ 351 switch((ctxt)->src.bytes) { \
350 case 1: \ 352 case 1: \
351 __emulate_1op_rax_rdx(_op, _src, _rax, _rdx, \ 353 __emulate_1op_rax_rdx(ctxt, _op, "b", _ex); \
352 _eflags, "b", _ex); \
353 break; \ 354 break; \
354 case 2: \ 355 case 2: \
355 __emulate_1op_rax_rdx(_op, _src, _rax, _rdx, \ 356 __emulate_1op_rax_rdx(ctxt, _op, "w", _ex); \
356 _eflags, "w", _ex); \
357 break; \ 357 break; \
358 case 4: \ 358 case 4: \
359 __emulate_1op_rax_rdx(_op, _src, _rax, _rdx, \ 359 __emulate_1op_rax_rdx(ctxt, _op, "l", _ex); \
360 _eflags, "l", _ex); \
361 break; \ 360 break; \
362 case 8: ON64( \ 361 case 8: ON64( \
363 __emulate_1op_rax_rdx(_op, _src, _rax, _rdx, \ 362 __emulate_1op_rax_rdx(ctxt, _op, "q", _ex)); \
364 _eflags, "q", _ex)); \
365 break; \ 363 break; \
366 } \ 364 } \
367 } while (0) 365 } while (0)
@@ -1667,8 +1665,6 @@ static int em_grp2(struct x86_emulate_ctxt *ctxt)
1667 1665
1668static int em_grp3(struct x86_emulate_ctxt *ctxt) 1666static int em_grp3(struct x86_emulate_ctxt *ctxt)
1669{ 1667{
1670 unsigned long *rax = &ctxt->regs[VCPU_REGS_RAX];
1671 unsigned long *rdx = &ctxt->regs[VCPU_REGS_RDX];
1672 u8 de = 0; 1668 u8 de = 0;
1673 1669
1674 switch (ctxt->modrm_reg) { 1670 switch (ctxt->modrm_reg) {
@@ -1682,20 +1678,16 @@ static int em_grp3(struct x86_emulate_ctxt *ctxt)
1682 emulate_1op(ctxt, "neg"); 1678 emulate_1op(ctxt, "neg");
1683 break; 1679 break;
1684 case 4: /* mul */ 1680 case 4: /* mul */
1685 emulate_1op_rax_rdx("mul", ctxt->src, *rax, *rdx, 1681 emulate_1op_rax_rdx(ctxt, "mul", de);
1686 ctxt->eflags, de);
1687 break; 1682 break;
1688 case 5: /* imul */ 1683 case 5: /* imul */
1689 emulate_1op_rax_rdx("imul", ctxt->src, *rax, *rdx, 1684 emulate_1op_rax_rdx(ctxt, "imul", de);
1690 ctxt->eflags, de);
1691 break; 1685 break;
1692 case 6: /* div */ 1686 case 6: /* div */
1693 emulate_1op_rax_rdx("div", ctxt->src, *rax, *rdx, 1687 emulate_1op_rax_rdx(ctxt, "div", de);
1694 ctxt->eflags, de);
1695 break; 1688 break;
1696 case 7: /* idiv */ 1689 case 7: /* idiv */
1697 emulate_1op_rax_rdx("idiv", ctxt->src, *rax, *rdx, 1690 emulate_1op_rax_rdx(ctxt, "idiv", de);
1698 ctxt->eflags, de);
1699 break; 1691 break;
1700 default: 1692 default:
1701 return X86EMUL_UNHANDLEABLE; 1693 return X86EMUL_UNHANDLEABLE;