Skip to content

Commit 9605157

Browse files
committed
KVM: x86 emulator: emulate SGDT/SIDT
Opcodes 0F 01 /0 and 0F 01 /1 Signed-off-by: Avi Kivity <[email protected]>
1 parent a6e3407 commit 9605157

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

arch/x86/kvm/emulate.c

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3026,6 +3026,35 @@ static int em_vmcall(struct x86_emulate_ctxt *ctxt)
30263026
return X86EMUL_CONTINUE;
30273027
}
30283028

3029+
static int emulate_store_desc_ptr(struct x86_emulate_ctxt *ctxt,
3030+
void (*get)(struct x86_emulate_ctxt *ctxt,
3031+
struct desc_ptr *ptr))
3032+
{
3033+
struct desc_ptr desc_ptr;
3034+
3035+
if (ctxt->mode == X86EMUL_MODE_PROT64)
3036+
ctxt->op_bytes = 8;
3037+
get(ctxt, &desc_ptr);
3038+
if (ctxt->op_bytes == 2) {
3039+
ctxt->op_bytes = 4;
3040+
desc_ptr.address &= 0x00ffffff;
3041+
}
3042+
/* Disable writeback. */
3043+
ctxt->dst.type = OP_NONE;
3044+
return segmented_write(ctxt, ctxt->dst.addr.mem,
3045+
&desc_ptr, 2 + ctxt->op_bytes);
3046+
}
3047+
3048+
static int em_sgdt(struct x86_emulate_ctxt *ctxt)
3049+
{
3050+
return emulate_store_desc_ptr(ctxt, ctxt->ops->get_gdt);
3051+
}
3052+
3053+
static int em_sidt(struct x86_emulate_ctxt *ctxt)
3054+
{
3055+
return emulate_store_desc_ptr(ctxt, ctxt->ops->get_idt);
3056+
}
3057+
30293058
static int em_lgdt(struct x86_emulate_ctxt *ctxt)
30303059
{
30313060
struct desc_ptr desc_ptr;
@@ -3485,8 +3514,8 @@ static struct opcode group6[] = {
34853514
};
34863515

34873516
static struct group_dual group7 = { {
3488-
DI(Mov | DstMem | Priv, sgdt),
3489-
DI(Mov | DstMem | Priv, sidt),
3517+
II(Mov | DstMem | Priv, em_sgdt, sgdt),
3518+
II(Mov | DstMem | Priv, em_sidt, sidt),
34903519
II(SrcMem | Priv, em_lgdt, lgdt),
34913520
II(SrcMem | Priv, em_lidt, lidt),
34923521
II(SrcNone | DstMem | Mov, em_smsw, smsw), N,

0 commit comments

Comments
 (0)