xen.h 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  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. #include "../xen.h"
  27. #ifndef __XEN_PUBLIC_ARCH_X86_XEN_H__
  28. #define __XEN_PUBLIC_ARCH_X86_XEN_H__
  29. /* Structural guest handles introduced in 0x00030201. */
  30. #if __XEN_INTERFACE_VERSION__ >= 0x00030201
  31. #define ___DEFINE_XEN_GUEST_HANDLE(name, type) \
  32. typedef struct { type *p; } __guest_handle_ ## name
  33. #else
  34. #define ___DEFINE_XEN_GUEST_HANDLE(name, type) \
  35. typedef type * __guest_handle_ ## name
  36. #endif
  37. /*
  38. * XEN_GUEST_HANDLE represents a guest pointer, when passed as a field
  39. * in a struct in memory.
  40. * XEN_GUEST_HANDLE_PARAM represent a guest pointer, when passed as an
  41. * hypercall argument.
  42. * XEN_GUEST_HANDLE_PARAM and XEN_GUEST_HANDLE are the same on X86 but
  43. * they might not be on other architectures.
  44. */
  45. #define __DEFINE_XEN_GUEST_HANDLE(name, type) \
  46. ___DEFINE_XEN_GUEST_HANDLE(name, type); \
  47. ___DEFINE_XEN_GUEST_HANDLE(const_##name, const type)
  48. #define DEFINE_XEN_GUEST_HANDLE(name) __DEFINE_XEN_GUEST_HANDLE(name, name)
  49. #define __XEN_GUEST_HANDLE(name) __guest_handle_ ## name
  50. #define XEN_GUEST_HANDLE(name) __XEN_GUEST_HANDLE(name)
  51. #define XEN_GUEST_HANDLE_PARAM(name) XEN_GUEST_HANDLE(name)
  52. #define set_xen_guest_handle_raw(hnd, val) do { (hnd).p = val; } while (0)
  53. #ifdef __XEN_TOOLS__
  54. #define get_xen_guest_handle(val, hnd) do { val = (hnd).p; } while (0)
  55. #endif
  56. #define set_xen_guest_handle(hnd, val) set_xen_guest_handle_raw(hnd, val)
  57. #if defined(__i386__)
  58. #include "xen-x86_32.h"
  59. #elif defined(__x86_64__)
  60. #include "xen-x86_64.h"
  61. #endif
  62. #ifndef __ASSEMBLY__
  63. typedef unsigned long xen_pfn_t;
  64. #define PRI_xen_pfn "lx"
  65. #endif
  66. #define XEN_HAVE_PV_GUEST_ENTRY 1
  67. #define XEN_HAVE_PV_UPCALL_MASK 1
  68. /*
  69. * `incontents 200 segdesc Segment Descriptor Tables
  70. */
  71. /*
  72. * ` enum neg_errnoval
  73. * ` HYPERVISOR_set_gdt(const xen_pfn_t frames[], unsigned int entries);
  74. * `
  75. */
  76. /*
  77. * A number of GDT entries are reserved by Xen. These are not situated at the
  78. * start of the GDT because some stupid OSes export hard-coded selector values
  79. * in their ABI. These hard-coded values are always near the start of the GDT,
  80. * so Xen places itself out of the way, at the far end of the GDT.
  81. *
  82. * NB The LDT is set using the MMUEXT_SET_LDT op of HYPERVISOR_mmuext_op
  83. */
  84. #define FIRST_RESERVED_GDT_PAGE 14
  85. #define FIRST_RESERVED_GDT_BYTE (FIRST_RESERVED_GDT_PAGE * 4096)
  86. #define FIRST_RESERVED_GDT_ENTRY (FIRST_RESERVED_GDT_BYTE / 8)
  87. /*
  88. * ` enum neg_errnoval
  89. * ` HYPERVISOR_update_descriptor(u64 pa, u64 desc);
  90. * `
  91. * ` @pa The machine physical address of the descriptor to
  92. * ` update. Must be either a descriptor page or writable.
  93. * ` @desc The descriptor value to update, in the same format as a
  94. * ` native descriptor table entry.
  95. */
  96. /* Maximum number of virtual CPUs in legacy multi-processor guests. */
  97. #define XEN_LEGACY_MAX_VCPUS 32
  98. #ifndef __ASSEMBLY__
  99. typedef unsigned long xen_ulong_t;
  100. #define PRI_xen_ulong "lx"
  101. /*
  102. * ` enum neg_errnoval
  103. * ` HYPERVISOR_stack_switch(unsigned long ss, unsigned long esp);
  104. * `
  105. * Sets the stack segment and pointer for the current vcpu.
  106. */
  107. /*
  108. * ` enum neg_errnoval
  109. * ` HYPERVISOR_set_trap_table(const struct trap_info traps[]);
  110. * `
  111. */
  112. /*
  113. * Send an array of these to HYPERVISOR_set_trap_table().
  114. * Terminate the array with a sentinel entry, with traps[].address==0.
  115. * The privilege level specifies which modes may enter a trap via a software
  116. * interrupt. On x86/64, since rings 1 and 2 are unavailable, we allocate
  117. * privilege levels as follows:
  118. * Level == 0: Noone may enter
  119. * Level == 1: Kernel may enter
  120. * Level == 2: Kernel may enter
  121. * Level == 3: Everyone may enter
  122. */
  123. #define TI_GET_DPL(_ti) ((_ti)->flags & 3)
  124. #define TI_GET_IF(_ti) ((_ti)->flags & 4)
  125. #define TI_SET_DPL(_ti,_dpl) ((_ti)->flags |= (_dpl))
  126. #define TI_SET_IF(_ti,_if) ((_ti)->flags |= ((!!(_if))<<2))
  127. struct trap_info {
  128. uint8_t vector; /* exception vector */
  129. uint8_t flags; /* 0-3: privilege level; 4: clear event enable? */
  130. uint16_t cs; /* code selector */
  131. unsigned long address; /* code offset */
  132. };
  133. typedef struct trap_info trap_info_t;
  134. DEFINE_XEN_GUEST_HANDLE(trap_info_t);
  135. typedef uint64_t tsc_timestamp_t; /* RDTSC timestamp */
  136. /*
  137. * The following is all CPU context. Note that the fpu_ctxt block is filled
  138. * in by FXSAVE if the CPU has feature FXSR; otherwise FSAVE is used.
  139. *
  140. * Also note that when calling DOMCTL_setvcpucontext and VCPU_initialise
  141. * for HVM and PVH guests, not all information in this structure is updated:
  142. *
  143. * - For HVM guests, the structures read include: fpu_ctxt (if
  144. * VGCT_I387_VALID is set), flags, user_regs, debugreg[*]
  145. *
  146. * - PVH guests are the same as HVM guests, but additionally use ctrlreg[3] to
  147. * set cr3. All other fields not used should be set to 0.
  148. */
  149. struct vcpu_guest_context {
  150. /* FPU registers come first so they can be aligned for FXSAVE/FXRSTOR. */
  151. struct { char x[512]; } fpu_ctxt; /* User-level FPU registers */
  152. #define VGCF_I387_VALID (1<<0)
  153. #define VGCF_IN_KERNEL (1<<2)
  154. #define _VGCF_i387_valid 0
  155. #define VGCF_i387_valid (1<<_VGCF_i387_valid)
  156. #define _VGCF_in_kernel 2
  157. #define VGCF_in_kernel (1<<_VGCF_in_kernel)
  158. #define _VGCF_failsafe_disables_events 3
  159. #define VGCF_failsafe_disables_events (1<<_VGCF_failsafe_disables_events)
  160. #define _VGCF_syscall_disables_events 4
  161. #define VGCF_syscall_disables_events (1<<_VGCF_syscall_disables_events)
  162. #define _VGCF_online 5
  163. #define VGCF_online (1<<_VGCF_online)
  164. unsigned long flags; /* VGCF_* flags */
  165. struct cpu_user_regs user_regs; /* User-level CPU registers */
  166. struct trap_info trap_ctxt[256]; /* Virtual IDT */
  167. unsigned long ldt_base, ldt_ents; /* LDT (linear address, # ents) */
  168. unsigned long gdt_frames[16], gdt_ents; /* GDT (machine frames, # ents) */
  169. unsigned long kernel_ss, kernel_sp; /* Virtual TSS (only SS1/SP1) */
  170. /* NB. User pagetable on x86/64 is placed in ctrlreg[1]. */
  171. unsigned long ctrlreg[8]; /* CR0-CR7 (control registers) */
  172. unsigned long debugreg[8]; /* DB0-DB7 (debug registers) */
  173. #ifdef __i386__
  174. unsigned long event_callback_cs; /* CS:EIP of event callback */
  175. unsigned long event_callback_eip;
  176. unsigned long failsafe_callback_cs; /* CS:EIP of failsafe callback */
  177. unsigned long failsafe_callback_eip;
  178. #else
  179. unsigned long event_callback_eip;
  180. unsigned long failsafe_callback_eip;
  181. #ifdef __XEN__
  182. union {
  183. unsigned long syscall_callback_eip;
  184. struct {
  185. unsigned int event_callback_cs; /* compat CS of event cb */
  186. unsigned int failsafe_callback_cs; /* compat CS of failsafe cb */
  187. };
  188. };
  189. #else
  190. unsigned long syscall_callback_eip;
  191. #endif
  192. #endif
  193. unsigned long vm_assist; /* VMASST_TYPE_* bitmap */
  194. #ifdef __x86_64__
  195. /* Segment base addresses. */
  196. uint64_t fs_base;
  197. uint64_t gs_base_kernel;
  198. uint64_t gs_base_user;
  199. #endif
  200. };
  201. typedef struct vcpu_guest_context vcpu_guest_context_t;
  202. DEFINE_XEN_GUEST_HANDLE(vcpu_guest_context_t);
  203. struct arch_shared_info {
  204. unsigned long max_pfn; /* max pfn that appears in table */
  205. /* Frame containing list of mfns containing list of mfns containing p2m. */
  206. xen_pfn_t pfn_to_mfn_frame_list_list;
  207. unsigned long nmi_reason;
  208. uint64_t pad[32];
  209. };
  210. typedef struct arch_shared_info arch_shared_info_t;
  211. #endif /* !__ASSEMBLY__ */
  212. /*
  213. * ` enum neg_errnoval
  214. * ` HYPERVISOR_fpu_taskswitch(int set);
  215. * `
  216. * Sets (if set!=0) or clears (if set==0) CR0.TS.
  217. */
  218. /*
  219. * ` enum neg_errnoval
  220. * ` HYPERVISOR_set_debugreg(int regno, unsigned long value);
  221. *
  222. * ` unsigned long
  223. * ` HYPERVISOR_get_debugreg(int regno);
  224. * For 0<=reg<=7, returns the debug register value.
  225. * For other values of reg, returns ((unsigned long)-EINVAL).
  226. * (Unfortunately, this interface is defective.)
  227. */
  228. /*
  229. * Prefix forces emulation of some non-trapping instructions.
  230. * Currently only CPUID.
  231. */
  232. #ifdef __ASSEMBLY__
  233. #define XEN_EMULATE_PREFIX .byte 0x0f,0x0b,0x78,0x65,0x6e ;
  234. #define XEN_CPUID XEN_EMULATE_PREFIX cpuid
  235. #else
  236. #define XEN_EMULATE_PREFIX ".byte 0x0f,0x0b,0x78,0x65,0x6e ; "
  237. #define XEN_CPUID XEN_EMULATE_PREFIX "cpuid"
  238. #endif
  239. #endif /* __XEN_PUBLIC_ARCH_X86_XEN_H__ */
  240. /*
  241. * Local variables:
  242. * mode: C
  243. * c-file-style: "BSD"
  244. * c-basic-offset: 4
  245. * tab-width: 4
  246. * indent-tabs-mode: nil
  247. * End:
  248. */