1 /* SPDX-License-Identifier: MIT */
2 /******************************************************************************
5 * Guest OS interface to x86 64-bit Xen.
7 * Copyright (c) 2004-2006, K A Fraser
10 #ifndef __XEN_PUBLIC_ARCH_X86_XEN_X86_64_H__
11 #define __XEN_PUBLIC_ARCH_X86_XEN_X86_64_H__
14 * Hypercall interface:
15 * Input: %rdi, %rsi, %rdx, %r10, %r8, %r9 (arguments 1-6)
17 * Access is via hypercall page (set up by guest loader or via a Xen MSR):
18 * call hypercall_page + hypercall-number * 32
19 * Clobbered: argument registers (e.g., 2-arg hypercall clobbers %rdi,%rsi)
23 * 64-bit segment selectors
24 * These flat segments are in the Xen-private section of every GDT. Since these
25 * are also present in the initial GDT, many OSes will be able to avoid
26 * installing their own GDT.
29 #define FLAT_RING3_CS32 0xe023 /* GDT index 260 */
30 #define FLAT_RING3_CS64 0xe033 /* GDT index 262 */
31 #define FLAT_RING3_DS32 0xe02b /* GDT index 261 */
32 #define FLAT_RING3_DS64 0x0000 /* NULL selector */
33 #define FLAT_RING3_SS32 0xe02b /* GDT index 261 */
34 #define FLAT_RING3_SS64 0xe02b /* GDT index 261 */
36 #define FLAT_KERNEL_DS64 FLAT_RING3_DS64
37 #define FLAT_KERNEL_DS32 FLAT_RING3_DS32
38 #define FLAT_KERNEL_DS FLAT_KERNEL_DS64
39 #define FLAT_KERNEL_CS64 FLAT_RING3_CS64
40 #define FLAT_KERNEL_CS32 FLAT_RING3_CS32
41 #define FLAT_KERNEL_CS FLAT_KERNEL_CS64
42 #define FLAT_KERNEL_SS64 FLAT_RING3_SS64
43 #define FLAT_KERNEL_SS32 FLAT_RING3_SS32
44 #define FLAT_KERNEL_SS FLAT_KERNEL_SS64
46 #define FLAT_USER_DS64 FLAT_RING3_DS64
47 #define FLAT_USER_DS32 FLAT_RING3_DS32
48 #define FLAT_USER_DS FLAT_USER_DS64
49 #define FLAT_USER_CS64 FLAT_RING3_CS64
50 #define FLAT_USER_CS32 FLAT_RING3_CS32
51 #define FLAT_USER_CS FLAT_USER_CS64
52 #define FLAT_USER_SS64 FLAT_RING3_SS64
53 #define FLAT_USER_SS32 FLAT_RING3_SS32
54 #define FLAT_USER_SS FLAT_USER_SS64
56 #define __HYPERVISOR_VIRT_START 0xFFFF800000000000
57 #define __HYPERVISOR_VIRT_END 0xFFFF880000000000
58 #define __MACH2PHYS_VIRT_START 0xFFFF800000000000
59 #define __MACH2PHYS_VIRT_END 0xFFFF804000000000
61 #ifndef HYPERVISOR_VIRT_START
62 #define HYPERVISOR_VIRT_START xen_mk_ulong(__HYPERVISOR_VIRT_START)
63 #define HYPERVISOR_VIRT_END xen_mk_ulong(__HYPERVISOR_VIRT_END)
66 #define MACH2PHYS_VIRT_START xen_mk_ulong(__MACH2PHYS_VIRT_START)
67 #define MACH2PHYS_VIRT_END xen_mk_ulong(__MACH2PHYS_VIRT_END)
68 #define MACH2PHYS_NR_ENTRIES ((MACH2PHYS_VIRT_END-MACH2PHYS_VIRT_START)>>3)
69 #ifndef machine_to_phys_mapping
70 #define machine_to_phys_mapping ((unsigned long *)HYPERVISOR_VIRT_START)
74 * int HYPERVISOR_set_segment_base(unsigned int which, unsigned long base)
75 * @which == SEGBASE_* ; @base == 64-bit base address
76 * Returns 0 on success.
79 #define SEGBASE_GS_USER 1
80 #define SEGBASE_GS_KERNEL 2
81 #define SEGBASE_GS_USER_SEL 3 /* Set user %gs specified in base[15:0] */
84 * int HYPERVISOR_iret(void)
85 * All arguments are on the kernel stack, in the following format.
86 * Never returns if successful. Current kernel context is lost.
87 * The saved CS is mapped as follows:
88 * RING0 -> RING3 kernel mode.
89 * RING1 -> RING3 kernel mode.
90 * RING2 -> RING3 kernel mode.
91 * RING3 -> RING3 user mode.
92 * However RING0 indicates that the guest kernel should return to iteself
96 * If flags contains VGCF_in_syscall:
97 * Restore RAX, RIP, RFLAGS, RSP.
98 * Discard R11, RCX, CS, SS.
100 * Restore RAX, R11, RCX, CS:RIP, RFLAGS, SS:RSP.
101 * All other registers are saved on hypercall entry and restored to user.
103 /* Guest exited in SYSCALL context? Return to guest with SYSRET? */
104 #define _VGCF_in_syscall 8
105 #define VGCF_in_syscall (1<<_VGCF_in_syscall)
106 #define VGCF_IN_SYSCALL VGCF_in_syscall
110 struct iret_context
{
111 /* Top of stack (%rsp at point of hypercall). */
112 uint64_t rax
, r11
, rcx
, flags
, rip
, cs
, rflags
, rsp
, ss
;
113 /* Bottom of iret stack frame. */
116 #if defined(__XEN__) || defined(__XEN_TOOLS__)
117 /* Anonymous unions include all permissible names (e.g., al/ah/ax/eax/rax). */
118 #define __DECL_REG_LOHI(which) union { \
119 uint64_t r ## which ## x; \
120 uint32_t e ## which ## x; \
121 uint16_t which ## x; \
123 uint8_t which ## l; \
124 uint8_t which ## h; \
127 #define __DECL_REG_LO8(name) union { \
128 uint64_t r ## name; \
129 uint32_t e ## name; \
133 #define __DECL_REG_LO16(name) union { \
134 uint64_t r ## name; \
135 uint32_t e ## name; \
138 #define __DECL_REG_HI(num) union { \
140 uint32_t r ## num ## d; \
141 uint16_t r ## num ## w; \
142 uint8_t r ## num ## b; \
144 #elif defined(__GNUC__) && !defined(__STRICT_ANSI__)
145 /* Anonymous union includes both 32- and 64-bit names (e.g., eax/rax). */
146 #define __DECL_REG(name) union { \
147 uint64_t r ## name, e ## name; \
148 uint32_t _e ## name; \
151 /* Non-gcc sources must always use the proper 64-bit name (e.g., rax). */
152 #define __DECL_REG(name) uint64_t r ## name
155 #ifndef __DECL_REG_LOHI
156 #define __DECL_REG_LOHI(name) __DECL_REG(name ## x)
157 #define __DECL_REG_LO8 __DECL_REG
158 #define __DECL_REG_LO16 __DECL_REG
159 #define __DECL_REG_HI(num) uint64_t r ## num
162 struct cpu_user_regs
{
178 uint32_t error_code
; /* private */
179 uint32_t entry_vector
; /* private */
181 uint16_t cs
, _pad0
[1];
182 uint8_t saved_upcall_mask
;
184 __DECL_REG_LO16(flags
); /* rflags.IF == !saved_upcall_mask */
186 uint16_t ss
, _pad2
[3];
187 uint16_t es
, _pad3
[3];
188 uint16_t ds
, _pad4
[3];
189 uint16_t fs
, _pad5
[3];
190 uint16_t gs
, _pad6
[3];
192 typedef struct cpu_user_regs cpu_user_regs_t
;
193 DEFINE_XEN_GUEST_HANDLE(cpu_user_regs_t
);
196 #undef __DECL_REG_LOHI
197 #undef __DECL_REG_LO8
198 #undef __DECL_REG_LO16
201 #define xen_pfn_to_cr3(pfn) ((unsigned long)(pfn) << 12)
202 #define xen_cr3_to_pfn(cr3) ((unsigned long)(cr3) >> 12)
204 struct arch_vcpu_info
{
206 unsigned long pad
; /* sizeof(vcpu_info_t) == 64 */
208 typedef struct arch_vcpu_info arch_vcpu_info_t
;
210 typedef unsigned long xen_callback_t
;
212 #endif /* !__ASSEMBLY__ */
214 #endif /* __XEN_PUBLIC_ARCH_X86_XEN_X86_64_H__ */
219 * c-file-style: "BSD"
222 * indent-tabs-mode: nil