interface.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. /******************************************************************************
  2. * arch-x86_32.h
  3. *
  4. * Guest OS interface to x86 Xen.
  5. *
  6. * Copyright (c) 2004, K A Fraser
  7. */
  8. #ifndef _ASM_X86_XEN_INTERFACE_H
  9. #define _ASM_X86_XEN_INTERFACE_H
  10. #ifdef __XEN__
  11. #define __DEFINE_GUEST_HANDLE(name, type) \
  12. typedef struct { type *p; } __guest_handle_ ## name
  13. #else
  14. #define __DEFINE_GUEST_HANDLE(name, type) \
  15. typedef type * __guest_handle_ ## name
  16. #endif
  17. #define DEFINE_GUEST_HANDLE_STRUCT(name) \
  18. __DEFINE_GUEST_HANDLE(name, struct name)
  19. #define DEFINE_GUEST_HANDLE(name) __DEFINE_GUEST_HANDLE(name, name)
  20. #define GUEST_HANDLE(name) __guest_handle_ ## name
  21. #ifdef __XEN__
  22. #if defined(__i386__)
  23. #define set_xen_guest_handle(hnd, val) \
  24. do { \
  25. if (sizeof(hnd) == 8) \
  26. *(uint64_t *)&(hnd) = 0; \
  27. (hnd).p = val; \
  28. } while (0)
  29. #elif defined(__x86_64__)
  30. #define set_xen_guest_handle(hnd, val) do { (hnd).p = val; } while (0)
  31. #endif
  32. #else
  33. #if defined(__i386__)
  34. #define set_xen_guest_handle(hnd, val) \
  35. do { \
  36. if (sizeof(hnd) == 8) \
  37. *(uint64_t *)&(hnd) = 0; \
  38. (hnd) = val; \
  39. } while (0)
  40. #elif defined(__x86_64__)
  41. #define set_xen_guest_handle(hnd, val) do { (hnd) = val; } while (0)
  42. #endif
  43. #endif
  44. #ifndef __ASSEMBLY__
  45. /* Explicitly size integers that represent pfns in the public interface
  46. * with Xen so that on ARM we can have one ABI that works for 32 and 64
  47. * bit guests. */
  48. typedef unsigned long xen_pfn_t;
  49. #define PRI_xen_pfn "lx"
  50. typedef unsigned long xen_ulong_t;
  51. #define PRI_xen_ulong "lx"
  52. /* Guest handles for primitive C types. */
  53. __DEFINE_GUEST_HANDLE(uchar, unsigned char);
  54. __DEFINE_GUEST_HANDLE(uint, unsigned int);
  55. DEFINE_GUEST_HANDLE(char);
  56. DEFINE_GUEST_HANDLE(int);
  57. DEFINE_GUEST_HANDLE(void);
  58. DEFINE_GUEST_HANDLE(uint64_t);
  59. DEFINE_GUEST_HANDLE(uint32_t);
  60. DEFINE_GUEST_HANDLE(xen_pfn_t);
  61. DEFINE_GUEST_HANDLE(xen_ulong_t);
  62. #endif
  63. #ifndef HYPERVISOR_VIRT_START
  64. #define HYPERVISOR_VIRT_START mk_unsigned_long(__HYPERVISOR_VIRT_START)
  65. #endif
  66. #define MACH2PHYS_VIRT_START mk_unsigned_long(__MACH2PHYS_VIRT_START)
  67. #define MACH2PHYS_VIRT_END mk_unsigned_long(__MACH2PHYS_VIRT_END)
  68. #define MACH2PHYS_NR_ENTRIES ((MACH2PHYS_VIRT_END-MACH2PHYS_VIRT_START)>>__MACH2PHYS_SHIFT)
  69. /* Maximum number of virtual CPUs in multi-processor guests. */
  70. #define MAX_VIRT_CPUS 32
  71. /*
  72. * SEGMENT DESCRIPTOR TABLES
  73. */
  74. /*
  75. * A number of GDT entries are reserved by Xen. These are not situated at the
  76. * start of the GDT because some stupid OSes export hard-coded selector values
  77. * in their ABI. These hard-coded values are always near the start of the GDT,
  78. * so Xen places itself out of the way, at the far end of the GDT.
  79. */
  80. #define FIRST_RESERVED_GDT_PAGE 14
  81. #define FIRST_RESERVED_GDT_BYTE (FIRST_RESERVED_GDT_PAGE * 4096)
  82. #define FIRST_RESERVED_GDT_ENTRY (FIRST_RESERVED_GDT_BYTE / 8)
  83. /*
  84. * Send an array of these to HYPERVISOR_set_trap_table()
  85. * The privilege level specifies which modes may enter a trap via a software
  86. * interrupt. On x86/64, since rings 1 and 2 are unavailable, we allocate
  87. * privilege levels as follows:
  88. * Level == 0: No one may enter
  89. * Level == 1: Kernel may enter
  90. * Level == 2: Kernel may enter
  91. * Level == 3: Everyone may enter
  92. */
  93. #define TI_GET_DPL(_ti) ((_ti)->flags & 3)
  94. #define TI_GET_IF(_ti) ((_ti)->flags & 4)
  95. #define TI_SET_DPL(_ti, _dpl) ((_ti)->flags |= (_dpl))
  96. #define TI_SET_IF(_ti, _if) ((_ti)->flags |= ((!!(_if))<<2))
  97. #ifndef __ASSEMBLY__
  98. struct trap_info {
  99. uint8_t vector; /* exception vector */
  100. uint8_t flags; /* 0-3: privilege level; 4: clear event enable? */
  101. uint16_t cs; /* code selector */
  102. unsigned long address; /* code offset */
  103. };
  104. DEFINE_GUEST_HANDLE_STRUCT(trap_info);
  105. struct arch_shared_info {
  106. unsigned long max_pfn; /* max pfn that appears in table */
  107. /* Frame containing list of mfns containing list of mfns containing p2m. */
  108. unsigned long pfn_to_mfn_frame_list_list;
  109. unsigned long nmi_reason;
  110. };
  111. #endif /* !__ASSEMBLY__ */
  112. #ifdef CONFIG_X86_32
  113. #include <asm/xen/interface_32.h>
  114. #else
  115. #include <asm/xen/interface_64.h>
  116. #endif
  117. #include <asm/pvclock-abi.h>
  118. #ifndef __ASSEMBLY__
  119. /*
  120. * The following is all CPU context. Note that the fpu_ctxt block is filled
  121. * in by FXSAVE if the CPU has feature FXSR; otherwise FSAVE is used.
  122. */
  123. struct vcpu_guest_context {
  124. /* FPU registers come first so they can be aligned for FXSAVE/FXRSTOR. */
  125. struct { char x[512]; } fpu_ctxt; /* User-level FPU registers */
  126. #define VGCF_I387_VALID (1<<0)
  127. #define VGCF_HVM_GUEST (1<<1)
  128. #define VGCF_IN_KERNEL (1<<2)
  129. unsigned long flags; /* VGCF_* flags */
  130. struct cpu_user_regs user_regs; /* User-level CPU registers */
  131. struct trap_info trap_ctxt[256]; /* Virtual IDT */
  132. unsigned long ldt_base, ldt_ents; /* LDT (linear address, # ents) */
  133. unsigned long gdt_frames[16], gdt_ents; /* GDT (machine frames, # ents) */
  134. unsigned long kernel_ss, kernel_sp; /* Virtual TSS (only SS1/SP1) */
  135. /* NB. User pagetable on x86/64 is placed in ctrlreg[1]. */
  136. unsigned long ctrlreg[8]; /* CR0-CR7 (control registers) */
  137. unsigned long debugreg[8]; /* DB0-DB7 (debug registers) */
  138. #ifdef __i386__
  139. unsigned long event_callback_cs; /* CS:EIP of event callback */
  140. unsigned long event_callback_eip;
  141. unsigned long failsafe_callback_cs; /* CS:EIP of failsafe callback */
  142. unsigned long failsafe_callback_eip;
  143. #else
  144. unsigned long event_callback_eip;
  145. unsigned long failsafe_callback_eip;
  146. unsigned long syscall_callback_eip;
  147. #endif
  148. unsigned long vm_assist; /* VMASST_TYPE_* bitmap */
  149. #ifdef __x86_64__
  150. /* Segment base addresses. */
  151. uint64_t fs_base;
  152. uint64_t gs_base_kernel;
  153. uint64_t gs_base_user;
  154. #endif
  155. };
  156. DEFINE_GUEST_HANDLE_STRUCT(vcpu_guest_context);
  157. #endif /* !__ASSEMBLY__ */
  158. /*
  159. * Prefix forces emulation of some non-trapping instructions.
  160. * Currently only CPUID.
  161. */
  162. #ifdef __ASSEMBLY__
  163. #define XEN_EMULATE_PREFIX .byte 0x0f,0x0b,0x78,0x65,0x6e ;
  164. #define XEN_CPUID XEN_EMULATE_PREFIX cpuid
  165. #else
  166. #define XEN_EMULATE_PREFIX ".byte 0x0f,0x0b,0x78,0x65,0x6e ; "
  167. #define XEN_CPUID XEN_EMULATE_PREFIX "cpuid"
  168. #endif
  169. #endif /* _ASM_X86_XEN_INTERFACE_H */