From patchwork Thu Aug 19 14:25:39 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mohammed Gamal X-Patchwork-Id: 120360 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 o7JEQAaq027072 for ; Thu, 19 Aug 2010 14:26:10 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753476Ab0HSO0F (ORCPT ); Thu, 19 Aug 2010 10:26:05 -0400 Received: from mail-ey0-f174.google.com ([209.85.215.174]:54380 "EHLO mail-ey0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753309Ab0HSO0E (ORCPT ); Thu, 19 Aug 2010 10:26:04 -0400 Received: by eyg5 with SMTP id 5so1290961eyg.19 for ; Thu, 19 Aug 2010 07:26:03 -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=ZdtRDjcO8bOEPBJ+rhYTsr2E/ymHERAHcC6iapVWxRY=; b=YKIYLB2IqB+zrIBopQkXEpSNq3eMO2ftHtMlxH/CN+xlKa9BejafY49r7xJHP4fqq7 cFJcLXbOVxCTkHuX/4+P7Y/eh56j00S6jmJSzr7wLwnb6idFA221iJfTtN/SXU+gJgZa bbGIcpLkpJsoo05dsvRew7xEZhgmNXcAI/o9c= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer; b=sFnl+GbdIKzDjHmaHyS/FoIsGDzkUccrRatr80jfbRPb469kXWiGCJFIoQuzVzLjAK sI8IoDaBdLrCFnIknYXj76hIOHZ18+zxqFZ39k4A0nph5kMYDlCM/os9BDo5D6vxsryQ ZvEvfo5fDWBEmIJVrSTKW7uGwMoiqccMwRo/Y= Received: by 10.216.233.163 with SMTP id p35mr721832weq.98.1282227951146; Thu, 19 Aug 2010 07:25:51 -0700 (PDT) Received: from localhost.localdomain ([188.50.104.147]) by mx.google.com with ESMTPS id k83sm1045388weq.38.2010.08.19.07.25.49 (version=TLSv1/SSLv3 cipher=RC4-MD5); Thu, 19 Aug 2010 07:25:50 -0700 (PDT) From: Mohammed Gamal To: avi@redhat.com Cc: kvm@vger.kernel.org, Mohammed Gamal Subject: [PATCH non-atomic-injection] x86 emulator: Add cwd/cdq/cqo instruction (opcode 0x99) Date: Thu, 19 Aug 2010 17:25:39 +0300 Message-Id: <1282227939-4378-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]); Thu, 19 Aug 2010 14:26:10 +0000 (UTC) diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c index ee4bb69..fddf76d 100644 --- a/arch/x86/kvm/emulate.c +++ b/arch/x86/kvm/emulate.c @@ -2421,7 +2421,7 @@ static struct opcode opcode_table[256] = { /* 0x90 - 0x97 */ X8(D(SrcAcc | DstReg)), /* 0x98 - 0x9F */ - D(DstAcc | SrcNone), N, D(SrcImmFAddr | No64), N, + D(DstAcc | SrcNone), D(ImplicitOps), D(SrcImmFAddr | No64), N, D(ImplicitOps | Stack), D(ImplicitOps | Stack), N, N, /* 0xA0 - 0xA7 */ D(ByteOp | DstAcc | SrcMem | Mov | MemAbs), D(DstAcc | SrcMem | Mov | MemAbs), @@ -3161,6 +3161,20 @@ special_insn: case 8: c->dst.val = (s32)c->dst.val; break; } break; + case 0x99: /* cwd/cdq/cqo */ { + unsigned long rax = c->regs[VCPU_REGS_RAX]; + unsigned long sign_bit = 1 << ((c->op_bytes * 8) - 1); + + if (rax & sign_bit) { + switch (c->op_bytes) { + case 2: c->regs[VCPU_REGS_RDX] = 0xffff; break; + case 4: c->regs[VCPU_REGS_RDX] = 0xffffffff; break; + case 8: c->regs[VCPU_REGS_RDX] = 0xffffffffffffffff; break; + } + } else + c->regs[VCPU_REGS_RDX] = 0; + } + break; case 0x9c: /* pushf */ c->src.val = (unsigned long) ctxt->eflags; emulate_push(ctxt, ops);