iPXE
xen-x86_32.h
Go to the documentation of this file.
00001 /******************************************************************************
00002  * xen-x86_32.h
00003  *
00004  * Guest OS interface to x86 32-bit Xen.
00005  *
00006  * Permission is hereby granted, free of charge, to any person obtaining a copy
00007  * of this software and associated documentation files (the "Software"), to
00008  * deal in the Software without restriction, including without limitation the
00009  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
00010  * sell copies of the Software, and to permit persons to whom the Software is
00011  * furnished to do so, subject to the following conditions:
00012  *
00013  * The above copyright notice and this permission notice shall be included in
00014  * all copies or substantial portions of the Software.
00015  *
00016  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00017  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00018  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00019  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00020  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
00021  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
00022  * DEALINGS IN THE SOFTWARE.
00023  *
00024  * Copyright (c) 2004-2007, K A Fraser
00025  */
00026 
00027 #ifndef __XEN_PUBLIC_ARCH_X86_XEN_X86_32_H__
00028 #define __XEN_PUBLIC_ARCH_X86_XEN_X86_32_H__
00029 
00030 FILE_LICENCE ( MIT );
00031 
00032 /*
00033  * Hypercall interface:
00034  *  Input:  %ebx, %ecx, %edx, %esi, %edi, %ebp (arguments 1-6)
00035  *  Output: %eax
00036  * Access is via hypercall page (set up by guest loader or via a Xen MSR):
00037  *  call hypercall_page + hypercall-number * 32
00038  * Clobbered: Argument registers (e.g., 2-arg hypercall clobbers %ebx,%ecx)
00039  */
00040 
00041 /*
00042  * These flat segments are in the Xen-private section of every GDT. Since these
00043  * are also present in the initial GDT, many OSes will be able to avoid
00044  * installing their own GDT.
00045  */
00046 #define FLAT_RING1_CS 0xe019    /* GDT index 259 */
00047 #define FLAT_RING1_DS 0xe021    /* GDT index 260 */
00048 #define FLAT_RING1_SS 0xe021    /* GDT index 260 */
00049 #define FLAT_RING3_CS 0xe02b    /* GDT index 261 */
00050 #define FLAT_RING3_DS 0xe033    /* GDT index 262 */
00051 #define FLAT_RING3_SS 0xe033    /* GDT index 262 */
00052 
00053 #define FLAT_KERNEL_CS FLAT_RING1_CS
00054 #define FLAT_KERNEL_DS FLAT_RING1_DS
00055 #define FLAT_KERNEL_SS FLAT_RING1_SS
00056 #define FLAT_USER_CS    FLAT_RING3_CS
00057 #define FLAT_USER_DS    FLAT_RING3_DS
00058 #define FLAT_USER_SS    FLAT_RING3_SS
00059 
00060 #define __HYPERVISOR_VIRT_START_PAE    0xF5800000
00061 #define __MACH2PHYS_VIRT_START_PAE     0xF5800000
00062 #define __MACH2PHYS_VIRT_END_PAE       0xF6800000
00063 #define HYPERVISOR_VIRT_START_PAE      \
00064     mk_unsigned_long(__HYPERVISOR_VIRT_START_PAE)
00065 #define MACH2PHYS_VIRT_START_PAE       \
00066     mk_unsigned_long(__MACH2PHYS_VIRT_START_PAE)
00067 #define MACH2PHYS_VIRT_END_PAE         \
00068     mk_unsigned_long(__MACH2PHYS_VIRT_END_PAE)
00069 
00070 /* Non-PAE bounds are obsolete. */
00071 #define __HYPERVISOR_VIRT_START_NONPAE 0xFC000000
00072 #define __MACH2PHYS_VIRT_START_NONPAE  0xFC000000
00073 #define __MACH2PHYS_VIRT_END_NONPAE    0xFC400000
00074 #define HYPERVISOR_VIRT_START_NONPAE   \
00075     mk_unsigned_long(__HYPERVISOR_VIRT_START_NONPAE)
00076 #define MACH2PHYS_VIRT_START_NONPAE    \
00077     mk_unsigned_long(__MACH2PHYS_VIRT_START_NONPAE)
00078 #define MACH2PHYS_VIRT_END_NONPAE      \
00079     mk_unsigned_long(__MACH2PHYS_VIRT_END_NONPAE)
00080 
00081 #define __HYPERVISOR_VIRT_START __HYPERVISOR_VIRT_START_PAE
00082 #define __MACH2PHYS_VIRT_START  __MACH2PHYS_VIRT_START_PAE
00083 #define __MACH2PHYS_VIRT_END    __MACH2PHYS_VIRT_END_PAE
00084 
00085 #ifndef HYPERVISOR_VIRT_START
00086 #define HYPERVISOR_VIRT_START mk_unsigned_long(__HYPERVISOR_VIRT_START)
00087 #endif
00088 
00089 #define MACH2PHYS_VIRT_START  mk_unsigned_long(__MACH2PHYS_VIRT_START)
00090 #define MACH2PHYS_VIRT_END    mk_unsigned_long(__MACH2PHYS_VIRT_END)
00091 #define MACH2PHYS_NR_ENTRIES  ((MACH2PHYS_VIRT_END-MACH2PHYS_VIRT_START)>>2)
00092 #ifndef machine_to_phys_mapping
00093 #define machine_to_phys_mapping ((unsigned long *)MACH2PHYS_VIRT_START)
00094 #endif
00095 
00096 /* 32-/64-bit invariability for control interfaces (domctl/sysctl). */
00097 #if defined(__XEN__) || defined(__XEN_TOOLS__)
00098 #undef ___DEFINE_XEN_GUEST_HANDLE
00099 #define ___DEFINE_XEN_GUEST_HANDLE(name, type)                  \
00100     typedef struct { type *p; }                                 \
00101         __guest_handle_ ## name;                                \
00102     typedef struct { union { type *p; uint64_aligned_t q; }; }  \
00103         __guest_handle_64_ ## name
00104 #undef set_xen_guest_handle_raw
00105 #define set_xen_guest_handle_raw(hnd, val)                  \
00106     do { if ( sizeof(hnd) == 8 ) *(uint64_t *)&(hnd) = 0;   \
00107          (hnd).p = val;                                     \
00108     } while ( 0 )
00109 #define uint64_aligned_t uint64_t __attribute__((aligned(8)))
00110 #define __XEN_GUEST_HANDLE_64(name) __guest_handle_64_ ## name
00111 #define XEN_GUEST_HANDLE_64(name) __XEN_GUEST_HANDLE_64(name)
00112 #endif
00113 
00114 #ifndef __ASSEMBLY__
00115 
00116 struct cpu_user_regs {
00117     uint32_t ebx;
00118     uint32_t ecx;
00119     uint32_t edx;
00120     uint32_t esi;
00121     uint32_t edi;
00122     uint32_t ebp;
00123     uint32_t eax;
00124     uint16_t error_code;    /* private */
00125     uint16_t entry_vector;  /* private */
00126     uint32_t eip;
00127     uint16_t cs;
00128     uint8_t  saved_upcall_mask;
00129     uint8_t  _pad0;
00130     uint32_t eflags;        /* eflags.IF == !saved_upcall_mask */
00131     uint32_t esp;
00132     uint16_t ss, _pad1;
00133     uint16_t es, _pad2;
00134     uint16_t ds, _pad3;
00135     uint16_t fs, _pad4;
00136     uint16_t gs, _pad5;
00137 };
00138 typedef struct cpu_user_regs cpu_user_regs_t;
00139 DEFINE_XEN_GUEST_HANDLE(cpu_user_regs_t);
00140 
00141 /*
00142  * Page-directory addresses above 4GB do not fit into architectural %cr3.
00143  * When accessing %cr3, or equivalent field in vcpu_guest_context, guests
00144  * must use the following accessor macros to pack/unpack valid MFNs.
00145  */
00146 #define xen_pfn_to_cr3(pfn) (((unsigned)(pfn) << 12) | ((unsigned)(pfn) >> 20))
00147 #define xen_cr3_to_pfn(cr3) (((unsigned)(cr3) >> 12) | ((unsigned)(cr3) << 20))
00148 
00149 struct arch_vcpu_info {
00150     unsigned long cr2;
00151     unsigned long pad[5]; /* sizeof(vcpu_info_t) == 64 */
00152 };
00153 typedef struct arch_vcpu_info arch_vcpu_info_t;
00154 
00155 struct xen_callback {
00156     unsigned long cs;
00157     unsigned long eip;
00158 };
00159 typedef struct xen_callback xen_callback_t;
00160 
00161 #endif /* !__ASSEMBLY__ */
00162 
00163 #endif /* __XEN_PUBLIC_ARCH_X86_XEN_X86_32_H__ */
00164 
00165 /*
00166  * Local variables:
00167  * mode: C
00168  * c-file-style: "BSD"
00169  * c-basic-offset: 4
00170  * tab-width: 4
00171  * indent-tabs-mode: nil
00172  * End:
00173  */