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