Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d54e4237 authored by Joerg Roedel's avatar Joerg Roedel Committed by Avi Kivity
Browse files

KVM: x86 emulator: convert bsf/bsr instructions to emulate_2op_SrcV_nobyte()



The instruction emulation for bsrw is broken in KVM because
the code always uses bsr with 32 or 64 bit operand size for
emulation. Fix that by using emulate_2op_SrcV_nobyte() macro
to use guest operand size for emulation.

Signed-off-by: default avatarJoerg Roedel <joerg.roedel@amd.com>
Signed-off-by: default avatarAvi Kivity <avi@redhat.com>
parent 5f3fbc34
Loading
Loading
Loading
Loading
+2 −24
Original line number Original line Diff line number Diff line
@@ -3133,35 +3133,13 @@ static int em_btc(struct x86_emulate_ctxt *ctxt)


static int em_bsf(struct x86_emulate_ctxt *ctxt)
static int em_bsf(struct x86_emulate_ctxt *ctxt)
{
{
	u8 zf;
	emulate_2op_SrcV_nobyte(ctxt, "bsf");

	__asm__ ("bsf %2, %0; setz %1"
		 : "=r"(ctxt->dst.val), "=q"(zf)
		 : "r"(ctxt->src.val));

	ctxt->eflags &= ~X86_EFLAGS_ZF;
	if (zf) {
		ctxt->eflags |= X86_EFLAGS_ZF;
		/* Disable writeback. */
		ctxt->dst.type = OP_NONE;
	}
	return X86EMUL_CONTINUE;
	return X86EMUL_CONTINUE;
}
}


static int em_bsr(struct x86_emulate_ctxt *ctxt)
static int em_bsr(struct x86_emulate_ctxt *ctxt)
{
{
	u8 zf;
	emulate_2op_SrcV_nobyte(ctxt, "bsr");

	__asm__ ("bsr %2, %0; setz %1"
		 : "=r"(ctxt->dst.val), "=q"(zf)
		 : "r"(ctxt->src.val));

	ctxt->eflags &= ~X86_EFLAGS_ZF;
	if (zf) {
		ctxt->eflags |= X86_EFLAGS_ZF;
		/* Disable writeback. */
		ctxt->dst.type = OP_NONE;
	}
	return X86EMUL_CONTINUE;
	return X86EMUL_CONTINUE;
}
}