From patchwork Tue Aug 18 12:48:05 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mohammed Gamal X-Patchwork-Id: 42328 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n7ICmQc3000599 for ; Tue, 18 Aug 2009 12:48:26 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754398AbZHRMsV (ORCPT ); Tue, 18 Aug 2009 08:48:21 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1757840AbZHRMsV (ORCPT ); Tue, 18 Aug 2009 08:48:21 -0400 Received: from mail-bw0-f222.google.com ([209.85.218.222]:33825 "EHLO mail-bw0-f222.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754379AbZHRMsV (ORCPT ); Tue, 18 Aug 2009 08:48:21 -0400 Received: by bwz22 with SMTP id 22so2988126bwz.18 for ; Tue, 18 Aug 2009 05:48:21 -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=n7w/nweCNtVNnrO1p9jFGlDGq7VsPiT135UpTsZccRA=; b=vCU/rVyjB38Jd0DvPGPTtCNNrlfxOv4YRImcWHjIcHsFvc/kH1Wpy0FgVgwttf3Lih PZ+g0/TxIFmISwgzhHKW3ipYJIZxFUFPl3VemtP/7Dm4E5a9iOb9qm/yonmxF3lvESLt VfqpgHWpGWUiSxv4GN8M5V4Mb1tD0jj/pp+pg= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer; b=NLSjuTCDHqWUFr6CF4ub+mlMe3jbaFyjLb8bKBCSOB0bZjcQqRQciSARDPyvmaL2VO mSQyQ4b0krBgOqRu58VcMsRmWDrEGJjI3Mi17JuI+oZn+25IV+DfNjtEoAI9D7iW5yWq BHAYoxP/5kB4s7b0+N5s9ZURiNblfd7T04VD8= Received: by 10.102.149.23 with SMTP id w23mr1901586mud.38.1250599700433; Tue, 18 Aug 2009 05:48:20 -0700 (PDT) Received: from localhost.localdomain ([188.51.87.106]) by mx.google.com with ESMTPS id 12sm24509183muq.22.2009.08.18.05.48.15 (version=TLSv1/SSLv3 cipher=RC4-MD5); Tue, 18 Aug 2009 05:48:19 -0700 (PDT) From: Mohammed Gamal To: avi@redhat.com Cc: kvm@vger.kernel.org, Mohammed Gamal Subject: [PATCH] x86 emulator: Add 'push/pop sreg' instructions Date: Tue, 18 Aug 2009 15:48:05 +0300 Message-Id: <1250599685-2351-1-git-send-email-m.gamal005@gmail.com> X-Mailer: git-send-email 1.6.0.4 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Signed-off-by: Mohammed Gamal --- arch/x86/kvm/emulate.c | 60 ++++++++++++++++++++++++++++++++++++++++++++--- 1 files changed, 56 insertions(+), 4 deletions(-) diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c index 2eb807a..438d423 100644 --- a/arch/x86/kvm/emulate.c +++ b/arch/x86/kvm/emulate.c @@ -92,19 +92,20 @@ static u32 opcode_table[256] = { /* 0x00 - 0x07 */ ByteOp | DstMem | SrcReg | ModRM, DstMem | SrcReg | ModRM, ByteOp | DstReg | SrcMem | ModRM, DstReg | SrcMem | ModRM, - ByteOp | DstAcc | SrcImm, DstAcc | SrcImm, 0, 0, + ByteOp | DstAcc | SrcImm, DstAcc | SrcImm, + ImplicitOps | Stack, ImplicitOps | Stack, /* 0x08 - 0x0F */ ByteOp | DstMem | SrcReg | ModRM, DstMem | SrcReg | ModRM, ByteOp | DstReg | SrcMem | ModRM, DstReg | SrcMem | ModRM, - 0, 0, 0, 0, + 0, 0, ImplicitOps | Stack, 0, /* 0x10 - 0x17 */ ByteOp | DstMem | SrcReg | ModRM, DstMem | SrcReg | ModRM, ByteOp | DstReg | SrcMem | ModRM, DstReg | SrcMem | ModRM, - 0, 0, 0, 0, + 0, 0, ImplicitOps | Stack, ImplicitOps | Stack, /* 0x18 - 0x1F */ ByteOp | DstMem | SrcReg | ModRM, DstMem | SrcReg | ModRM, ByteOp | DstReg | SrcMem | ModRM, DstReg | SrcMem | ModRM, - 0, 0, 0, 0, + 0, 0, ImplicitOps | Stack, ImplicitOps | Stack, /* 0x20 - 0x27 */ ByteOp | DstMem | SrcReg | ModRM, DstMem | SrcReg | ModRM, ByteOp | DstReg | SrcMem | ModRM, DstReg | SrcMem | ModRM, @@ -1186,6 +1187,30 @@ static int emulate_pop(struct x86_emulate_ctxt *ctxt, return rc; } +static void emulate_push_sreg(struct x86_emulate_ctxt *ctxt, int seg) +{ + struct decode_cache *c = &ctxt->decode; + struct kvm_segment segment; + + kvm_x86_ops->get_segment(ctxt->vcpu, &segment, seg); + + c->src.val = segment.selector; + emulate_push(ctxt); +} + +static int emulate_pop_sreg(struct x86_emulate_ctxt *ctxt, + struct x86_emulate_ops *ops, int seg) +{ + struct kvm_segment segment; + int rc; + + kvm_x86_ops->get_segment(ctxt->vcpu, &segment, seg); + rc = emulate_pop(ctxt, ops, &segment.selector, sizeof(uint16_t)); + kvm_x86_ops->set_segment(ctxt->vcpu, &segment, seg); + + return rc; +} + static inline int emulate_grp1a(struct x86_emulate_ctxt *ctxt, struct x86_emulate_ops *ops) { @@ -1707,18 +1732,45 @@ special_insn: add: /* add */ emulate_2op_SrcV("add", c->src, c->dst, ctxt->eflags); break; + case 0x06: /* push es */ + emulate_push_sreg(ctxt, VCPU_SREG_ES); + break; + case 0x07: /* pop es */ + rc = emulate_pop_sreg(ctxt, ops, VCPU_SREG_ES); + if (rc != 0) + goto done; + break; case 0x08 ... 0x0d: or: /* or */ emulate_2op_SrcV("or", c->src, c->dst, ctxt->eflags); break; + case 0x0e: /* push cs */ + emulate_push_sreg(ctxt, VCPU_SREG_CS); + break; case 0x10 ... 0x15: adc: /* adc */ emulate_2op_SrcV("adc", c->src, c->dst, ctxt->eflags); break; + case 0x16: /* push ss */ + emulate_push_sreg(ctxt, VCPU_SREG_SS); + break; + case 0x17: /* pop ss */ + rc = emulate_pop_sreg(ctxt, ops, VCPU_SREG_SS); + if (rc != 0) + goto done; + break; case 0x18 ... 0x1d: sbb: /* sbb */ emulate_2op_SrcV("sbb", c->src, c->dst, ctxt->eflags); break; + case 0x1e: /* push ds */ + emulate_push_sreg(ctxt, VCPU_SREG_DS); + break; + case 0x1f: /* pop ds */ + rc = emulate_pop_sreg(ctxt, ops, VCPU_SREG_DS); + if (rc != 0) + goto done; + break; case 0x20 ... 0x25: and: /* and */ emulate_2op_SrcV("and", c->src, c->dst, ctxt->eflags);