~ubuntu-branches/ubuntu/quantal/linux-linaro-mx51/quantal

« back to all changes in this revision

Viewing changes to arch/x86/include/asm/kvm_emulate.h

  • Committer: Package Import Robot
  • Author(s): John Rigby, John Rigby
  • Date: 2011-09-26 10:44:23 UTC
  • Revision ID: package-import@ubuntu.com-20110926104423-3o58a3c1bj7x00rs
Tags: 3.0.0-1007.9
[ John Rigby ]

Enable crypto modules and remove crypto-modules from
exclude-module files
LP: #826021

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
#include <asm/desc_defs.h>
15
15
 
16
16
struct x86_emulate_ctxt;
 
17
enum x86_intercept;
 
18
enum x86_intercept_stage;
17
19
 
18
20
struct x86_exception {
19
21
        u8 vector;
24
26
};
25
27
 
26
28
/*
 
29
 * This struct is used to carry enough information from the instruction
 
30
 * decoder to main KVM so that a decision can be made whether the
 
31
 * instruction needs to be intercepted or not.
 
32
 */
 
33
struct x86_instruction_info {
 
34
        u8  intercept;          /* which intercept                      */
 
35
        u8  rep_prefix;         /* rep prefix?                          */
 
36
        u8  modrm_mod;          /* mod part of modrm                    */
 
37
        u8  modrm_reg;          /* index of register used               */
 
38
        u8  modrm_rm;           /* rm part of modrm                     */
 
39
        u64 src_val;            /* value of source operand              */
 
40
        u8  src_bytes;          /* size of source operand               */
 
41
        u8  dst_bytes;          /* size of destination operand          */
 
42
        u8  ad_bytes;           /* size of src/dst address              */
 
43
        u64 next_rip;           /* rip following the instruction        */
 
44
};
 
45
 
 
46
/*
27
47
 * x86_emulate_ops:
28
48
 *
29
49
 * These operations represent the instruction emulator's interface to memory.
62
82
#define X86EMUL_RETRY_INSTR     3 /* retry the instruction for some reason */
63
83
#define X86EMUL_CMPXCHG_FAILED  4 /* cmpxchg did not see expected value */
64
84
#define X86EMUL_IO_NEEDED       5 /* IO is needed to complete emulation */
 
85
#define X86EMUL_INTERCEPTED     6 /* Intercepted by nested VMCB/VMCS */
65
86
 
66
87
struct x86_emulate_ops {
67
88
        /*
71
92
         *  @val:   [OUT] Value read from memory, zero-extended to 'u_long'.
72
93
         *  @bytes: [IN ] Number of bytes to read from memory.
73
94
         */
74
 
        int (*read_std)(unsigned long addr, void *val,
75
 
                        unsigned int bytes, struct kvm_vcpu *vcpu,
 
95
        int (*read_std)(struct x86_emulate_ctxt *ctxt,
 
96
                        unsigned long addr, void *val,
 
97
                        unsigned int bytes,
76
98
                        struct x86_exception *fault);
77
99
 
78
100
        /*
82
104
         *  @val:   [OUT] Value write to memory, zero-extended to 'u_long'.
83
105
         *  @bytes: [IN ] Number of bytes to write to memory.
84
106
         */
85
 
        int (*write_std)(unsigned long addr, void *val,
86
 
                         unsigned int bytes, struct kvm_vcpu *vcpu,
 
107
        int (*write_std)(struct x86_emulate_ctxt *ctxt,
 
108
                         unsigned long addr, void *val, unsigned int bytes,
87
109
                         struct x86_exception *fault);
88
110
        /*
89
111
         * fetch: Read bytes of standard (non-emulated/special) memory.
92
114
         *  @val:   [OUT] Value read from memory, zero-extended to 'u_long'.
93
115
         *  @bytes: [IN ] Number of bytes to read from memory.
94
116
         */
95
 
        int (*fetch)(unsigned long addr, void *val,
96
 
                     unsigned int bytes, struct kvm_vcpu *vcpu,
 
117
        int (*fetch)(struct x86_emulate_ctxt *ctxt,
 
118
                     unsigned long addr, void *val, unsigned int bytes,
97
119
                     struct x86_exception *fault);
98
120
 
99
121
        /*
102
124
         *  @val:   [OUT] Value read from memory, zero-extended to 'u_long'.
103
125
         *  @bytes: [IN ] Number of bytes to read from memory.
104
126
         */
105
 
        int (*read_emulated)(unsigned long addr,
106
 
                             void *val,
107
 
                             unsigned int bytes,
108
 
                             struct x86_exception *fault,
109
 
                             struct kvm_vcpu *vcpu);
 
127
        int (*read_emulated)(struct x86_emulate_ctxt *ctxt,
 
128
                             unsigned long addr, void *val, unsigned int bytes,
 
129
                             struct x86_exception *fault);
110
130
 
111
131
        /*
112
132
         * write_emulated: Write bytes to emulated/special memory area.
115
135
         *                required).
116
136
         *  @bytes: [IN ] Number of bytes to write to memory.
117
137
         */
118
 
        int (*write_emulated)(unsigned long addr,
119
 
                              const void *val,
 
138
        int (*write_emulated)(struct x86_emulate_ctxt *ctxt,
 
139
                              unsigned long addr, const void *val,
120
140
                              unsigned int bytes,
121
 
                              struct x86_exception *fault,
122
 
                              struct kvm_vcpu *vcpu);
 
141
                              struct x86_exception *fault);
123
142
 
124
143
        /*
125
144
         * cmpxchg_emulated: Emulate an atomic (LOCKed) CMPXCHG operation on an
129
148
         *  @new:   [IN ] Value to write to @addr.
130
149
         *  @bytes: [IN ] Number of bytes to access using CMPXCHG.
131
150
         */
132
 
        int (*cmpxchg_emulated)(unsigned long addr,
 
151
        int (*cmpxchg_emulated)(struct x86_emulate_ctxt *ctxt,
 
152
                                unsigned long addr,
133
153
                                const void *old,
134
154
                                const void *new,
135
155
                                unsigned int bytes,
136
 
                                struct x86_exception *fault,
137
 
                                struct kvm_vcpu *vcpu);
138
 
 
139
 
        int (*pio_in_emulated)(int size, unsigned short port, void *val,
140
 
                               unsigned int count, struct kvm_vcpu *vcpu);
141
 
 
142
 
        int (*pio_out_emulated)(int size, unsigned short port, const void *val,
143
 
                                unsigned int count, struct kvm_vcpu *vcpu);
144
 
 
145
 
        bool (*get_cached_descriptor)(struct desc_struct *desc, u32 *base3,
146
 
                                      int seg, struct kvm_vcpu *vcpu);
147
 
        void (*set_cached_descriptor)(struct desc_struct *desc, u32 base3,
148
 
                                      int seg, struct kvm_vcpu *vcpu);
149
 
        u16 (*get_segment_selector)(int seg, struct kvm_vcpu *vcpu);
150
 
        void (*set_segment_selector)(u16 sel, int seg, struct kvm_vcpu *vcpu);
151
 
        unsigned long (*get_cached_segment_base)(int seg, struct kvm_vcpu *vcpu);
152
 
        void (*get_gdt)(struct desc_ptr *dt, struct kvm_vcpu *vcpu);
153
 
        void (*get_idt)(struct desc_ptr *dt, struct kvm_vcpu *vcpu);
154
 
        ulong (*get_cr)(int cr, struct kvm_vcpu *vcpu);
155
 
        int (*set_cr)(int cr, ulong val, struct kvm_vcpu *vcpu);
156
 
        int (*cpl)(struct kvm_vcpu *vcpu);
157
 
        int (*get_dr)(int dr, unsigned long *dest, struct kvm_vcpu *vcpu);
158
 
        int (*set_dr)(int dr, unsigned long value, struct kvm_vcpu *vcpu);
159
 
        int (*set_msr)(struct kvm_vcpu *vcpu, u32 msr_index, u64 data);
160
 
        int (*get_msr)(struct kvm_vcpu *vcpu, u32 msr_index, u64 *pdata);
 
156
                                struct x86_exception *fault);
 
157
        void (*invlpg)(struct x86_emulate_ctxt *ctxt, ulong addr);
 
158
 
 
159
        int (*pio_in_emulated)(struct x86_emulate_ctxt *ctxt,
 
160
                               int size, unsigned short port, void *val,
 
161
                               unsigned int count);
 
162
 
 
163
        int (*pio_out_emulated)(struct x86_emulate_ctxt *ctxt,
 
164
                                int size, unsigned short port, const void *val,
 
165
                                unsigned int count);
 
166
 
 
167
        bool (*get_segment)(struct x86_emulate_ctxt *ctxt, u16 *selector,
 
168
                            struct desc_struct *desc, u32 *base3, int seg);
 
169
        void (*set_segment)(struct x86_emulate_ctxt *ctxt, u16 selector,
 
170
                            struct desc_struct *desc, u32 base3, int seg);
 
171
        unsigned long (*get_cached_segment_base)(struct x86_emulate_ctxt *ctxt,
 
172
                                                 int seg);
 
173
        void (*get_gdt)(struct x86_emulate_ctxt *ctxt, struct desc_ptr *dt);
 
174
        void (*get_idt)(struct x86_emulate_ctxt *ctxt, struct desc_ptr *dt);
 
175
        void (*set_gdt)(struct x86_emulate_ctxt *ctxt, struct desc_ptr *dt);
 
176
        void (*set_idt)(struct x86_emulate_ctxt *ctxt, struct desc_ptr *dt);
 
177
        ulong (*get_cr)(struct x86_emulate_ctxt *ctxt, int cr);
 
178
        int (*set_cr)(struct x86_emulate_ctxt *ctxt, int cr, ulong val);
 
179
        int (*cpl)(struct x86_emulate_ctxt *ctxt);
 
180
        int (*get_dr)(struct x86_emulate_ctxt *ctxt, int dr, ulong *dest);
 
181
        int (*set_dr)(struct x86_emulate_ctxt *ctxt, int dr, ulong value);
 
182
        int (*set_msr)(struct x86_emulate_ctxt *ctxt, u32 msr_index, u64 data);
 
183
        int (*get_msr)(struct x86_emulate_ctxt *ctxt, u32 msr_index, u64 *pdata);
 
184
        void (*halt)(struct x86_emulate_ctxt *ctxt);
 
185
        void (*wbinvd)(struct x86_emulate_ctxt *ctxt);
 
186
        int (*fix_hypercall)(struct x86_emulate_ctxt *ctxt);
 
187
        void (*get_fpu)(struct x86_emulate_ctxt *ctxt); /* disables preempt */
 
188
        void (*put_fpu)(struct x86_emulate_ctxt *ctxt); /* reenables preempt */
 
189
        int (*intercept)(struct x86_emulate_ctxt *ctxt,
 
190
                         struct x86_instruction_info *info,
 
191
                         enum x86_intercept_stage stage);
161
192
};
162
193
 
 
194
typedef u32 __attribute__((vector_size(16))) sse128_t;
 
195
 
163
196
/* Type, address-of, and value of an instruction's operand. */
164
197
struct operand {
165
 
        enum { OP_REG, OP_MEM, OP_IMM, OP_NONE } type;
 
198
        enum { OP_REG, OP_MEM, OP_IMM, OP_XMM, OP_NONE } type;
166
199
        unsigned int bytes;
167
200
        union {
168
201
                unsigned long orig_val;
174
207
                        ulong ea;
175
208
                        unsigned seg;
176
209
                } mem;
 
210
                unsigned xmm;
177
211
        } addr;
178
212
        union {
179
213
                unsigned long val;
180
214
                u64 val64;
181
215
                char valptr[sizeof(unsigned long) + 2];
 
216
                sse128_t vec_val;
182
217
        };
183
218
};
184
219
 
197
232
struct decode_cache {
198
233
        u8 twobyte;
199
234
        u8 b;
 
235
        u8 intercept;
200
236
        u8 lock_prefix;
201
237
        u8 rep_prefix;
202
238
        u8 op_bytes;
209
245
        u8 seg_override;
210
246
        unsigned int d;
211
247
        int (*execute)(struct x86_emulate_ctxt *ctxt);
 
248
        int (*check_perm)(struct x86_emulate_ctxt *ctxt);
212
249
        unsigned long regs[NR_VCPU_REGS];
213
250
        unsigned long eip;
214
251
        /* modrm */
227
264
        struct x86_emulate_ops *ops;
228
265
 
229
266
        /* Register state before/after emulation. */
230
 
        struct kvm_vcpu *vcpu;
231
 
 
232
267
        unsigned long eflags;
233
268
        unsigned long eip; /* eip before instruction emulation */
234
269
        /* Emulated execution mode, represented by an X86EMUL_MODE value. */
235
270
        int mode;
236
 
        u32 cs_base;
237
271
 
238
272
        /* interruptibility state, as a result of execution of STI or MOV SS */
239
273
        int interruptibility;
240
274
 
 
275
        bool guest_mode; /* guest running a nested guest */
241
276
        bool perm_ok; /* do not check permissions if true */
242
277
        bool only_vendor_specific_insn;
243
278
 
249
284
};
250
285
 
251
286
/* Repeat String Operation Prefix */
252
 
#define REPE_PREFIX     1
253
 
#define REPNE_PREFIX    2
 
287
#define REPE_PREFIX     0xf3
 
288
#define REPNE_PREFIX    0xf2
254
289
 
255
290
/* Execution mode, passed to the emulator. */
256
291
#define X86EMUL_MODE_REAL     0 /* Real mode.             */
259
294
#define X86EMUL_MODE_PROT32   4 /* 32-bit protected mode. */
260
295
#define X86EMUL_MODE_PROT64   8 /* 64-bit (long) mode.    */
261
296
 
 
297
/* any protected mode   */
 
298
#define X86EMUL_MODE_PROT     (X86EMUL_MODE_PROT16|X86EMUL_MODE_PROT32| \
 
299
                               X86EMUL_MODE_PROT64)
 
300
 
 
301
enum x86_intercept_stage {
 
302
        X86_ICTP_NONE = 0,   /* Allow zero-init to not match anything */
 
303
        X86_ICPT_PRE_EXCEPT,
 
304
        X86_ICPT_POST_EXCEPT,
 
305
        X86_ICPT_POST_MEMACCESS,
 
306
};
 
307
 
 
308
enum x86_intercept {
 
309
        x86_intercept_none,
 
310
        x86_intercept_cr_read,
 
311
        x86_intercept_cr_write,
 
312
        x86_intercept_clts,
 
313
        x86_intercept_lmsw,
 
314
        x86_intercept_smsw,
 
315
        x86_intercept_dr_read,
 
316
        x86_intercept_dr_write,
 
317
        x86_intercept_lidt,
 
318
        x86_intercept_sidt,
 
319
        x86_intercept_lgdt,
 
320
        x86_intercept_sgdt,
 
321
        x86_intercept_lldt,
 
322
        x86_intercept_sldt,
 
323
        x86_intercept_ltr,
 
324
        x86_intercept_str,
 
325
        x86_intercept_rdtsc,
 
326
        x86_intercept_rdpmc,
 
327
        x86_intercept_pushf,
 
328
        x86_intercept_popf,
 
329
        x86_intercept_cpuid,
 
330
        x86_intercept_rsm,
 
331
        x86_intercept_iret,
 
332
        x86_intercept_intn,
 
333
        x86_intercept_invd,
 
334
        x86_intercept_pause,
 
335
        x86_intercept_hlt,
 
336
        x86_intercept_invlpg,
 
337
        x86_intercept_invlpga,
 
338
        x86_intercept_vmrun,
 
339
        x86_intercept_vmload,
 
340
        x86_intercept_vmsave,
 
341
        x86_intercept_vmmcall,
 
342
        x86_intercept_stgi,
 
343
        x86_intercept_clgi,
 
344
        x86_intercept_skinit,
 
345
        x86_intercept_rdtscp,
 
346
        x86_intercept_icebp,
 
347
        x86_intercept_wbinvd,
 
348
        x86_intercept_monitor,
 
349
        x86_intercept_mwait,
 
350
        x86_intercept_rdmsr,
 
351
        x86_intercept_wrmsr,
 
352
        x86_intercept_in,
 
353
        x86_intercept_ins,
 
354
        x86_intercept_out,
 
355
        x86_intercept_outs,
 
356
 
 
357
        nr_x86_intercepts
 
358
};
 
359
 
262
360
/* Host execution mode. */
263
361
#if defined(CONFIG_X86_32)
264
362
#define X86EMUL_MODE_HOST X86EMUL_MODE_PROT32
270
368
#define EMULATION_FAILED -1
271
369
#define EMULATION_OK 0
272
370
#define EMULATION_RESTART 1
 
371
#define EMULATION_INTERCEPTED 2
273
372
int x86_emulate_insn(struct x86_emulate_ctxt *ctxt);
274
373
int emulator_task_switch(struct x86_emulate_ctxt *ctxt,
275
374
                         u16 tss_selector, int reason,