xref: /illumos-gate/usr/src/uts/common/xen/public/arch-x86/xen-x86_32.h (revision 45ede40b2394db7967e59f19288fae9b62efd4aa)
1 /******************************************************************************
2  * xen-x86_32.h
3  *
4  * Guest OS interface to x86 32-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-2007, K A Fraser
25  */
26 
27 #ifndef __XEN_PUBLIC_ARCH_X86_XEN_X86_32_H__
28 #define __XEN_PUBLIC_ARCH_X86_XEN_X86_32_H__
29 
30 /*
31  * Hypercall interface:
32  *  Input:  %ebx, %ecx, %edx, %esi, %edi (arguments 1-5)
33  *  Output: %eax
34  * Access is via hypercall page (set up by guest loader or via a Xen MSR):
35  *  call hypercall_page + hypercall-number * 32
36  * Clobbered: Argument registers (e.g., 2-arg hypercall clobbers %ebx,%ecx)
37  */
38 
39 /*
40  * Direct hypercall interface:
41  * As above, except the entry sequence to the hypervisor is:
42  *  mov $hypercall-number*32,%eax ; int $0x82
43  */
44 #if !defined(_ASM)
45 #define TRAP_INSTR "int $0x82"
46 #else
47 #define TRAP_INSTR int $0x82
48 #endif
49 
50 /*
51  * These flat segments are in the Xen-private section of every GDT. Since these
52  * are also present in the initial GDT, many OSes will be able to avoid
53  * installing their own GDT.
54  */
55 #define FLAT_RING1_CS 0xe019    /* GDT index 259 */
56 #define FLAT_RING1_DS 0xe021    /* GDT index 260 */
57 #define FLAT_RING1_SS 0xe021    /* GDT index 260 */
58 #define FLAT_RING3_CS 0xe02b    /* GDT index 261 */
59 #define FLAT_RING3_DS 0xe033    /* GDT index 262 */
60 #define FLAT_RING3_SS 0xe033    /* GDT index 262 */
61 
62 #define FLAT_KERNEL_CS FLAT_RING1_CS
63 #define FLAT_KERNEL_DS FLAT_RING1_DS
64 #define FLAT_KERNEL_SS FLAT_RING1_SS
65 #define FLAT_USER_CS    FLAT_RING3_CS
66 #define FLAT_USER_DS    FLAT_RING3_DS
67 #define FLAT_USER_SS    FLAT_RING3_SS
68 
69 #define __HYPERVISOR_VIRT_START_PAE    0xF5800000
70 #define __MACH2PHYS_VIRT_START_PAE     0xF5800000
71 #define __MACH2PHYS_VIRT_END_PAE       0xF6800000
72 #define HYPERVISOR_VIRT_START_PAE      \
73     mk_unsigned_long(__HYPERVISOR_VIRT_START_PAE)
74 #define MACH2PHYS_VIRT_START_PAE       \
75     mk_unsigned_long(__MACH2PHYS_VIRT_START_PAE)
76 #define MACH2PHYS_VIRT_END_PAE         \
77     mk_unsigned_long(__MACH2PHYS_VIRT_END_PAE)
78 
79 /* Non-PAE bounds are obsolete. */
80 #define __HYPERVISOR_VIRT_START_NONPAE 0xFC000000
81 #define __MACH2PHYS_VIRT_START_NONPAE  0xFC000000
82 #define __MACH2PHYS_VIRT_END_NONPAE    0xFC400000
83 #define HYPERVISOR_VIRT_START_NONPAE   \
84     mk_unsigned_long(__HYPERVISOR_VIRT_START_NONPAE)
85 #define MACH2PHYS_VIRT_START_NONPAE    \
86     mk_unsigned_long(__MACH2PHYS_VIRT_START_NONPAE)
87 #define MACH2PHYS_VIRT_END_NONPAE      \
88     mk_unsigned_long(__MACH2PHYS_VIRT_END_NONPAE)
89 
90 #define __HYPERVISOR_VIRT_START __HYPERVISOR_VIRT_START_PAE
91 #define __MACH2PHYS_VIRT_START  __MACH2PHYS_VIRT_START_PAE
92 #define __MACH2PHYS_VIRT_END    __MACH2PHYS_VIRT_END_PAE
93 
94 #ifndef HYPERVISOR_VIRT_START
95 #define HYPERVISOR_VIRT_START mk_unsigned_long(__HYPERVISOR_VIRT_START)
96 #endif
97 
98 #define MACH2PHYS_VIRT_START  mk_unsigned_long(__MACH2PHYS_VIRT_START)
99 #define MACH2PHYS_VIRT_END    mk_unsigned_long(__MACH2PHYS_VIRT_END)
100 #define MACH2PHYS_NR_ENTRIES  ((MACH2PHYS_VIRT_END-MACH2PHYS_VIRT_START)>>2)
101 #ifndef machine_to_phys_mapping
102 #define machine_to_phys_mapping ((unsigned long *)MACH2PHYS_VIRT_START)
103 #endif
104 
105 /* 32-/64-bit invariability for control interfaces (domctl/sysctl). */
106 #if defined(__XEN__) || defined(__XEN_TOOLS__)
107 #undef ___DEFINE_XEN_GUEST_HANDLE
108 
109 #ifdef __GNUC__
110 
111 #define ___DEFINE_XEN_GUEST_HANDLE(name, type)                  \
112     typedef struct { type *p; }                                 \
113         __guest_handle_ ## name;                                \
114     typedef struct { union { type *p; uint64_aligned_t q; }; }  \
115         __guest_handle_64_ ## name
116 
117 #else /* __GNUC__ */
118 
119 /*
120  * Workaround for 6671857.
121  */
122 #define ___DEFINE_XEN_GUEST_HANDLE(name, type)                  \
123     typedef struct { type *p; }                                 \
124         __guest_handle_ ## name;                                \
125     typedef struct { union { type *p; uint64_aligned_t q; } u; }\
126         __guest_handle_64_ ## name
127 
128 #endif /* __GNUC__ */
129 
130 #undef set_xen_guest_handle
131 #define set_xen_guest_handle(hnd, val)                      \
132     do { if ( sizeof(hnd) == 8 ) *(uint64_t *)&(hnd) = 0;   \
133          (hnd).p = val;                                     \
134     } while ( 0 )
135 #define uint64_aligned_t uint64_t __attribute__((aligned(8)))
136 #define __XEN_GUEST_HANDLE_64(name) __guest_handle_64_ ## name
137 #define XEN_GUEST_HANDLE_64(name) __XEN_GUEST_HANDLE_64(name)
138 #endif
139 
140 #ifndef __ASSEMBLY__
141 
142 struct cpu_user_regs {
143     uint32_t ebx;
144     uint32_t ecx;
145     uint32_t edx;
146     uint32_t esi;
147     uint32_t edi;
148     uint32_t ebp;
149     uint32_t eax;
150     uint16_t error_code;    /* private */
151     uint16_t entry_vector;  /* private */
152     uint32_t eip;
153     uint16_t cs;
154     uint8_t  saved_upcall_mask;
155     uint8_t  _pad0;
156     uint32_t eflags;        /* eflags.IF == !saved_upcall_mask */
157     uint32_t esp;
158     uint16_t ss, _pad1;
159     uint16_t es, _pad2;
160     uint16_t ds, _pad3;
161     uint16_t fs, _pad4;
162     uint16_t gs, _pad5;
163 };
164 typedef struct cpu_user_regs cpu_user_regs_t;
165 DEFINE_XEN_GUEST_HANDLE(cpu_user_regs_t);
166 
167 /*
168  * Page-directory addresses above 4GB do not fit into architectural %cr3.
169  * When accessing %cr3, or equivalent field in vcpu_guest_context, guests
170  * must use the following accessor macros to pack/unpack valid MFNs.
171  */
172 #define xen_pfn_to_cr3(pfn) (((unsigned)(pfn) << 12) | ((unsigned)(pfn) >> 20))
173 #define xen_cr3_to_pfn(cr3) (((unsigned)(cr3) >> 12) | ((unsigned)(cr3) << 20))
174 
175 struct arch_vcpu_info {
176     unsigned long cr2;
177     unsigned long pad[5]; /* sizeof(vcpu_info_t) == 64 */
178 };
179 typedef struct arch_vcpu_info arch_vcpu_info_t;
180 
181 struct xen_callback {
182     unsigned long cs;
183     unsigned long eip;
184 };
185 typedef struct xen_callback xen_callback_t;
186 
187 /*
188  * Structure used to capture the register state at panic time.  This struct
189  * is built to mimic a similar structure in Solaris.  If there is interest
190  * in making this panic implementation an official part of Xen, this should
191  * be made more platform-neutral.
192  */
193 struct panic_regs {
194 	unsigned long pad1;
195 	unsigned long pad2;
196 
197 	unsigned long gs;
198 	unsigned long fs;
199 	unsigned long es;
200 	unsigned long ds;
201 	unsigned long edi;
202 	unsigned long esi;
203 	unsigned long ebp;
204 	unsigned long esp;
205 	unsigned long ebx;
206 	unsigned long edx;
207 	unsigned long ecx;
208 	unsigned long eax;
209 	unsigned long pad3;
210 	unsigned long pad4;
211 	unsigned long eip;
212 	unsigned long cs;
213 	unsigned long efl;
214 	unsigned long pad5;
215 	unsigned long ss;
216 };
217 
218 #endif /* !__ASSEMBLY__ */
219 
220 /* Offsets of each field in the xen_panic_regs structure.  */
221 #define PANIC_REG_PAD1		0
222 #define PANIC_REG_PAD2		4
223 #define PANIC_REG_GS		8
224 #define PANIC_REG_FS		12
225 #define PANIC_REG_ES		16
226 #define PANIC_REG_DS		20
227 #define PANIC_REG_EDI		24
228 #define PANIC_REG_ESI		28
229 #define PANIC_REG_EBP		32
230 #define PANIC_REG_ESP		36
231 #define PANIC_REG_EBX		40
232 #define PANIC_REG_EDX		44
233 #define PANIC_REG_ECX		48
234 #define PANIC_REG_EAX		52
235 #define PANIC_REG_PAD3		56
236 #define PANIC_REG_PAD4		60
237 #define PANIC_REG_EIP		64
238 #define PANIC_REG_CS		68
239 #define PANIC_REG_EFL		72
240 #define PANIC_REG_PAD5		76
241 #define PANIC_REG_SS		80
242 #define PANIC_REG_STRUCT_SIZE	84
243 
244 #endif /* __XEN_PUBLIC_ARCH_X86_XEN_X86_32_H__ */
245 
246 /*
247  * Local variables:
248  * mode: C
249  * c-set-style: "BSD"
250  * c-basic-offset: 4
251  * tab-width: 4
252  * indent-tabs-mode: nil
253  * End:
254  */
255