* [PATCH 2/2] x86 emulator: Add into, int, and int3 instructions (opcodes 0xcc-0xce)
@ 2010-08-04 2:44 Mohammed Gamal
2010-08-04 6:21 ` Avi Kivity
0 siblings, 1 reply; 4+ messages in thread
From: Mohammed Gamal @ 2010-08-04 2:44 UTC (permalink / raw)
To: avi; +Cc: mtosatti, kvm, Mohammed Gamal
This adds support for int instructions to the emulator
Signed-off-by: Mohammed Gamal <m.gamal005@gmail.com>
---
arch/x86/kvm/emulate.c | 77 ++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 77 insertions(+), 0 deletions(-)
diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
index f03ff26..5afcc32 100644
--- a/arch/x86/kvm/emulate.c
+++ b/arch/x86/kvm/emulate.c
@@ -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)
{
@@ -2619,6 +2680,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;
@@ -2963,6 +3025,21 @@ special_insn:
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;
+ }
case 0xcf: /* iret */
rc = emulate_iret(ctxt, ops);
--
1.7.0.4
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 2/2] x86 emulator: Add into, int, and int3 instructions (opcodes 0xcc-0xce)
2010-08-04 2:44 [PATCH 2/2] x86 emulator: Add into, int, and int3 instructions (opcodes 0xcc-0xce) Mohammed Gamal
@ 2010-08-04 6:21 ` Avi Kivity
0 siblings, 0 replies; 4+ messages in thread
From: Avi Kivity @ 2010-08-04 6:21 UTC (permalink / raw)
To: Mohammed Gamal; +Cc: mtosatti, kvm
On 08/04/2010 05:44 AM, Mohammed Gamal wrote:
> This adds support for int instructions to the emulator
>
> @@ -2963,6 +3025,21 @@ special_insn:
> 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;
> + }
If OF is clear, you fall through and emulate an IRET.
> case 0xcf: /* iret */
> rc = emulate_iret(ctxt, ops);
>
--
I have a truly marvellous patch that fixes the bug which this
signature is too narrow to contain.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 2/2] x86 emulator: Add into, int, and int3 instructions (opcodes 0xcc-0xce)
@ 2010-08-04 11:38 Mohammed Gamal
2010-08-05 9:25 ` Avi Kivity
0 siblings, 1 reply; 4+ messages in thread
From: Mohammed Gamal @ 2010-08-04 11:38 UTC (permalink / raw)
To: avi; +Cc: mtosatti, kvm, Mohammed Gamal
This adds support for int instructions to the emulator
Signed-off-by: Mohammed Gamal <m.gamal005@gmail.com>
---
arch/x86/kvm/emulate.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 78 insertions(+), 0 deletions(-)
diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
index f03ff26..e4e2b20 100644
--- a/arch/x86/kvm/emulate.c
+++ b/arch/x86/kvm/emulate.c
@@ -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)
{
@@ -2619,6 +2680,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;
@@ -2963,6 +3025,22 @@ special_insn:
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);
--
1.7.0.4
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 2/2] x86 emulator: Add into, int, and int3 instructions (opcodes 0xcc-0xce)
2010-08-04 11:38 Mohammed Gamal
@ 2010-08-05 9:25 ` Avi Kivity
0 siblings, 0 replies; 4+ messages in thread
From: Avi Kivity @ 2010-08-05 9:25 UTC (permalink / raw)
To: Mohammed Gamal; +Cc: mtosatti, kvm
On 08/04/2010 02:38 PM, Mohammed Gamal wrote:
> This adds support for int instructions to the emulator
Applied, thanks. Please use v2 markers so I can distinguish between
different versions (list of changes helps too).
--
error compiling committee.c: too many arguments to function
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2010-08-05 9:25 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-08-04 2:44 [PATCH 2/2] x86 emulator: Add into, int, and int3 instructions (opcodes 0xcc-0xce) Mohammed Gamal
2010-08-04 6:21 ` Avi Kivity
-- strict thread matches above, loose matches on Subject: below --
2010-08-04 11:38 Mohammed Gamal
2010-08-05 9:25 ` Avi Kivity
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox