Message ID | 1251768390-27694-1-git-send-email-m.gamal005@gmail.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
On Tue, Sep 01, 2009 at 03:26:30AM +0200, Mohammed Gamal wrote: > This adds pusha and popa instructions (opcodes 0x60-0x61), this enables booting > MINIX with invalid guest state emulation on. > > Signed-off-by: Mohammed Gamal <m.gamal005@gmail.com> > --- > 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; Why is it necessary to restore the local VCPU_REGS_RSP copy on failure? -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On Tue, Sep 1, 2009 at 2:57 PM, Marcelo Tosatti<mtosatti@redhat.com> wrote: > On Tue, Sep 01, 2009 at 03:26:30AM +0200, Mohammed Gamal wrote: >> This adds pusha and popa instructions (opcodes 0x60-0x61), this enables booting >> MINIX with invalid guest state emulation on. >> >> Signed-off-by: Mohammed Gamal <m.gamal005@gmail.com> >> --- >> Â 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; > > Why is it necessary to restore the local VCPU_REGS_RSP copy on failure? Right. Perhaps this is a little too paranoid since we'll fail anyway -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
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;
This adds pusha and popa instructions (opcodes 0x60-0x61), this enables booting MINIX with invalid guest state emulation on. Signed-off-by: Mohammed Gamal <m.gamal005@gmail.com> --- arch/x86/kvm/emulate.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 51 insertions(+), 1 deletions(-)