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