iPXE
xen-x86_64.h
Go to the documentation of this file.
1 /******************************************************************************
2  * xen-x86_64.h
3  *
4  * Guest OS interface to x86 64-bit Xen.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to
8  * deal in the Software without restriction, including without limitation the
9  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10  * sell copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22  * DEALINGS IN THE SOFTWARE.
23  *
24  * Copyright (c) 2004-2006, K A Fraser
25  */
26 
27 #ifndef __XEN_PUBLIC_ARCH_X86_XEN_X86_64_H__
28 #define __XEN_PUBLIC_ARCH_X86_XEN_X86_64_H__
29 
30 FILE_LICENCE ( MIT );
31 
32 /*
33  * Hypercall interface:
34  * Input: %rdi, %rsi, %rdx, %r10, %r8, %r9 (arguments 1-6)
35  * Output: %rax
36  * Access is via hypercall page (set up by guest loader or via a Xen MSR):
37  * call hypercall_page + hypercall-number * 32
38  * Clobbered: argument registers (e.g., 2-arg hypercall clobbers %rdi,%rsi)
39  */
40 
41 /*
42  * 64-bit segment selectors
43  * These flat segments are in the Xen-private section of every GDT. Since these
44  * are also present in the initial GDT, many OSes will be able to avoid
45  * installing their own GDT.
46  */
47 
48 #define FLAT_RING3_CS32 0xe023 /* GDT index 260 */
49 #define FLAT_RING3_CS64 0xe033 /* GDT index 261 */
50 #define FLAT_RING3_DS32 0xe02b /* GDT index 262 */
51 #define FLAT_RING3_DS64 0x0000 /* NULL selector */
52 #define FLAT_RING3_SS32 0xe02b /* GDT index 262 */
53 #define FLAT_RING3_SS64 0xe02b /* GDT index 262 */
54 
55 #define FLAT_KERNEL_DS64 FLAT_RING3_DS64
56 #define FLAT_KERNEL_DS32 FLAT_RING3_DS32
57 #define FLAT_KERNEL_DS FLAT_KERNEL_DS64
58 #define FLAT_KERNEL_CS64 FLAT_RING3_CS64
59 #define FLAT_KERNEL_CS32 FLAT_RING3_CS32
60 #define FLAT_KERNEL_CS FLAT_KERNEL_CS64
61 #define FLAT_KERNEL_SS64 FLAT_RING3_SS64
62 #define FLAT_KERNEL_SS32 FLAT_RING3_SS32
63 #define FLAT_KERNEL_SS FLAT_KERNEL_SS64
64 
65 #define FLAT_USER_DS64 FLAT_RING3_DS64
66 #define FLAT_USER_DS32 FLAT_RING3_DS32
67 #define FLAT_USER_DS FLAT_USER_DS64
68 #define FLAT_USER_CS64 FLAT_RING3_CS64
69 #define FLAT_USER_CS32 FLAT_RING3_CS32
70 #define FLAT_USER_CS FLAT_USER_CS64
71 #define FLAT_USER_SS64 FLAT_RING3_SS64
72 #define FLAT_USER_SS32 FLAT_RING3_SS32
73 #define FLAT_USER_SS FLAT_USER_SS64
74 
75 #define __HYPERVISOR_VIRT_START 0xFFFF800000000000
76 #define __HYPERVISOR_VIRT_END 0xFFFF880000000000
77 #define __MACH2PHYS_VIRT_START 0xFFFF800000000000
78 #define __MACH2PHYS_VIRT_END 0xFFFF804000000000
79 
80 #ifndef HYPERVISOR_VIRT_START
81 #define HYPERVISOR_VIRT_START mk_unsigned_long(__HYPERVISOR_VIRT_START)
82 #define HYPERVISOR_VIRT_END mk_unsigned_long(__HYPERVISOR_VIRT_END)
83 #endif
84 
85 #define MACH2PHYS_VIRT_START mk_unsigned_long(__MACH2PHYS_VIRT_START)
86 #define MACH2PHYS_VIRT_END mk_unsigned_long(__MACH2PHYS_VIRT_END)
87 #define MACH2PHYS_NR_ENTRIES ((MACH2PHYS_VIRT_END-MACH2PHYS_VIRT_START)>>3)
88 #ifndef machine_to_phys_mapping
89 #define machine_to_phys_mapping ((unsigned long *)HYPERVISOR_VIRT_START)
90 #endif
91 
92 /*
93  * int HYPERVISOR_set_segment_base(unsigned int which, unsigned long base)
94  * @which == SEGBASE_* ; @base == 64-bit base address
95  * Returns 0 on success.
96  */
97 #define SEGBASE_FS 0
98 #define SEGBASE_GS_USER 1
99 #define SEGBASE_GS_KERNEL 2
100 #define SEGBASE_GS_USER_SEL 3 /* Set user %gs specified in base[15:0] */
101 
102 /*
103  * int HYPERVISOR_iret(void)
104  * All arguments are on the kernel stack, in the following format.
105  * Never returns if successful. Current kernel context is lost.
106  * The saved CS is mapped as follows:
107  * RING0 -> RING3 kernel mode.
108  * RING1 -> RING3 kernel mode.
109  * RING2 -> RING3 kernel mode.
110  * RING3 -> RING3 user mode.
111  * However RING0 indicates that the guest kernel should return to iteself
112  * directly with
113  * orb $3,1*8(%rsp)
114  * iretq
115  * If flags contains VGCF_in_syscall:
116  * Restore RAX, RIP, RFLAGS, RSP.
117  * Discard R11, RCX, CS, SS.
118  * Otherwise:
119  * Restore RAX, R11, RCX, CS:RIP, RFLAGS, SS:RSP.
120  * All other registers are saved on hypercall entry and restored to user.
121  */
122 /* Guest exited in SYSCALL context? Return to guest with SYSRET? */
123 #define _VGCF_in_syscall 8
124 #define VGCF_in_syscall (1<<_VGCF_in_syscall)
125 #define VGCF_IN_SYSCALL VGCF_in_syscall
126 
127 #ifndef __ASSEMBLY__
128 
129 struct iret_context {
130  /* Top of stack (%rsp at point of hypercall). */
132  /* Bottom of iret stack frame. */
133 };
134 
135 #if defined(__GNUC__) && !defined(__STRICT_ANSI__)
136 /* Anonymous union includes both 32- and 64-bit names (e.g., eax/rax). */
137 #define __DECL_REG(name) union { \
138  uint64_t r ## name, e ## name; \
139  uint32_t _e ## name; \
140 }
141 #else
142 /* Non-gcc sources must always use the proper 64-bit name (e.g., rax). */
143 #define __DECL_REG(name) uint64_t r ## name
144 #endif
145 
146 struct cpu_user_regs {
151  __DECL_REG(bp);
152  __DECL_REG(bx);
157  __DECL_REG(ax);
158  __DECL_REG(cx);
159  __DECL_REG(dx);
160  __DECL_REG(si);
161  __DECL_REG(di);
162  uint32_t error_code; /* private */
163  uint32_t entry_vector; /* private */
164  __DECL_REG(ip);
168  __DECL_REG(flags); /* rflags.IF == !saved_upcall_mask */
169  __DECL_REG(sp);
170  uint16_t ss, _pad2[3];
171  uint16_t es, _pad3[3];
172  uint16_t ds, _pad4[3];
173  uint16_t fs, _pad5[3]; /* Non-zero => takes precedence over fs_base. */
174  uint16_t gs, _pad6[3]; /* Non-zero => takes precedence over gs_base_usr. */
175 };
178 
179 #undef __DECL_REG
180 
181 #define xen_pfn_to_cr3(pfn) ((unsigned long)(pfn) << 12)
182 #define xen_cr3_to_pfn(cr3) ((unsigned long)(cr3) >> 12)
183 
184 struct arch_vcpu_info {
185  unsigned long cr2;
186  unsigned long pad; /* sizeof(vcpu_info_t) == 64 */
187 };
189 
190 typedef unsigned long xen_callback_t;
191 
192 #endif /* !__ASSEMBLY__ */
193 
194 #endif /* __XEN_PUBLIC_ARCH_X86_XEN_X86_64_H__ */
195 
196 /*
197  * Local variables:
198  * mode: C
199  * c-file-style: "BSD"
200  * c-basic-offset: 4
201  * tab-width: 4
202  * indent-tabs-mode: nil
203  * End:
204  */
uint64_t r11
Definition: xen-x86_64.h:153
DEFINE_XEN_GUEST_HANDLE(cpu_user_regs_t)
unsigned short uint16_t
Definition: stdint.h:11
uint16_t ax
Definition: registers.h:59
uint16_t cs
Definition: xen-x86_32.h:127
uint64_t rax
Definition: xen-x86_64.h:131
uint64_t rip
Definition: xen-x86_64.h:131
uint16_t di
Definition: registers.h:15
uint64_t r9
Definition: xen-x86_64.h:155
uint16_t bp
Definition: registers.h:23
unsigned long long uint64_t
Definition: stdint.h:13
uint8_t _pad0
Definition: xen-x86_32.h:129
uint64_t r8
Definition: xen-x86_64.h:156
uint8_t saved_upcall_mask
Definition: xen-x86_32.h:128
unsigned long pad[5]
Definition: xen-x86_32.h:151
uint16_t cx
Definition: registers.h:51
uint16_t _pad6[3]
Definition: xen-x86_64.h:174
uint16_t ss
Definition: xen-x86_32.h:132
uint64_t rflags
Definition: xen-x86_64.h:131
uint16_t bx
Definition: registers.h:35
uint16_t _pad3
Definition: xen-x86_32.h:134
uint64_t r13
Definition: xen-x86_64.h:149
uint64_t flags
Definition: xen-x86_64.h:131
uint16_t dx
Definition: registers.h:43
uint16_t es
Definition: xen-x86_32.h:133
uint64_t r11
Definition: xen-x86_64.h:131
uint16_t _pad4
Definition: xen-x86_32.h:135
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:133
unsigned int uint32_t
Definition: stdint.h:12
uint32_t error_code
Definition: xen-x86_64.h:162
uint64_t r15
Definition: xen-x86_64.h:147
uint16_t _pad5
Definition: xen-x86_32.h:136
uint64_t cs
Definition: xen-x86_64.h:131
unsigned long xen_callback_t
Definition: xen-x86_64.h:190
unsigned long cr2
Definition: xen-x86_32.h:150
uint64_t r10
Definition: xen-x86_64.h:154
uint16_t si
Definition: registers.h:19
uint64_t r14
Definition: xen-x86_64.h:148
uint16_t _pad1
Definition: xen-x86_32.h:132
uint64_t rsp
Definition: xen-x86_64.h:131
uint16_t fs
Definition: xen-x86_32.h:135
FILE_LICENCE(MIT)
uint64_t ss
Definition: xen-x86_64.h:131
uint64_t r12
Definition: xen-x86_64.h:150
uint32_t entry_vector
Definition: xen-x86_64.h:163
uint16_t ds
Definition: xen-x86_32.h:134
uint64_t rcx
Definition: xen-x86_64.h:131
uint16_t gs
Definition: xen-x86_32.h:136
uint16_t sp
Definition: registers.h:27
uint8_t flags
Flags.
Definition: ena.h:18