ia64/xen-unstable

view xen/include/asm-x86/processor.h @ 15812:86a154e1ef5d

[HVM] Shadow: don't shadow the p2m table.
For HVM vcpus with paging disabled, we used to shadow the p2m table,
and skip the p2m lookup to go from gfn to mfn. Instead, we now
provide a simple pagetable that gives a one-to-one mapping of 4GB, and
shadow that, making the translations from gfn to mfn via the p2m.
This removes the paging-disabled special-case code from the shadow
fault handler, and allows us to expand the p2m interface, since all HVM
translations now go through the same p2m lookups.
Signed-off-by: Tim Deegan <Tim.Deegan@xensource.com>
author Tim Deegan <Tim.Deegan@xensource.com>
date Fri Aug 31 11:06:22 2007 +0100 (2007-08-31)
parents 9554ec3e27cd
children 5ccf8bbf8628
line source
2 /* Portions are: Copyright (c) 1994 Linus Torvalds */
4 #ifndef __ASM_X86_PROCESSOR_H
5 #define __ASM_X86_PROCESSOR_H
7 #ifndef __ASSEMBLY__
8 #include <xen/config.h>
9 #include <xen/cache.h>
10 #include <xen/types.h>
11 #include <public/xen.h>
12 #include <asm/types.h>
13 #include <asm/cpufeature.h>
14 #include <asm/desc.h>
15 #endif
17 /*
18 * CPU vendor IDs
19 */
20 #define X86_VENDOR_INTEL 0
21 #define X86_VENDOR_CYRIX 1
22 #define X86_VENDOR_AMD 2
23 #define X86_VENDOR_UMC 3
24 #define X86_VENDOR_NEXGEN 4
25 #define X86_VENDOR_CENTAUR 5
26 #define X86_VENDOR_RISE 6
27 #define X86_VENDOR_TRANSMETA 7
28 #define X86_VENDOR_NSC 8
29 #define X86_VENDOR_NUM 9
30 #define X86_VENDOR_UNKNOWN 0xff
32 /*
33 * EFLAGS bits
34 */
35 #define X86_EFLAGS_CF 0x00000001 /* Carry Flag */
36 #define X86_EFLAGS_PF 0x00000004 /* Parity Flag */
37 #define X86_EFLAGS_AF 0x00000010 /* Auxillary carry Flag */
38 #define X86_EFLAGS_ZF 0x00000040 /* Zero Flag */
39 #define X86_EFLAGS_SF 0x00000080 /* Sign Flag */
40 #define X86_EFLAGS_TF 0x00000100 /* Trap Flag */
41 #define X86_EFLAGS_IF 0x00000200 /* Interrupt Flag */
42 #define X86_EFLAGS_DF 0x00000400 /* Direction Flag */
43 #define X86_EFLAGS_OF 0x00000800 /* Overflow Flag */
44 #define X86_EFLAGS_IOPL 0x00003000 /* IOPL mask */
45 #define X86_EFLAGS_NT 0x00004000 /* Nested Task */
46 #define X86_EFLAGS_RF 0x00010000 /* Resume Flag */
47 #define X86_EFLAGS_VM 0x00020000 /* Virtual Mode */
48 #define X86_EFLAGS_AC 0x00040000 /* Alignment Check */
49 #define X86_EFLAGS_VIF 0x00080000 /* Virtual Interrupt Flag */
50 #define X86_EFLAGS_VIP 0x00100000 /* Virtual Interrupt Pending */
51 #define X86_EFLAGS_ID 0x00200000 /* CPUID detection flag */
53 /*
54 * Intel CPU flags in CR0
55 */
56 #define X86_CR0_PE 0x00000001 /* Enable Protected Mode (RW) */
57 #define X86_CR0_MP 0x00000002 /* Monitor Coprocessor (RW) */
58 #define X86_CR0_EM 0x00000004 /* Require FPU Emulation (RO) */
59 #define X86_CR0_TS 0x00000008 /* Task Switched (RW) */
60 #define X86_CR0_ET 0x00000010 /* Extension type (RO) */
61 #define X86_CR0_NE 0x00000020 /* Numeric Error Reporting (RW) */
62 #define X86_CR0_WP 0x00010000 /* Supervisor Write Protect (RW) */
63 #define X86_CR0_AM 0x00040000 /* Alignment Checking (RW) */
64 #define X86_CR0_NW 0x20000000 /* Not Write-Through (RW) */
65 #define X86_CR0_CD 0x40000000 /* Cache Disable (RW) */
66 #define X86_CR0_PG 0x80000000 /* Paging (RW) */
68 /*
69 * Intel CPU features in CR4
70 */
71 #define X86_CR4_VME 0x0001 /* enable vm86 extensions */
72 #define X86_CR4_PVI 0x0002 /* virtual interrupts flag enable */
73 #define X86_CR4_TSD 0x0004 /* disable time stamp at ipl 3 */
74 #define X86_CR4_DE 0x0008 /* enable debugging extensions */
75 #define X86_CR4_PSE 0x0010 /* enable page size extensions */
76 #define X86_CR4_PAE 0x0020 /* enable physical address extensions */
77 #define X86_CR4_MCE 0x0040 /* Machine check enable */
78 #define X86_CR4_PGE 0x0080 /* enable global pages */
79 #define X86_CR4_PCE 0x0100 /* enable performance counters at ipl 3 */
80 #define X86_CR4_OSFXSR 0x0200 /* enable fast FPU save and restore */
81 #define X86_CR4_OSXMMEXCPT 0x0400 /* enable unmasked SSE exceptions */
82 #define X86_CR4_VMXE 0x2000 /* enable VMX */
83 #define X86_CR4_SMXE 0x4000 /* enable SMX */
85 /*
86 * Trap/fault mnemonics.
87 */
88 #define TRAP_divide_error 0
89 #define TRAP_debug 1
90 #define TRAP_nmi 2
91 #define TRAP_int3 3
92 #define TRAP_overflow 4
93 #define TRAP_bounds 5
94 #define TRAP_invalid_op 6
95 #define TRAP_no_device 7
96 #define TRAP_double_fault 8
97 #define TRAP_copro_seg 9
98 #define TRAP_invalid_tss 10
99 #define TRAP_no_segment 11
100 #define TRAP_stack_error 12
101 #define TRAP_gp_fault 13
102 #define TRAP_page_fault 14
103 #define TRAP_spurious_int 15
104 #define TRAP_copro_error 16
105 #define TRAP_alignment_check 17
106 #define TRAP_machine_check 18
107 #define TRAP_simd_error 19
109 /* Set for entry via SYSCALL. Informs return code to use SYSRETQ not IRETQ. */
110 /* NB. Same as VGCF_in_syscall. No bits in common with any other TRAP_ defn. */
111 #define TRAP_syscall 256
113 /*
114 * Non-fatal fault/trap handlers return an error code to the caller. If the
115 * code is non-zero, it means that either the exception was not due to a fault
116 * (i.e., it was a trap) or that the fault has been fixed up so the instruction
117 * replay ought to succeed.
118 */
119 #define EXCRET_not_a_fault 1 /* It was a trap. No instruction replay needed. */
120 #define EXCRET_fault_fixed 1 /* It was fault that we fixed: try a replay. */
122 /* 'trap_bounce' flags values */
123 #define TBF_EXCEPTION 1
124 #define TBF_EXCEPTION_ERRCODE 2
125 #define TBF_INTERRUPT 8
126 #define TBF_FAILSAFE 16
128 /* 'arch_vcpu' flags values */
129 #define _TF_kernel_mode 0
130 #define TF_kernel_mode (1<<_TF_kernel_mode)
132 /* #PF error code values. */
133 #define PFEC_page_present (1U<<0)
134 #define PFEC_write_access (1U<<1)
135 #define PFEC_user_mode (1U<<2)
136 #define PFEC_reserved_bit (1U<<3)
137 #define PFEC_insn_fetch (1U<<4)
139 #ifndef __ASSEMBLY__
141 struct domain;
142 struct vcpu;
144 /*
145 * Default implementation of macro that returns current
146 * instruction pointer ("program counter").
147 */
148 #ifdef __x86_64__
149 #define current_text_addr() ({ void *pc; asm volatile("leaq 1f(%%rip),%0\n1:":"=r"(pc)); pc; })
150 #else
151 #define current_text_addr() \
152 ({ void *pc; __asm__("movl $1f,%0\n1:":"=g" (pc)); pc; })
153 #endif
155 struct cpuinfo_x86 {
156 __u8 x86; /* CPU family */
157 __u8 x86_vendor; /* CPU vendor */
158 __u8 x86_model;
159 __u8 x86_mask;
160 char wp_works_ok; /* It doesn't on 386's */
161 char hlt_works_ok; /* Problems on some 486Dx4's and old 386's */
162 char hard_math;
163 char rfu;
164 int cpuid_level; /* Maximum supported CPUID level, -1=no CPUID */
165 unsigned int x86_capability[NCAPINTS];
166 char x86_vendor_id[16];
167 char x86_model_id[64];
168 int x86_cache_size; /* in KB - valid for CPUS which support this call */
169 int x86_cache_alignment; /* In bytes */
170 char fdiv_bug;
171 char f00f_bug;
172 char coma_bug;
173 char pad0;
174 int x86_power;
175 unsigned char x86_max_cores; /* cpuid returned max cores value */
176 unsigned char booted_cores; /* number of cores as seen by OS */
177 unsigned char apicid;
178 } __cacheline_aligned;
180 /*
181 * capabilities of CPUs
182 */
184 extern struct cpuinfo_x86 boot_cpu_data;
186 #ifdef CONFIG_SMP
187 extern struct cpuinfo_x86 cpu_data[];
188 #define current_cpu_data cpu_data[smp_processor_id()]
189 #else
190 #define cpu_data (&boot_cpu_data)
191 #define current_cpu_data boot_cpu_data
192 #endif
194 extern int phys_proc_id[NR_CPUS];
195 extern int cpu_core_id[NR_CPUS];
197 extern void identify_cpu(struct cpuinfo_x86 *);
198 extern void print_cpu_info(struct cpuinfo_x86 *);
199 extern unsigned int init_intel_cacheinfo(struct cpuinfo_x86 *c);
200 extern void dodgy_tsc(void);
202 #ifdef CONFIG_X86_HT
203 extern void detect_ht(struct cpuinfo_x86 *c);
204 #else
205 static always_inline void detect_ht(struct cpuinfo_x86 *c) {}
206 #endif
208 /*
209 * Generic CPUID function
210 * clear %ecx since some cpus (Cyrix MII) do not set or clear %ecx
211 * resulting in stale register contents being returned.
212 */
213 #define cpuid(_op,_eax,_ebx,_ecx,_edx) \
214 __asm__("cpuid" \
215 : "=a" (*(int *)(_eax)), \
216 "=b" (*(int *)(_ebx)), \
217 "=c" (*(int *)(_ecx)), \
218 "=d" (*(int *)(_edx)) \
219 : "0" (_op), "2" (0))
221 /* Some CPUID calls want 'count' to be placed in ecx */
222 static inline void cpuid_count(
223 int op,
224 int count,
225 unsigned int *eax,
226 unsigned int *ebx,
227 unsigned int *ecx,
228 unsigned int *edx)
229 {
230 __asm__("cpuid"
231 : "=a" (*eax), "=b" (*ebx), "=c" (*ecx), "=d" (*edx)
232 : "0" (op), "c" (count));
233 }
235 /*
236 * CPUID functions returning a single datum
237 */
238 static always_inline unsigned int cpuid_eax(unsigned int op)
239 {
240 unsigned int eax;
242 __asm__("cpuid"
243 : "=a" (eax)
244 : "0" (op)
245 : "bx", "cx", "dx");
246 return eax;
247 }
248 static always_inline unsigned int cpuid_ebx(unsigned int op)
249 {
250 unsigned int eax, ebx;
252 __asm__("cpuid"
253 : "=a" (eax), "=b" (ebx)
254 : "0" (op)
255 : "cx", "dx" );
256 return ebx;
257 }
258 static always_inline unsigned int cpuid_ecx(unsigned int op)
259 {
260 unsigned int eax, ecx;
262 __asm__("cpuid"
263 : "=a" (eax), "=c" (ecx)
264 : "0" (op)
265 : "bx", "dx" );
266 return ecx;
267 }
268 static always_inline unsigned int cpuid_edx(unsigned int op)
269 {
270 unsigned int eax, edx;
272 __asm__("cpuid"
273 : "=a" (eax), "=d" (edx)
274 : "0" (op)
275 : "bx", "cx");
276 return edx;
277 }
281 static inline unsigned long read_cr0(void)
282 {
283 unsigned long __cr0;
284 __asm__("mov %%cr0,%0\n\t" :"=r" (__cr0));
285 return __cr0;
286 }
288 static inline void write_cr0(unsigned long val)
289 {
290 __asm__("mov %0,%%cr0": :"r" ((unsigned long)val));
291 }
293 static inline unsigned long read_cr2(void)
294 {
295 unsigned long __cr2;
296 __asm__("mov %%cr2,%0\n\t" :"=r" (__cr2));
297 return __cr2;
298 }
300 static inline unsigned long read_cr4(void)
301 {
302 unsigned long __cr4;
303 __asm__("mov %%cr4,%0\n\t" :"=r" (__cr4));
304 return __cr4;
305 }
307 static inline void write_cr4(unsigned long val)
308 {
309 __asm__("mov %0,%%cr4": :"r" ((unsigned long)val));
310 }
313 /* Clear and set 'TS' bit respectively */
314 static inline void clts(void)
315 {
316 __asm__ __volatile__ ("clts");
317 }
319 static inline void stts(void)
320 {
321 write_cr0(X86_CR0_TS|read_cr0());
322 }
325 /*
326 * Save the cr4 feature set we're using (ie
327 * Pentium 4MB enable and PPro Global page
328 * enable), so that any CPU's that boot up
329 * after us can get the correct flags.
330 */
331 extern unsigned long mmu_cr4_features;
333 static always_inline void set_in_cr4 (unsigned long mask)
334 {
335 mmu_cr4_features |= mask;
336 write_cr4(mmu_cr4_features);
337 }
339 /*
340 * NSC/Cyrix CPU configuration register indexes
341 */
343 #define CX86_PCR0 0x20
344 #define CX86_GCR 0xb8
345 #define CX86_CCR0 0xc0
346 #define CX86_CCR1 0xc1
347 #define CX86_CCR2 0xc2
348 #define CX86_CCR3 0xc3
349 #define CX86_CCR4 0xe8
350 #define CX86_CCR5 0xe9
351 #define CX86_CCR6 0xea
352 #define CX86_CCR7 0xeb
353 #define CX86_PCR1 0xf0
354 #define CX86_DIR0 0xfe
355 #define CX86_DIR1 0xff
356 #define CX86_ARR_BASE 0xc4
357 #define CX86_RCR_BASE 0xdc
359 /*
360 * NSC/Cyrix CPU indexed register access macros
361 */
363 #define getCx86(reg) ({ outb((reg), 0x22); inb(0x23); })
365 #define setCx86(reg, data) do { \
366 outb((reg), 0x22); \
367 outb((data), 0x23); \
368 } while (0)
370 /* Stop speculative execution */
371 static inline void sync_core(void)
372 {
373 int tmp;
374 asm volatile("cpuid" : "=a" (tmp) : "0" (1) : "ebx","ecx","edx","memory");
375 }
377 static always_inline void __monitor(const void *eax, unsigned long ecx,
378 unsigned long edx)
379 {
380 /* "monitor %eax,%ecx,%edx;" */
381 asm volatile(
382 ".byte 0x0f,0x01,0xc8;"
383 : :"a" (eax), "c" (ecx), "d"(edx));
384 }
386 static always_inline void __mwait(unsigned long eax, unsigned long ecx)
387 {
388 /* "mwait %eax,%ecx;" */
389 asm volatile(
390 ".byte 0x0f,0x01,0xc9;"
391 : :"a" (eax), "c" (ecx));
392 }
394 #define IOBMP_BYTES 8192
395 #define IOBMP_INVALID_OFFSET 0x8000
397 struct tss_struct {
398 unsigned short back_link,__blh;
399 #ifdef __x86_64__
400 union { u64 rsp0, esp0; };
401 union { u64 rsp1, esp1; };
402 union { u64 rsp2, esp2; };
403 u64 reserved1;
404 u64 ist[7];
405 u64 reserved2;
406 u16 reserved3;
407 #else
408 u32 esp0;
409 u16 ss0,__ss0h;
410 u32 esp1;
411 u16 ss1,__ss1h;
412 u32 esp2;
413 u16 ss2,__ss2h;
414 u32 __cr3;
415 u32 eip;
416 u32 eflags;
417 u32 eax,ecx,edx,ebx;
418 u32 esp;
419 u32 ebp;
420 u32 esi;
421 u32 edi;
422 u16 es, __esh;
423 u16 cs, __csh;
424 u16 ss, __ssh;
425 u16 ds, __dsh;
426 u16 fs, __fsh;
427 u16 gs, __gsh;
428 u16 ldt, __ldth;
429 u16 trace;
430 #endif
431 u16 bitmap;
432 /* Pads the TSS to be cacheline-aligned (total size is 0x80). */
433 u8 __cacheline_filler[24];
434 } __cacheline_aligned __attribute__((packed));
436 #ifdef __x86_64__
437 # define IST_DF 1UL
438 # define IST_NMI 2UL
439 # define IST_MCE 3UL
440 # define IST_MAX 3UL
441 #endif
443 #define IDT_ENTRIES 256
444 extern idt_entry_t idt_table[];
445 extern idt_entry_t *idt_tables[];
447 extern struct tss_struct init_tss[NR_CPUS];
449 extern void init_int80_direct_trap(struct vcpu *v);
451 #if defined(CONFIG_X86_32)
453 #define set_int80_direct_trap(_ed) \
454 (memcpy(idt_tables[(_ed)->processor] + 0x80, \
455 &((_ed)->arch.int80_desc), 8))
457 #else
459 #define set_int80_direct_trap(_ed) ((void)0)
461 #endif
463 extern int gpf_emulate_4gb(struct cpu_user_regs *regs);
465 extern void write_ptbase(struct vcpu *v);
467 void destroy_gdt(struct vcpu *d);
468 long set_gdt(struct vcpu *d,
469 unsigned long *frames,
470 unsigned int entries);
472 long set_debugreg(struct vcpu *p, int reg, unsigned long value);
474 struct microcode_header {
475 unsigned int hdrver;
476 unsigned int rev;
477 unsigned int date;
478 unsigned int sig;
479 unsigned int cksum;
480 unsigned int ldrver;
481 unsigned int pf;
482 unsigned int datasize;
483 unsigned int totalsize;
484 unsigned int reserved[3];
485 };
487 struct microcode {
488 struct microcode_header hdr;
489 unsigned int bits[0];
490 };
492 typedef struct microcode microcode_t;
493 typedef struct microcode_header microcode_header_t;
495 /* microcode format is extended from prescott processors */
496 struct extended_signature {
497 unsigned int sig;
498 unsigned int pf;
499 unsigned int cksum;
500 };
502 struct extended_sigtable {
503 unsigned int count;
504 unsigned int cksum;
505 unsigned int reserved[3];
506 struct extended_signature sigs[0];
507 };
509 /* REP NOP (PAUSE) is a good thing to insert into busy-wait loops. */
510 static always_inline void rep_nop(void)
511 {
512 __asm__ __volatile__ ( "rep;nop" : : : "memory" );
513 }
515 #define cpu_relax() rep_nop()
517 /* Prefetch instructions for Pentium III and AMD Athlon */
518 #ifdef CONFIG_MPENTIUMIII
520 #define ARCH_HAS_PREFETCH
521 extern always_inline void prefetch(const void *x)
522 {
523 __asm__ __volatile__ ("prefetchnta (%0)" : : "r"(x));
524 }
526 #elif CONFIG_X86_USE_3DNOW
528 #define ARCH_HAS_PREFETCH
529 #define ARCH_HAS_PREFETCHW
530 #define ARCH_HAS_SPINLOCK_PREFETCH
532 extern always_inline void prefetch(const void *x)
533 {
534 __asm__ __volatile__ ("prefetch (%0)" : : "r"(x));
535 }
537 extern always_inline void prefetchw(const void *x)
538 {
539 __asm__ __volatile__ ("prefetchw (%0)" : : "r"(x));
540 }
541 #define spin_lock_prefetch(x) prefetchw(x)
543 #endif
545 void show_stack(struct cpu_user_regs *regs);
546 void show_stack_overflow(unsigned int cpu, unsigned long esp);
547 void show_registers(struct cpu_user_regs *regs);
548 void show_execution_state(struct cpu_user_regs *regs);
549 void show_page_walk(unsigned long addr);
550 asmlinkage void fatal_trap(int trapnr, struct cpu_user_regs *regs);
552 #ifdef CONFIG_COMPAT
553 void compat_show_guest_stack(struct cpu_user_regs *, int lines);
554 #else
555 #define compat_show_guest_stack(regs, lines) ((void)0)
556 #endif
558 extern void mtrr_ap_init(void);
559 extern void mtrr_bp_init(void);
561 void mcheck_init(struct cpuinfo_x86 *c);
562 asmlinkage void do_machine_check(struct cpu_user_regs *regs);
564 int cpuid_hypervisor_leaves(
565 uint32_t idx, uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx);
566 int rdmsr_hypervisor_regs(
567 uint32_t idx, uint32_t *eax, uint32_t *edx);
568 int wrmsr_hypervisor_regs(
569 uint32_t idx, uint32_t eax, uint32_t edx);
571 #endif /* !__ASSEMBLY__ */
573 #endif /* __ASM_X86_PROCESSOR_H */
575 /*
576 * Local variables:
577 * mode: C
578 * c-set-style: "BSD"
579 * c-basic-offset: 4
580 * tab-width: 4
581 * indent-tabs-mode: nil
582 * End:
583 */