blob: fd9cb7695b5f444266abebafe6c3fcfa59e2d66b [file] [log] [blame]
Jeremy Fitzhardingea42089d2007-07-17 18:37:04 -07001/******************************************************************************
2 * arch-x86_32.h
3 *
Jeremy Fitzhardinge48b5db22008-07-08 15:06:34 -07004 * Guest OS interface to x86 Xen.
Jeremy Fitzhardingea42089d2007-07-17 18:37:04 -07005 *
6 * Copyright (c) 2004, K A Fraser
7 */
8
H. Peter Anvin05e4d312008-10-23 00:01:39 -07009#ifndef _ASM_X86_XEN_INTERFACE_H
10#define _ASM_X86_XEN_INTERFACE_H
Jeremy Fitzhardingea42089d2007-07-17 18:37:04 -070011
12#ifdef __XEN__
13#define __DEFINE_GUEST_HANDLE(name, type) \
14 typedef struct { type *p; } __guest_handle_ ## name
15#else
16#define __DEFINE_GUEST_HANDLE(name, type) \
17 typedef type * __guest_handle_ ## name
18#endif
19
20#define DEFINE_GUEST_HANDLE_STRUCT(name) \
21 __DEFINE_GUEST_HANDLE(name, struct name)
22#define DEFINE_GUEST_HANDLE(name) __DEFINE_GUEST_HANDLE(name, name)
23#define GUEST_HANDLE(name) __guest_handle_ ## name
24
Isaku Yamahata87e27cf2008-04-02 10:53:52 -070025#ifdef __XEN__
26#if defined(__i386__)
27#define set_xen_guest_handle(hnd, val) \
28 do { \
29 if (sizeof(hnd) == 8) \
30 *(uint64_t *)&(hnd) = 0; \
31 (hnd).p = val; \
32 } while (0)
33#elif defined(__x86_64__)
34#define set_xen_guest_handle(hnd, val) do { (hnd).p = val; } while (0)
35#endif
36#else
37#if defined(__i386__)
38#define set_xen_guest_handle(hnd, val) \
39 do { \
40 if (sizeof(hnd) == 8) \
41 *(uint64_t *)&(hnd) = 0; \
42 (hnd) = val; \
43 } while (0)
44#elif defined(__x86_64__)
45#define set_xen_guest_handle(hnd, val) do { (hnd) = val; } while (0)
46#endif
47#endif
48
Jeremy Fitzhardingea42089d2007-07-17 18:37:04 -070049#ifndef __ASSEMBLY__
Stefano Stabellinibd3f79b2012-08-22 17:20:14 +010050/* Explicitly size integers that represent pfns in the public interface
51 * with Xen so that on ARM we can have one ABI that works for 32 and 64
52 * bit guests. */
53typedef unsigned long xen_pfn_t;
Ian Campbell37ea0fc2012-10-17 09:39:10 +010054#define PRI_xen_pfn "lx"
Stefano Stabellini256f6312012-09-14 13:34:43 +000055typedef unsigned long xen_ulong_t;
Ian Campbell37ea0fc2012-10-17 09:39:10 +010056#define PRI_xen_ulong "lx"
Jeremy Fitzhardingea42089d2007-07-17 18:37:04 -070057/* Guest handles for primitive C types. */
58__DEFINE_GUEST_HANDLE(uchar, unsigned char);
59__DEFINE_GUEST_HANDLE(uint, unsigned int);
Jeremy Fitzhardingea42089d2007-07-17 18:37:04 -070060DEFINE_GUEST_HANDLE(char);
61DEFINE_GUEST_HANDLE(int);
Jeremy Fitzhardingea42089d2007-07-17 18:37:04 -070062DEFINE_GUEST_HANDLE(void);
Yu Ke3e099672010-03-24 11:01:13 -070063DEFINE_GUEST_HANDLE(uint64_t);
Konrad Rzeszutek Wilk73c154c2012-02-13 22:26:32 -050064DEFINE_GUEST_HANDLE(uint32_t);
Stefano Stabellinibd3f79b2012-08-22 17:20:14 +010065DEFINE_GUEST_HANDLE(xen_pfn_t);
Ian Campbellf832da02012-10-03 16:37:09 +010066DEFINE_GUEST_HANDLE(xen_ulong_t);
Jeremy Fitzhardingea42089d2007-07-17 18:37:04 -070067#endif
68
Jeremy Fitzhardinge48b5db22008-07-08 15:06:34 -070069#ifndef HYPERVISOR_VIRT_START
70#define HYPERVISOR_VIRT_START mk_unsigned_long(__HYPERVISOR_VIRT_START)
71#endif
72
Ian Campbell7e775062010-09-30 12:37:26 +010073#define MACH2PHYS_VIRT_START mk_unsigned_long(__MACH2PHYS_VIRT_START)
74#define MACH2PHYS_VIRT_END mk_unsigned_long(__MACH2PHYS_VIRT_END)
75#define MACH2PHYS_NR_ENTRIES ((MACH2PHYS_VIRT_END-MACH2PHYS_VIRT_START)>>__MACH2PHYS_SHIFT)
Jeremy Fitzhardinge48b5db22008-07-08 15:06:34 -070076
77/* Maximum number of virtual CPUs in multi-processor guests. */
78#define MAX_VIRT_CPUS 32
79
Jeremy Fitzhardingea42089d2007-07-17 18:37:04 -070080/*
81 * SEGMENT DESCRIPTOR TABLES
82 */
83/*
84 * A number of GDT entries are reserved by Xen. These are not situated at the
85 * start of the GDT because some stupid OSes export hard-coded selector values
86 * in their ABI. These hard-coded values are always near the start of the GDT,
87 * so Xen places itself out of the way, at the far end of the GDT.
88 */
89#define FIRST_RESERVED_GDT_PAGE 14
90#define FIRST_RESERVED_GDT_BYTE (FIRST_RESERVED_GDT_PAGE * 4096)
91#define FIRST_RESERVED_GDT_ENTRY (FIRST_RESERVED_GDT_BYTE / 8)
92
93/*
Jeremy Fitzhardingea42089d2007-07-17 18:37:04 -070094 * Send an array of these to HYPERVISOR_set_trap_table()
Jeremy Fitzhardinge48b5db22008-07-08 15:06:34 -070095 * The privilege level specifies which modes may enter a trap via a software
96 * interrupt. On x86/64, since rings 1 and 2 are unavailable, we allocate
97 * privilege levels as follows:
Lucas De Marchi0d2eb442011-03-17 16:24:16 -030098 * Level == 0: No one may enter
Jeremy Fitzhardinge48b5db22008-07-08 15:06:34 -070099 * Level == 1: Kernel may enter
100 * Level == 2: Kernel may enter
101 * Level == 3: Everyone may enter
Jeremy Fitzhardingea42089d2007-07-17 18:37:04 -0700102 */
103#define TI_GET_DPL(_ti) ((_ti)->flags & 3)
104#define TI_GET_IF(_ti) ((_ti)->flags & 4)
105#define TI_SET_DPL(_ti, _dpl) ((_ti)->flags |= (_dpl))
106#define TI_SET_IF(_ti, _if) ((_ti)->flags |= ((!!(_if))<<2))
107
Jeremy Fitzhardinge48b5db22008-07-08 15:06:34 -0700108#ifndef __ASSEMBLY__
Jeremy Fitzhardingea42089d2007-07-17 18:37:04 -0700109struct trap_info {
110 uint8_t vector; /* exception vector */
111 uint8_t flags; /* 0-3: privilege level; 4: clear event enable? */
112 uint16_t cs; /* code selector */
113 unsigned long address; /* code offset */
114};
115DEFINE_GUEST_HANDLE_STRUCT(trap_info);
116
Jeremy Fitzhardinge48b5db22008-07-08 15:06:34 -0700117struct arch_shared_info {
118 unsigned long max_pfn; /* max pfn that appears in table */
119 /* Frame containing list of mfns containing list of mfns containing p2m. */
120 unsigned long pfn_to_mfn_frame_list_list;
121 unsigned long nmi_reason;
Jeremy Fitzhardingea42089d2007-07-17 18:37:04 -0700122};
Jeremy Fitzhardinge48b5db22008-07-08 15:06:34 -0700123#endif /* !__ASSEMBLY__ */
Jeremy Fitzhardingea42089d2007-07-17 18:37:04 -0700124
Jeremy Fitzhardinge48b5db22008-07-08 15:06:34 -0700125#ifdef CONFIG_X86_32
David Howellsa1ce3922012-10-02 18:01:25 +0100126#include <asm/xen/interface_32.h>
Jeremy Fitzhardinge48b5db22008-07-08 15:06:34 -0700127#else
David Howellsa1ce3922012-10-02 18:01:25 +0100128#include <asm/xen/interface_64.h>
Jeremy Fitzhardinge48b5db22008-07-08 15:06:34 -0700129#endif
Jeremy Fitzhardingea42089d2007-07-17 18:37:04 -0700130
Stefano Stabellini4d9310e2012-08-06 15:27:09 +0100131#include <asm/pvclock-abi.h>
132
Jeremy Fitzhardinge48b5db22008-07-08 15:06:34 -0700133#ifndef __ASSEMBLY__
Jeremy Fitzhardingea42089d2007-07-17 18:37:04 -0700134/*
135 * The following is all CPU context. Note that the fpu_ctxt block is filled
136 * in by FXSAVE if the CPU has feature FXSR; otherwise FSAVE is used.
137 */
138struct vcpu_guest_context {
139 /* FPU registers come first so they can be aligned for FXSAVE/FXRSTOR. */
140 struct { char x[512]; } fpu_ctxt; /* User-level FPU registers */
141#define VGCF_I387_VALID (1<<0)
142#define VGCF_HVM_GUEST (1<<1)
143#define VGCF_IN_KERNEL (1<<2)
144 unsigned long flags; /* VGCF_* flags */
145 struct cpu_user_regs user_regs; /* User-level CPU registers */
146 struct trap_info trap_ctxt[256]; /* Virtual IDT */
147 unsigned long ldt_base, ldt_ents; /* LDT (linear address, # ents) */
148 unsigned long gdt_frames[16], gdt_ents; /* GDT (machine frames, # ents) */
149 unsigned long kernel_ss, kernel_sp; /* Virtual TSS (only SS1/SP1) */
Jeremy Fitzhardinge48b5db22008-07-08 15:06:34 -0700150 /* NB. User pagetable on x86/64 is placed in ctrlreg[1]. */
Jeremy Fitzhardingea42089d2007-07-17 18:37:04 -0700151 unsigned long ctrlreg[8]; /* CR0-CR7 (control registers) */
152 unsigned long debugreg[8]; /* DB0-DB7 (debug registers) */
Jeremy Fitzhardinge48b5db22008-07-08 15:06:34 -0700153#ifdef __i386__
Jeremy Fitzhardingea42089d2007-07-17 18:37:04 -0700154 unsigned long event_callback_cs; /* CS:EIP of event callback */
155 unsigned long event_callback_eip;
156 unsigned long failsafe_callback_cs; /* CS:EIP of failsafe callback */
157 unsigned long failsafe_callback_eip;
Jeremy Fitzhardinge48b5db22008-07-08 15:06:34 -0700158#else
159 unsigned long event_callback_eip;
160 unsigned long failsafe_callback_eip;
161 unsigned long syscall_callback_eip;
162#endif
Jeremy Fitzhardingea42089d2007-07-17 18:37:04 -0700163 unsigned long vm_assist; /* VMASST_TYPE_* bitmap */
Jeremy Fitzhardinge48b5db22008-07-08 15:06:34 -0700164#ifdef __x86_64__
165 /* Segment base addresses. */
166 uint64_t fs_base;
167 uint64_t gs_base_kernel;
168 uint64_t gs_base_user;
169#endif
Jeremy Fitzhardingea42089d2007-07-17 18:37:04 -0700170};
171DEFINE_GUEST_HANDLE_STRUCT(vcpu_guest_context);
Jeremy Fitzhardinge48b5db22008-07-08 15:06:34 -0700172#endif /* !__ASSEMBLY__ */
Jeremy Fitzhardingea42089d2007-07-17 18:37:04 -0700173
174/*
175 * Prefix forces emulation of some non-trapping instructions.
176 * Currently only CPUID.
177 */
178#ifdef __ASSEMBLY__
179#define XEN_EMULATE_PREFIX .byte 0x0f,0x0b,0x78,0x65,0x6e ;
180#define XEN_CPUID XEN_EMULATE_PREFIX cpuid
181#else
182#define XEN_EMULATE_PREFIX ".byte 0x0f,0x0b,0x78,0x65,0x6e ; "
183#define XEN_CPUID XEN_EMULATE_PREFIX "cpuid"
184#endif
185
H. Peter Anvin05e4d312008-10-23 00:01:39 -0700186#endif /* _ASM_X86_XEN_INTERFACE_H */