From patchwork Sun Aug 8 02:27:38 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mohammed Gamal X-Patchwork-Id: 118210 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.4/8.14.3) with ESMTP id o782RpuS011783 for ; Sun, 8 Aug 2010 02:27:51 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751461Ab0HHC1r (ORCPT ); Sat, 7 Aug 2010 22:27:47 -0400 Received: from mail-wy0-f174.google.com ([74.125.82.174]:37902 "EHLO mail-wy0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750699Ab0HHC1q (ORCPT ); Sat, 7 Aug 2010 22:27:46 -0400 Received: by wyb39 with SMTP id 39so8954144wyb.19 for ; Sat, 07 Aug 2010 19:27:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:from:to:cc:subject:date :message-id:x-mailer; bh=XMHFMWmGUovf73e/IpxqGpPhMIQNgZeyGdTzGgSq/cw=; b=u46cD+o+QPfasraIpkeu/LhrdCKJDyOX80xRcVrmM179sde34JfWDQxb3cNVfR5YrI bJFVh8x9TemLhrKp+0ob7vc9MsC+mKdVHx92WZu9Lke9jEIDWv0TVlT2BIr/LyAY3q8d HYtaZGx6JXCxmm2C4C8AipPk89pNTclvZbaKo= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer; b=Rd7kl/cA1+fOhPHrCrH3QlyBl6PWYt4JfJdiYv791NnIw+6Lpi0Mk/J2uc//Zx5cbm ArlIm5FVBz4zaVqKFV1XHmTTBB42zYtCq1dj2WlPcrjf9a/UxAQswEAVnIUKSGoWbkr7 llDWlLRZaR13P1X/w8S6xDzAQEBKOBEVQg8Ro= Received: by 10.227.137.199 with SMTP id x7mr12277687wbt.107.1281234465606; Sat, 07 Aug 2010 19:27:45 -0700 (PDT) Received: from localhost ([188.53.16.202]) by mx.google.com with ESMTPS id e31sm2889851wbe.5.2010.08.07.19.27.43 (version=TLSv1/SSLv3 cipher=RC4-MD5); Sat, 07 Aug 2010 19:27:44 -0700 (PDT) From: Mohammed Gamal To: avi@redhat.com Cc: mtosatti@redhat.com, kvm@vger.kernel.org, Mohammed Gamal Subject: [PATCH 1/2] x86 emulator: Add unary mul, imul, div, and idiv instructions Date: Sun, 8 Aug 2010 05:27:38 +0300 Message-Id: <1281234459-9248-1-git-send-email-m.gamal005@gmail.com> X-Mailer: git-send-email 1.7.0.4 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Sun, 08 Aug 2010 02:27:51 +0000 (UTC) diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c index 7d78832..6d1ec53 100644 --- a/arch/x86/kvm/emulate.c +++ b/arch/x86/kvm/emulate.c @@ -315,6 +315,31 @@ struct group_dual { } \ } while (0) +#define __emulate_1op_src(_op, _src, _ax, _dx, _eflags, _suffix) \ + do { \ + unsigned long _tmp; \ + \ + __asm__ __volatile__ ( \ + _PRE_EFLAGS("0", "4", "1") \ + _op _suffix " %5; " \ + _POST_EFLAGS("0", "4", "1") \ + : "=m" (_eflags), "=&r" (_tmp), \ + "=a" (_ax), "=d" (_dx) \ + : "i" (EFLAGS_MASK), "m" ((_src).val), \ + "a" (_ax), "d" (_dx)); \ + } while (0) + +/* instruction has only one source operand, destination is implicit (e.g. mul, div, imul, idiv) */ +#define emulate_1op_src(_op, _src, _ax, _dx, _eflags) \ + do { \ + switch((_src).bytes) { \ + case 1: __emulate_1op_src(_op, _src, _ax, _dx, _eflags, "b"); break; \ + case 2: __emulate_1op_src(_op, _src, _ax, _dx, _eflags, "w"); break; \ + case 4: __emulate_1op_src(_op, _src, _ax, _dx, _eflags, "l"); break; \ + case 8: ON64(__emulate_1op_src(_op, _src, _dx, _ax, _eflags, "q")); break; \ + } \ + } while (0) + /* Fetch next part of the instruction being emulated. */ #define insn_fetch(_type, _size, _eip) \ ({ unsigned long _x; \ @@ -1354,6 +1379,8 @@ static inline int emulate_grp3(struct x86_emulate_ctxt *ctxt, struct x86_emulate_ops *ops) { struct decode_cache *c = &ctxt->decode; + unsigned long *eax = &c->regs[VCPU_REGS_RAX]; + unsigned long *edx = &c->regs[VCPU_REGS_RDX]; switch (c->modrm_reg) { case 0 ... 1: /* test */ @@ -1365,6 +1392,18 @@ static inline int emulate_grp3(struct x86_emulate_ctxt *ctxt, case 3: /* neg */ emulate_1op("neg", c->dst, ctxt->eflags); break; + case 4: /* mul */ + emulate_1op_src("mul", c->src, *eax, *edx, ctxt->eflags); + break; + case 5: /* imul */ + emulate_1op_src("imul", c->src, *eax, *edx, ctxt->eflags); + break; + case 6: /* div */ + emulate_1op_src("div", c->src, *eax, *edx, ctxt->eflags); + break; + case 7: /* idiv */ + emulate_1op_src("idiv", c->src, *eax, *edx, ctxt->eflags); + break; default: return 0; } @@ -2120,7 +2159,7 @@ static struct opcode group1A[] = { static struct opcode group3[] = { D(DstMem | SrcImm | ModRM), D(DstMem | SrcImm | ModRM), D(DstMem | SrcNone | ModRM | Lock), D(DstMem | SrcNone | ModRM | Lock), - X4(D(Undefined)), + X4(D(SrcMem | ModRM)), }; static struct opcode group4[] = {