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