xen-x86_64.h revision 183340
138465Smsmith/****************************************************************************** 238465Smsmith * xen-x86_64.h 338465Smsmith * 438465Smsmith * Guest OS interface to x86 64-bit Xen. 538465Smsmith * 638465Smsmith * Permission is hereby granted, free of charge, to any person obtaining a copy 738465Smsmith * of this software and associated documentation files (the "Software"), to 838465Smsmith * deal in the Software without restriction, including without limitation the 938465Smsmith * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 1038465Smsmith * sell copies of the Software, and to permit persons to whom the Software is 1138465Smsmith * furnished to do so, subject to the following conditions: 1238465Smsmith * 1338465Smsmith * The above copyright notice and this permission notice shall be included in 1438465Smsmith * all copies or substantial portions of the Software. 1538465Smsmith * 1638465Smsmith * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 1738465Smsmith * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 1838465Smsmith * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 1938465Smsmith * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 2038465Smsmith * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 2138465Smsmith * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 2238465Smsmith * DEALINGS IN THE SOFTWARE. 2338465Smsmith * 2438465Smsmith * Copyright (c) 2004-2006, K A Fraser 2538465Smsmith */ 2640146Speter 2738465Smsmith#ifndef __XEN_PUBLIC_ARCH_X86_XEN_X86_64_H__ 2838465Smsmith#define __XEN_PUBLIC_ARCH_X86_XEN_X86_64_H__ 2939902Smsmith 3039902Smsmith/* 3138465Smsmith * Hypercall interface: 3240146Speter * Input: %rdi, %rsi, %rdx, %r10, %r8 (arguments 1-5) 3339902Smsmith * Output: %rax 3438465Smsmith * Access is via hypercall page (set up by guest loader or via a Xen MSR): 3539902Smsmith * call hypercall_page + hypercall-number * 32 3639902Smsmith * Clobbered: argument registers (e.g., 2-arg hypercall clobbers %rdi,%rsi) 3738465Smsmith */ 3839902Smsmith 3938465Smsmith#if __XEN_INTERFACE_VERSION__ < 0x00030203 4038465Smsmith/* 4138465Smsmith * Legacy hypercall interface: 4238465Smsmith * As above, except the entry sequence to the hypervisor is: 4338465Smsmith * mov $hypercall-number*32,%eax ; syscall 4438465Smsmith * Clobbered: %rcx, %r11, argument registers (as above) 4538465Smsmith */ 4638465Smsmith#define TRAP_INSTR "syscall" 4738465Smsmith#endif 4838465Smsmith 4938465Smsmith/* 5038465Smsmith * 64-bit segment selectors 5138465Smsmith * These flat segments are in the Xen-private section of every GDT. Since these 5238465Smsmith * are also present in the initial GDT, many OSes will be able to avoid 5338465Smsmith * installing their own GDT. 5438465Smsmith */ 5538465Smsmith 5638465Smsmith#define FLAT_RING3_CS32 0xe023 /* GDT index 260 */ 5738465Smsmith#define FLAT_RING3_CS64 0xe033 /* GDT index 261 */ 5838465Smsmith#define FLAT_RING3_DS32 0xe02b /* GDT index 262 */ 5938465Smsmith#define FLAT_RING3_DS64 0x0000 /* NULL selector */ 6038465Smsmith#define FLAT_RING3_SS32 0xe02b /* GDT index 262 */ 6138465Smsmith#define FLAT_RING3_SS64 0xe02b /* GDT index 262 */ 6238465Smsmith 6338465Smsmith#define FLAT_KERNEL_DS64 FLAT_RING3_DS64 6438465Smsmith#define FLAT_KERNEL_DS32 FLAT_RING3_DS32 6538465Smsmith#define FLAT_KERNEL_DS FLAT_KERNEL_DS64 6639178Smsmith#define FLAT_KERNEL_CS64 FLAT_RING3_CS64 6738465Smsmith#define FLAT_KERNEL_CS32 FLAT_RING3_CS32 6838465Smsmith#define FLAT_KERNEL_CS FLAT_KERNEL_CS64 6938465Smsmith#define FLAT_KERNEL_SS64 FLAT_RING3_SS64 7038465Smsmith#define FLAT_KERNEL_SS32 FLAT_RING3_SS32 7138465Smsmith#define FLAT_KERNEL_SS FLAT_KERNEL_SS64 7238465Smsmith 7338465Smsmith#define FLAT_USER_DS64 FLAT_RING3_DS64 7438465Smsmith#define FLAT_USER_DS32 FLAT_RING3_DS32 7538465Smsmith#define FLAT_USER_DS FLAT_USER_DS64 7638465Smsmith#define FLAT_USER_CS64 FLAT_RING3_CS64 7738465Smsmith#define FLAT_USER_CS32 FLAT_RING3_CS32 7838465Smsmith#define FLAT_USER_CS FLAT_USER_CS64 7938465Smsmith#define FLAT_USER_SS64 FLAT_RING3_SS64 8038465Smsmith#define FLAT_USER_SS32 FLAT_RING3_SS32 8138465Smsmith#define FLAT_USER_SS FLAT_USER_SS64 8238465Smsmith 8338465Smsmith#define __HYPERVISOR_VIRT_START 0xFFFF800000000000 8438465Smsmith#define __HYPERVISOR_VIRT_END 0xFFFF880000000000 8538465Smsmith#define __MACH2PHYS_VIRT_START 0xFFFF800000000000 8638465Smsmith#define __MACH2PHYS_VIRT_END 0xFFFF804000000000 8738465Smsmith 8838465Smsmith#ifndef HYPERVISOR_VIRT_START 8938465Smsmith#define HYPERVISOR_VIRT_START mk_unsigned_long(__HYPERVISOR_VIRT_START) 9038465Smsmith#define HYPERVISOR_VIRT_END mk_unsigned_long(__HYPERVISOR_VIRT_END) 9138465Smsmith#endif 9238465Smsmith 9338465Smsmith#define MACH2PHYS_VIRT_START mk_unsigned_long(__MACH2PHYS_VIRT_START) 9438465Smsmith#define MACH2PHYS_VIRT_END mk_unsigned_long(__MACH2PHYS_VIRT_END) 9538465Smsmith#define MACH2PHYS_NR_ENTRIES ((MACH2PHYS_VIRT_END-MACH2PHYS_VIRT_START)>>3) 9638465Smsmith#ifndef machine_to_phys_mapping 9738465Smsmith#define machine_to_phys_mapping ((unsigned long *)HYPERVISOR_VIRT_START) 9838465Smsmith#endif 9938465Smsmith 10038465Smsmith/* 10138465Smsmith * int HYPERVISOR_set_segment_base(unsigned int which, unsigned long base) 10238465Smsmith * @which == SEGBASE_* ; @base == 64-bit base address 10338465Smsmith * Returns 0 on success. 10439178Smsmith */ 10538465Smsmith#define SEGBASE_FS 0 10638465Smsmith#define SEGBASE_GS_USER 1 10739178Smsmith#define SEGBASE_GS_KERNEL 2 10838465Smsmith#define SEGBASE_GS_USER_SEL 3 /* Set user %gs specified in base[15:0] */ 10938465Smsmith 11038465Smsmith/* 11138465Smsmith * int HYPERVISOR_iret(void) 11238465Smsmith * All arguments are on the kernel stack, in the following format. 11338465Smsmith * Never returns if successful. Current kernel context is lost. 11438465Smsmith * The saved CS is mapped as follows: 11538465Smsmith * RING0 -> RING3 kernel mode. 11638465Smsmith * RING1 -> RING3 kernel mode. 11738465Smsmith * RING2 -> RING3 kernel mode. 11838465Smsmith * RING3 -> RING3 user mode. 11938465Smsmith * However RING0 indicates that the guest kernel should return to iteself 12038465Smsmith * directly with 12138465Smsmith * orb $3,1*8(%rsp) 12238465Smsmith * iretq 12338465Smsmith * If flags contains VGCF_in_syscall: 12438465Smsmith * Restore RAX, RIP, RFLAGS, RSP. 12538465Smsmith * Discard R11, RCX, CS, SS. 12638465Smsmith * Otherwise: 12738465Smsmith * Restore RAX, R11, RCX, CS:RIP, RFLAGS, SS:RSP. 12839441Smsmith * All other registers are saved on hypercall entry and restored to user. 12938465Smsmith */ 13039441Smsmith/* Guest exited in SYSCALL context? Return to guest with SYSRET? */ 13138465Smsmith#define _VGCF_in_syscall 8 13238465Smsmith#define VGCF_in_syscall (1<<_VGCF_in_syscall) 13339441Smsmith#define VGCF_IN_SYSCALL VGCF_in_syscall 13438465Smsmith 13538465Smsmith#ifndef __ASSEMBLY__ 13639441Smsmith 13738465Smsmithstruct iret_context { 13838465Smsmith /* Top of stack (%rsp at point of hypercall). */ 13939441Smsmith uint64_t rax, r11, rcx, flags, rip, cs, rflags, rsp, ss; 14038465Smsmith /* Bottom of iret stack frame. */ 14139730Speter}; 14238465Smsmith 14338465Smsmith#if defined(__GNUC__) && !defined(__STRICT_ANSI__) 14438465Smsmith/* Anonymous union includes both 32- and 64-bit names (e.g., eax/rax). */ 14538465Smsmith#define __DECL_REG(name) union { \ 14638465Smsmith uint64_t r ## name, e ## name; \ 14738465Smsmith uint32_t _e ## name; \ 14838465Smsmith} 14939178Smsmith#else 15038465Smsmith/* Non-gcc sources must always use the proper 64-bit name (e.g., rax). */ 15138465Smsmith#define __DECL_REG(name) uint64_t r ## name 15238465Smsmith#endif 15338465Smsmith 15438465Smsmithstruct cpu_user_regs { 15538465Smsmith uint64_t r15; 15638465Smsmith uint64_t r14; 15738465Smsmith uint64_t r13; 15838465Smsmith uint64_t r12; 15940107Smsmith __DECL_REG(bp); 16040107Smsmith __DECL_REG(bx); 16140107Smsmith uint64_t r11; 16240107Smsmith uint64_t r10; 16338465Smsmith uint64_t r9; 16438465Smsmith uint64_t r8; 16540107Smsmith __DECL_REG(ax); 16640107Smsmith __DECL_REG(cx); 16740107Smsmith __DECL_REG(dx); 16840107Smsmith __DECL_REG(si); 16940146Speter __DECL_REG(di); 17040107Smsmith uint32_t error_code; /* private */ 17140107Smsmith uint32_t entry_vector; /* private */ 17238465Smsmith __DECL_REG(ip); 17338465Smsmith uint16_t cs, _pad0[1]; 17438465Smsmith uint8_t saved_upcall_mask; 17538465Smsmith uint8_t _pad1[3]; 17640107Smsmith __DECL_REG(flags); /* rflags.IF == !saved_upcall_mask */ 17740107Smsmith __DECL_REG(sp); 17839441Smsmith uint16_t ss, _pad2[3]; 17940146Speter uint16_t es, _pad3[3]; 18038465Smsmith uint16_t ds, _pad4[3]; 18138465Smsmith uint16_t fs, _pad5[3]; /* Non-zero => takes precedence over fs_base. */ 18238465Smsmith uint16_t gs, _pad6[3]; /* Non-zero => takes precedence over gs_base_usr. */ 18338465Smsmith}; 18438465Smsmithtypedef struct cpu_user_regs cpu_user_regs_t; 18540107SmsmithDEFINE_XEN_GUEST_HANDLE(cpu_user_regs_t); 18640107Smsmith 18740107Smsmith#undef __DECL_REG 18840107Smsmith 18940146Speter#define xen_pfn_to_cr3(pfn) ((unsigned long)(pfn) << 12) 19038465Smsmith#define xen_cr3_to_pfn(cr3) ((unsigned long)(cr3) >> 12) 19138465Smsmith 19239441Smsmithstruct arch_vcpu_info { 19340107Smsmith unsigned long cr2; 19440107Smsmith unsigned long pad; /* sizeof(vcpu_info_t) == 64 */ 19539178Smsmith}; 19639178Smsmithtypedef struct arch_vcpu_info arch_vcpu_info_t; 19738465Smsmith 19838465Smsmithtypedef unsigned long xen_callback_t; 19938465Smsmith 20038465Smsmith#endif /* !__ASSEMBLY__ */ 20138465Smsmith 20238465Smsmith#endif /* __XEN_PUBLIC_ARCH_X86_XEN_X86_64_H__ */ 20338465Smsmith 20438465Smsmith/* 20540146Speter * Local variables: 20639178Smsmith * mode: C 20738465Smsmith * c-set-style: "BSD" 20838465Smsmith * c-basic-offset: 4 20938465Smsmith * tab-width: 4 21038465Smsmith * indent-tabs-mode: nil 21138764Smsmith * End: 21238764Smsmith */ 21338465Smsmith