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-2006, 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 #ifndef __ASSEMBLY__
119 
120 struct cpu_user_regs {
121     uint32_t ebx;
122     uint32_t ecx;
123     uint32_t edx;
124     uint32_t esi;
125     uint32_t edi;
126     uint32_t ebp;
127     uint32_t eax;
128     uint16_t error_code;    /* private */
129     uint16_t entry_vector;  /* private */
130     uint32_t eip;
131     uint16_t cs;
132     uint8_t  saved_upcall_mask;
133     uint8_t  _pad0;
134     uint32_t eflags;        /* eflags.IF == !saved_upcall_mask */
135     uint32_t esp;
136     uint16_t ss, _pad1;
137     uint16_t es, _pad2;
138     uint16_t ds, _pad3;
139     uint16_t fs, _pad4;
140     uint16_t gs, _pad5;
141 };
142 typedef struct cpu_user_regs cpu_user_regs_t;
143 DEFINE_XEN_GUEST_HANDLE(cpu_user_regs_t);
144 
145 /*
146  * Page-directory addresses above 4GB do not fit into architectural %cr3.
147  * When accessing %cr3, or equivalent field in vcpu_guest_context, guests
148  * must use the following accessor macros to pack/unpack valid MFNs.
149  */
150 #define xen_pfn_to_cr3(pfn) (((unsigned)(pfn) << 12) | ((unsigned)(pfn) >> 20))
151 #define xen_cr3_to_pfn(cr3) (((unsigned)(cr3) >> 12) | ((unsigned)(cr3) << 20))
152 
153 struct arch_vcpu_info {
154     unsigned long cr2;
155     unsigned long pad[5]; /* sizeof(vcpu_info_t) == 64 */
156 };
157 typedef struct arch_vcpu_info arch_vcpu_info_t;
158 
159 struct xen_callback {
160     unsigned long cs;
161     unsigned long eip;
162 };
163 typedef struct xen_callback xen_callback_t;
164 
165 /*
166  * Structure used to capture the register state at panic time.  This struct
167  * is built to mimic a similar structure in Solaris.  If there is interest
168  * in making this panic implementation an official part of Xen, this should
169  * be made more platform-neutral.
170  */
171 struct panic_regs {
172 	unsigned long pad1;
173 	unsigned long pad2;
174 
175 	unsigned long gs;
176 	unsigned long fs;
177 	unsigned long es;
178 	unsigned long ds;
179 	unsigned long edi;
180 	unsigned long esi;
181 	unsigned long ebp;
182 	unsigned long esp;
183 	unsigned long ebx;
184 	unsigned long edx;
185 	unsigned long ecx;
186 	unsigned long eax;
187 	unsigned long pad3;
188 	unsigned long pad4;
189 	unsigned long eip;
190 	unsigned long cs;
191 	unsigned long efl;
192 	unsigned long pad5;
193 	unsigned long ss;
194 };
195 
196 #endif /* !__ASSEMBLY__ */
197 
198 /* Offsets of each field in the xen_panic_regs structure.  */
199 #define PANIC_REG_PAD1		0
200 #define PANIC_REG_PAD2		4
201 #define PANIC_REG_GS		8
202 #define PANIC_REG_FS		12
203 #define PANIC_REG_ES		16
204 #define PANIC_REG_DS		20
205 #define PANIC_REG_EDI		24
206 #define PANIC_REG_ESI		28
207 #define PANIC_REG_EBP		32
208 #define PANIC_REG_ESP		36
209 #define PANIC_REG_EBX		40
210 #define PANIC_REG_EDX		44
211 #define PANIC_REG_ECX		48
212 #define PANIC_REG_EAX		52
213 #define PANIC_REG_PAD3		56
214 #define PANIC_REG_PAD4		60
215 #define PANIC_REG_EIP		64
216 #define PANIC_REG_CS		68
217 #define PANIC_REG_EFL		72
218 #define PANIC_REG_PAD5		76
219 #define PANIC_REG_SS		80
220 #define PANIC_REG_STRUCT_SIZE	84
221 
222 #endif /* __XEN_PUBLIC_ARCH_X86_XEN_X86_32_H__ */
223 
224 /*
225  * Local variables:
226  * mode: C
227  * c-set-style: "BSD"
228  * c-basic-offset: 4
229  * tab-width: 4
230  * indent-tabs-mode: nil
231  * End:
232  */
233