Merge git://git.kernel.org/pub/scm/linux/kernel/git/lethal/fbdev-2.6
[cascardo/linux.git] / arch / x86 / include / asm / kvm_emulate.h
index 51cfd73..8e37deb 100644 (file)
 
 struct x86_emulate_ctxt;
 
+struct x86_exception {
+       u8 vector;
+       bool error_code_valid;
+       u16 error_code;
+       bool nested_page_fault;
+       u64 address; /* cr2 or nested page fault gpa */
+};
+
 /*
  * x86_emulate_ops:
  *
@@ -64,7 +72,8 @@ struct x86_emulate_ops {
         *  @bytes: [IN ] Number of bytes to read from memory.
         */
        int (*read_std)(unsigned long addr, void *val,
-                       unsigned int bytes, struct kvm_vcpu *vcpu, u32 *error);
+                       unsigned int bytes, struct kvm_vcpu *vcpu,
+                       struct x86_exception *fault);
 
        /*
         * write_std: Write bytes of standard (non-emulated/special) memory.
@@ -74,7 +83,8 @@ struct x86_emulate_ops {
         *  @bytes: [IN ] Number of bytes to write to memory.
         */
        int (*write_std)(unsigned long addr, void *val,
-                        unsigned int bytes, struct kvm_vcpu *vcpu, u32 *error);
+                        unsigned int bytes, struct kvm_vcpu *vcpu,
+                        struct x86_exception *fault);
        /*
         * fetch: Read bytes of standard (non-emulated/special) memory.
         *        Used for instruction fetch.
@@ -83,7 +93,8 @@ struct x86_emulate_ops {
         *  @bytes: [IN ] Number of bytes to read from memory.
         */
        int (*fetch)(unsigned long addr, void *val,
-                       unsigned int bytes, struct kvm_vcpu *vcpu, u32 *error);
+                    unsigned int bytes, struct kvm_vcpu *vcpu,
+                    struct x86_exception *fault);
 
        /*
         * read_emulated: Read bytes from emulated/special memory area.
@@ -94,7 +105,7 @@ struct x86_emulate_ops {
        int (*read_emulated)(unsigned long addr,
                             void *val,
                             unsigned int bytes,
-                            unsigned int *error,
+                            struct x86_exception *fault,
                             struct kvm_vcpu *vcpu);
 
        /*
@@ -107,7 +118,7 @@ struct x86_emulate_ops {
        int (*write_emulated)(unsigned long addr,
                              const void *val,
                              unsigned int bytes,
-                             unsigned int *error,
+                             struct x86_exception *fault,
                              struct kvm_vcpu *vcpu);
 
        /*
@@ -122,7 +133,7 @@ struct x86_emulate_ops {
                                const void *old,
                                const void *new,
                                unsigned int bytes,
-                               unsigned int *error,
+                               struct x86_exception *fault,
                                struct kvm_vcpu *vcpu);
 
        int (*pio_in_emulated)(int size, unsigned short port, void *val,
@@ -139,6 +150,7 @@ struct x86_emulate_ops {
        void (*set_segment_selector)(u16 sel, int seg, struct kvm_vcpu *vcpu);
        unsigned long (*get_cached_segment_base)(int seg, struct kvm_vcpu *vcpu);
        void (*get_gdt)(struct desc_ptr *dt, struct kvm_vcpu *vcpu);
+       void (*get_idt)(struct desc_ptr *dt, struct kvm_vcpu *vcpu);
        ulong (*get_cr)(int cr, struct kvm_vcpu *vcpu);
        int (*set_cr)(int cr, ulong val, struct kvm_vcpu *vcpu);
        int (*cpl)(struct kvm_vcpu *vcpu);
@@ -152,9 +164,20 @@ struct x86_emulate_ops {
 struct operand {
        enum { OP_REG, OP_MEM, OP_IMM, OP_NONE } type;
        unsigned int bytes;
-       unsigned long orig_val, *ptr;
+       union {
+               unsigned long orig_val;
+               u64 orig_val64;
+       };
+       union {
+               unsigned long *reg;
+               struct segmented_address {
+                       ulong ea;
+                       unsigned seg;
+               } mem;
+       } addr;
        union {
                unsigned long val;
+               u64 val64;
                char valptr[sizeof(unsigned long) + 2];
        };
 };
@@ -185,6 +208,7 @@ struct decode_cache {
        bool has_seg_override;
        u8 seg_override;
        unsigned int d;
+       int (*execute)(struct x86_emulate_ctxt *ctxt);
        unsigned long regs[NR_VCPU_REGS];
        unsigned long eip;
        /* modrm */
@@ -192,17 +216,16 @@ struct decode_cache {
        u8 modrm_mod;
        u8 modrm_reg;
        u8 modrm_rm;
-       u8 use_modrm_ea;
+       u8 modrm_seg;
        bool rip_relative;
-       unsigned long modrm_ea;
-       void *modrm_ptr;
-       unsigned long modrm_val;
        struct fetch_cache fetch;
        struct read_cache io_read;
        struct read_cache mem_read;
 };
 
 struct x86_emulate_ctxt {
+       struct x86_emulate_ops *ops;
+
        /* Register state before/after emulation. */
        struct kvm_vcpu *vcpu;
 
@@ -215,12 +238,10 @@ struct x86_emulate_ctxt {
        /* interruptibility state, as a result of execution of STI or MOV SS */
        int interruptibility;
 
-       bool restart; /* restart string instruction after writeback */
+       bool perm_ok; /* do not check permissions if true */
 
-       int exception; /* exception that happens during emulation or -1 */
-       u32 error_code; /* error code for exception */
-       bool error_code_valid;
-       unsigned long cr2; /* faulted address in case of #PF */
+       bool have_exception;
+       struct x86_exception exception;
 
        /* decode cache */
        struct decode_cache decode;
@@ -244,13 +265,14 @@ struct x86_emulate_ctxt {
 #define X86EMUL_MODE_HOST X86EMUL_MODE_PROT64
 #endif
 
-int x86_decode_insn(struct x86_emulate_ctxt *ctxt,
-                   struct x86_emulate_ops *ops);
-int x86_emulate_insn(struct x86_emulate_ctxt *ctxt,
-                    struct x86_emulate_ops *ops);
+int x86_decode_insn(struct x86_emulate_ctxt *ctxt, void *insn, int insn_len);
+#define EMULATION_FAILED -1
+#define EMULATION_OK 0
+#define EMULATION_RESTART 1
+int x86_emulate_insn(struct x86_emulate_ctxt *ctxt);
 int emulator_task_switch(struct x86_emulate_ctxt *ctxt,
-                        struct x86_emulate_ops *ops,
                         u16 tss_selector, int reason,
                         bool has_error_code, u32 error_code);
-
+int emulate_int_real(struct x86_emulate_ctxt *ctxt,
+                    struct x86_emulate_ops *ops, int irq);
 #endif /* _ASM_X86_KVM_X86_EMULATE_H */