From patchwork Tue Sep 1 01:26:30 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mohammed Gamal X-Patchwork-Id: 44976 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 n811QbmZ031628 for ; Tue, 1 Sep 2009 01:26:37 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752591AbZIAB0d (ORCPT ); Mon, 31 Aug 2009 21:26:33 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1752559AbZIAB0d (ORCPT ); Mon, 31 Aug 2009 21:26:33 -0400 Received: from mail-bw0-f219.google.com ([209.85.218.219]:44475 "EHLO mail-bw0-f219.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752472AbZIAB0c (ORCPT ); Mon, 31 Aug 2009 21:26:32 -0400 Received: by bwz19 with SMTP id 19so3188150bwz.37 for ; Mon, 31 Aug 2009 18:26:32 -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=SB5hd1iBGN2nGJnrlkSW85/26S6Qvxy70B+cTSzbVuw=; b=l96tuatJ0NrtuMlMLNmM05IV9J26XSabAWN/nvfdugMxnHt9gbNun09ivJG6cnuxAn gwytMViM3BJ+sNqaB6rkxnBGpEiSHSVcGsTIOiw9xiPEYcdangLv5vqI1EHjfBgAivXm uqZTQF8ii5TGsPtGr0Ox70J+d2jZCSo8Ye0M0= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer; b=mMqW0phBiAnMu1KpaIlElws4FBTRmcGCcQh6LOVe/Nl+Ir5TQCOywgHKkHv9qpHSkv UwdYJGLCp9UCHlwaDSzoxISa+1Nf5MNE3qd37r+bweXbXjArnbxTibc8GYRsOoMlSAHq ++fPvh5UnFSWZwoEUPnur+QY7BnhNficwhIZ0= Received: by 10.102.245.20 with SMTP id s20mr2570857muh.74.1251768392663; Mon, 31 Aug 2009 18:26:32 -0700 (PDT) Received: from localhost ([41.238.115.147]) by mx.google.com with ESMTPS id s10sm2622741muh.17.2009.08.31.18.26.31 (version=TLSv1/SSLv3 cipher=RC4-MD5); Mon, 31 Aug 2009 18:26:32 -0700 (PDT) From: Mohammed Gamal To: avi@redhat.com Cc: kvm@vger.kernel.org, mtosatti@redhat.com, Mohammed Gamal Subject: [PATCH][RESEND] x86 emulator: Add pusha and popa instructions Date: Tue, 1 Sep 2009 03:26:30 +0200 Message-Id: <1251768390-27694-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 This adds pusha and popa instructions (opcodes 0x60-0x61), this enables booting MINIX with invalid guest state emulation on. Signed-off-by: Mohammed Gamal --- arch/x86/kvm/emulate.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 51 insertions(+), 1 deletions(-) diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c index db0820d..9be2e6e 100644 --- a/arch/x86/kvm/emulate.c +++ b/arch/x86/kvm/emulate.c @@ -139,7 +139,8 @@ static u32 opcode_table[256] = { DstReg | Stack, DstReg | Stack, DstReg | Stack, DstReg | Stack, DstReg | Stack, DstReg | Stack, DstReg | Stack, DstReg | Stack, /* 0x60 - 0x67 */ - 0, 0, 0, DstReg | SrcMem32 | ModRM | Mov /* movsxd (x86/64) */ , + ImplicitOps | Stack | No64, ImplicitOps | Stack | No64, + 0, DstReg | SrcMem32 | ModRM | Mov /* movsxd (x86/64) */ , 0, 0, 0, 0, /* 0x68 - 0x6F */ SrcImm | Mov | Stack, 0, SrcImmByte | Mov | Stack, 0, @@ -1225,6 +1226,47 @@ static int emulate_pop_sreg(struct x86_emulate_ctxt *ctxt, return rc; } +static void emulate_pusha(struct x86_emulate_ctxt *ctxt) +{ + struct decode_cache *c = &ctxt->decode; + unsigned long old_esp = c->regs[VCPU_REGS_RSP]; + int reg = VCPU_REGS_RAX; + + while (reg <= VCPU_REGS_RDI) { + (reg == VCPU_REGS_RSP) ? + (c->src.val = old_esp) : (c->src.val = c->regs[reg]); + + emulate_push(ctxt); + ++reg; + } +} + +static int emulate_popa(struct x86_emulate_ctxt *ctxt, + struct x86_emulate_ops *ops) +{ + struct decode_cache *c = &ctxt->decode; + unsigned long old_esp = c->regs[VCPU_REGS_RSP]; + int rc = 0; + int reg = VCPU_REGS_RDI; + + while (reg >= VCPU_REGS_RAX) { + if (reg == VCPU_REGS_RSP) { + register_address_increment(c, &c->regs[VCPU_REGS_RSP], + c->op_bytes); + --reg; + } + + rc = emulate_pop(ctxt, ops, &c->regs[reg], c->op_bytes); + if (rc != 0) { + c->regs[VCPU_REGS_RSP] = old_esp; + break; + } + + --reg; + } + return rc; +} + static inline int emulate_grp1a(struct x86_emulate_ctxt *ctxt, struct x86_emulate_ops *ops) { @@ -1816,6 +1858,14 @@ special_insn: if (rc != 0) goto done; break; + case 0x60: /* pusha */ + emulate_pusha(ctxt); + break; + case 0x61: /* popa */ + rc = emulate_popa(ctxt, ops); + if (rc != 0) + goto done; + break; case 0x63: /* movsxd */ if (ctxt->mode != X86EMUL_MODE_PROT64) goto cannot_emulate;