iPXE
xen-x86_64.h
Go to the documentation of this file.
00001 /******************************************************************************
00002  * xen-x86_64.h
00003  *
00004  * Guest OS interface to x86 64-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-2006, K A Fraser
00025  */
00026 
00027 #ifndef __XEN_PUBLIC_ARCH_X86_XEN_X86_64_H__
00028 #define __XEN_PUBLIC_ARCH_X86_XEN_X86_64_H__
00029 
00030 FILE_LICENCE ( MIT );
00031 
00032 /*
00033  * Hypercall interface:
00034  *  Input:  %rdi, %rsi, %rdx, %r10, %r8, %r9 (arguments 1-6)
00035  *  Output: %rax
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 %rdi,%rsi)
00039  */
00040 
00041 /*
00042  * 64-bit segment selectors
00043  * These flat segments are in the Xen-private section of every GDT. Since these
00044  * are also present in the initial GDT, many OSes will be able to avoid
00045  * installing their own GDT.
00046  */
00047 
00048 #define FLAT_RING3_CS32 0xe023  /* GDT index 260 */
00049 #define FLAT_RING3_CS64 0xe033  /* GDT index 261 */
00050 #define FLAT_RING3_DS32 0xe02b  /* GDT index 262 */
00051 #define FLAT_RING3_DS64 0x0000  /* NULL selector */
00052 #define FLAT_RING3_SS32 0xe02b  /* GDT index 262 */
00053 #define FLAT_RING3_SS64 0xe02b  /* GDT index 262 */
00054 
00055 #define FLAT_KERNEL_DS64 FLAT_RING3_DS64
00056 #define FLAT_KERNEL_DS32 FLAT_RING3_DS32
00057 #define FLAT_KERNEL_DS   FLAT_KERNEL_DS64
00058 #define FLAT_KERNEL_CS64 FLAT_RING3_CS64
00059 #define FLAT_KERNEL_CS32 FLAT_RING3_CS32
00060 #define FLAT_KERNEL_CS   FLAT_KERNEL_CS64
00061 #define FLAT_KERNEL_SS64 FLAT_RING3_SS64
00062 #define FLAT_KERNEL_SS32 FLAT_RING3_SS32
00063 #define FLAT_KERNEL_SS   FLAT_KERNEL_SS64
00064 
00065 #define FLAT_USER_DS64 FLAT_RING3_DS64
00066 #define FLAT_USER_DS32 FLAT_RING3_DS32
00067 #define FLAT_USER_DS   FLAT_USER_DS64
00068 #define FLAT_USER_CS64 FLAT_RING3_CS64
00069 #define FLAT_USER_CS32 FLAT_RING3_CS32
00070 #define FLAT_USER_CS   FLAT_USER_CS64
00071 #define FLAT_USER_SS64 FLAT_RING3_SS64
00072 #define FLAT_USER_SS32 FLAT_RING3_SS32
00073 #define FLAT_USER_SS   FLAT_USER_SS64
00074 
00075 #define __HYPERVISOR_VIRT_START 0xFFFF800000000000
00076 #define __HYPERVISOR_VIRT_END   0xFFFF880000000000
00077 #define __MACH2PHYS_VIRT_START  0xFFFF800000000000
00078 #define __MACH2PHYS_VIRT_END    0xFFFF804000000000
00079 
00080 #ifndef HYPERVISOR_VIRT_START
00081 #define HYPERVISOR_VIRT_START mk_unsigned_long(__HYPERVISOR_VIRT_START)
00082 #define HYPERVISOR_VIRT_END   mk_unsigned_long(__HYPERVISOR_VIRT_END)
00083 #endif
00084 
00085 #define MACH2PHYS_VIRT_START  mk_unsigned_long(__MACH2PHYS_VIRT_START)
00086 #define MACH2PHYS_VIRT_END    mk_unsigned_long(__MACH2PHYS_VIRT_END)
00087 #define MACH2PHYS_NR_ENTRIES  ((MACH2PHYS_VIRT_END-MACH2PHYS_VIRT_START)>>3)
00088 #ifndef machine_to_phys_mapping
00089 #define machine_to_phys_mapping ((unsigned long *)HYPERVISOR_VIRT_START)
00090 #endif
00091 
00092 /*
00093  * int HYPERVISOR_set_segment_base(unsigned int which, unsigned long base)
00094  *  @which == SEGBASE_*  ;  @base == 64-bit base address
00095  * Returns 0 on success.
00096  */
00097 #define SEGBASE_FS          0
00098 #define SEGBASE_GS_USER     1
00099 #define SEGBASE_GS_KERNEL   2
00100 #define SEGBASE_GS_USER_SEL 3 /* Set user %gs specified in base[15:0] */
00101 
00102 /*
00103  * int HYPERVISOR_iret(void)
00104  * All arguments are on the kernel stack, in the following format.
00105  * Never returns if successful. Current kernel context is lost.
00106  * The saved CS is mapped as follows:
00107  *   RING0 -> RING3 kernel mode.
00108  *   RING1 -> RING3 kernel mode.
00109  *   RING2 -> RING3 kernel mode.
00110  *   RING3 -> RING3 user mode.
00111  * However RING0 indicates that the guest kernel should return to iteself
00112  * directly with
00113  *      orb   $3,1*8(%rsp)
00114  *      iretq
00115  * If flags contains VGCF_in_syscall:
00116  *   Restore RAX, RIP, RFLAGS, RSP.
00117  *   Discard R11, RCX, CS, SS.
00118  * Otherwise:
00119  *   Restore RAX, R11, RCX, CS:RIP, RFLAGS, SS:RSP.
00120  * All other registers are saved on hypercall entry and restored to user.
00121  */
00122 /* Guest exited in SYSCALL context? Return to guest with SYSRET? */
00123 #define _VGCF_in_syscall 8
00124 #define VGCF_in_syscall  (1<<_VGCF_in_syscall)
00125 #define VGCF_IN_SYSCALL  VGCF_in_syscall
00126 
00127 #ifndef __ASSEMBLY__
00128 
00129 struct iret_context {
00130     /* Top of stack (%rsp at point of hypercall). */
00131     uint64_t rax, r11, rcx, flags, rip, cs, rflags, rsp, ss;
00132     /* Bottom of iret stack frame. */
00133 };
00134 
00135 #if defined(__GNUC__) && !defined(__STRICT_ANSI__)
00136 /* Anonymous union includes both 32- and 64-bit names (e.g., eax/rax). */
00137 #define __DECL_REG(name) union { \
00138     uint64_t r ## name, e ## name; \
00139     uint32_t _e ## name; \
00140 }
00141 #else
00142 /* Non-gcc sources must always use the proper 64-bit name (e.g., rax). */
00143 #define __DECL_REG(name) uint64_t r ## name
00144 #endif
00145 
00146 struct cpu_user_regs {
00147     uint64_t r15;
00148     uint64_t r14;
00149     uint64_t r13;
00150     uint64_t r12;
00151     __DECL_REG(bp);
00152     __DECL_REG(bx);
00153     uint64_t r11;
00154     uint64_t r10;
00155     uint64_t r9;
00156     uint64_t r8;
00157     __DECL_REG(ax);
00158     __DECL_REG(cx);
00159     __DECL_REG(dx);
00160     __DECL_REG(si);
00161     __DECL_REG(di);
00162     uint32_t error_code;    /* private */
00163     uint32_t entry_vector;  /* private */
00164     __DECL_REG(ip);
00165     uint16_t cs, _pad0[1];
00166     uint8_t  saved_upcall_mask;
00167     uint8_t  _pad1[3];
00168     __DECL_REG(flags);      /* rflags.IF == !saved_upcall_mask */
00169     __DECL_REG(sp);
00170     uint16_t ss, _pad2[3];
00171     uint16_t es, _pad3[3];
00172     uint16_t ds, _pad4[3];
00173     uint16_t fs, _pad5[3]; /* Non-zero => takes precedence over fs_base.     */
00174     uint16_t gs, _pad6[3]; /* Non-zero => takes precedence over gs_base_usr. */
00175 };
00176 typedef struct cpu_user_regs cpu_user_regs_t;
00177 DEFINE_XEN_GUEST_HANDLE(cpu_user_regs_t);
00178 
00179 #undef __DECL_REG
00180 
00181 #define xen_pfn_to_cr3(pfn) ((unsigned long)(pfn) << 12)
00182 #define xen_cr3_to_pfn(cr3) ((unsigned long)(cr3) >> 12)
00183 
00184 struct arch_vcpu_info {
00185     unsigned long cr2;
00186     unsigned long pad; /* sizeof(vcpu_info_t) == 64 */
00187 };
00188 typedef struct arch_vcpu_info arch_vcpu_info_t;
00189 
00190 typedef unsigned long xen_callback_t;
00191 
00192 #endif /* !__ASSEMBLY__ */
00193 
00194 #endif /* __XEN_PUBLIC_ARCH_X86_XEN_X86_64_H__ */
00195 
00196 /*
00197  * Local variables:
00198  * mode: C
00199  * c-file-style: "BSD"
00200  * c-basic-offset: 4
00201  * tab-width: 4
00202  * indent-tabs-mode: nil
00203  * End:
00204  */