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