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

Commit 1ce19dc1 authored by Borislav Petkov's avatar Borislav Petkov Committed by Paolo Bonzini
Browse files

kvm, emulator: Use opcode length



Add a field to the current emulation context which contains the
instruction opcode length. This will streamline handling of opcodes of
different length.

Signed-off-by: default avatarBorislav Petkov <bp@suse.de>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent 9c15bb1d
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -279,8 +279,12 @@ struct x86_emulate_ctxt {
	bool have_exception;
	struct x86_exception exception;

	/* decode cache */
	u8 twobyte;
	/*
	 * decode cache
	 */

	/* current opcode length in bytes */
	u8 opcode_len;
	u8 b;
	u8 intercept;
	u8 lock_prefix;
+3 −2
Original line number Diff line number Diff line
@@ -4126,6 +4126,7 @@ int x86_decode_insn(struct x86_emulate_ctxt *ctxt, void *insn, int insn_len)
	ctxt->_eip = ctxt->eip;
	ctxt->fetch.start = ctxt->_eip;
	ctxt->fetch.end = ctxt->fetch.start + insn_len;
	ctxt->opcode_len = 1;
	if (insn_len > 0)
		memcpy(ctxt->fetch.data, insn, insn_len);

@@ -4208,7 +4209,7 @@ int x86_decode_insn(struct x86_emulate_ctxt *ctxt, void *insn, int insn_len)
	opcode = opcode_table[ctxt->b];
	/* Two-byte opcode? */
	if (ctxt->b == 0x0f) {
		ctxt->twobyte = 1;
		ctxt->opcode_len = 2;
		ctxt->b = insn_fetch(u8, ctxt);
		opcode = twobyte_table[ctxt->b];
	}
@@ -4540,7 +4541,7 @@ int x86_emulate_insn(struct x86_emulate_ctxt *ctxt)
		goto writeback;
	}

	if (ctxt->twobyte)
	if (ctxt->opcode_len == 2)
		goto twobyte_insn;

	switch (ctxt->b) {
+2 −2
Original line number Diff line number Diff line
@@ -4789,8 +4789,8 @@ static void inject_emulated_exception(struct kvm_vcpu *vcpu)

static void init_decode_cache(struct x86_emulate_ctxt *ctxt)
{
	memset(&ctxt->twobyte, 0,
	       (void *)&ctxt->_regs - (void *)&ctxt->twobyte);
	memset(&ctxt->opcode_len, 0,
	       (void *)&ctxt->_regs - (void *)&ctxt->opcode_len);

	ctxt->fetch.start = 0;
	ctxt->fetch.end = 0;