]> Pileus Git - ~andy/linux/blobdiff - arch/x86/include/asm/kvm_emulate.h
Merge tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm
[~andy/linux] / arch / x86 / include / asm / kvm_emulate.h
index c764f43b71c5c851f46be710023d4945f1df3c76..24ec1216596e9de4f57ebd1f75ebe7a95e77160f 100644 (file)
@@ -85,6 +85,19 @@ struct x86_instruction_info {
 #define X86EMUL_INTERCEPTED     6 /* Intercepted by nested VMCB/VMCS */
 
 struct x86_emulate_ops {
+       /*
+        * read_gpr: read a general purpose register (rax - r15)
+        *
+        * @reg: gpr number.
+        */
+       ulong (*read_gpr)(struct x86_emulate_ctxt *ctxt, unsigned reg);
+       /*
+        * write_gpr: write a general purpose register (rax - r15)
+        *
+        * @reg: gpr number.
+        * @val: value to write.
+        */
+       void (*write_gpr)(struct x86_emulate_ctxt *ctxt, unsigned reg, ulong val);
        /*
         * read_std: Read bytes of standard (non-emulated/special) memory.
         *           Used for descriptor reading.
@@ -200,8 +213,9 @@ typedef u32 __attribute__((vector_size(16))) sse128_t;
 
 /* Type, address-of, and value of an instruction's operand. */
 struct operand {
-       enum { OP_REG, OP_MEM, OP_IMM, OP_XMM, OP_MM, OP_NONE } type;
+       enum { OP_REG, OP_MEM, OP_MEM_STR, OP_IMM, OP_XMM, OP_MM, OP_NONE } type;
        unsigned int bytes;
+       unsigned int count;
        union {
                unsigned long orig_val;
                u64 orig_val64;
@@ -221,6 +235,7 @@ struct operand {
                char valptr[sizeof(unsigned long) + 2];
                sse128_t vec_val;
                u64 mm_val;
+               void *data;
        };
 };
 
@@ -236,27 +251,40 @@ struct read_cache {
        unsigned long end;
 };
 
+/* Execution mode, passed to the emulator. */
+enum x86emul_mode {
+       X86EMUL_MODE_REAL,      /* Real mode.             */
+       X86EMUL_MODE_VM86,      /* Virtual 8086 mode.     */
+       X86EMUL_MODE_PROT16,    /* 16-bit protected mode. */
+       X86EMUL_MODE_PROT32,    /* 32-bit protected mode. */
+       X86EMUL_MODE_PROT64,    /* 64-bit (long) mode.    */
+};
+
 struct x86_emulate_ctxt {
-       struct x86_emulate_ops *ops;
+       const struct x86_emulate_ops *ops;
 
        /* Register state before/after emulation. */
        unsigned long eflags;
        unsigned long eip; /* eip before instruction emulation */
        /* Emulated execution mode, represented by an X86EMUL_MODE value. */
-       int mode;
+       enum x86emul_mode mode;
 
        /* interruptibility state, as a result of execution of STI or MOV SS */
        int interruptibility;
 
        bool guest_mode; /* guest running a nested guest */
        bool perm_ok; /* do not check permissions if true */
-       bool only_vendor_specific_insn;
+       bool ud;        /* inject an #UD if host doesn't support insn */
 
        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;
@@ -281,8 +309,10 @@ struct x86_emulate_ctxt {
        bool rip_relative;
        unsigned long _eip;
        struct operand memop;
+       u32 regs_valid;  /* bitmaps of registers in _regs[] that can be read */
+       u32 regs_dirty;  /* bitmaps of registers in _regs[] that have been written */
        /* Fields above regs are cleared together. */
-       unsigned long regs[NR_VCPU_REGS];
+       unsigned long _regs[NR_VCPU_REGS];
        struct operand *memopp;
        struct fetch_cache fetch;
        struct read_cache io_read;
@@ -293,17 +323,6 @@ struct x86_emulate_ctxt {
 #define REPE_PREFIX    0xf3
 #define REPNE_PREFIX   0xf2
 
-/* Execution mode, passed to the emulator. */
-#define X86EMUL_MODE_REAL     0        /* Real mode.             */
-#define X86EMUL_MODE_VM86     1        /* Virtual 8086 mode.     */
-#define X86EMUL_MODE_PROT16   2        /* 16-bit protected mode. */
-#define X86EMUL_MODE_PROT32   4        /* 32-bit protected mode. */
-#define X86EMUL_MODE_PROT64   8        /* 64-bit (long) mode.    */
-
-/* any protected mode   */
-#define X86EMUL_MODE_PROT     (X86EMUL_MODE_PROT16|X86EMUL_MODE_PROT32| \
-                              X86EMUL_MODE_PROT64)
-
 /* CPUID vendors */
 #define X86EMUL_CPUID_VENDOR_AuthenticAMD_ebx 0x68747541
 #define X86EMUL_CPUID_VENDOR_AuthenticAMD_ecx 0x444d4163
@@ -394,4 +413,7 @@ int emulator_task_switch(struct x86_emulate_ctxt *ctxt,
                         u16 tss_selector, int idt_index, int reason,
                         bool has_error_code, u32 error_code);
 int emulate_int_real(struct x86_emulate_ctxt *ctxt, int irq);
+void emulator_invalidate_register_cache(struct x86_emulate_ctxt *ctxt);
+void emulator_writeback_register_cache(struct x86_emulate_ctxt *ctxt);
+
 #endif /* _ASM_X86_KVM_X86_EMULATE_H */