From patchwork Sun Aug 8 18:11:37 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mohammed Gamal X-Patchwork-Id: 118287 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 o78IBq0c016927 for ; Sun, 8 Aug 2010 18:11:52 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753551Ab0HHSLu (ORCPT ); Sun, 8 Aug 2010 14:11:50 -0400 Received: from mail-ww0-f42.google.com ([74.125.82.42]:64075 "EHLO mail-ww0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753197Ab0HHSLt (ORCPT ); Sun, 8 Aug 2010 14:11:49 -0400 Received: by wwf26 with SMTP id 26so1615874wwf.1 for ; Sun, 08 Aug 2010 11:11:48 -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=nvoENcVR9s6wWG3d/nAcOEvdKl3ToreuYvYz2hdcwEE=; b=Ty1vHMlqfhtZNsfUmbzs7jsP++/BiAYDAgiEQzMbHI/0AoIqkRi9500TBaucF6TWIc Pe11lyaDUg9Nioe8yAjBTxLDPnz0whaj1KoEjpMGO2OK+MdYcmrlPz6RNaNh95oczE+J FVxuvEnVDabi0u8AdEgDAWuQhHe0xrU+UEu5I= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer; b=i9ifprk05sT11SI2pyQzfwHsb7gBJzSS7uR2rIrMIVGfXdW9jBcVR3MyTSrQlENhvi PeyB3eHqUBoA/ZyNTFkZ7qMCSi6wa848NTNr+aYNxl0UpstvJciUk6QUlWVBgMUMXXR9 4qc8ZQM8XGwv4tgwFyhb33wqpVOFtmsQxB1a0= Received: by 10.216.53.74 with SMTP id f52mr12832288wec.112.1281291108465; Sun, 08 Aug 2010 11:11:48 -0700 (PDT) Received: from localhost.localdomain ([188.48.101.98]) by mx.google.com with ESMTPS id u11sm2093508weq.31.2010.08.08.11.11.46 (version=TLSv1/SSLv3 cipher=RC4-MD5); Sun, 08 Aug 2010 11:11:47 -0700 (PDT) From: Mohammed Gamal To: avi@redhat.com Cc: mtosatti@redhat.com, kvm@vger.kernel.org, Mohammed Gamal Subject: [PATCH v2 1/2] x86 emulator: Add unary mul, imul, div, and idiv instructions Date: Sun, 8 Aug 2010 21:11:37 +0300 Message-Id: <1281291098-4658-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 18:11:53 +0000 (UTC) diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c index a2a079f..790f700 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_rax_rdx(_op, _src, _rax, _rdx, _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" (_rax), "+d" (_rdx) \ + : "i" (EFLAGS_MASK), "m" ((_src).val), \ + "a" (_rax), "d" (_rdx)); \ + } while (0) + +/* instruction has only one source operand, destination is implicit (e.g. mul, div, imul, idiv) */ +#define emulate_1op_rax_rdx(_op, _src, _rax, _rdx, _eflags) \ + do { \ + switch((_src).bytes) { \ + case 1: __emulate_1op_rax_rdx(_op, _src, _rax, _rdx, _eflags, "b"); break; \ + case 2: __emulate_1op_rax_rdx(_op, _src, _rax, _rdx, _eflags, "w"); break; \ + case 4: __emulate_1op_rax_rdx(_op, _src, _rax, _rdx, _eflags, "l"); break; \ + case 8: ON64(__emulate_1op_rax_rdx(_op, _src, _rax, _rdx, _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 *rax = &c->regs[VCPU_REGS_RAX]; + unsigned long *rdx = &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_rax_rdx("mul", c->src, *rax, *rdx, ctxt->eflags); + break; + case 5: /* imul */ + emulate_1op_rax_rdx("imul", c->src, *rax, *rdx, ctxt->eflags); + break; + case 6: /* div */ + emulate_1op_rax_rdx("div", c->src, *rax, *rdx, ctxt->eflags); + break; + case 7: /* idiv */ + emulate_1op_rax_rdx("idiv", c->src, *rax, *rdx, 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[] = {