iPXE
xen-x86_64.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: MIT */
2/******************************************************************************
3 * xen-x86_64.h
4 *
5 * Guest OS interface to x86 64-bit Xen.
6 *
7 * Copyright (c) 2004-2006, K A Fraser
8 */
9
10#ifndef __XEN_PUBLIC_ARCH_X86_XEN_X86_64_H__
11#define __XEN_PUBLIC_ARCH_X86_XEN_X86_64_H__
12
14FILE_SECBOOT ( PERMITTED );
15
16/*
17 * Hypercall interface:
18 * Input: %rdi, %rsi, %rdx, %r10, %r8 (arguments 1-5)
19 * Output: %rax
20 * Access is via hypercall page (set up by guest loader or via a Xen MSR):
21 * call hypercall_page + hypercall-number * 32
22 * Clobbered: argument registers (e.g., 2-arg hypercall clobbers %rdi,%rsi)
23 */
24
25/*
26 * 64-bit segment selectors
27 * These flat segments are in the Xen-private section of every GDT. Since these
28 * are also present in the initial GDT, many OSes will be able to avoid
29 * installing their own GDT.
30 */
31
32#define FLAT_RING3_CS32 0xe023 /* GDT index 260 */
33#define FLAT_RING3_CS64 0xe033 /* GDT index 262 */
34#define FLAT_RING3_DS32 0xe02b /* GDT index 261 */
35#define FLAT_RING3_DS64 0x0000 /* NULL selector */
36#define FLAT_RING3_SS32 0xe02b /* GDT index 261 */
37#define FLAT_RING3_SS64 0xe02b /* GDT index 261 */
38
39#define FLAT_KERNEL_DS64 FLAT_RING3_DS64
40#define FLAT_KERNEL_DS32 FLAT_RING3_DS32
41#define FLAT_KERNEL_DS FLAT_KERNEL_DS64
42#define FLAT_KERNEL_CS64 FLAT_RING3_CS64
43#define FLAT_KERNEL_CS32 FLAT_RING3_CS32
44#define FLAT_KERNEL_CS FLAT_KERNEL_CS64
45#define FLAT_KERNEL_SS64 FLAT_RING3_SS64
46#define FLAT_KERNEL_SS32 FLAT_RING3_SS32
47#define FLAT_KERNEL_SS FLAT_KERNEL_SS64
48
49#define FLAT_USER_DS64 FLAT_RING3_DS64
50#define FLAT_USER_DS32 FLAT_RING3_DS32
51#define FLAT_USER_DS FLAT_USER_DS64
52#define FLAT_USER_CS64 FLAT_RING3_CS64
53#define FLAT_USER_CS32 FLAT_RING3_CS32
54#define FLAT_USER_CS FLAT_USER_CS64
55#define FLAT_USER_SS64 FLAT_RING3_SS64
56#define FLAT_USER_SS32 FLAT_RING3_SS32
57#define FLAT_USER_SS FLAT_USER_SS64
58
59#define __HYPERVISOR_VIRT_START 0xFFFF800000000000
60#define __HYPERVISOR_VIRT_END 0xFFFF880000000000
61#define __MACH2PHYS_VIRT_START 0xFFFF800000000000
62#define __MACH2PHYS_VIRT_END 0xFFFF804000000000
63
64#ifndef HYPERVISOR_VIRT_START
65#define HYPERVISOR_VIRT_START xen_mk_ulong(__HYPERVISOR_VIRT_START)
66#define HYPERVISOR_VIRT_END xen_mk_ulong(__HYPERVISOR_VIRT_END)
67#endif
68
69#define MACH2PHYS_VIRT_START xen_mk_ulong(__MACH2PHYS_VIRT_START)
70#define MACH2PHYS_VIRT_END xen_mk_ulong(__MACH2PHYS_VIRT_END)
71#define MACH2PHYS_NR_ENTRIES ((MACH2PHYS_VIRT_END-MACH2PHYS_VIRT_START)>>3)
72#ifndef machine_to_phys_mapping
73#define machine_to_phys_mapping ((unsigned long *)HYPERVISOR_VIRT_START)
74#endif
75
76/*
77 * int HYPERVISOR_set_segment_base(unsigned int which, unsigned long base)
78 * @which == SEGBASE_* ; @base == 64-bit base address
79 * Returns 0 on success.
80 */
81#define SEGBASE_FS 0
82#define SEGBASE_GS_USER 1
83#define SEGBASE_GS_KERNEL 2
84#define SEGBASE_GS_USER_SEL 3 /* Set user %gs specified in base[15:0] */
85
86/*
87 * int HYPERVISOR_iret(void)
88 * All arguments are on the kernel stack, in the following format.
89 * Never returns if successful. Current kernel context is lost.
90 * The saved CS is mapped as follows:
91 * RING0 -> RING3 kernel mode.
92 * RING1 -> RING3 kernel mode.
93 * RING2 -> RING3 kernel mode.
94 * RING3 -> RING3 user mode.
95 * However RING0 indicates that the guest kernel should return to iteself
96 * directly with
97 * orb $3,1*8(%rsp)
98 * iretq
99 * If flags contains VGCF_in_syscall:
100 * Restore RAX, RIP, RFLAGS, RSP.
101 * Discard R11, RCX, CS, SS.
102 * Otherwise:
103 * Restore RAX, R11, RCX, CS:RIP, RFLAGS, SS:RSP.
104 * All other registers are saved on hypercall entry and restored to user.
105 */
106/* Guest exited in SYSCALL context? Return to guest with SYSRET? */
107#define _VGCF_in_syscall 8
108#define VGCF_in_syscall (1<<_VGCF_in_syscall)
109#define VGCF_IN_SYSCALL VGCF_in_syscall
110
111#ifndef __ASSEMBLY__
112
114 /* Top of stack (%rsp at point of hypercall). */
116 /* Bottom of iret stack frame. */
117};
118
119#if defined(__XEN__) || defined(__XEN_TOOLS__)
120/* Anonymous unions include all permissible names (e.g., al/ah/ax/eax/rax). */
121#define __DECL_REG_LOHI(which) union { \
122 uint64_t r ## which ## x; \
123 uint32_t e ## which ## x; \
124 uint16_t which ## x; \
125 struct { \
126 uint8_t which ## l; \
127 uint8_t which ## h; \
128 }; \
129}
130#define __DECL_REG_LO8(name) union { \
131 uint64_t r ## name; \
132 uint32_t e ## name; \
133 uint16_t name; \
134 uint8_t name ## l; \
135}
136#define __DECL_REG_LO16(name) union { \
137 uint64_t r ## name; \
138 uint32_t e ## name; \
139 uint16_t name; \
140}
141#define __DECL_REG_HI(num) union { \
142 uint64_t r ## num; \
143 uint32_t r ## num ## d; \
144 uint16_t r ## num ## w; \
145 uint8_t r ## num ## b; \
146}
147#elif defined(__GNUC__) && !defined(__STRICT_ANSI__)
148/* Anonymous union includes both 32- and 64-bit names (e.g., eax/rax). */
149#define __DECL_REG(name) union { \
150 uint64_t r ## name, e ## name; \
151 uint32_t _e ## name; \
152}
153#else
154/* Non-gcc sources must always use the proper 64-bit name (e.g., rax). */
155#define __DECL_REG(name) uint64_t r ## name
156#endif
157
158#ifndef __DECL_REG_LOHI
159#define __DECL_REG_LOHI(name) __DECL_REG(name ## x)
160#define __DECL_REG_LO8 __DECL_REG
161#define __DECL_REG_LO16 __DECL_REG
162#define __DECL_REG_HI(num) uint64_t r ## num
163#endif
164
165#ifdef __XEN__
166#define cpu_user_regs guest_user_regs
167#endif
168
169struct cpu_user_regs {
185 uint32_t error_code; /* private */
186 uint32_t entry_vector; /* private */
191 __DECL_REG_LO16(flags); /* rflags.IF == !saved_upcall_mask */
193 uint16_t ss, _pad2[3];
194 uint16_t es, _pad3[3];
195 uint16_t ds, _pad4[3];
196 uint16_t fs, _pad5[3];
198};
199
200#ifdef __XEN__
201#undef cpu_user_regs
202#else
203typedef struct cpu_user_regs cpu_user_regs_t;
205#endif
206
207#undef __DECL_REG
208#undef __DECL_REG_LOHI
209#undef __DECL_REG_LO8
210#undef __DECL_REG_LO16
211#undef __DECL_REG_HI
212
213#define xen_pfn_to_cr3(pfn) ((unsigned long)(pfn) << 12)
214#define xen_cr3_to_pfn(cr3) ((unsigned long)(cr3) >> 12)
215
216struct arch_vcpu_info {
217 unsigned long cr2;
218 unsigned long pad; /* sizeof(vcpu_info_t) == 64 */
219};
220typedef struct arch_vcpu_info arch_vcpu_info_t;
221
222typedef unsigned long xen_callback_t;
223
224#endif /* !__ASSEMBLY__ */
225
226#endif /* __XEN_PUBLIC_ARCH_X86_XEN_X86_64_H__ */
227
228/*
229 * Local variables:
230 * mode: C
231 * c-file-style: "BSD"
232 * c-basic-offset: 4
233 * tab-width: 4
234 * indent-tabs-mode: nil
235 * End:
236 */
u32 pad[9]
Padding.
Definition ar9003_mac.h:23
struct arch_vcpu_info arch_vcpu_info_t
Definition arch-arm.h:366
uint64_t xen_callback_t
Definition arch-arm.h:371
unsigned short uint16_t
Definition stdint.h:11
unsigned int uint32_t
Definition stdint.h:12
unsigned long long uint64_t
Definition stdint.h:13
unsigned char uint8_t
Definition stdint.h:10
uint8_t flags
Flags.
Definition ena.h:7
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
Definition compiler.h:896
#define FILE_SECBOOT(_status)
Declare a file's UEFI Secure Boot permission status.
Definition compiler.h:926
#define DEFINE_XEN_GUEST_HANDLE(name)
Definition nonxen.h:26
IP4_t ip
Destination IP address.
Definition pxe_api.h:1
uint16_t sp
Definition registers.h:13
uint16_t bp
Definition registers.h:9
uint16_t di
Definition registers.h:1
uint16_t si
Definition registers.h:5
unsigned long cr2
Definition xen-x86_32.h:166
uint16_t ss
Definition xen-x86_32.h:140
__DECL_REG_LO16(flags)
uint8_t saved_upcall_mask
Definition xen-x86_32.h:136
uint16_t _pad3
Definition xen-x86_32.h:142
uint16_t cs
Definition xen-x86_32.h:135
uint16_t fs
Definition xen-x86_32.h:143
uint8_t _pad0
Definition xen-x86_32.h:137
uint16_t _pad4
Definition xen-x86_32.h:143
uint16_t _pad6[3]
Definition xen-x86_64.h:197
uint16_t _pad1
Definition xen-x86_32.h:140
uint16_t error_code
Definition xen-x86_32.h:132
uint16_t _pad2
Definition xen-x86_32.h:141
uint16_t _pad5
Definition xen-x86_32.h:144
uint16_t entry_vector
Definition xen-x86_32.h:133
uint16_t es
Definition xen-x86_32.h:141
uint16_t gs
Definition xen-x86_32.h:144
uint16_t ds
Definition xen-x86_32.h:142
uint64_t rflags
Definition xen-x86_64.h:115
uint64_t r11
Definition xen-x86_64.h:115
uint64_t cs
Definition xen-x86_64.h:115
uint64_t rip
Definition xen-x86_64.h:115
uint64_t rcx
Definition xen-x86_64.h:115
uint64_t ss
Definition xen-x86_64.h:115
uint64_t rsp
Definition xen-x86_64.h:115
uint64_t flags
Definition xen-x86_64.h:115
uint64_t rax
Definition xen-x86_64.h:115
struct cpu_user_regs cpu_user_regs_t
Definition xen-x86_32.h:150