interface.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. /******************************************************************************
  2. * arch-x86_32.h
  3. *
  4. * Guest OS interface to x86 32-bit Xen.
  5. *
  6. * Copyright (c) 2004, K A Fraser
  7. */
  8. #ifndef __XEN_PUBLIC_ARCH_X86_32_H__
  9. #define __XEN_PUBLIC_ARCH_X86_32_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. /* Guest handles for primitive C types. */
  46. __DEFINE_GUEST_HANDLE(uchar, unsigned char);
  47. __DEFINE_GUEST_HANDLE(uint, unsigned int);
  48. __DEFINE_GUEST_HANDLE(ulong, unsigned long);
  49. DEFINE_GUEST_HANDLE(char);
  50. DEFINE_GUEST_HANDLE(int);
  51. DEFINE_GUEST_HANDLE(long);
  52. DEFINE_GUEST_HANDLE(void);
  53. #endif
  54. /*
  55. * SEGMENT DESCRIPTOR TABLES
  56. */
  57. /*
  58. * A number of GDT entries are reserved by Xen. These are not situated at the
  59. * start of the GDT because some stupid OSes export hard-coded selector values
  60. * in their ABI. These hard-coded values are always near the start of the GDT,
  61. * so Xen places itself out of the way, at the far end of the GDT.
  62. */
  63. #define FIRST_RESERVED_GDT_PAGE 14
  64. #define FIRST_RESERVED_GDT_BYTE (FIRST_RESERVED_GDT_PAGE * 4096)
  65. #define FIRST_RESERVED_GDT_ENTRY (FIRST_RESERVED_GDT_BYTE / 8)
  66. /*
  67. * These flat segments are in the Xen-private section of every GDT. Since these
  68. * are also present in the initial GDT, many OSes will be able to avoid
  69. * installing their own GDT.
  70. */
  71. #define FLAT_RING1_CS 0xe019 /* GDT index 259 */
  72. #define FLAT_RING1_DS 0xe021 /* GDT index 260 */
  73. #define FLAT_RING1_SS 0xe021 /* GDT index 260 */
  74. #define FLAT_RING3_CS 0xe02b /* GDT index 261 */
  75. #define FLAT_RING3_DS 0xe033 /* GDT index 262 */
  76. #define FLAT_RING3_SS 0xe033 /* GDT index 262 */
  77. #define FLAT_KERNEL_CS FLAT_RING1_CS
  78. #define FLAT_KERNEL_DS FLAT_RING1_DS
  79. #define FLAT_KERNEL_SS FLAT_RING1_SS
  80. #define FLAT_USER_CS FLAT_RING3_CS
  81. #define FLAT_USER_DS FLAT_RING3_DS
  82. #define FLAT_USER_SS FLAT_RING3_SS
  83. /* And the trap vector is... */
  84. #define TRAP_INSTR "int $0x82"
  85. /*
  86. * Virtual addresses beyond this are not modifiable by guest OSes. The
  87. * machine->physical mapping table starts at this address, read-only.
  88. */
  89. #ifdef CONFIG_X86_PAE
  90. #define __HYPERVISOR_VIRT_START 0xF5800000
  91. #else
  92. #define __HYPERVISOR_VIRT_START 0xFC000000
  93. #endif
  94. #ifndef HYPERVISOR_VIRT_START
  95. #define HYPERVISOR_VIRT_START mk_unsigned_long(__HYPERVISOR_VIRT_START)
  96. #endif
  97. #ifndef machine_to_phys_mapping
  98. #define machine_to_phys_mapping ((unsigned long *)HYPERVISOR_VIRT_START)
  99. #endif
  100. /* Maximum number of virtual CPUs in multi-processor guests. */
  101. #define MAX_VIRT_CPUS 32
  102. #ifndef __ASSEMBLY__
  103. /*
  104. * Send an array of these to HYPERVISOR_set_trap_table()
  105. */
  106. #define TI_GET_DPL(_ti) ((_ti)->flags & 3)
  107. #define TI_GET_IF(_ti) ((_ti)->flags & 4)
  108. #define TI_SET_DPL(_ti, _dpl) ((_ti)->flags |= (_dpl))
  109. #define TI_SET_IF(_ti, _if) ((_ti)->flags |= ((!!(_if))<<2))
  110. struct trap_info {
  111. uint8_t vector; /* exception vector */
  112. uint8_t flags; /* 0-3: privilege level; 4: clear event enable? */
  113. uint16_t cs; /* code selector */
  114. unsigned long address; /* code offset */
  115. };
  116. DEFINE_GUEST_HANDLE_STRUCT(trap_info);
  117. struct cpu_user_regs {
  118. uint32_t ebx;
  119. uint32_t ecx;
  120. uint32_t edx;
  121. uint32_t esi;
  122. uint32_t edi;
  123. uint32_t ebp;
  124. uint32_t eax;
  125. uint16_t error_code; /* private */
  126. uint16_t entry_vector; /* private */
  127. uint32_t eip;
  128. uint16_t cs;
  129. uint8_t saved_upcall_mask;
  130. uint8_t _pad0;
  131. uint32_t eflags; /* eflags.IF == !saved_upcall_mask */
  132. uint32_t esp;
  133. uint16_t ss, _pad1;
  134. uint16_t es, _pad2;
  135. uint16_t ds, _pad3;
  136. uint16_t fs, _pad4;
  137. uint16_t gs, _pad5;
  138. };
  139. DEFINE_GUEST_HANDLE_STRUCT(cpu_user_regs);
  140. typedef uint64_t tsc_timestamp_t; /* RDTSC timestamp */
  141. /*
  142. * The following is all CPU context. Note that the fpu_ctxt block is filled
  143. * in by FXSAVE if the CPU has feature FXSR; otherwise FSAVE is used.
  144. */
  145. struct vcpu_guest_context {
  146. /* FPU registers come first so they can be aligned for FXSAVE/FXRSTOR. */
  147. struct { char x[512]; } fpu_ctxt; /* User-level FPU registers */
  148. #define VGCF_I387_VALID (1<<0)
  149. #define VGCF_HVM_GUEST (1<<1)
  150. #define VGCF_IN_KERNEL (1<<2)
  151. unsigned long flags; /* VGCF_* flags */
  152. struct cpu_user_regs user_regs; /* User-level CPU registers */
  153. struct trap_info trap_ctxt[256]; /* Virtual IDT */
  154. unsigned long ldt_base, ldt_ents; /* LDT (linear address, # ents) */
  155. unsigned long gdt_frames[16], gdt_ents; /* GDT (machine frames, # ents) */
  156. unsigned long kernel_ss, kernel_sp; /* Virtual TSS (only SS1/SP1) */
  157. unsigned long ctrlreg[8]; /* CR0-CR7 (control registers) */
  158. unsigned long debugreg[8]; /* DB0-DB7 (debug registers) */
  159. unsigned long event_callback_cs; /* CS:EIP of event callback */
  160. unsigned long event_callback_eip;
  161. unsigned long failsafe_callback_cs; /* CS:EIP of failsafe callback */
  162. unsigned long failsafe_callback_eip;
  163. unsigned long vm_assist; /* VMASST_TYPE_* bitmap */
  164. };
  165. DEFINE_GUEST_HANDLE_STRUCT(vcpu_guest_context);
  166. struct arch_shared_info {
  167. unsigned long max_pfn; /* max pfn that appears in table */
  168. /* Frame containing list of mfns containing list of mfns containing p2m. */
  169. unsigned long pfn_to_mfn_frame_list_list;
  170. unsigned long nmi_reason;
  171. };
  172. struct arch_vcpu_info {
  173. unsigned long cr2;
  174. unsigned long pad[5]; /* sizeof(struct vcpu_info) == 64 */
  175. };
  176. struct xen_callback {
  177. unsigned long cs;
  178. unsigned long eip;
  179. };
  180. #endif /* !__ASSEMBLY__ */
  181. /*
  182. * Prefix forces emulation of some non-trapping instructions.
  183. * Currently only CPUID.
  184. */
  185. #ifdef __ASSEMBLY__
  186. #define XEN_EMULATE_PREFIX .byte 0x0f,0x0b,0x78,0x65,0x6e ;
  187. #define XEN_CPUID XEN_EMULATE_PREFIX cpuid
  188. #else
  189. #define XEN_EMULATE_PREFIX ".byte 0x0f,0x0b,0x78,0x65,0x6e ; "
  190. #define XEN_CPUID XEN_EMULATE_PREFIX "cpuid"
  191. #endif
  192. #endif