* [PATCH 1/4] KVM: x86 emulator: use SrcAcc to simplify stos decoding
@ 2010-08-04 7:36 Wei Yongjun
2010-08-04 7:38 ` [PATCH 2/4] KVM: x86 emulator: disable writeback when decode dest operand Wei Yongjun
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Wei Yongjun @ 2010-08-04 7:36 UTC (permalink / raw)
To: Avi Kivity, kvm
Use SrcAcc to simplify stos decoding.
Signed-off-by: Wei Yongjun <yjwei@cn.fujitsu.com>
---
arch/x86/kvm/emulate.c | 5 ++---
1 files changed, 2 insertions(+), 3 deletions(-)
diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
index f03ff26..4624b11 100644
--- a/arch/x86/kvm/emulate.c
+++ b/arch/x86/kvm/emulate.c
@@ -2175,7 +2175,8 @@ static struct opcode opcode_table[256] = {
D(ByteOp | SrcSI | DstDI | Mov | String), D(SrcSI | DstDI | Mov | String),
D(ByteOp | SrcSI | DstDI | String), D(SrcSI | DstDI | String),
/* 0xA8 - 0xAF */
- D(DstAcc | SrcImmByte | ByteOp), D(DstAcc | SrcImm), D(ByteOp | DstDI | Mov | String), D(DstDI | Mov | String),
+ D(DstAcc | SrcImmByte | ByteOp), D(DstAcc | SrcImm),
+ D(ByteOp | SrcAcc | DstDI | Mov | String), D(SrcAcc | DstDI | Mov | String),
D(ByteOp | SrcSI | DstAcc | Mov | String), D(SrcSI | DstAcc | Mov | String),
D(ByteOp | DstDI | String), D(DstDI | String),
/* 0xB0 - 0xB7 */
@@ -2937,8 +2938,6 @@ special_insn:
case 0xa8 ... 0xa9: /* test ax, imm */
goto test;
case 0xaa ... 0xab: /* stos */
- c->dst.val = c->regs[VCPU_REGS_RAX];
- break;
case 0xac ... 0xad: /* lods */
goto mov;
case 0xae ... 0xaf: /* scas */
--
1.7.0.4
^ permalink raw reply related [flat|nested] 6+ messages in thread* [PATCH 2/4] KVM: x86 emulator: disable writeback when decode dest operand 2010-08-04 7:36 [PATCH 1/4] KVM: x86 emulator: use SrcAcc to simplify stos decoding Wei Yongjun @ 2010-08-04 7:38 ` Wei Yongjun 2010-08-04 7:38 ` [PATCH 3/4] KVM: x86 emulator: using SrcOne for instruction d0/d1 decoding Wei Yongjun 2010-08-04 7:40 ` [PATCH 4/4] KVM: x86 emulator: remove dup code of in/out instruction Wei Yongjun 2 siblings, 0 replies; 6+ messages in thread From: Wei Yongjun @ 2010-08-04 7:38 UTC (permalink / raw) To: Avi Kivity, kvm This patch change to disable writeback when decode dest operand if the dest type is ImplicitOps or not specified. Signed-off-by: Wei Yongjun <yjwei@cn.fujitsu.com> --- arch/x86/kvm/emulate.c | 23 ++++++----------------- 1 files changed, 6 insertions(+), 17 deletions(-) diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c index 4624b11..31c33f4 100644 --- a/arch/x86/kvm/emulate.c +++ b/arch/x86/kvm/emulate.c @@ -2569,9 +2569,6 @@ done_prefixes: /* Decode and fetch the destination operand: register or memory. */ switch (c->d & DstMask) { - case ImplicitOps: - /* Special instructions do their own operand decoding. */ - return 0; case DstReg: decode_register_operand(&c->dst, c, c->twobyte && (c->b == 0xb6 || c->b == 0xb7)); @@ -2606,6 +2603,11 @@ done_prefixes: c->regs[VCPU_REGS_RDI]); c->dst.val = 0; break; + case ImplicitOps: + /* Special instructions do their own operand decoding. */ + default: + c->dst.type = OP_NONE; /* Disable writeback. */ + return 0; } done: @@ -3040,7 +3042,6 @@ special_insn: case 0xf5: /* cmc */ /* complement carry flag from eflags reg */ ctxt->eflags ^= EFLG_CF; - c->dst.type = OP_NONE; /* Disable writeback. */ break; case 0xf6 ... 0xf7: /* Grp3 */ if (!emulate_grp3(ctxt, ops)) @@ -3048,16 +3049,13 @@ special_insn: break; case 0xf8: /* clc */ ctxt->eflags &= ~EFLG_CF; - c->dst.type = OP_NONE; /* Disable writeback. */ break; case 0xfa: /* cli */ if (emulator_bad_iopl(ctxt, ops)) { emulate_gp(ctxt, 0); goto done; - } else { + } else ctxt->eflags &= ~X86_EFLAGS_IF; - c->dst.type = OP_NONE; /* Disable writeback. */ - } break; case 0xfb: /* sti */ if (emulator_bad_iopl(ctxt, ops)) { @@ -3066,16 +3064,13 @@ special_insn: } else { ctxt->interruptibility = KVM_X86_SHADOW_INT_STI; ctxt->eflags |= X86_EFLAGS_IF; - c->dst.type = OP_NONE; /* Disable writeback. */ } break; case 0xfc: /* cld */ ctxt->eflags &= ~EFLG_DF; - c->dst.type = OP_NONE; /* Disable writeback. */ break; case 0xfd: /* std */ ctxt->eflags |= EFLG_DF; - c->dst.type = OP_NONE; /* Disable writeback. */ break; case 0xfe: /* Grp4 */ grp45: @@ -3212,16 +3207,13 @@ twobyte_insn: break; case 0x06: emulate_clts(ctxt->vcpu); - c->dst.type = OP_NONE; break; case 0x09: /* wbinvd */ kvm_emulate_wbinvd(ctxt->vcpu); - c->dst.type = OP_NONE; break; case 0x08: /* invd */ case 0x0d: /* GrpP (prefetch) */ case 0x18: /* Grp16 (prefetch/nop) */ - c->dst.type = OP_NONE; break; case 0x20: /* mov cr, reg */ switch (c->modrm_reg) { @@ -3274,7 +3266,6 @@ twobyte_insn: goto done; } rc = X86EMUL_CONTINUE; - c->dst.type = OP_NONE; break; case 0x32: /* rdmsr */ @@ -3286,7 +3277,6 @@ twobyte_insn: c->regs[VCPU_REGS_RDX] = msr_data >> 32; } rc = X86EMUL_CONTINUE; - c->dst.type = OP_NONE; break; case 0x34: /* sysenter */ rc = emulate_sysenter(ctxt, ops); @@ -3310,7 +3300,6 @@ twobyte_insn: case 0x80 ... 0x8f: /* jnz rel, etc*/ if (test_cc(c->b, ctxt->eflags)) jmp_rel(c, c->src.val); - c->dst.type = OP_NONE; break; case 0xa0: /* push fs */ emulate_push_sreg(ctxt, ops, VCPU_SREG_FS); -- 1.7.0.4 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 3/4] KVM: x86 emulator: using SrcOne for instruction d0/d1 decoding 2010-08-04 7:36 [PATCH 1/4] KVM: x86 emulator: use SrcAcc to simplify stos decoding Wei Yongjun 2010-08-04 7:38 ` [PATCH 2/4] KVM: x86 emulator: disable writeback when decode dest operand Wei Yongjun @ 2010-08-04 7:38 ` Wei Yongjun 2010-08-05 9:38 ` Avi Kivity 2010-08-04 7:40 ` [PATCH 4/4] KVM: x86 emulator: remove dup code of in/out instruction Wei Yongjun 2 siblings, 1 reply; 6+ messages in thread From: Wei Yongjun @ 2010-08-04 7:38 UTC (permalink / raw) To: Avi Kivity, kvm Using SrcOne for instruction d0/d1 decoding. Signed-off-by: Wei Yongjun <yjwei@cn.fujitsu.com> --- arch/x86/kvm/emulate.c | 3 +-- 1 files changed, 1 insertions(+), 2 deletions(-) diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c index 31c33f4..1ce3c4f 100644 --- a/arch/x86/kvm/emulate.c +++ b/arch/x86/kvm/emulate.c @@ -2191,7 +2191,7 @@ static struct opcode opcode_table[256] = { N, N, N, D(ImplicitOps | Stack), D(ImplicitOps), D(SrcImmByte), D(ImplicitOps | No64), D(ImplicitOps), /* 0xD0 - 0xD7 */ - D(ByteOp | DstMem | SrcImplicit | ModRM), D(DstMem | SrcImplicit | ModRM), + D(ByteOp | DstMem | SrcOne | ModRM), D(DstMem | SrcOne | ModRM), D(ByteOp | DstMem | SrcImplicit | ModRM), D(DstMem | SrcImplicit | ModRM), N, N, N, N, /* 0xD8 - 0xDF */ @@ -2971,7 +2971,6 @@ special_insn: goto done; break; case 0xd0 ... 0xd1: /* Grp2 */ - c->src.val = 1; emulate_grp2(ctxt); break; case 0xd2 ... 0xd3: /* Grp2 */ -- 1.7.0.4 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 3/4] KVM: x86 emulator: using SrcOne for instruction d0/d1 decoding 2010-08-04 7:38 ` [PATCH 3/4] KVM: x86 emulator: using SrcOne for instruction d0/d1 decoding Wei Yongjun @ 2010-08-05 9:38 ` Avi Kivity 0 siblings, 0 replies; 6+ messages in thread From: Avi Kivity @ 2010-08-05 9:38 UTC (permalink / raw) To: Wei Yongjun; +Cc: kvm On 08/04/2010 10:38 AM, Wei Yongjun wrote: > Using SrcOne for instruction d0/d1 decoding. > Applied 1-3, thanks. -- error compiling committee.c: too many arguments to function ^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 4/4] KVM: x86 emulator: remove dup code of in/out instruction 2010-08-04 7:36 [PATCH 1/4] KVM: x86 emulator: use SrcAcc to simplify stos decoding Wei Yongjun 2010-08-04 7:38 ` [PATCH 2/4] KVM: x86 emulator: disable writeback when decode dest operand Wei Yongjun 2010-08-04 7:38 ` [PATCH 3/4] KVM: x86 emulator: using SrcOne for instruction d0/d1 decoding Wei Yongjun @ 2010-08-04 7:40 ` Wei Yongjun 2010-08-05 9:37 ` Avi Kivity 2 siblings, 1 reply; 6+ messages in thread From: Wei Yongjun @ 2010-08-04 7:40 UTC (permalink / raw) To: Avi Kivity, kvm Signed-off-by: Wei Yongjun <yjwei@cn.fujitsu.com> --- arch/x86/kvm/emulate.c | 50 ++++++++++++++++++++--------------------------- 1 files changed, 21 insertions(+), 29 deletions(-) diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c index 1ce3c4f..d197b46 100644 --- a/arch/x86/kvm/emulate.c +++ b/arch/x86/kvm/emulate.c @@ -54,6 +54,7 @@ #define DstAcc (4<<1) /* Destination Accumulator */ #define DstDI (5<<1) /* Destination is in ES:(E)DI */ #define DstMem64 (6<<1) /* 64bit memory operand */ +#define DstImmUByte (7<<1) /* 8-bit unsigned immediate operand */ #define DstMask (7<<1) /* Source operand type. */ #define SrcNone (0<<4) /* No source operand. */ @@ -2199,12 +2200,12 @@ static struct opcode opcode_table[256] = { /* 0xE0 - 0xE7 */ N, N, N, N, D(ByteOp | SrcImmUByte | DstAcc), D(SrcImmUByte | DstAcc), - D(ByteOp | SrcImmUByte | DstAcc), D(SrcImmUByte | DstAcc), + D(ByteOp | SrcAcc | DstImmUByte), D(SrcAcc | DstImmUByte), /* 0xE8 - 0xEF */ D(SrcImm | Stack), D(SrcImm | ImplicitOps), D(SrcImmFAddr | No64), D(SrcImmByte | ImplicitOps), D(SrcNone | ByteOp | DstAcc), D(SrcNone | DstAcc), - D(SrcNone | ByteOp | DstAcc), D(SrcNone | DstAcc), + D(ByteOp | SrcAcc | ImplicitOps), D(SrcAcc | ImplicitOps), /* 0xF0 - 0xF7 */ N, N, N, N, D(ImplicitOps | Priv), D(ImplicitOps), G(ByteOp, group3), G(0, group3), @@ -2573,6 +2574,12 @@ done_prefixes: decode_register_operand(&c->dst, c, c->twobyte && (c->b == 0xb6 || c->b == 0xb7)); break; + case DstImmUByte: + c->dst.type = OP_IMM; + c->dst.addr.mem = c->eip; + c->dst.bytes = 1; + c->dst.val = insn_fetch(u8, 1, c->eip); + break; case DstMem: case DstMem64: c->dst = memop; @@ -2803,29 +2810,12 @@ special_insn: break; case 0x6c: /* insb */ case 0x6d: /* insw/insd */ - c->dst.bytes = min(c->dst.bytes, 4u); - if (!emulator_io_permited(ctxt, ops, c->regs[VCPU_REGS_RDX], - c->dst.bytes)) { - emulate_gp(ctxt, 0); - goto done; - } - if (!pio_in_emulated(ctxt, ops, c->dst.bytes, - c->regs[VCPU_REGS_RDX], &c->dst.val)) - goto done; /* IO is needed, skip writeback */ - break; + c->src.val = c->regs[VCPU_REGS_RDX]; + goto do_io_in; case 0x6e: /* outsb */ case 0x6f: /* outsw/outsd */ - c->src.bytes = min(c->src.bytes, 4u); - if (!emulator_io_permited(ctxt, ops, c->regs[VCPU_REGS_RDX], - c->src.bytes)) { - emulate_gp(ctxt, 0); - goto done; - } - ops->pio_out_emulated(c->src.bytes, c->regs[VCPU_REGS_RDX], - &c->src.val, 1, ctxt->vcpu); - - c->dst.type = OP_NONE; /* nothing to writeback */ - break; + c->dst.val = c->regs[VCPU_REGS_RDX]; + goto do_io_out; case 0x70 ... 0x7f: /* jcc (short) */ if (test_cc(c->b, ctxt->eflags)) jmp_rel(c, c->src.val); @@ -3024,16 +3014,18 @@ special_insn: break; case 0xee: /* out dx,al */ case 0xef: /* out dx,(e/r)ax */ - c->src.val = c->regs[VCPU_REGS_RDX]; + c->dst.val = c->regs[VCPU_REGS_RDX]; do_io_out: - c->dst.bytes = min(c->dst.bytes, 4u); - if (!emulator_io_permited(ctxt, ops, c->src.val, c->dst.bytes)) { + c->src.bytes = min(c->src.bytes, 4u); + if (!emulator_io_permited(ctxt, ops, c->dst.val, + c->src.bytes)) { emulate_gp(ctxt, 0); goto done; } - ops->pio_out_emulated(c->dst.bytes, c->src.val, &c->dst.val, 1, - ctxt->vcpu); - c->dst.type = OP_NONE; /* Disable writeback. */ + ops->pio_out_emulated(c->src.bytes, c->dst.val, + &c->src.val, 1, ctxt->vcpu); + + c->dst.type = OP_NONE; /* nothing to writeback */ break; case 0xf4: /* hlt */ ctxt->vcpu->arch.halt_request = 1; -- 1.7.0.4 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 4/4] KVM: x86 emulator: remove dup code of in/out instruction 2010-08-04 7:40 ` [PATCH 4/4] KVM: x86 emulator: remove dup code of in/out instruction Wei Yongjun @ 2010-08-05 9:37 ` Avi Kivity 0 siblings, 0 replies; 6+ messages in thread From: Avi Kivity @ 2010-08-05 9:37 UTC (permalink / raw) To: Wei Yongjun; +Cc: kvm On 08/04/2010 10:40 AM, Wei Yongjun wrote: > Signed-off-by: Wei Yongjun <yjwei@cn.fujitsu.com> Patch is good, but too big. Please separate into DstImmUByte, change OUT to use dst instead of src, IN consolidationn and OUT consolidation. > --- > arch/x86/kvm/emulate.c | 50 ++++++++++++++++++++--------------------------- > 1 files changed, 21 insertions(+), 29 deletions(-) > > diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c > index 1ce3c4f..d197b46 100644 > --- a/arch/x86/kvm/emulate.c > +++ b/arch/x86/kvm/emulate.c > @@ -54,6 +54,7 @@ > #define DstAcc (4<<1) /* Destination Accumulator */ > #define DstDI (5<<1) /* Destination is in ES:(E)DI */ > #define DstMem64 (6<<1) /* 64bit memory operand */ > +#define DstImmUByte (7<<1) /* 8-bit unsigned immediate operand */ > #define DstMask (7<<1) > /* Source operand type. */ > #define SrcNone (0<<4) /* No source operand. */ > @@ -2199,12 +2200,12 @@ static struct opcode opcode_table[256] = { > /* 0xE0 - 0xE7 */ > N, N, N, N, > D(ByteOp | SrcImmUByte | DstAcc), D(SrcImmUByte | DstAcc), > - D(ByteOp | SrcImmUByte | DstAcc), D(SrcImmUByte | DstAcc), > + D(ByteOp | SrcAcc | DstImmUByte), D(SrcAcc | DstImmUByte), > /* 0xE8 - 0xEF */ > D(SrcImm | Stack), D(SrcImm | ImplicitOps), > D(SrcImmFAddr | No64), D(SrcImmByte | ImplicitOps), > D(SrcNone | ByteOp | DstAcc), D(SrcNone | DstAcc), > - D(SrcNone | ByteOp | DstAcc), D(SrcNone | DstAcc), > + D(ByteOp | SrcAcc | ImplicitOps), D(SrcAcc | ImplicitOps), > /* 0xF0 - 0xF7 */ > N, N, N, N, > D(ImplicitOps | Priv), D(ImplicitOps), G(ByteOp, group3), G(0, group3), > @@ -2573,6 +2574,12 @@ done_prefixes: > decode_register_operand(&c->dst, c, > c->twobyte && (c->b == 0xb6 || c->b == 0xb7)); > break; > + case DstImmUByte: > + c->dst.type = OP_IMM; > + c->dst.addr.mem = c->eip; > + c->dst.bytes = 1; > + c->dst.val = insn_fetch(u8, 1, c->eip); > + break; > case DstMem: > case DstMem64: > c->dst = memop; > @@ -2803,29 +2810,12 @@ special_insn: > break; > case 0x6c: /* insb */ > case 0x6d: /* insw/insd */ > - c->dst.bytes = min(c->dst.bytes, 4u); > - if (!emulator_io_permited(ctxt, ops, c->regs[VCPU_REGS_RDX], > - c->dst.bytes)) { > - emulate_gp(ctxt, 0); > - goto done; > - } > - if (!pio_in_emulated(ctxt, ops, c->dst.bytes, > - c->regs[VCPU_REGS_RDX], &c->dst.val)) > - goto done; /* IO is needed, skip writeback */ > - break; > + c->src.val = c->regs[VCPU_REGS_RDX]; > + goto do_io_in; > case 0x6e: /* outsb */ > case 0x6f: /* outsw/outsd */ > - c->src.bytes = min(c->src.bytes, 4u); > - if (!emulator_io_permited(ctxt, ops, c->regs[VCPU_REGS_RDX], > - c->src.bytes)) { > - emulate_gp(ctxt, 0); > - goto done; > - } > - ops->pio_out_emulated(c->src.bytes, c->regs[VCPU_REGS_RDX], > - &c->src.val, 1, ctxt->vcpu); > - > - c->dst.type = OP_NONE; /* nothing to writeback */ > - break; > + c->dst.val = c->regs[VCPU_REGS_RDX]; > + goto do_io_out; > case 0x70 ... 0x7f: /* jcc (short) */ > if (test_cc(c->b, ctxt->eflags)) > jmp_rel(c, c->src.val); > @@ -3024,16 +3014,18 @@ special_insn: > break; > case 0xee: /* out dx,al */ > case 0xef: /* out dx,(e/r)ax */ > - c->src.val = c->regs[VCPU_REGS_RDX]; > + c->dst.val = c->regs[VCPU_REGS_RDX]; > do_io_out: > - c->dst.bytes = min(c->dst.bytes, 4u); > - if (!emulator_io_permited(ctxt, ops, c->src.val, c->dst.bytes)) { > + c->src.bytes = min(c->src.bytes, 4u); > + if (!emulator_io_permited(ctxt, ops, c->dst.val, > + c->src.bytes)) { > emulate_gp(ctxt, 0); > goto done; > } > - ops->pio_out_emulated(c->dst.bytes, c->src.val, &c->dst.val, 1, > - ctxt->vcpu); > - c->dst.type = OP_NONE; /* Disable writeback. */ > + ops->pio_out_emulated(c->src.bytes, c->dst.val, > + &c->src.val, 1, ctxt->vcpu); > + > + c->dst.type = OP_NONE; /* nothing to writeback */ > break; > case 0xf4: /* hlt */ > ctxt->vcpu->arch.halt_request = 1; -- error compiling committee.c: too many arguments to function ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2010-08-05 9:38 UTC | newest] Thread overview: 6+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2010-08-04 7:36 [PATCH 1/4] KVM: x86 emulator: use SrcAcc to simplify stos decoding Wei Yongjun 2010-08-04 7:38 ` [PATCH 2/4] KVM: x86 emulator: disable writeback when decode dest operand Wei Yongjun 2010-08-04 7:38 ` [PATCH 3/4] KVM: x86 emulator: using SrcOne for instruction d0/d1 decoding Wei Yongjun 2010-08-05 9:38 ` Avi Kivity 2010-08-04 7:40 ` [PATCH 4/4] KVM: x86 emulator: remove dup code of in/out instruction Wei Yongjun 2010-08-05 9:37 ` Avi Kivity
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox