KVM: x86: Push potential exception error code on task switches
[safe/jmp/linux-2.6] / arch / x86 / include / asm / kvm_emulate.h
index 2666d7a..0b2729b 100644 (file)
@@ -11,6 +11,8 @@
 #ifndef _ASM_X86_KVM_X86_EMULATE_H
 #define _ASM_X86_KVM_X86_EMULATE_H
 
+#include <asm/desc_defs.h>
+
 struct x86_emulate_ctxt;
 
 /*
@@ -63,6 +65,15 @@ struct x86_emulate_ops {
                        unsigned int bytes, struct kvm_vcpu *vcpu, u32 *error);
 
        /*
+        * write_std: Write bytes of standard (non-emulated/special) memory.
+        *            Used for descriptor writing.
+        *  @addr:  [IN ] Linear address to which to write.
+        *  @val:   [OUT] Value write to memory, zero-extended to 'u_long'.
+        *  @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);
+       /*
         * fetch: Read bytes of standard (non-emulated/special) memory.
         *        Used for instruction fetch.
         *  @addr:  [IN ] Linear address from which to read.
@@ -109,6 +120,23 @@ struct x86_emulate_ops {
                                unsigned int bytes,
                                struct kvm_vcpu *vcpu);
 
+       int (*pio_in_emulated)(int size, unsigned short port, void *val,
+                              unsigned int count, struct kvm_vcpu *vcpu);
+
+       int (*pio_out_emulated)(int size, unsigned short port, const void *val,
+                               unsigned int count, struct kvm_vcpu *vcpu);
+
+       bool (*get_cached_descriptor)(struct desc_struct *desc,
+                                     int seg, struct kvm_vcpu *vcpu);
+       void (*set_cached_descriptor)(struct desc_struct *desc,
+                                     int seg, struct kvm_vcpu *vcpu);
+       u16 (*get_segment_selector)(int seg, struct kvm_vcpu *vcpu);
+       void (*set_segment_selector)(u16 sel, int seg, struct kvm_vcpu *vcpu);
+       void (*get_gdt)(struct desc_ptr *dt, struct kvm_vcpu *vcpu);
+       ulong (*get_cr)(int cr, struct kvm_vcpu *vcpu);
+       void (*set_cr)(int cr, ulong val, struct kvm_vcpu *vcpu);
+       int (*cpl)(struct kvm_vcpu *vcpu);
+       void (*set_rflags)(struct kvm_vcpu *vcpu, unsigned long rflags);
 };
 
 /* Type, address-of, and value of an instruction's operand. */
@@ -124,6 +152,12 @@ struct fetch_cache {
        unsigned long end;
 };
 
+struct read_cache {
+       u8 data[1024];
+       unsigned long pos;
+       unsigned long end;
+};
+
 struct decode_cache {
        u8 twobyte;
        u8 b;
@@ -139,7 +173,7 @@ struct decode_cache {
        u8 seg_override;
        unsigned int d;
        unsigned long regs[NR_VCPU_REGS];
-       unsigned long eip, eip_orig;
+       unsigned long eip;
        /* modrm */
        u8 modrm;
        u8 modrm_mod;
@@ -151,6 +185,7 @@ struct decode_cache {
        void *modrm_ptr;
        unsigned long modrm_val;
        struct fetch_cache fetch;
+       struct read_cache io_read;
 };
 
 struct x86_emulate_ctxt {
@@ -158,6 +193,7 @@ struct x86_emulate_ctxt {
        struct kvm_vcpu *vcpu;
 
        unsigned long eflags;
+       unsigned long eip; /* eip before instruction emulation */
        /* Emulated execution mode, represented by an X86EMUL_MODE value. */
        int mode;
        u32 cs_base;
@@ -165,6 +201,7 @@ 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 */
        /* decode cache */
        struct decode_cache decode;
 };
@@ -191,5 +228,9 @@ 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 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);
 
 #endif /* _ASM_X86_KVM_X86_EMULATE_H */