Path: blob/main/sys/contrib/xen/arch-x86/xen-x86_32.h
48255 views
/******************************************************************************1* xen-x86_32.h2*3* Guest OS interface to x86 32-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-2007, K A Fraser24*/2526#ifndef __XEN_PUBLIC_ARCH_X86_XEN_X86_32_H__27#define __XEN_PUBLIC_ARCH_X86_XEN_X86_32_H__2829/*30* Hypercall interface:31* Input: %ebx, %ecx, %edx, %esi, %edi, %ebp (arguments 1-6)32* Output: %eax33* 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 %ebx,%ecx)36*/3738/*39* These flat segments are in the Xen-private section of every GDT. Since these40* are also present in the initial GDT, many OSes will be able to avoid41* installing their own GDT.42*/43#define FLAT_RING1_CS 0xe019 /* GDT index 259 */44#define FLAT_RING1_DS 0xe021 /* GDT index 260 */45#define FLAT_RING1_SS 0xe021 /* GDT index 260 */46#define FLAT_RING3_CS 0xe02b /* GDT index 261 */47#define FLAT_RING3_DS 0xe033 /* GDT index 262 */48#define FLAT_RING3_SS 0xe033 /* GDT index 262 */4950#define FLAT_KERNEL_CS FLAT_RING1_CS51#define FLAT_KERNEL_DS FLAT_RING1_DS52#define FLAT_KERNEL_SS FLAT_RING1_SS53#define FLAT_USER_CS FLAT_RING3_CS54#define FLAT_USER_DS FLAT_RING3_DS55#define FLAT_USER_SS FLAT_RING3_SS5657#define __HYPERVISOR_VIRT_START_PAE 0xF580000058#define __MACH2PHYS_VIRT_START_PAE 0xF580000059#define __MACH2PHYS_VIRT_END_PAE 0xF680000060#define HYPERVISOR_VIRT_START_PAE xen_mk_ulong(__HYPERVISOR_VIRT_START_PAE)61#define MACH2PHYS_VIRT_START_PAE xen_mk_ulong(__MACH2PHYS_VIRT_START_PAE)62#define MACH2PHYS_VIRT_END_PAE xen_mk_ulong(__MACH2PHYS_VIRT_END_PAE)6364/* Non-PAE bounds are obsolete. */65#define __HYPERVISOR_VIRT_START_NONPAE 0xFC00000066#define __MACH2PHYS_VIRT_START_NONPAE 0xFC00000067#define __MACH2PHYS_VIRT_END_NONPAE 0xFC40000068#define HYPERVISOR_VIRT_START_NONPAE \69xen_mk_ulong(__HYPERVISOR_VIRT_START_NONPAE)70#define MACH2PHYS_VIRT_START_NONPAE \71xen_mk_ulong(__MACH2PHYS_VIRT_START_NONPAE)72#define MACH2PHYS_VIRT_END_NONPAE \73xen_mk_ulong(__MACH2PHYS_VIRT_END_NONPAE)7475#define __HYPERVISOR_VIRT_START __HYPERVISOR_VIRT_START_PAE76#define __MACH2PHYS_VIRT_START __MACH2PHYS_VIRT_START_PAE77#define __MACH2PHYS_VIRT_END __MACH2PHYS_VIRT_END_PAE7879#ifndef HYPERVISOR_VIRT_START80#define HYPERVISOR_VIRT_START xen_mk_ulong(__HYPERVISOR_VIRT_START)81#endif8283#define MACH2PHYS_VIRT_START xen_mk_ulong(__MACH2PHYS_VIRT_START)84#define MACH2PHYS_VIRT_END xen_mk_ulong(__MACH2PHYS_VIRT_END)85#define MACH2PHYS_NR_ENTRIES ((MACH2PHYS_VIRT_END-MACH2PHYS_VIRT_START)>>2)86#ifndef machine_to_phys_mapping87#define machine_to_phys_mapping ((unsigned long *)MACH2PHYS_VIRT_START)88#endif8990/* 32-/64-bit invariability for control interfaces (domctl/sysctl). */91#if defined(__XEN__) || defined(__XEN_TOOLS__)92#undef ___DEFINE_XEN_GUEST_HANDLE93#define ___DEFINE_XEN_GUEST_HANDLE(name, type) \94typedef struct { type *p; } \95__guest_handle_ ## name; \96typedef struct { union { type *p; uint64_aligned_t q; }; } \97__guest_handle_64_ ## name98#undef set_xen_guest_handle_raw99#define set_xen_guest_handle_raw(hnd, val) \100do { if ( sizeof(hnd) == 8 ) *(uint64_t *)&(hnd) = 0; \101(hnd).p = val; \102} while ( 0 )103#define int64_aligned_t int64_t __attribute__((aligned(8)))104#define uint64_aligned_t uint64_t __attribute__((aligned(8)))105#define __XEN_GUEST_HANDLE_64(name) __guest_handle_64_ ## name106#define XEN_GUEST_HANDLE_64(name) __XEN_GUEST_HANDLE_64(name)107#endif108109#ifndef __ASSEMBLY__110111#if defined(XEN_GENERATING_COMPAT_HEADERS)112/* nothing */113#elif defined(__XEN__) || defined(__XEN_TOOLS__)114/* Anonymous unions include all permissible names (e.g., al/ah/ax/eax). */115#define __DECL_REG_LO8(which) union { \116uint32_t e ## which ## x; \117uint16_t which ## x; \118struct { \119uint8_t which ## l; \120uint8_t which ## h; \121}; \122}123#define __DECL_REG_LO16(name) union { \124uint32_t e ## name, _e ## name; \125uint16_t name; \126}127#else128/* Other sources must always use the proper 32-bit name (e.g., eax). */129#define __DECL_REG_LO8(which) uint32_t e ## which ## x130#define __DECL_REG_LO16(name) uint32_t e ## name131#endif132133struct cpu_user_regs {134__DECL_REG_LO8(b);135__DECL_REG_LO8(c);136__DECL_REG_LO8(d);137__DECL_REG_LO16(si);138__DECL_REG_LO16(di);139__DECL_REG_LO16(bp);140__DECL_REG_LO8(a);141uint16_t error_code; /* private */142uint16_t entry_vector; /* private */143__DECL_REG_LO16(ip);144uint16_t cs;145uint8_t saved_upcall_mask;146uint8_t _pad0;147__DECL_REG_LO16(flags); /* eflags.IF == !saved_upcall_mask */148__DECL_REG_LO16(sp);149uint16_t ss, _pad1;150uint16_t es, _pad2;151uint16_t ds, _pad3;152uint16_t fs, _pad4;153uint16_t gs, _pad5;154};155typedef struct cpu_user_regs cpu_user_regs_t;156DEFINE_XEN_GUEST_HANDLE(cpu_user_regs_t);157158#undef __DECL_REG_LO8159#undef __DECL_REG_LO16160161/*162* Page-directory addresses above 4GB do not fit into architectural %cr3.163* When accessing %cr3, or equivalent field in vcpu_guest_context, guests164* must use the following accessor macros to pack/unpack valid MFNs.165*/166#define xen_pfn_to_cr3(pfn) (((unsigned)(pfn) << 12) | ((unsigned)(pfn) >> 20))167#define xen_cr3_to_pfn(cr3) (((unsigned)(cr3) >> 12) | ((unsigned)(cr3) << 20))168169struct arch_vcpu_info {170unsigned long cr2;171unsigned long pad[5]; /* sizeof(vcpu_info_t) == 64 */172};173typedef struct arch_vcpu_info arch_vcpu_info_t;174175struct xen_callback {176unsigned long cs;177unsigned long eip;178};179typedef struct xen_callback xen_callback_t;180181#endif /* !__ASSEMBLY__ */182183#endif /* __XEN_PUBLIC_ARCH_X86_XEN_X86_32_H__ */184185/*186* Local variables:187* mode: C188* c-file-style: "BSD"189* c-basic-offset: 4190* tab-width: 4191* indent-tabs-mode: nil192* End:193*/194195196