interface_64.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. #ifndef _ASM_X86_XEN_INTERFACE_64_H
  2. #define _ASM_X86_XEN_INTERFACE_64_H
  3. /*
  4. * 64-bit segment selectors
  5. * These flat segments are in the Xen-private section of every GDT. Since these
  6. * are also present in the initial GDT, many OSes will be able to avoid
  7. * installing their own GDT.
  8. */
  9. #define FLAT_RING3_CS32 0xe023 /* GDT index 260 */
  10. #define FLAT_RING3_CS64 0xe033 /* GDT index 261 */
  11. #define FLAT_RING3_DS32 0xe02b /* GDT index 262 */
  12. #define FLAT_RING3_DS64 0x0000 /* NULL selector */
  13. #define FLAT_RING3_SS32 0xe02b /* GDT index 262 */
  14. #define FLAT_RING3_SS64 0xe02b /* GDT index 262 */
  15. #define FLAT_KERNEL_DS64 FLAT_RING3_DS64
  16. #define FLAT_KERNEL_DS32 FLAT_RING3_DS32
  17. #define FLAT_KERNEL_DS FLAT_KERNEL_DS64
  18. #define FLAT_KERNEL_CS64 FLAT_RING3_CS64
  19. #define FLAT_KERNEL_CS32 FLAT_RING3_CS32
  20. #define FLAT_KERNEL_CS FLAT_KERNEL_CS64
  21. #define FLAT_KERNEL_SS64 FLAT_RING3_SS64
  22. #define FLAT_KERNEL_SS32 FLAT_RING3_SS32
  23. #define FLAT_KERNEL_SS FLAT_KERNEL_SS64
  24. #define FLAT_USER_DS64 FLAT_RING3_DS64
  25. #define FLAT_USER_DS32 FLAT_RING3_DS32
  26. #define FLAT_USER_DS FLAT_USER_DS64
  27. #define FLAT_USER_CS64 FLAT_RING3_CS64
  28. #define FLAT_USER_CS32 FLAT_RING3_CS32
  29. #define FLAT_USER_CS FLAT_USER_CS64
  30. #define FLAT_USER_SS64 FLAT_RING3_SS64
  31. #define FLAT_USER_SS32 FLAT_RING3_SS32
  32. #define FLAT_USER_SS FLAT_USER_SS64
  33. #define __HYPERVISOR_VIRT_START 0xFFFF800000000000
  34. #define __HYPERVISOR_VIRT_END 0xFFFF880000000000
  35. #define __MACH2PHYS_VIRT_START 0xFFFF800000000000
  36. #define __MACH2PHYS_VIRT_END 0xFFFF804000000000
  37. #ifndef HYPERVISOR_VIRT_START
  38. #define HYPERVISOR_VIRT_START mk_unsigned_long(__HYPERVISOR_VIRT_START)
  39. #define HYPERVISOR_VIRT_END mk_unsigned_long(__HYPERVISOR_VIRT_END)
  40. #endif
  41. #define MACH2PHYS_VIRT_START mk_unsigned_long(__MACH2PHYS_VIRT_START)
  42. #define MACH2PHYS_VIRT_END mk_unsigned_long(__MACH2PHYS_VIRT_END)
  43. #define MACH2PHYS_NR_ENTRIES ((MACH2PHYS_VIRT_END-MACH2PHYS_VIRT_START)>>3)
  44. #ifndef machine_to_phys_mapping
  45. #define machine_to_phys_mapping ((unsigned long *)HYPERVISOR_VIRT_START)
  46. #endif
  47. /*
  48. * int HYPERVISOR_set_segment_base(unsigned int which, unsigned long base)
  49. * @which == SEGBASE_* ; @base == 64-bit base address
  50. * Returns 0 on success.
  51. */
  52. #define SEGBASE_FS 0
  53. #define SEGBASE_GS_USER 1
  54. #define SEGBASE_GS_KERNEL 2
  55. #define SEGBASE_GS_USER_SEL 3 /* Set user %gs specified in base[15:0] */
  56. /*
  57. * int HYPERVISOR_iret(void)
  58. * All arguments are on the kernel stack, in the following format.
  59. * Never returns if successful. Current kernel context is lost.
  60. * The saved CS is mapped as follows:
  61. * RING0 -> RING3 kernel mode.
  62. * RING1 -> RING3 kernel mode.
  63. * RING2 -> RING3 kernel mode.
  64. * RING3 -> RING3 user mode.
  65. * However RING0 indicates that the guest kernel should return to iteself
  66. * directly with
  67. * orb $3,1*8(%rsp)
  68. * iretq
  69. * If flags contains VGCF_in_syscall:
  70. * Restore RAX, RIP, RFLAGS, RSP.
  71. * Discard R11, RCX, CS, SS.
  72. * Otherwise:
  73. * Restore RAX, R11, RCX, CS:RIP, RFLAGS, SS:RSP.
  74. * All other registers are saved on hypercall entry and restored to user.
  75. */
  76. /* Guest exited in SYSCALL context? Return to guest with SYSRET? */
  77. #define _VGCF_in_syscall 8
  78. #define VGCF_in_syscall (1<<_VGCF_in_syscall)
  79. #define VGCF_IN_SYSCALL VGCF_in_syscall
  80. #ifndef __ASSEMBLY__
  81. struct iret_context {
  82. /* Top of stack (%rsp at point of hypercall). */
  83. uint64_t rax, r11, rcx, flags, rip, cs, rflags, rsp, ss;
  84. /* Bottom of iret stack frame. */
  85. };
  86. #if defined(__GNUC__) && !defined(__STRICT_ANSI__)
  87. /* Anonymous union includes both 32- and 64-bit names (e.g., eax/rax). */
  88. #define __DECL_REG(name) union { \
  89. uint64_t r ## name, e ## name; \
  90. uint32_t _e ## name; \
  91. }
  92. #else
  93. /* Non-gcc sources must always use the proper 64-bit name (e.g., rax). */
  94. #define __DECL_REG(name) uint64_t r ## name
  95. #endif
  96. struct cpu_user_regs {
  97. uint64_t r15;
  98. uint64_t r14;
  99. uint64_t r13;
  100. uint64_t r12;
  101. __DECL_REG(bp);
  102. __DECL_REG(bx);
  103. uint64_t r11;
  104. uint64_t r10;
  105. uint64_t r9;
  106. uint64_t r8;
  107. __DECL_REG(ax);
  108. __DECL_REG(cx);
  109. __DECL_REG(dx);
  110. __DECL_REG(si);
  111. __DECL_REG(di);
  112. uint32_t error_code; /* private */
  113. uint32_t entry_vector; /* private */
  114. __DECL_REG(ip);
  115. uint16_t cs, _pad0[1];
  116. uint8_t saved_upcall_mask;
  117. uint8_t _pad1[3];
  118. __DECL_REG(flags); /* rflags.IF == !saved_upcall_mask */
  119. __DECL_REG(sp);
  120. uint16_t ss, _pad2[3];
  121. uint16_t es, _pad3[3];
  122. uint16_t ds, _pad4[3];
  123. uint16_t fs, _pad5[3]; /* Non-zero => takes precedence over fs_base. */
  124. uint16_t gs, _pad6[3]; /* Non-zero => takes precedence over gs_base_usr. */
  125. };
  126. DEFINE_GUEST_HANDLE_STRUCT(cpu_user_regs);
  127. #undef __DECL_REG
  128. #define xen_pfn_to_cr3(pfn) ((unsigned long)(pfn) << 12)
  129. #define xen_cr3_to_pfn(cr3) ((unsigned long)(cr3) >> 12)
  130. struct arch_vcpu_info {
  131. unsigned long cr2;
  132. unsigned long pad; /* sizeof(vcpu_info_t) == 64 */
  133. };
  134. typedef unsigned long xen_callback_t;
  135. #define XEN_CALLBACK(__cs, __rip) \
  136. ((unsigned long)(__rip))
  137. #endif /* !__ASSEMBLY__ */
  138. #endif /* _ASM_X86_XEN_INTERFACE_64_H */