Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 215712
b: refs/heads/master
c: 6e154e5
h: refs/heads/master
v: v3
  • Loading branch information
Mohammed Gamal authored and Avi Kivity committed Oct 24, 2010
1 parent 6f6dbe2 commit 05f1367
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 1 deletion.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 160ce1f1a8fe64b3e2686ae73fbf051ccfe7c7ef
refs/heads/master: 6e154e56b4d7a6a28c54f0984e13d3f8defc4755
78 changes: 78 additions & 0 deletions trunk/arch/x86/kvm/emulate.c
Original file line number Diff line number Diff line change
Expand Up @@ -1180,6 +1180,67 @@ static int emulate_popa(struct x86_emulate_ctxt *ctxt,
return rc;
}

int emulate_int_real(struct x86_emulate_ctxt *ctxt,
struct x86_emulate_ops *ops, int irq)
{
struct decode_cache *c = &ctxt->decode;
int rc = X86EMUL_CONTINUE;
struct desc_ptr dt;
gva_t cs_addr;
gva_t eip_addr;
u16 cs, eip;
u32 err;

/* TODO: Add limit checks */
c->src.val = ctxt->eflags;
emulate_push(ctxt, ops);

ctxt->eflags &= ~(EFLG_IF | EFLG_TF | EFLG_AC);

c->src.val = ops->get_segment_selector(VCPU_SREG_CS, ctxt->vcpu);
emulate_push(ctxt, ops);

c->src.val = c->eip;
emulate_push(ctxt, ops);

ops->get_idt(&dt, ctxt->vcpu);

eip_addr = dt.address + (irq << 2);
cs_addr = dt.address + (irq << 2) + 2;

rc = ops->read_std(cs_addr, &cs, 2, ctxt->vcpu, &err);
if (rc != X86EMUL_CONTINUE)
return rc;

rc = ops->read_std(eip_addr, &eip, 2, ctxt->vcpu, &err);
if (rc != X86EMUL_CONTINUE)
return rc;

rc = load_segment_descriptor(ctxt, ops, cs, VCPU_SREG_CS);
if (rc != X86EMUL_CONTINUE)
return rc;

c->eip = eip;

return rc;
}

static int emulate_int(struct x86_emulate_ctxt *ctxt,
struct x86_emulate_ops *ops, int irq)
{
switch(ctxt->mode) {
case X86EMUL_MODE_REAL:
return emulate_int_real(ctxt, ops, irq);
case X86EMUL_MODE_VM86:
case X86EMUL_MODE_PROT16:
case X86EMUL_MODE_PROT32:
case X86EMUL_MODE_PROT64:
default:
/* Protected mode interrupts unimplemented yet */
return X86EMUL_UNHANDLEABLE;
}
}

static int emulate_iret_real(struct x86_emulate_ctxt *ctxt,
struct x86_emulate_ops *ops)
{
Expand Down Expand Up @@ -2616,6 +2677,7 @@ x86_emulate_insn(struct x86_emulate_ctxt *ctxt)
struct decode_cache *c = &ctxt->decode;
int rc = X86EMUL_CONTINUE;
int saved_dst_type = c->dst.type;
int irq; /* Used for int 3, int, and into */

ctxt->decode.mem_read.pos = 0;

Expand Down Expand Up @@ -2960,6 +3022,22 @@ x86_emulate_insn(struct x86_emulate_ctxt *ctxt)
if (rc != X86EMUL_CONTINUE)
goto done;
break;
case 0xcc: /* int3 */
irq = 3;
goto do_interrupt;
case 0xcd: /* int n */
irq = c->src.val;
do_interrupt:
rc = emulate_int(ctxt, ops, irq);
if (rc != X86EMUL_CONTINUE)
goto done;
break;
case 0xce: /* into */
if (ctxt->eflags & EFLG_OF) {
irq = 4;
goto do_interrupt;
}
break;
case 0xcf: /* iret */
rc = emulate_iret(ctxt, ops);

Expand Down

0 comments on commit 05f1367

Please sign in to comment.