1181624Skmacy/******************************************************************************
2181624Skmacy * xen-x86_32.h
3181624Skmacy *
4181624Skmacy * Guest OS interface to x86 32-bit Xen.
5181624Skmacy *
6181624Skmacy * Permission is hereby granted, free of charge, to any person obtaining a copy
7181624Skmacy * of this software and associated documentation files (the "Software"), to
8181624Skmacy * deal in the Software without restriction, including without limitation the
9181624Skmacy * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10181624Skmacy * sell copies of the Software, and to permit persons to whom the Software is
11181624Skmacy * furnished to do so, subject to the following conditions:
12181624Skmacy *
13181624Skmacy * The above copyright notice and this permission notice shall be included in
14181624Skmacy * all copies or substantial portions of the Software.
15181624Skmacy *
16181624Skmacy * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17181624Skmacy * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18181624Skmacy * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19181624Skmacy * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20181624Skmacy * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21181624Skmacy * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22181624Skmacy * DEALINGS IN THE SOFTWARE.
23181624Skmacy *
24181624Skmacy * Copyright (c) 2004-2007, K A Fraser
25181624Skmacy */
26181624Skmacy
27181624Skmacy#ifndef __XEN_PUBLIC_ARCH_X86_XEN_X86_32_H__
28181624Skmacy#define __XEN_PUBLIC_ARCH_X86_XEN_X86_32_H__
29181624Skmacy
30181624Skmacy/*
31181624Skmacy * Hypercall interface:
32251767Sgibbs *  Input:  %ebx, %ecx, %edx, %esi, %edi, %ebp (arguments 1-6)
33181624Skmacy *  Output: %eax
34181624Skmacy * Access is via hypercall page (set up by guest loader or via a Xen MSR):
35181624Skmacy *  call hypercall_page + hypercall-number * 32
36181624Skmacy * Clobbered: Argument registers (e.g., 2-arg hypercall clobbers %ebx,%ecx)
37181624Skmacy */
38181624Skmacy
39181624Skmacy/*
40181624Skmacy * These flat segments are in the Xen-private section of every GDT. Since these
41181624Skmacy * are also present in the initial GDT, many OSes will be able to avoid
42181624Skmacy * installing their own GDT.
43181624Skmacy */
44181624Skmacy#define FLAT_RING1_CS 0xe019    /* GDT index 259 */
45181624Skmacy#define FLAT_RING1_DS 0xe021    /* GDT index 260 */
46181624Skmacy#define FLAT_RING1_SS 0xe021    /* GDT index 260 */
47181624Skmacy#define FLAT_RING3_CS 0xe02b    /* GDT index 261 */
48181624Skmacy#define FLAT_RING3_DS 0xe033    /* GDT index 262 */
49181624Skmacy#define FLAT_RING3_SS 0xe033    /* GDT index 262 */
50181624Skmacy
51181624Skmacy#define FLAT_KERNEL_CS FLAT_RING1_CS
52181624Skmacy#define FLAT_KERNEL_DS FLAT_RING1_DS
53181624Skmacy#define FLAT_KERNEL_SS FLAT_RING1_SS
54181624Skmacy#define FLAT_USER_CS    FLAT_RING3_CS
55181624Skmacy#define FLAT_USER_DS    FLAT_RING3_DS
56181624Skmacy#define FLAT_USER_SS    FLAT_RING3_SS
57181624Skmacy
58181624Skmacy#define __HYPERVISOR_VIRT_START_PAE    0xF5800000
59181624Skmacy#define __MACH2PHYS_VIRT_START_PAE     0xF5800000
60181624Skmacy#define __MACH2PHYS_VIRT_END_PAE       0xF6800000
61181624Skmacy#define HYPERVISOR_VIRT_START_PAE      \
62181624Skmacy    mk_unsigned_long(__HYPERVISOR_VIRT_START_PAE)
63181624Skmacy#define MACH2PHYS_VIRT_START_PAE       \
64181624Skmacy    mk_unsigned_long(__MACH2PHYS_VIRT_START_PAE)
65181624Skmacy#define MACH2PHYS_VIRT_END_PAE         \
66181624Skmacy    mk_unsigned_long(__MACH2PHYS_VIRT_END_PAE)
67181624Skmacy
68183340Skmacy/* Non-PAE bounds are obsolete. */
69181624Skmacy#define __HYPERVISOR_VIRT_START_NONPAE 0xFC000000
70181624Skmacy#define __MACH2PHYS_VIRT_START_NONPAE  0xFC000000
71181624Skmacy#define __MACH2PHYS_VIRT_END_NONPAE    0xFC400000
72181624Skmacy#define HYPERVISOR_VIRT_START_NONPAE   \
73181624Skmacy    mk_unsigned_long(__HYPERVISOR_VIRT_START_NONPAE)
74181624Skmacy#define MACH2PHYS_VIRT_START_NONPAE    \
75181624Skmacy    mk_unsigned_long(__MACH2PHYS_VIRT_START_NONPAE)
76181624Skmacy#define MACH2PHYS_VIRT_END_NONPAE      \
77181624Skmacy    mk_unsigned_long(__MACH2PHYS_VIRT_END_NONPAE)
78181624Skmacy
79181624Skmacy#define __HYPERVISOR_VIRT_START __HYPERVISOR_VIRT_START_PAE
80181624Skmacy#define __MACH2PHYS_VIRT_START  __MACH2PHYS_VIRT_START_PAE
81181624Skmacy#define __MACH2PHYS_VIRT_END    __MACH2PHYS_VIRT_END_PAE
82181624Skmacy
83181624Skmacy#ifndef HYPERVISOR_VIRT_START
84181624Skmacy#define HYPERVISOR_VIRT_START mk_unsigned_long(__HYPERVISOR_VIRT_START)
85181624Skmacy#endif
86181624Skmacy
87181624Skmacy#define MACH2PHYS_VIRT_START  mk_unsigned_long(__MACH2PHYS_VIRT_START)
88181624Skmacy#define MACH2PHYS_VIRT_END    mk_unsigned_long(__MACH2PHYS_VIRT_END)
89181624Skmacy#define MACH2PHYS_NR_ENTRIES  ((MACH2PHYS_VIRT_END-MACH2PHYS_VIRT_START)>>2)
90181624Skmacy#ifndef machine_to_phys_mapping
91181624Skmacy#define machine_to_phys_mapping ((unsigned long *)MACH2PHYS_VIRT_START)
92181624Skmacy#endif
93181624Skmacy
94181624Skmacy/* 32-/64-bit invariability for control interfaces (domctl/sysctl). */
95181624Skmacy#if defined(__XEN__) || defined(__XEN_TOOLS__)
96183340Skmacy#undef ___DEFINE_XEN_GUEST_HANDLE
97183340Skmacy#define ___DEFINE_XEN_GUEST_HANDLE(name, type)                  \
98181624Skmacy    typedef struct { type *p; }                                 \
99181624Skmacy        __guest_handle_ ## name;                                \
100181624Skmacy    typedef struct { union { type *p; uint64_aligned_t q; }; }  \
101181624Skmacy        __guest_handle_64_ ## name
102251767Sgibbs#undef set_xen_guest_handle_raw
103251767Sgibbs#define set_xen_guest_handle_raw(hnd, val)                  \
104181624Skmacy    do { if ( sizeof(hnd) == 8 ) *(uint64_t *)&(hnd) = 0;   \
105181624Skmacy         (hnd).p = val;                                     \
106181624Skmacy    } while ( 0 )
107181624Skmacy#define uint64_aligned_t uint64_t __attribute__((aligned(8)))
108183340Skmacy#define __XEN_GUEST_HANDLE_64(name) __guest_handle_64_ ## name
109183340Skmacy#define XEN_GUEST_HANDLE_64(name) __XEN_GUEST_HANDLE_64(name)
110181624Skmacy#endif
111181624Skmacy
112181624Skmacy#ifndef __ASSEMBLY__
113181624Skmacy
114181624Skmacystruct cpu_user_regs {
115181624Skmacy    uint32_t ebx;
116181624Skmacy    uint32_t ecx;
117181624Skmacy    uint32_t edx;
118181624Skmacy    uint32_t esi;
119181624Skmacy    uint32_t edi;
120181624Skmacy    uint32_t ebp;
121181624Skmacy    uint32_t eax;
122181624Skmacy    uint16_t error_code;    /* private */
123181624Skmacy    uint16_t entry_vector;  /* private */
124181624Skmacy    uint32_t eip;
125181624Skmacy    uint16_t cs;
126181624Skmacy    uint8_t  saved_upcall_mask;
127181624Skmacy    uint8_t  _pad0;
128181624Skmacy    uint32_t eflags;        /* eflags.IF == !saved_upcall_mask */
129181624Skmacy    uint32_t esp;
130181624Skmacy    uint16_t ss, _pad1;
131181624Skmacy    uint16_t es, _pad2;
132181624Skmacy    uint16_t ds, _pad3;
133181624Skmacy    uint16_t fs, _pad4;
134181624Skmacy    uint16_t gs, _pad5;
135181624Skmacy};
136181624Skmacytypedef struct cpu_user_regs cpu_user_regs_t;
137183340SkmacyDEFINE_XEN_GUEST_HANDLE(cpu_user_regs_t);
138181624Skmacy
139181624Skmacy/*
140181624Skmacy * Page-directory addresses above 4GB do not fit into architectural %cr3.
141181624Skmacy * When accessing %cr3, or equivalent field in vcpu_guest_context, guests
142181624Skmacy * must use the following accessor macros to pack/unpack valid MFNs.
143181624Skmacy */
144181624Skmacy#define xen_pfn_to_cr3(pfn) (((unsigned)(pfn) << 12) | ((unsigned)(pfn) >> 20))
145181624Skmacy#define xen_cr3_to_pfn(cr3) (((unsigned)(cr3) >> 12) | ((unsigned)(cr3) << 20))
146181624Skmacy
147181624Skmacystruct arch_vcpu_info {
148181624Skmacy    unsigned long cr2;
149181624Skmacy    unsigned long pad[5]; /* sizeof(vcpu_info_t) == 64 */
150181624Skmacy};
151181624Skmacytypedef struct arch_vcpu_info arch_vcpu_info_t;
152181624Skmacy
153181624Skmacystruct xen_callback {
154181624Skmacy    unsigned long cs;
155181624Skmacy    unsigned long eip;
156181624Skmacy};
157181624Skmacytypedef struct xen_callback xen_callback_t;
158181624Skmacy
159181624Skmacy#endif /* !__ASSEMBLY__ */
160181624Skmacy
161181624Skmacy#endif /* __XEN_PUBLIC_ARCH_X86_XEN_X86_32_H__ */
162181624Skmacy
163181624Skmacy/*
164181624Skmacy * Local variables:
165181624Skmacy * mode: C
166181624Skmacy * c-set-style: "BSD"
167181624Skmacy * c-basic-offset: 4
168181624Skmacy * tab-width: 4
169181624Skmacy * indent-tabs-mode: nil
170181624Skmacy * End:
171181624Skmacy */
172