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 
13 FILE_LICENCE ( MIT );
14 FILE_SECBOOT ( PERMITTED );
15 
16 /*
17  * Hypercall interface:
18  * Input: %rdi, %rsi, %rdx, %r10, %r8, %r9 (arguments 1-6)
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 
113 struct iret_context {
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 struct cpu_user_regs {
166  __DECL_REG_HI(15);
167  __DECL_REG_HI(14);
168  __DECL_REG_HI(13);
169  __DECL_REG_HI(12);
171  __DECL_REG_LOHI(b);
172  __DECL_REG_HI(11);
173  __DECL_REG_HI(10);
174  __DECL_REG_HI(9);
175  __DECL_REG_HI(8);
176  __DECL_REG_LOHI(a);
177  __DECL_REG_LOHI(c);
178  __DECL_REG_LOHI(d);
181  uint32_t error_code; /* private */
182  uint32_t entry_vector; /* private */
187  __DECL_REG_LO16(flags); /* rflags.IF == !saved_upcall_mask */
189  uint16_t ss, _pad2[3];
190  uint16_t es, _pad3[3];
191  uint16_t ds, _pad4[3];
192  uint16_t fs, _pad5[3];
194 };
197 
198 #undef __DECL_REG
199 #undef __DECL_REG_LOHI
200 #undef __DECL_REG_LO8
201 #undef __DECL_REG_LO16
202 #undef __DECL_REG_HI
203 
204 #define xen_pfn_to_cr3(pfn) ((unsigned long)(pfn) << 12)
205 #define xen_cr3_to_pfn(cr3) ((unsigned long)(cr3) >> 12)
206 
207 struct arch_vcpu_info {
208  unsigned long cr2;
209  unsigned long pad; /* sizeof(vcpu_info_t) == 64 */
210 };
212 
213 typedef unsigned long xen_callback_t;
214 
215 #endif /* !__ASSEMBLY__ */
216 
217 #endif /* __XEN_PUBLIC_ARCH_X86_XEN_X86_64_H__ */
218 
219 /*
220  * Local variables:
221  * mode: C
222  * c-file-style: "BSD"
223  * c-basic-offset: 4
224  * tab-width: 4
225  * indent-tabs-mode: nil
226  * End:
227  */
DEFINE_XEN_GUEST_HANDLE(cpu_user_regs_t)
unsigned short uint16_t
Definition: stdint.h:11
uint16_t cs
Definition: xen-x86_32.h:130
FILE_SECBOOT(PERMITTED)
uint64_t rax
Definition: xen-x86_64.h:115
uint64_t rip
Definition: xen-x86_64.h:115
uint16_t di
Definition: registers.h:15
uint16_t bp
Definition: registers.h:23
unsigned long long uint64_t
Definition: stdint.h:13
uint8_t _pad0
Definition: xen-x86_32.h:132
uint8_t saved_upcall_mask
Definition: xen-x86_32.h:131
unsigned long pad[5]
Definition: xen-x86_32.h:157
uint16_t _pad6[3]
Definition: xen-x86_64.h:193
uint16_t ss
Definition: xen-x86_32.h:135
uint64_t rflags
Definition: xen-x86_64.h:115
uint16_t _pad3
Definition: xen-x86_32.h:137
uint64_t flags
Definition: xen-x86_64.h:115
uint16_t es
Definition: xen-x86_32.h:136
uint64_t r11
Definition: xen-x86_64.h:115
uint16_t _pad4
Definition: xen-x86_32.h:138
uint8_t flags
Flags.
Definition: ena.h:18
IP4_t ip
Destination IP address.
Definition: pxe_api.h:58
unsigned char uint8_t
Definition: stdint.h:10
uint16_t _pad2
Definition: xen-x86_32.h:136
unsigned int uint32_t
Definition: stdint.h:12
uint32_t error_code
Definition: xen-x86_64.h:181
uint16_t _pad5
Definition: xen-x86_32.h:139
uint64_t cs
Definition: xen-x86_64.h:115
unsigned long xen_callback_t
Definition: xen-x86_64.h:213
unsigned long cr2
Definition: xen-x86_32.h:156
uint16_t si
Definition: registers.h:19
uint16_t _pad1
Definition: xen-x86_32.h:135
uint64_t rsp
Definition: xen-x86_64.h:115
uint16_t fs
Definition: xen-x86_32.h:138
FILE_LICENCE(MIT)
uint64_t ss
Definition: xen-x86_64.h:115
uint32_t entry_vector
Definition: xen-x86_64.h:182
uint16_t ds
Definition: xen-x86_32.h:137
uint64_t rcx
Definition: xen-x86_64.h:115
uint16_t gs
Definition: xen-x86_32.h:139
uint16_t sp
Definition: registers.h:27