iPXE
xen.h
Go to the documentation of this file.
00001 /******************************************************************************
00002  * arch-x86/xen.h
00003  *
00004  * Guest OS interface to x86 Xen.
00005  *
00006  * Permission is hereby granted, free of charge, to any person obtaining a copy
00007  * of this software and associated documentation files (the "Software"), to
00008  * deal in the Software without restriction, including without limitation the
00009  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
00010  * sell copies of the Software, and to permit persons to whom the Software is
00011  * furnished to do so, subject to the following conditions:
00012  *
00013  * The above copyright notice and this permission notice shall be included in
00014  * all copies or substantial portions of the Software.
00015  *
00016  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00017  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00018  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00019  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00020  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
00021  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
00022  * DEALINGS IN THE SOFTWARE.
00023  *
00024  * Copyright (c) 2004-2006, K A Fraser
00025  */
00026 
00027 #include "../xen.h"
00028 
00029 #ifndef __XEN_PUBLIC_ARCH_X86_XEN_H__
00030 #define __XEN_PUBLIC_ARCH_X86_XEN_H__
00031 
00032 FILE_LICENCE ( MIT );
00033 
00034 /* Structural guest handles introduced in 0x00030201. */
00035 #if __XEN_INTERFACE_VERSION__ >= 0x00030201
00036 #define ___DEFINE_XEN_GUEST_HANDLE(name, type) \
00037     typedef struct { type *p; } __guest_handle_ ## name
00038 #else
00039 #define ___DEFINE_XEN_GUEST_HANDLE(name, type) \
00040     typedef type * __guest_handle_ ## name
00041 #endif
00042 
00043 /*
00044  * XEN_GUEST_HANDLE represents a guest pointer, when passed as a field
00045  * in a struct in memory.
00046  * XEN_GUEST_HANDLE_PARAM represent a guest pointer, when passed as an
00047  * hypercall argument.
00048  * XEN_GUEST_HANDLE_PARAM and XEN_GUEST_HANDLE are the same on X86 but
00049  * they might not be on other architectures.
00050  */
00051 #define __DEFINE_XEN_GUEST_HANDLE(name, type) \
00052     ___DEFINE_XEN_GUEST_HANDLE(name, type);   \
00053     ___DEFINE_XEN_GUEST_HANDLE(const_##name, const type)
00054 #define DEFINE_XEN_GUEST_HANDLE(name)   __DEFINE_XEN_GUEST_HANDLE(name, name)
00055 #define __XEN_GUEST_HANDLE(name)        __guest_handle_ ## name
00056 #define XEN_GUEST_HANDLE(name)          __XEN_GUEST_HANDLE(name)
00057 #define XEN_GUEST_HANDLE_PARAM(name)    XEN_GUEST_HANDLE(name)
00058 #define set_xen_guest_handle_raw(hnd, val)  do { (hnd).p = val; } while (0)
00059 #ifdef __XEN_TOOLS__
00060 #define get_xen_guest_handle(val, hnd)  do { val = (hnd).p; } while (0)
00061 #endif
00062 #define set_xen_guest_handle(hnd, val) set_xen_guest_handle_raw(hnd, val)
00063 
00064 #if defined(__i386__)
00065 #include "xen-x86_32.h"
00066 #elif defined(__x86_64__)
00067 #include "xen-x86_64.h"
00068 #endif
00069 
00070 #ifndef __ASSEMBLY__
00071 typedef unsigned long xen_pfn_t;
00072 #define PRI_xen_pfn "lx"
00073 #endif
00074 
00075 #define XEN_HAVE_PV_GUEST_ENTRY 1
00076 
00077 #define XEN_HAVE_PV_UPCALL_MASK 1
00078 
00079 /*
00080  * `incontents 200 segdesc Segment Descriptor Tables
00081  */
00082 /*
00083  * ` enum neg_errnoval
00084  * ` HYPERVISOR_set_gdt(const xen_pfn_t frames[], unsigned int entries);
00085  * `
00086  */
00087 /*
00088  * A number of GDT entries are reserved by Xen. These are not situated at the
00089  * start of the GDT because some stupid OSes export hard-coded selector values
00090  * in their ABI. These hard-coded values are always near the start of the GDT,
00091  * so Xen places itself out of the way, at the far end of the GDT.
00092  *
00093  * NB The LDT is set using the MMUEXT_SET_LDT op of HYPERVISOR_mmuext_op
00094  */
00095 #define FIRST_RESERVED_GDT_PAGE  14
00096 #define FIRST_RESERVED_GDT_BYTE  (FIRST_RESERVED_GDT_PAGE * 4096)
00097 #define FIRST_RESERVED_GDT_ENTRY (FIRST_RESERVED_GDT_BYTE / 8)
00098 
00099 
00100 /*
00101  * ` enum neg_errnoval
00102  * ` HYPERVISOR_update_descriptor(u64 pa, u64 desc);
00103  * `
00104  * ` @pa   The machine physical address of the descriptor to
00105  * `       update. Must be either a descriptor page or writable.
00106  * ` @desc The descriptor value to update, in the same format as a
00107  * `       native descriptor table entry.
00108  */
00109 
00110 /* Maximum number of virtual CPUs in legacy multi-processor guests. */
00111 #define XEN_LEGACY_MAX_VCPUS 32
00112 
00113 #ifndef __ASSEMBLY__
00114 
00115 typedef unsigned long xen_ulong_t;
00116 #define PRI_xen_ulong "lx"
00117 
00118 /*
00119  * ` enum neg_errnoval
00120  * ` HYPERVISOR_stack_switch(unsigned long ss, unsigned long esp);
00121  * `
00122  * Sets the stack segment and pointer for the current vcpu.
00123  */
00124 
00125 /*
00126  * ` enum neg_errnoval
00127  * ` HYPERVISOR_set_trap_table(const struct trap_info traps[]);
00128  * `
00129  */
00130 /*
00131  * Send an array of these to HYPERVISOR_set_trap_table().
00132  * Terminate the array with a sentinel entry, with traps[].address==0.
00133  * The privilege level specifies which modes may enter a trap via a software
00134  * interrupt. On x86/64, since rings 1 and 2 are unavailable, we allocate
00135  * privilege levels as follows:
00136  *  Level == 0: Noone may enter
00137  *  Level == 1: Kernel may enter
00138  *  Level == 2: Kernel may enter
00139  *  Level == 3: Everyone may enter
00140  */
00141 #define TI_GET_DPL(_ti)      ((_ti)->flags & 3)
00142 #define TI_GET_IF(_ti)       ((_ti)->flags & 4)
00143 #define TI_SET_DPL(_ti,_dpl) ((_ti)->flags |= (_dpl))
00144 #define TI_SET_IF(_ti,_if)   ((_ti)->flags |= ((!!(_if))<<2))
00145 struct trap_info {
00146     uint8_t       vector;  /* exception vector                              */
00147     uint8_t       flags;   /* 0-3: privilege level; 4: clear event enable?  */
00148     uint16_t      cs;      /* code selector                                 */
00149     unsigned long address; /* code offset                                   */
00150 };
00151 typedef struct trap_info trap_info_t;
00152 DEFINE_XEN_GUEST_HANDLE(trap_info_t);
00153 
00154 typedef uint64_t tsc_timestamp_t; /* RDTSC timestamp */
00155 
00156 /*
00157  * The following is all CPU context. Note that the fpu_ctxt block is filled
00158  * in by FXSAVE if the CPU has feature FXSR; otherwise FSAVE is used.
00159  *
00160  * Also note that when calling DOMCTL_setvcpucontext and VCPU_initialise
00161  * for HVM and PVH guests, not all information in this structure is updated:
00162  *
00163  * - For HVM guests, the structures read include: fpu_ctxt (if
00164  * VGCT_I387_VALID is set), flags, user_regs, debugreg[*]
00165  *
00166  * - PVH guests are the same as HVM guests, but additionally use ctrlreg[3] to
00167  * set cr3. All other fields not used should be set to 0.
00168  */
00169 struct vcpu_guest_context {
00170     /* FPU registers come first so they can be aligned for FXSAVE/FXRSTOR. */
00171     struct { char x[512]; } fpu_ctxt;       /* User-level FPU registers     */
00172 #define VGCF_I387_VALID                (1<<0)
00173 #define VGCF_IN_KERNEL                 (1<<2)
00174 #define _VGCF_i387_valid               0
00175 #define VGCF_i387_valid                (1<<_VGCF_i387_valid)
00176 #define _VGCF_in_kernel                2
00177 #define VGCF_in_kernel                 (1<<_VGCF_in_kernel)
00178 #define _VGCF_failsafe_disables_events 3
00179 #define VGCF_failsafe_disables_events  (1<<_VGCF_failsafe_disables_events)
00180 #define _VGCF_syscall_disables_events  4
00181 #define VGCF_syscall_disables_events   (1<<_VGCF_syscall_disables_events)
00182 #define _VGCF_online                   5
00183 #define VGCF_online                    (1<<_VGCF_online)
00184     unsigned long flags;                    /* VGCF_* flags                 */
00185     struct cpu_user_regs user_regs;         /* User-level CPU registers     */
00186     struct trap_info trap_ctxt[256];        /* Virtual IDT                  */
00187     unsigned long ldt_base, ldt_ents;       /* LDT (linear address, # ents) */
00188     unsigned long gdt_frames[16], gdt_ents; /* GDT (machine frames, # ents) */
00189     unsigned long kernel_ss, kernel_sp;     /* Virtual TSS (only SS1/SP1)   */
00190     /* NB. User pagetable on x86/64 is placed in ctrlreg[1]. */
00191     unsigned long ctrlreg[8];               /* CR0-CR7 (control registers)  */
00192     unsigned long debugreg[8];              /* DB0-DB7 (debug registers)    */
00193 #ifdef __i386__
00194     unsigned long event_callback_cs;        /* CS:EIP of event callback     */
00195     unsigned long event_callback_eip;
00196     unsigned long failsafe_callback_cs;     /* CS:EIP of failsafe callback  */
00197     unsigned long failsafe_callback_eip;
00198 #else
00199     unsigned long event_callback_eip;
00200     unsigned long failsafe_callback_eip;
00201 #ifdef __XEN__
00202     union {
00203         unsigned long syscall_callback_eip;
00204         struct {
00205             unsigned int event_callback_cs;    /* compat CS of event cb     */
00206             unsigned int failsafe_callback_cs; /* compat CS of failsafe cb  */
00207         };
00208     };
00209 #else
00210     unsigned long syscall_callback_eip;
00211 #endif
00212 #endif
00213     unsigned long vm_assist;                /* VMASST_TYPE_* bitmap */
00214 #ifdef __x86_64__
00215     /* Segment base addresses. */
00216     uint64_t      fs_base;
00217     uint64_t      gs_base_kernel;
00218     uint64_t      gs_base_user;
00219 #endif
00220 };
00221 typedef struct vcpu_guest_context vcpu_guest_context_t;
00222 DEFINE_XEN_GUEST_HANDLE(vcpu_guest_context_t);
00223 
00224 struct arch_shared_info {
00225     unsigned long max_pfn;                  /* max pfn that appears in table */
00226     /* Frame containing list of mfns containing list of mfns containing p2m. */
00227     xen_pfn_t     pfn_to_mfn_frame_list_list;
00228     unsigned long nmi_reason;
00229     uint64_t pad[32];
00230 };
00231 typedef struct arch_shared_info arch_shared_info_t;
00232 
00233 #endif /* !__ASSEMBLY__ */
00234 
00235 /*
00236  * ` enum neg_errnoval
00237  * ` HYPERVISOR_fpu_taskswitch(int set);
00238  * `
00239  * Sets (if set!=0) or clears (if set==0) CR0.TS.
00240  */
00241 
00242 /*
00243  * ` enum neg_errnoval
00244  * ` HYPERVISOR_set_debugreg(int regno, unsigned long value);
00245  *
00246  * ` unsigned long
00247  * ` HYPERVISOR_get_debugreg(int regno);
00248  * For 0<=reg<=7, returns the debug register value.
00249  * For other values of reg, returns ((unsigned long)-EINVAL).
00250  * (Unfortunately, this interface is defective.)
00251  */
00252 
00253 /*
00254  * Prefix forces emulation of some non-trapping instructions.
00255  * Currently only CPUID.
00256  */
00257 #ifdef __ASSEMBLY__
00258 #define XEN_EMULATE_PREFIX .byte 0x0f,0x0b,0x78,0x65,0x6e ;
00259 #define XEN_CPUID          XEN_EMULATE_PREFIX cpuid
00260 #else
00261 #define XEN_EMULATE_PREFIX ".byte 0x0f,0x0b,0x78,0x65,0x6e ; "
00262 #define XEN_CPUID          XEN_EMULATE_PREFIX "cpuid"
00263 #endif
00264 
00265 #endif /* __XEN_PUBLIC_ARCH_X86_XEN_H__ */
00266 
00267 /*
00268  * Local variables:
00269  * mode: C
00270  * c-file-style: "BSD"
00271  * c-basic-offset: 4
00272  * tab-width: 4
00273  * indent-tabs-mode: nil
00274  * End:
00275  */