1 #ifndef __ASM_X86_XEN_INTERFACE_64_H
2 #define __ASM_X86_XEN_INTERFACE_64_H
5 * 64-bit segment selectors
6 * These flat segments are in the Xen-private section of every GDT. Since these
7 * are also present in the initial GDT, many OSes will be able to avoid
8 * installing their own GDT.
11 #define FLAT_RING3_CS32 0xe023 /* GDT index 260 */
12 #define FLAT_RING3_CS64 0xe033 /* GDT index 261 */
13 #define FLAT_RING3_DS32 0xe02b /* GDT index 262 */
14 #define FLAT_RING3_DS64 0x0000 /* NULL selector */
15 #define FLAT_RING3_SS32 0xe02b /* GDT index 262 */
16 #define FLAT_RING3_SS64 0xe02b /* GDT index 262 */
18 #define FLAT_KERNEL_DS64 FLAT_RING3_DS64
19 #define FLAT_KERNEL_DS32 FLAT_RING3_DS32
20 #define FLAT_KERNEL_DS FLAT_KERNEL_DS64
21 #define FLAT_KERNEL_CS64 FLAT_RING3_CS64
22 #define FLAT_KERNEL_CS32 FLAT_RING3_CS32
23 #define FLAT_KERNEL_CS FLAT_KERNEL_CS64
24 #define FLAT_KERNEL_SS64 FLAT_RING3_SS64
25 #define FLAT_KERNEL_SS32 FLAT_RING3_SS32
26 #define FLAT_KERNEL_SS FLAT_KERNEL_SS64
28 #define FLAT_USER_DS64 FLAT_RING3_DS64
29 #define FLAT_USER_DS32 FLAT_RING3_DS32
30 #define FLAT_USER_DS FLAT_USER_DS64
31 #define FLAT_USER_CS64 FLAT_RING3_CS64
32 #define FLAT_USER_CS32 FLAT_RING3_CS32
33 #define FLAT_USER_CS FLAT_USER_CS64
34 #define FLAT_USER_SS64 FLAT_RING3_SS64
35 #define FLAT_USER_SS32 FLAT_RING3_SS32
36 #define FLAT_USER_SS FLAT_USER_SS64
38 #define __HYPERVISOR_VIRT_START 0xFFFF800000000000
39 #define __HYPERVISOR_VIRT_END 0xFFFF880000000000
40 #define __MACH2PHYS_VIRT_START 0xFFFF800000000000
41 #define __MACH2PHYS_VIRT_END 0xFFFF804000000000
43 #ifndef HYPERVISOR_VIRT_START
44 #define HYPERVISOR_VIRT_START mk_unsigned_long(__HYPERVISOR_VIRT_START)
45 #define HYPERVISOR_VIRT_END mk_unsigned_long(__HYPERVISOR_VIRT_END)
48 #define MACH2PHYS_VIRT_START mk_unsigned_long(__MACH2PHYS_VIRT_START)
49 #define MACH2PHYS_VIRT_END mk_unsigned_long(__MACH2PHYS_VIRT_END)
50 #define MACH2PHYS_NR_ENTRIES ((MACH2PHYS_VIRT_END-MACH2PHYS_VIRT_START)>>3)
51 #ifndef machine_to_phys_mapping
52 #define machine_to_phys_mapping ((unsigned long *)HYPERVISOR_VIRT_START)
56 * int HYPERVISOR_set_segment_base(unsigned int which, unsigned long base)
57 * @which == SEGBASE_* ; @base == 64-bit base address
58 * Returns 0 on success.
61 #define SEGBASE_GS_USER 1
62 #define SEGBASE_GS_KERNEL 2
63 #define SEGBASE_GS_USER_SEL 3 /* Set user %gs specified in base[15:0] */
66 * int HYPERVISOR_iret(void)
67 * All arguments are on the kernel stack, in the following format.
68 * Never returns if successful. Current kernel context is lost.
69 * The saved CS is mapped as follows:
70 * RING0 -> RING3 kernel mode.
71 * RING1 -> RING3 kernel mode.
72 * RING2 -> RING3 kernel mode.
73 * RING3 -> RING3 user mode.
74 * However RING0 indicates that the guest kernel should return to iteself
78 * If flags contains VGCF_in_syscall:
79 * Restore RAX, RIP, RFLAGS, RSP.
80 * Discard R11, RCX, CS, SS.
82 * Restore RAX, R11, RCX, CS:RIP, RFLAGS, SS:RSP.
83 * All other registers are saved on hypercall entry and restored to user.
85 /* Guest exited in SYSCALL context? Return to guest with SYSRET? */
86 #define _VGCF_in_syscall 8
87 #define VGCF_in_syscall (1<<_VGCF_in_syscall)
88 #define VGCF_IN_SYSCALL VGCF_in_syscall
93 /* Top of stack (%rsp at point of hypercall). */
94 uint64_t rax, r11, rcx, flags, rip, cs, rflags, rsp, ss;
95 /* Bottom of iret stack frame. */
98 #if defined(__GNUC__) && !defined(__STRICT_ANSI__)
99 /* Anonymous union includes both 32- and 64-bit names (e.g., eax/rax). */
100 #define __DECL_REG(name) union { \
101 uint64_t r ## name, e ## name; \
102 uint32_t _e ## name; \
105 /* Non-gcc sources must always use the proper 64-bit name (e.g., rax). */
106 #define __DECL_REG(name) uint64_t r ## name
109 struct cpu_user_regs {
125 uint32_t error_code; /* private */
126 uint32_t entry_vector; /* private */
128 uint16_t cs, _pad0[1];
129 uint8_t saved_upcall_mask;
131 __DECL_REG(flags); /* rflags.IF == !saved_upcall_mask */
133 uint16_t ss, _pad2[3];
134 uint16_t es, _pad3[3];
135 uint16_t ds, _pad4[3];
136 uint16_t fs, _pad5[3]; /* Non-zero => takes precedence over fs_base. */
137 uint16_t gs, _pad6[3]; /* Non-zero => takes precedence over gs_base_usr. */
139 DEFINE_GUEST_HANDLE_STRUCT(cpu_user_regs);
143 #define xen_pfn_to_cr3(pfn) ((unsigned long)(pfn) << 12)
144 #define xen_cr3_to_pfn(cr3) ((unsigned long)(cr3) >> 12)
146 struct arch_vcpu_info {
148 unsigned long pad; /* sizeof(vcpu_info_t) == 64 */
151 typedef unsigned long xen_callback_t;
153 #define XEN_CALLBACK(__cs, __rip) \
154 ((unsigned long)(__rip))
156 #endif /* !__ASSEMBLY__ */
159 #endif /* __ASM_X86_XEN_INTERFACE_64_H */