Commit 31be40b3 authored by Wei Yongjun's avatar Wei Yongjun Committed by Avi Kivity

KVM: x86 emulator: put register operand write back to a function

Introduce function write_register_operand() to write back the
register operand.
Signed-off-by: default avatarWei Yongjun <yjwei@cn.fujitsu.com>
Signed-off-by: default avatarAvi Kivity <avi@redhat.com>
parent 646bab55
...@@ -1020,32 +1020,35 @@ static int load_segment_descriptor(struct x86_emulate_ctxt *ctxt, ...@@ -1020,32 +1020,35 @@ static int load_segment_descriptor(struct x86_emulate_ctxt *ctxt,
return X86EMUL_PROPAGATE_FAULT; return X86EMUL_PROPAGATE_FAULT;
} }
static inline int writeback(struct x86_emulate_ctxt *ctxt, static void write_register_operand(struct operand *op)
struct x86_emulate_ops *ops)
{ {
int rc; /* The 4-byte case *is* correct: in 64-bit mode we zero-extend. */
struct decode_cache *c = &ctxt->decode; switch (op->bytes) {
u32 err;
switch (c->dst.type) {
case OP_REG:
/* The 4-byte case *is* correct:
* in 64-bit mode we zero-extend.
*/
switch (c->dst.bytes) {
case 1: case 1:
*(u8 *)c->dst.addr.reg = (u8)c->dst.val; *(u8 *)op->addr.reg = (u8)op->val;
break; break;
case 2: case 2:
*(u16 *)c->dst.addr.reg = (u16)c->dst.val; *(u16 *)op->addr.reg = (u16)op->val;
break; break;
case 4: case 4:
*c->dst.addr.reg = (u32)c->dst.val; *op->addr.reg = (u32)op->val;
break; /* 64b: zero-ext */ break; /* 64b: zero-extend */
case 8: case 8:
*c->dst.addr.reg = c->dst.val; *op->addr.reg = op->val;
break; break;
} }
}
static inline int writeback(struct x86_emulate_ctxt *ctxt,
struct x86_emulate_ops *ops)
{
int rc;
struct decode_cache *c = &ctxt->decode;
u32 err;
switch (c->dst.type) {
case OP_REG:
write_register_operand(&c->dst);
break; break;
case OP_MEM: case OP_MEM:
if (c->lock_prefix) if (c->lock_prefix)
...@@ -2970,25 +2973,13 @@ x86_emulate_insn(struct x86_emulate_ctxt *ctxt) ...@@ -2970,25 +2973,13 @@ x86_emulate_insn(struct x86_emulate_ctxt *ctxt)
case 0x86 ... 0x87: /* xchg */ case 0x86 ... 0x87: /* xchg */
xchg: xchg:
/* Write back the register source. */ /* Write back the register source. */
switch (c->dst.bytes) { c->src.val = c->dst.val;
case 1: write_register_operand(&c->src);
*(u8 *) c->src.addr.reg = (u8) c->dst.val;
break;
case 2:
*(u16 *) c->src.addr.reg = (u16) c->dst.val;
break;
case 4:
*c->src.addr.reg = (u32) c->dst.val;
break; /* 64b reg: zero-extend */
case 8:
*c->src.addr.reg = c->dst.val;
break;
}
/* /*
* Write back the memory destination with implicit LOCK * Write back the memory destination with implicit LOCK
* prefix. * prefix.
*/ */
c->dst.val = c->src.val; c->dst.val = c->src.orig_val;
c->lock_prefix = 1; c->lock_prefix = 1;
break; break;
case 0x88 ... 0x8b: /* mov */ case 0x88 ... 0x8b: /* mov */
......
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