mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-08-23 17:30:02 +00:00
KVM: x86 emulator: implement ENTER
Opcode C8. Only ENTER with lexical nesting depth 0 is implemented, since others are very rare. We'll fail emulation if nonzero lexical depth is used so data is not corrupted. Signed-off-by: Avi Kivity <avi@redhat.com>
This commit is contained in:
parent
51ddff50cb
commit
612e89f015
1 changed files with 27 additions and 1 deletions
|
@ -454,6 +454,11 @@ static ulong stack_mask(struct x86_emulate_ctxt *ctxt)
|
|||
return ~0U >> ((ss.d ^ 1) * 16); /* d=0: 0xffff; d=1: 0xffffffff */
|
||||
}
|
||||
|
||||
static int stack_size(struct x86_emulate_ctxt *ctxt)
|
||||
{
|
||||
return (__fls(stack_mask(ctxt)) + 1) >> 3;
|
||||
}
|
||||
|
||||
/* Access/update address held in a register, based on addressing mode. */
|
||||
static inline unsigned long
|
||||
address_mask(struct x86_emulate_ctxt *ctxt, unsigned long reg)
|
||||
|
@ -1592,6 +1597,26 @@ static int em_popf(struct x86_emulate_ctxt *ctxt)
|
|||
return emulate_popf(ctxt, &ctxt->dst.val, ctxt->op_bytes);
|
||||
}
|
||||
|
||||
static int em_enter(struct x86_emulate_ctxt *ctxt)
|
||||
{
|
||||
int rc;
|
||||
unsigned frame_size = ctxt->src.val;
|
||||
unsigned nesting_level = ctxt->src2.val & 31;
|
||||
|
||||
if (nesting_level)
|
||||
return X86EMUL_UNHANDLEABLE;
|
||||
|
||||
rc = push(ctxt, &ctxt->regs[VCPU_REGS_RBP], stack_size(ctxt));
|
||||
if (rc != X86EMUL_CONTINUE)
|
||||
return rc;
|
||||
assign_masked(&ctxt->regs[VCPU_REGS_RBP], ctxt->regs[VCPU_REGS_RSP],
|
||||
stack_mask(ctxt));
|
||||
assign_masked(&ctxt->regs[VCPU_REGS_RSP],
|
||||
ctxt->regs[VCPU_REGS_RSP] - frame_size,
|
||||
stack_mask(ctxt));
|
||||
return X86EMUL_CONTINUE;
|
||||
}
|
||||
|
||||
static int em_leave(struct x86_emulate_ctxt *ctxt)
|
||||
{
|
||||
assign_masked(&ctxt->regs[VCPU_REGS_RSP], ctxt->regs[VCPU_REGS_RBP],
|
||||
|
@ -3657,7 +3682,8 @@ static struct opcode opcode_table[256] = {
|
|||
I(DstReg | SrcMemFAddr | ModRM | No64 | Src2DS, em_lseg),
|
||||
G(ByteOp, group11), G(0, group11),
|
||||
/* 0xC8 - 0xCF */
|
||||
N, I(Stack, em_leave), N, I(ImplicitOps | Stack, em_ret_far),
|
||||
I(Stack | SrcImmU16 | Src2ImmByte, em_enter), I(Stack, em_leave),
|
||||
N, I(ImplicitOps | Stack, em_ret_far),
|
||||
D(ImplicitOps), DI(SrcImmByte, intn),
|
||||
D(ImplicitOps | No64), II(ImplicitOps, em_iret, iret),
|
||||
/* 0xD0 - 0xD7 */
|
||||
|
|
Loading…
Reference in a new issue