xen.h revision 181624
1/******************************************************************************
2 * arch-x86/xen.h
3 *
4 * Guest OS interface to x86 Xen.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 *
24 * Copyright (c) 2004-2006, K A Fraser
25 */
26
27#ifndef __XEN_PUBLIC_ARCH_X86_XEN_H__
28#define __XEN_PUBLIC_ARCH_X86_XEN_H__
29
30#if defined(__i386__)
31#include <xen/interface/arch-x86/xen-x86_32.h>
32#elif defined(__x86_64__)
33#include "xen-x86_64.h"
34#endif
35
36#ifndef __ASSEMBLY__
37/* Guest handles for primitive C types. */
38__DEFINE_XEN_GUEST_HANDLE(uchar, unsigned char);
39__DEFINE_XEN_GUEST_HANDLE(uint,  unsigned int);
40__DEFINE_XEN_GUEST_HANDLE(ulong, unsigned long);
41#if 0
42DEFINE_XEN_GUEST_HANDLE(char);
43DEFINE_XEN_GUEST_HANDLE(int);
44DEFINE_XEN_GUEST_HANDLE(long);
45DEFINE_XEN_GUEST_HANDLE(void);
46#endif
47typedef unsigned long xen_pfn_t;
48DEFINE_XEN_GUEST_HANDLE(xen_pfn_t);
49#define PRI_xen_pfn "lx"
50#endif
51
52/*
53 * SEGMENT DESCRIPTOR TABLES
54 */
55/*
56 * A number of GDT entries are reserved by Xen. These are not situated at the
57 * start of the GDT because some stupid OSes export hard-coded selector values
58 * in their ABI. These hard-coded values are always near the start of the GDT,
59 * so Xen places itself out of the way, at the far end of the GDT.
60 */
61#define FIRST_RESERVED_GDT_PAGE  14
62#define FIRST_RESERVED_GDT_BYTE  (FIRST_RESERVED_GDT_PAGE * 4096)
63#define FIRST_RESERVED_GDT_ENTRY (FIRST_RESERVED_GDT_BYTE / 8)
64
65/* Maximum number of virtual CPUs in multi-processor guests. */
66#define MAX_VIRT_CPUS 32
67
68#ifndef __ASSEMBLY__
69
70typedef unsigned long xen_ulong_t;
71
72/*
73 * Send an array of these to HYPERVISOR_set_trap_table().
74 * The privilege level specifies which modes may enter a trap via a software
75 * interrupt. On x86/64, since rings 1 and 2 are unavailable, we allocate
76 * privilege levels as follows:
77 *  Level == 0: Noone may enter
78 *  Level == 1: Kernel may enter
79 *  Level == 2: Kernel may enter
80 *  Level == 3: Everyone may enter
81 */
82#define TI_GET_DPL(_ti)      ((_ti)->flags & 3)
83#define TI_GET_IF(_ti)       ((_ti)->flags & 4)
84#define TI_SET_DPL(_ti,_dpl) ((_ti)->flags |= (_dpl))
85#define TI_SET_IF(_ti,_if)   ((_ti)->flags |= ((!!(_if))<<2))
86struct trap_info {
87    uint8_t       vector;  /* exception vector                              */
88    uint8_t       flags;   /* 0-3: privilege level; 4: clear event enable?  */
89    uint16_t      cs;      /* code selector                                 */
90    unsigned long address; /* code offset                                   */
91};
92typedef struct trap_info trap_info_t;
93DEFINE_XEN_GUEST_HANDLE(trap_info_t);
94
95typedef uint64_t tsc_timestamp_t; /* RDTSC timestamp */
96
97/*
98 * The following is all CPU context. Note that the fpu_ctxt block is filled
99 * in by FXSAVE if the CPU has feature FXSR; otherwise FSAVE is used.
100 */
101struct vcpu_guest_context {
102    /* FPU registers come first so they can be aligned for FXSAVE/FXRSTOR. */
103    struct { char x[512]; } fpu_ctxt;       /* User-level FPU registers     */
104#define VGCF_I387_VALID                (1<<0)
105#define VGCF_IN_KERNEL                 (1<<2)
106#define _VGCF_i387_valid               0
107#define VGCF_i387_valid                (1<<_VGCF_i387_valid)
108#define _VGCF_in_kernel                2
109#define VGCF_in_kernel                 (1<<_VGCF_in_kernel)
110#define _VGCF_failsafe_disables_events 3
111#define VGCF_failsafe_disables_events  (1<<_VGCF_failsafe_disables_events)
112#define _VGCF_syscall_disables_events  4
113#define VGCF_syscall_disables_events   (1<<_VGCF_syscall_disables_events)
114#define _VGCF_online                   5
115#define VGCF_online                    (1<<_VGCF_online)
116    unsigned long flags;                    /* VGCF_* flags                 */
117    struct cpu_user_regs user_regs;         /* User-level CPU registers     */
118    struct trap_info trap_ctxt[256];        /* Virtual IDT                  */
119    unsigned long ldt_base, ldt_ents;       /* LDT (linear address, # ents) */
120    unsigned long gdt_frames[16], gdt_ents; /* GDT (machine frames, # ents) */
121    unsigned long kernel_ss, kernel_sp;     /* Virtual TSS (only SS1/SP1)   */
122    /* NB. User pagetable on x86/64 is placed in ctrlreg[1]. */
123    unsigned long ctrlreg[8];               /* CR0-CR7 (control registers)  */
124    unsigned long debugreg[8];              /* DB0-DB7 (debug registers)    */
125#ifdef __i386__
126    unsigned long event_callback_cs;        /* CS:EIP of event callback     */
127    unsigned long event_callback_eip;
128    unsigned long failsafe_callback_cs;     /* CS:EIP of failsafe callback  */
129    unsigned long failsafe_callback_eip;
130#else
131    unsigned long event_callback_eip;
132    unsigned long failsafe_callback_eip;
133#ifdef __XEN__
134    union {
135        unsigned long syscall_callback_eip;
136        struct {
137            unsigned int event_callback_cs;    /* compat CS of event cb     */
138            unsigned int failsafe_callback_cs; /* compat CS of failsafe cb  */
139        };
140    } u;
141#else
142    unsigned long syscall_callback_eip;
143#endif
144#endif
145    unsigned long vm_assist;                /* VMASST_TYPE_* bitmap */
146#ifdef __x86_64__
147    /* Segment base addresses. */
148    uint64_t      fs_base;
149    uint64_t      gs_base_kernel;
150    uint64_t      gs_base_user;
151#endif
152};
153typedef struct vcpu_guest_context vcpu_guest_context_t;
154DEFINE_XEN_GUEST_HANDLE(vcpu_guest_context_t);
155
156struct arch_shared_info {
157    unsigned long max_pfn;                  /* max pfn that appears in table */
158    /* Frame containing list of mfns containing list of mfns containing p2m. */
159    xen_pfn_t     pfn_to_mfn_frame_list_list;
160    unsigned long nmi_reason;
161    uint64_t pad[32];
162};
163typedef struct arch_shared_info arch_shared_info_t;
164
165#endif /* !__ASSEMBLY__ */
166
167/*
168 * Prefix forces emulation of some non-trapping instructions.
169 * Currently only CPUID.
170 */
171#ifdef __ASSEMBLY__
172#define XEN_EMULATE_PREFIX .byte 0x0f,0x0b,0x78,0x65,0x6e ;
173#define XEN_CPUID          XEN_EMULATE_PREFIX cpuid
174#else
175#define XEN_EMULATE_PREFIX ".byte 0x0f,0x0b,0x78,0x65,0x6e ; "
176#define XEN_CPUID          XEN_EMULATE_PREFIX "cpuid"
177#endif
178
179#endif /* __XEN_PUBLIC_ARCH_X86_XEN_H__ */
180
181/*
182 * Local variables:
183 * mode: C
184 * c-set-style: "BSD"
185 * c-basic-offset: 4
186 * tab-width: 4
187 * indent-tabs-mode: nil
188 * End:
189 */
190