Commit 34d1f490 authored by Avi Kivity's avatar Avi Kivity

KVM: x86 emulator: trap and propagate #DE from DIV and IDIV

Signed-off-by: default avatarAvi Kivity <avi@redhat.com>
Signed-off-by: default avatarMarcelo Tosatti <mtosatti@redhat.com>
parent f6b3597b
...@@ -504,6 +504,12 @@ static void emulate_ts(struct x86_emulate_ctxt *ctxt, int err) ...@@ -504,6 +504,12 @@ static void emulate_ts(struct x86_emulate_ctxt *ctxt, int err)
emulate_exception(ctxt, TS_VECTOR, err, true); emulate_exception(ctxt, TS_VECTOR, err, true);
} }
static int emulate_de(struct x86_emulate_ctxt *ctxt)
{
emulate_exception(ctxt, DE_VECTOR, 0, false);
return X86EMUL_PROPAGATE_FAULT;
}
static int do_fetch_insn_byte(struct x86_emulate_ctxt *ctxt, static int do_fetch_insn_byte(struct x86_emulate_ctxt *ctxt,
struct x86_emulate_ops *ops, struct x86_emulate_ops *ops,
unsigned long eip, u8 *dest) unsigned long eip, u8 *dest)
...@@ -1458,6 +1464,7 @@ static inline int emulate_grp3(struct x86_emulate_ctxt *ctxt, ...@@ -1458,6 +1464,7 @@ static inline int emulate_grp3(struct x86_emulate_ctxt *ctxt,
struct decode_cache *c = &ctxt->decode; struct decode_cache *c = &ctxt->decode;
unsigned long *rax = &c->regs[VCPU_REGS_RAX]; unsigned long *rax = &c->regs[VCPU_REGS_RAX];
unsigned long *rdx = &c->regs[VCPU_REGS_RDX]; unsigned long *rdx = &c->regs[VCPU_REGS_RDX];
u8 de = 0;
switch (c->modrm_reg) { switch (c->modrm_reg) {
case 0 ... 1: /* test */ case 0 ... 1: /* test */
...@@ -1476,14 +1483,18 @@ static inline int emulate_grp3(struct x86_emulate_ctxt *ctxt, ...@@ -1476,14 +1483,18 @@ static inline int emulate_grp3(struct x86_emulate_ctxt *ctxt,
emulate_1op_rax_rdx("imul", c->src, *rax, *rdx, ctxt->eflags); emulate_1op_rax_rdx("imul", c->src, *rax, *rdx, ctxt->eflags);
break; break;
case 6: /* div */ case 6: /* div */
emulate_1op_rax_rdx("div", c->src, *rax, *rdx, ctxt->eflags); emulate_1op_rax_rdx_ex("div", c->src, *rax, *rdx,
ctxt->eflags, de);
break; break;
case 7: /* idiv */ case 7: /* idiv */
emulate_1op_rax_rdx("idiv", c->src, *rax, *rdx, ctxt->eflags); emulate_1op_rax_rdx_ex("idiv", c->src, *rax, *rdx,
ctxt->eflags, de);
break; break;
default: default:
return X86EMUL_UNHANDLEABLE; return X86EMUL_UNHANDLEABLE;
} }
if (de)
return emulate_de(ctxt);
return X86EMUL_CONTINUE; return X86EMUL_CONTINUE;
} }
...@@ -3413,8 +3424,9 @@ x86_emulate_insn(struct x86_emulate_ctxt *ctxt) ...@@ -3413,8 +3424,9 @@ x86_emulate_insn(struct x86_emulate_ctxt *ctxt)
ctxt->eflags ^= EFLG_CF; ctxt->eflags ^= EFLG_CF;
break; break;
case 0xf6 ... 0xf7: /* Grp3 */ case 0xf6 ... 0xf7: /* Grp3 */
if (emulate_grp3(ctxt, ops) != X86EMUL_CONTINUE) rc = emulate_grp3(ctxt, ops);
goto cannot_emulate; if (rc != X86EMUL_CONTINUE)
goto done;
break; break;
case 0xf8: /* clc */ case 0xf8: /* clc */
ctxt->eflags &= ~EFLG_CF; ctxt->eflags &= ~EFLG_CF;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment