Path: blob/main/sys/contrib/xen/arch-x86/xen-x86_64.h
48255 views
/******************************************************************************1* xen-x86_64.h2*3* Guest OS interface to x86 64-bit Xen.4*5* Permission is hereby granted, free of charge, to any person obtaining a copy6* of this software and associated documentation files (the "Software"), to7* deal in the Software without restriction, including without limitation the8* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or9* sell copies of the Software, and to permit persons to whom the Software is10* furnished to do so, subject to the following conditions:11*12* The above copyright notice and this permission notice shall be included in13* all copies or substantial portions of the Software.14*15* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR16* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,17* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE18* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER19* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING20* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER21* DEALINGS IN THE SOFTWARE.22*23* Copyright (c) 2004-2006, K A Fraser24*/2526#ifndef __XEN_PUBLIC_ARCH_X86_XEN_X86_64_H__27#define __XEN_PUBLIC_ARCH_X86_XEN_X86_64_H__2829/*30* Hypercall interface:31* Input: %rdi, %rsi, %rdx, %r10, %r8, %r9 (arguments 1-6)32* Output: %rax33* Access is via hypercall page (set up by guest loader or via a Xen MSR):34* call hypercall_page + hypercall-number * 3235* Clobbered: argument registers (e.g., 2-arg hypercall clobbers %rdi,%rsi)36*/3738/*39* 64-bit segment selectors40* These flat segments are in the Xen-private section of every GDT. Since these41* are also present in the initial GDT, many OSes will be able to avoid42* installing their own GDT.43*/4445#define FLAT_RING3_CS32 0xe023 /* GDT index 260 */46#define FLAT_RING3_CS64 0xe033 /* GDT index 262 */47#define FLAT_RING3_DS32 0xe02b /* GDT index 261 */48#define FLAT_RING3_DS64 0x0000 /* NULL selector */49#define FLAT_RING3_SS32 0xe02b /* GDT index 261 */50#define FLAT_RING3_SS64 0xe02b /* GDT index 261 */5152#define FLAT_KERNEL_DS64 FLAT_RING3_DS6453#define FLAT_KERNEL_DS32 FLAT_RING3_DS3254#define FLAT_KERNEL_DS FLAT_KERNEL_DS6455#define FLAT_KERNEL_CS64 FLAT_RING3_CS6456#define FLAT_KERNEL_CS32 FLAT_RING3_CS3257#define FLAT_KERNEL_CS FLAT_KERNEL_CS6458#define FLAT_KERNEL_SS64 FLAT_RING3_SS6459#define FLAT_KERNEL_SS32 FLAT_RING3_SS3260#define FLAT_KERNEL_SS FLAT_KERNEL_SS646162#define FLAT_USER_DS64 FLAT_RING3_DS6463#define FLAT_USER_DS32 FLAT_RING3_DS3264#define FLAT_USER_DS FLAT_USER_DS6465#define FLAT_USER_CS64 FLAT_RING3_CS6466#define FLAT_USER_CS32 FLAT_RING3_CS3267#define FLAT_USER_CS FLAT_USER_CS6468#define FLAT_USER_SS64 FLAT_RING3_SS6469#define FLAT_USER_SS32 FLAT_RING3_SS3270#define FLAT_USER_SS FLAT_USER_SS647172#define __HYPERVISOR_VIRT_START 0xFFFF80000000000073#define __HYPERVISOR_VIRT_END 0xFFFF88000000000074#define __MACH2PHYS_VIRT_START 0xFFFF80000000000075#define __MACH2PHYS_VIRT_END 0xFFFF8040000000007677#ifndef HYPERVISOR_VIRT_START78#define HYPERVISOR_VIRT_START xen_mk_ulong(__HYPERVISOR_VIRT_START)79#define HYPERVISOR_VIRT_END xen_mk_ulong(__HYPERVISOR_VIRT_END)80#endif8182#define MACH2PHYS_VIRT_START xen_mk_ulong(__MACH2PHYS_VIRT_START)83#define MACH2PHYS_VIRT_END xen_mk_ulong(__MACH2PHYS_VIRT_END)84#define MACH2PHYS_NR_ENTRIES ((MACH2PHYS_VIRT_END-MACH2PHYS_VIRT_START)>>3)85#ifndef machine_to_phys_mapping86#define machine_to_phys_mapping ((unsigned long *)HYPERVISOR_VIRT_START)87#endif8889/*90* int HYPERVISOR_set_segment_base(unsigned int which, unsigned long base)91* @which == SEGBASE_* ; @base == 64-bit base address92* Returns 0 on success.93*/94#define SEGBASE_FS 095#define SEGBASE_GS_USER 196#define SEGBASE_GS_KERNEL 297#define SEGBASE_GS_USER_SEL 3 /* Set user %gs specified in base[15:0] */9899/*100* int HYPERVISOR_iret(void)101* All arguments are on the kernel stack, in the following format.102* Never returns if successful. Current kernel context is lost.103* The saved CS is mapped as follows:104* RING0 -> RING3 kernel mode.105* RING1 -> RING3 kernel mode.106* RING2 -> RING3 kernel mode.107* RING3 -> RING3 user mode.108* However RING0 indicates that the guest kernel should return to iteself109* directly with110* orb $3,1*8(%rsp)111* iretq112* If flags contains VGCF_in_syscall:113* Restore RAX, RIP, RFLAGS, RSP.114* Discard R11, RCX, CS, SS.115* Otherwise:116* Restore RAX, R11, RCX, CS:RIP, RFLAGS, SS:RSP.117* All other registers are saved on hypercall entry and restored to user.118*/119/* Guest exited in SYSCALL context? Return to guest with SYSRET? */120#define _VGCF_in_syscall 8121#define VGCF_in_syscall (1<<_VGCF_in_syscall)122#define VGCF_IN_SYSCALL VGCF_in_syscall123124#ifndef __ASSEMBLY__125126struct iret_context {127/* Top of stack (%rsp at point of hypercall). */128uint64_t rax, r11, rcx, flags, rip, cs, rflags, rsp, ss;129/* Bottom of iret stack frame. */130};131132#if defined(__XEN__) || defined(__XEN_TOOLS__)133/* Anonymous unions include all permissible names (e.g., al/ah/ax/eax/rax). */134#define __DECL_REG_LOHI(which) union { \135uint64_t r ## which ## x; \136uint32_t e ## which ## x; \137uint16_t which ## x; \138struct { \139uint8_t which ## l; \140uint8_t which ## h; \141}; \142}143#define __DECL_REG_LO8(name) union { \144uint64_t r ## name; \145uint32_t e ## name; \146uint16_t name; \147uint8_t name ## l; \148}149#define __DECL_REG_LO16(name) union { \150uint64_t r ## name; \151uint32_t e ## name; \152uint16_t name; \153}154#define __DECL_REG_HI(num) union { \155uint64_t r ## num; \156uint32_t r ## num ## d; \157uint16_t r ## num ## w; \158uint8_t r ## num ## b; \159}160#elif defined(__GNUC__) && !defined(__STRICT_ANSI__)161/* Anonymous union includes both 32- and 64-bit names (e.g., eax/rax). */162#define __DECL_REG(name) union { \163uint64_t r ## name, e ## name; \164uint32_t _e ## name; \165}166#else167/* Non-gcc sources must always use the proper 64-bit name (e.g., rax). */168#define __DECL_REG(name) uint64_t r ## name169#endif170171#ifndef __DECL_REG_LOHI172#define __DECL_REG_LOHI(name) __DECL_REG(name ## x)173#define __DECL_REG_LO8 __DECL_REG174#define __DECL_REG_LO16 __DECL_REG175#define __DECL_REG_HI(num) uint64_t r ## num176#endif177178struct cpu_user_regs {179__DECL_REG_HI(15);180__DECL_REG_HI(14);181__DECL_REG_HI(13);182__DECL_REG_HI(12);183__DECL_REG_LO8(bp);184__DECL_REG_LOHI(b);185__DECL_REG_HI(11);186__DECL_REG_HI(10);187__DECL_REG_HI(9);188__DECL_REG_HI(8);189__DECL_REG_LOHI(a);190__DECL_REG_LOHI(c);191__DECL_REG_LOHI(d);192__DECL_REG_LO8(si);193__DECL_REG_LO8(di);194uint32_t error_code; /* private */195uint32_t entry_vector; /* private */196__DECL_REG_LO16(ip);197uint16_t cs, _pad0[1];198uint8_t saved_upcall_mask;199uint8_t _pad1[3];200__DECL_REG_LO16(flags); /* rflags.IF == !saved_upcall_mask */201__DECL_REG_LO8(sp);202uint16_t ss, _pad2[3];203uint16_t es, _pad3[3];204uint16_t ds, _pad4[3];205uint16_t fs, _pad5[3];206uint16_t gs, _pad6[3];207};208typedef struct cpu_user_regs cpu_user_regs_t;209DEFINE_XEN_GUEST_HANDLE(cpu_user_regs_t);210211#undef __DECL_REG212#undef __DECL_REG_LOHI213#undef __DECL_REG_LO8214#undef __DECL_REG_LO16215#undef __DECL_REG_HI216217#define xen_pfn_to_cr3(pfn) ((unsigned long)(pfn) << 12)218#define xen_cr3_to_pfn(cr3) ((unsigned long)(cr3) >> 12)219220struct arch_vcpu_info {221unsigned long cr2;222unsigned long pad; /* sizeof(vcpu_info_t) == 64 */223};224typedef struct arch_vcpu_info arch_vcpu_info_t;225226typedef unsigned long xen_callback_t;227228#endif /* !__ASSEMBLY__ */229230#endif /* __XEN_PUBLIC_ARCH_X86_XEN_X86_64_H__ */231232/*233* Local variables:234* mode: C235* c-file-style: "BSD"236* c-basic-offset: 4237* tab-width: 4238* indent-tabs-mode: nil239* End:240*/241242243