xen-x86_64.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. /******************************************************************************
  2. * xen-x86_64.h
  3. *
  4. * Guest OS interface to x86 64-bit 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. #ifndef __XEN_PUBLIC_ARCH_X86_XEN_X86_64_H__
  27. #define __XEN_PUBLIC_ARCH_X86_XEN_X86_64_H__
  28. /*
  29. * Hypercall interface:
  30. * Input: %rdi, %rsi, %rdx, %r10, %r8, %r9 (arguments 1-6)
  31. * Output: %rax
  32. * Access is via hypercall page (set up by guest loader or via a Xen MSR):
  33. * call hypercall_page + hypercall-number * 32
  34. * Clobbered: argument registers (e.g., 2-arg hypercall clobbers %rdi,%rsi)
  35. */
  36. /*
  37. * 64-bit segment selectors
  38. * These flat segments are in the Xen-private section of every GDT. Since these
  39. * are also present in the initial GDT, many OSes will be able to avoid
  40. * installing their own GDT.
  41. */
  42. #define FLAT_RING3_CS32 0xe023 /* GDT index 260 */
  43. #define FLAT_RING3_CS64 0xe033 /* GDT index 261 */
  44. #define FLAT_RING3_DS32 0xe02b /* GDT index 262 */
  45. #define FLAT_RING3_DS64 0x0000 /* NULL selector */
  46. #define FLAT_RING3_SS32 0xe02b /* GDT index 262 */
  47. #define FLAT_RING3_SS64 0xe02b /* GDT index 262 */
  48. #define FLAT_KERNEL_DS64 FLAT_RING3_DS64
  49. #define FLAT_KERNEL_DS32 FLAT_RING3_DS32
  50. #define FLAT_KERNEL_DS FLAT_KERNEL_DS64
  51. #define FLAT_KERNEL_CS64 FLAT_RING3_CS64
  52. #define FLAT_KERNEL_CS32 FLAT_RING3_CS32
  53. #define FLAT_KERNEL_CS FLAT_KERNEL_CS64
  54. #define FLAT_KERNEL_SS64 FLAT_RING3_SS64
  55. #define FLAT_KERNEL_SS32 FLAT_RING3_SS32
  56. #define FLAT_KERNEL_SS FLAT_KERNEL_SS64
  57. #define FLAT_USER_DS64 FLAT_RING3_DS64
  58. #define FLAT_USER_DS32 FLAT_RING3_DS32
  59. #define FLAT_USER_DS FLAT_USER_DS64
  60. #define FLAT_USER_CS64 FLAT_RING3_CS64
  61. #define FLAT_USER_CS32 FLAT_RING3_CS32
  62. #define FLAT_USER_CS FLAT_USER_CS64
  63. #define FLAT_USER_SS64 FLAT_RING3_SS64
  64. #define FLAT_USER_SS32 FLAT_RING3_SS32
  65. #define FLAT_USER_SS FLAT_USER_SS64
  66. #define __HYPERVISOR_VIRT_START 0xFFFF800000000000
  67. #define __HYPERVISOR_VIRT_END 0xFFFF880000000000
  68. #define __MACH2PHYS_VIRT_START 0xFFFF800000000000
  69. #define __MACH2PHYS_VIRT_END 0xFFFF804000000000
  70. #ifndef HYPERVISOR_VIRT_START
  71. #define HYPERVISOR_VIRT_START xen_mk_ulong(__HYPERVISOR_VIRT_START)
  72. #define HYPERVISOR_VIRT_END xen_mk_ulong(__HYPERVISOR_VIRT_END)
  73. #endif
  74. #define MACH2PHYS_VIRT_START xen_mk_ulong(__MACH2PHYS_VIRT_START)
  75. #define MACH2PHYS_VIRT_END xen_mk_ulong(__MACH2PHYS_VIRT_END)
  76. #define MACH2PHYS_NR_ENTRIES ((MACH2PHYS_VIRT_END-MACH2PHYS_VIRT_START)>>3)
  77. #ifndef machine_to_phys_mapping
  78. #define machine_to_phys_mapping ((unsigned long *)HYPERVISOR_VIRT_START)
  79. #endif
  80. /*
  81. * int HYPERVISOR_set_segment_base(unsigned int which, unsigned long base)
  82. * @which == SEGBASE_* ; @base == 64-bit base address
  83. * Returns 0 on success.
  84. */
  85. #define SEGBASE_FS 0
  86. #define SEGBASE_GS_USER 1
  87. #define SEGBASE_GS_KERNEL 2
  88. #define SEGBASE_GS_USER_SEL 3 /* Set user %gs specified in base[15:0] */
  89. /*
  90. * int HYPERVISOR_iret(void)
  91. * All arguments are on the kernel stack, in the following format.
  92. * Never returns if successful. Current kernel context is lost.
  93. * The saved CS is mapped as follows:
  94. * RING0 -> RING3 kernel mode.
  95. * RING1 -> RING3 kernel mode.
  96. * RING2 -> RING3 kernel mode.
  97. * RING3 -> RING3 user mode.
  98. * However RING0 indicates that the guest kernel should return to iteself
  99. * directly with
  100. * orb $3,1*8(%rsp)
  101. * iretq
  102. * If flags contains VGCF_in_syscall:
  103. * Restore RAX, RIP, RFLAGS, RSP.
  104. * Discard R11, RCX, CS, SS.
  105. * Otherwise:
  106. * Restore RAX, R11, RCX, CS:RIP, RFLAGS, SS:RSP.
  107. * All other registers are saved on hypercall entry and restored to user.
  108. */
  109. /* Guest exited in SYSCALL context? Return to guest with SYSRET? */
  110. #define _VGCF_in_syscall 8
  111. #define VGCF_in_syscall (1<<_VGCF_in_syscall)
  112. #define VGCF_IN_SYSCALL VGCF_in_syscall
  113. #ifndef __ASSEMBLY__
  114. struct iret_context {
  115. /* Top of stack (%rsp at point of hypercall). */
  116. uint64_t rax, r11, rcx, flags, rip, cs, rflags, rsp, ss;
  117. /* Bottom of iret stack frame. */
  118. };
  119. #if defined(__GNUC__) && !defined(__STRICT_ANSI__)
  120. /* Anonymous union includes both 32- and 64-bit names (e.g., eax/rax). */
  121. #define __DECL_REG(name) union { \
  122. uint64_t r ## name, e ## name; \
  123. uint32_t _e ## name; \
  124. }
  125. #else
  126. /* Non-gcc sources must always use the proper 64-bit name (e.g., rax). */
  127. #define __DECL_REG(name) uint64_t r ## name
  128. #endif
  129. struct cpu_user_regs {
  130. uint64_t r15;
  131. uint64_t r14;
  132. uint64_t r13;
  133. uint64_t r12;
  134. __DECL_REG(bp);
  135. __DECL_REG(bx);
  136. uint64_t r11;
  137. uint64_t r10;
  138. uint64_t r9;
  139. uint64_t r8;
  140. __DECL_REG(ax);
  141. __DECL_REG(cx);
  142. __DECL_REG(dx);
  143. __DECL_REG(si);
  144. __DECL_REG(di);
  145. uint32_t error_code; /* private */
  146. uint32_t entry_vector; /* private */
  147. __DECL_REG(ip);
  148. uint16_t cs, _pad0[1];
  149. uint8_t saved_upcall_mask;
  150. uint8_t _pad1[3];
  151. __DECL_REG(flags); /* rflags.IF == !saved_upcall_mask */
  152. __DECL_REG(sp);
  153. uint16_t ss, _pad2[3];
  154. uint16_t es, _pad3[3];
  155. uint16_t ds, _pad4[3];
  156. uint16_t fs, _pad5[3]; /* Non-zero => takes precedence over fs_base. */
  157. uint16_t gs, _pad6[3]; /* Non-zero => takes precedence over gs_base_usr. */
  158. };
  159. typedef struct cpu_user_regs cpu_user_regs_t;
  160. DEFINE_XEN_GUEST_HANDLE(cpu_user_regs_t);
  161. #undef __DECL_REG
  162. #define xen_pfn_to_cr3(pfn) ((unsigned long)(pfn) << 12)
  163. #define xen_cr3_to_pfn(cr3) ((unsigned long)(cr3) >> 12)
  164. struct arch_vcpu_info {
  165. unsigned long cr2;
  166. unsigned long pad; /* sizeof(vcpu_info_t) == 64 */
  167. };
  168. typedef struct arch_vcpu_info arch_vcpu_info_t;
  169. typedef unsigned long xen_callback_t;
  170. #endif /* !__ASSEMBLY__ */
  171. #endif /* __XEN_PUBLIC_ARCH_X86_XEN_X86_64_H__ */
  172. /*
  173. * Local variables:
  174. * mode: C
  175. * c-file-style: "BSD"
  176. * c-basic-offset: 4
  177. * tab-width: 4
  178. * indent-tabs-mode: nil
  179. * End:
  180. */