aboutsummaryrefslogtreecommitdiffstats
path: root/arch
diff options
context:
space:
mode:
authorAvi Kivity <avi@redhat.com>2011-09-07 09:41:39 -0400
committerAvi Kivity <avi@redhat.com>2011-09-25 12:52:36 -0400
commit9fef72ce10dc8263fec9350a8e2a1c505ebedaae (patch)
tree89371f2d32e783882bf2766d13e0dbb47c8e8f69 /arch
parentd1eef45d5906a0738684833cf1e0395b4d098340 (diff)
KVM: x86 emulator: merge the two emulate_1op_rax_rdx implementations
We have two emulate-with-extended-accumulator implementations: once which expect traps (_ex) and one which doesn't (plain). Drop the plain implementation and always use the one which expects traps; it will simply return 0 in the _ex argument and we can happily ignore it. 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.c64
1 files changed, 15 insertions, 49 deletions
diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
index 5b4e1d46aa2d..6f2e4197fe74 100644
--- a/arch/x86/kvm/emulate.c
+++ b/arch/x86/kvm/emulate.c
@@ -322,21 +322,7 @@ struct gprefix {
322 } \ 322 } \
323 } while (0) 323 } while (0)
324 324
325#define __emulate_1op_rax_rdx(_op, _src, _rax, _rdx, _eflags, _suffix) \ 325#define __emulate_1op_rax_rdx(_op, _src, _rax, _rdx, _eflags, _suffix, _ex) \
326 do { \
327 unsigned long _tmp; \
328 \
329 __asm__ __volatile__ ( \
330 _PRE_EFLAGS("0", "4", "1") \
331 _op _suffix " %5; " \
332 _POST_EFLAGS("0", "4", "1") \
333 : "=m" (_eflags), "=&r" (_tmp), \
334 "+a" (_rax), "+d" (_rdx) \
335 : "i" (EFLAGS_MASK), "m" ((_src).val), \
336 "a" (_rax), "d" (_rdx)); \
337 } while (0)
338
339#define __emulate_1op_rax_rdx_ex(_op, _src, _rax, _rdx, _eflags, _suffix, _ex) \
340 do { \ 326 do { \
341 unsigned long _tmp; \ 327 unsigned long _tmp; \
342 \ 328 \
@@ -358,46 +344,24 @@ struct gprefix {
358 } while (0) 344 } while (0)
359 345
360/* instruction has only one source operand, destination is implicit (e.g. mul, div, imul, idiv) */ 346/* instruction has only one source operand, destination is implicit (e.g. mul, div, imul, idiv) */
361#define emulate_1op_rax_rdx(_op, _src, _rax, _rdx, _eflags) \ 347#define emulate_1op_rax_rdx(_op, _src, _rax, _rdx, _eflags, _ex) \
362 do { \ 348 do { \
363 switch((_src).bytes) { \ 349 switch((_src).bytes) { \
364 case 1: \ 350 case 1: \
365 __emulate_1op_rax_rdx(_op, _src, _rax, _rdx, \ 351 __emulate_1op_rax_rdx(_op, _src, _rax, _rdx, \
366 _eflags, "b"); \ 352 _eflags, "b", _ex); \
367 break; \ 353 break; \
368 case 2: \ 354 case 2: \
369 __emulate_1op_rax_rdx(_op, _src, _rax, _rdx, \ 355 __emulate_1op_rax_rdx(_op, _src, _rax, _rdx, \
370 _eflags, "w"); \ 356 _eflags, "w", _ex); \
371 break; \ 357 break; \
372 case 4: \ 358 case 4: \
373 __emulate_1op_rax_rdx(_op, _src, _rax, _rdx, \ 359 __emulate_1op_rax_rdx(_op, _src, _rax, _rdx, \
374 _eflags, "l"); \ 360 _eflags, "l", _ex); \
375 break; \
376 case 8: \
377 ON64(__emulate_1op_rax_rdx(_op, _src, _rax, _rdx, \
378 _eflags, "q")); \
379 break; \
380 } \
381 } while (0)
382
383#define emulate_1op_rax_rdx_ex(_op, _src, _rax, _rdx, _eflags, _ex) \
384 do { \
385 switch((_src).bytes) { \
386 case 1: \
387 __emulate_1op_rax_rdx_ex(_op, _src, _rax, _rdx, \
388 _eflags, "b", _ex); \
389 break; \
390 case 2: \
391 __emulate_1op_rax_rdx_ex(_op, _src, _rax, _rdx, \
392 _eflags, "w", _ex); \
393 break; \
394 case 4: \
395 __emulate_1op_rax_rdx_ex(_op, _src, _rax, _rdx, \
396 _eflags, "l", _ex); \
397 break; \ 361 break; \
398 case 8: ON64( \ 362 case 8: ON64( \
399 __emulate_1op_rax_rdx_ex(_op, _src, _rax, _rdx, \ 363 __emulate_1op_rax_rdx(_op, _src, _rax, _rdx, \
400 _eflags, "q", _ex)); \ 364 _eflags, "q", _ex)); \
401 break; \ 365 break; \
402 } \ 366 } \
403 } while (0) 367 } while (0)
@@ -1718,18 +1682,20 @@ static int em_grp3(struct x86_emulate_ctxt *ctxt)
1718 emulate_1op(ctxt, "neg"); 1682 emulate_1op(ctxt, "neg");
1719 break; 1683 break;
1720 case 4: /* mul */ 1684 case 4: /* mul */
1721 emulate_1op_rax_rdx("mul", ctxt->src, *rax, *rdx, ctxt->eflags); 1685 emulate_1op_rax_rdx("mul", ctxt->src, *rax, *rdx,
1686 ctxt->eflags, de);
1722 break; 1687 break;
1723 case 5: /* imul */ 1688 case 5: /* imul */
1724 emulate_1op_rax_rdx("imul", ctxt->src, *rax, *rdx, ctxt->eflags); 1689 emulate_1op_rax_rdx("imul", ctxt->src, *rax, *rdx,
1690 ctxt->eflags, de);
1725 break; 1691 break;
1726 case 6: /* div */ 1692 case 6: /* div */
1727 emulate_1op_rax_rdx_ex("div", ctxt->src, *rax, *rdx, 1693 emulate_1op_rax_rdx("div", ctxt->src, *rax, *rdx,
1728 ctxt->eflags, de); 1694 ctxt->eflags, de);
1729 break; 1695 break;
1730 case 7: /* idiv */ 1696 case 7: /* idiv */
1731 emulate_1op_rax_rdx_ex("idiv", ctxt->src, *rax, *rdx, 1697 emulate_1op_rax_rdx("idiv", ctxt->src, *rax, *rdx,
1732 ctxt->eflags, de); 1698 ctxt->eflags, de);
1733 break; 1699 break;
1734 default: 1700 default:
1735 return X86EMUL_UNHANDLEABLE; 1701 return X86EMUL_UNHANDLEABLE;