15084Sjohnlev /****************************************************************************** 25084Sjohnlev * arch-x86/xen.h 35084Sjohnlev * 45084Sjohnlev * Guest OS interface to x86 Xen. 55084Sjohnlev * 65084Sjohnlev * Permission is hereby granted, free of charge, to any person obtaining a copy 75084Sjohnlev * of this software and associated documentation files (the "Software"), to 85084Sjohnlev * deal in the Software without restriction, including without limitation the 95084Sjohnlev * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 105084Sjohnlev * sell copies of the Software, and to permit persons to whom the Software is 115084Sjohnlev * furnished to do so, subject to the following conditions: 125084Sjohnlev * 135084Sjohnlev * The above copyright notice and this permission notice shall be included in 145084Sjohnlev * all copies or substantial portions of the Software. 155084Sjohnlev * 165084Sjohnlev * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 175084Sjohnlev * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 185084Sjohnlev * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 195084Sjohnlev * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 205084Sjohnlev * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 215084Sjohnlev * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 225084Sjohnlev * DEALINGS IN THE SOFTWARE. 235084Sjohnlev * 245084Sjohnlev * Copyright (c) 2004-2006, K A Fraser 255084Sjohnlev */ 265084Sjohnlev 277532SSean.Ye@Sun.COM #include "../xen.h" 287532SSean.Ye@Sun.COM 295084Sjohnlev #ifndef __XEN_PUBLIC_ARCH_X86_XEN_H__ 305084Sjohnlev #define __XEN_PUBLIC_ARCH_X86_XEN_H__ 315084Sjohnlev 325084Sjohnlev /* Structural guest handles introduced in 0x00030201. */ 335084Sjohnlev #if __XEN_INTERFACE_VERSION__ >= 0x00030201 347532SSean.Ye@Sun.COM #define ___DEFINE_XEN_GUEST_HANDLE(name, type) \ 355084Sjohnlev typedef struct { type *p; } __guest_handle_ ## name 365084Sjohnlev #else 377532SSean.Ye@Sun.COM #define ___DEFINE_XEN_GUEST_HANDLE(name, type) \ 385084Sjohnlev typedef type * __guest_handle_ ## name 395084Sjohnlev #endif 405084Sjohnlev 417532SSean.Ye@Sun.COM #define __DEFINE_XEN_GUEST_HANDLE(name, type) \ 42*10175SStuart.Maybee@Sun.COM ___DEFINE_XEN_GUEST_HANDLE(name, type); \ 43*10175SStuart.Maybee@Sun.COM ___DEFINE_XEN_GUEST_HANDLE(const_##name, const type) 445084Sjohnlev #define DEFINE_XEN_GUEST_HANDLE(name) __DEFINE_XEN_GUEST_HANDLE(name, name) 456144Srab #define __XEN_GUEST_HANDLE(name) __guest_handle_ ## name 466144Srab #define XEN_GUEST_HANDLE(name) __XEN_GUEST_HANDLE(name) 47*10175SStuart.Maybee@Sun.COM #define set_xen_guest_handle(hnd, val) do { (hnd).p = val; } while (0) 48*10175SStuart.Maybee@Sun.COM #ifdef __XEN_TOOLS__ 49*10175SStuart.Maybee@Sun.COM #define get_xen_guest_handle(val, hnd) do { val = (hnd).p; } while (0) 506144Srab #endif 516144Srab 526144Srab #if defined(__i386__) 536144Srab #include "xen-x86_32.h" 546144Srab #elif defined(__x86_64__) 556144Srab #include "xen-x86_64.h" 566144Srab #endif 575084Sjohnlev 585084Sjohnlev #ifndef __ASSEMBLY__ 595084Sjohnlev typedef unsigned long xen_pfn_t; 606144Srab #define PRI_xen_pfn "lx" 615084Sjohnlev #endif 625084Sjohnlev 635084Sjohnlev /* 645084Sjohnlev * SEGMENT DESCRIPTOR TABLES 655084Sjohnlev */ 665084Sjohnlev /* 675084Sjohnlev * A number of GDT entries are reserved by Xen. These are not situated at the 685084Sjohnlev * start of the GDT because some stupid OSes export hard-coded selector values 695084Sjohnlev * in their ABI. These hard-coded values are always near the start of the GDT, 705084Sjohnlev * so Xen places itself out of the way, at the far end of the GDT. 715084Sjohnlev */ 725084Sjohnlev #define FIRST_RESERVED_GDT_PAGE 14 735084Sjohnlev #define FIRST_RESERVED_GDT_BYTE (FIRST_RESERVED_GDT_PAGE * 4096) 745084Sjohnlev #define FIRST_RESERVED_GDT_ENTRY (FIRST_RESERVED_GDT_BYTE / 8) 755084Sjohnlev 765084Sjohnlev /* Maximum number of virtual CPUs in multi-processor guests. */ 775084Sjohnlev #define MAX_VIRT_CPUS 32 785084Sjohnlev 795084Sjohnlev #ifndef __ASSEMBLY__ 805084Sjohnlev 815084Sjohnlev typedef unsigned long xen_ulong_t; 825084Sjohnlev 835084Sjohnlev /* 845084Sjohnlev * Send an array of these to HYPERVISOR_set_trap_table(). 855084Sjohnlev * The privilege level specifies which modes may enter a trap via a software 865084Sjohnlev * interrupt. On x86/64, since rings 1 and 2 are unavailable, we allocate 875084Sjohnlev * privilege levels as follows: 885084Sjohnlev * Level == 0: Noone may enter 895084Sjohnlev * Level == 1: Kernel may enter 905084Sjohnlev * Level == 2: Kernel may enter 915084Sjohnlev * Level == 3: Everyone may enter 925084Sjohnlev */ 935084Sjohnlev #define TI_GET_DPL(_ti) ((_ti)->flags & 3) 945084Sjohnlev #define TI_GET_IF(_ti) ((_ti)->flags & 4) 955084Sjohnlev #define TI_SET_DPL(_ti,_dpl) ((_ti)->flags |= (_dpl)) 965084Sjohnlev #define TI_SET_IF(_ti,_if) ((_ti)->flags |= ((!!(_if))<<2)) 975084Sjohnlev struct trap_info { 985084Sjohnlev uint8_t vector; /* exception vector */ 995084Sjohnlev uint8_t flags; /* 0-3: privilege level; 4: clear event enable? */ 1005084Sjohnlev uint16_t cs; /* code selector */ 1015084Sjohnlev unsigned long address; /* code offset */ 1025084Sjohnlev }; 1035084Sjohnlev typedef struct trap_info trap_info_t; 1045084Sjohnlev DEFINE_XEN_GUEST_HANDLE(trap_info_t); 1055084Sjohnlev 1065084Sjohnlev typedef uint64_t tsc_timestamp_t; /* RDTSC timestamp */ 1075084Sjohnlev 1085084Sjohnlev /* 1095084Sjohnlev * The following is all CPU context. Note that the fpu_ctxt block is filled 1105084Sjohnlev * in by FXSAVE if the CPU has feature FXSR; otherwise FSAVE is used. 1115084Sjohnlev */ 1125084Sjohnlev struct vcpu_guest_context { 1135084Sjohnlev /* FPU registers come first so they can be aligned for FXSAVE/FXRSTOR. */ 1145084Sjohnlev struct { char x[512]; } fpu_ctxt; /* User-level FPU registers */ 1155084Sjohnlev #define VGCF_I387_VALID (1<<0) 1165084Sjohnlev #define VGCF_IN_KERNEL (1<<2) 1175084Sjohnlev #define _VGCF_i387_valid 0 1185084Sjohnlev #define VGCF_i387_valid (1<<_VGCF_i387_valid) 1195084Sjohnlev #define _VGCF_in_kernel 2 1205084Sjohnlev #define VGCF_in_kernel (1<<_VGCF_in_kernel) 1215084Sjohnlev #define _VGCF_failsafe_disables_events 3 1225084Sjohnlev #define VGCF_failsafe_disables_events (1<<_VGCF_failsafe_disables_events) 1235084Sjohnlev #define _VGCF_syscall_disables_events 4 1245084Sjohnlev #define VGCF_syscall_disables_events (1<<_VGCF_syscall_disables_events) 1256144Srab #define _VGCF_online 5 1266144Srab #define VGCF_online (1<<_VGCF_online) 1275084Sjohnlev unsigned long flags; /* VGCF_* flags */ 1285084Sjohnlev struct cpu_user_regs user_regs; /* User-level CPU registers */ 1295084Sjohnlev struct trap_info trap_ctxt[256]; /* Virtual IDT */ 1305084Sjohnlev unsigned long ldt_base, ldt_ents; /* LDT (linear address, # ents) */ 1315084Sjohnlev unsigned long gdt_frames[16], gdt_ents; /* GDT (machine frames, # ents) */ 1325084Sjohnlev unsigned long kernel_ss, kernel_sp; /* Virtual TSS (only SS1/SP1) */ 1336144Srab /* NB. User pagetable on x86/64 is placed in ctrlreg[1]. */ 1345084Sjohnlev unsigned long ctrlreg[8]; /* CR0-CR7 (control registers) */ 1355084Sjohnlev unsigned long debugreg[8]; /* DB0-DB7 (debug registers) */ 1365084Sjohnlev #ifdef __i386__ 1375084Sjohnlev unsigned long event_callback_cs; /* CS:EIP of event callback */ 1385084Sjohnlev unsigned long event_callback_eip; 1395084Sjohnlev unsigned long failsafe_callback_cs; /* CS:EIP of failsafe callback */ 1405084Sjohnlev unsigned long failsafe_callback_eip; 1415084Sjohnlev #else 1425084Sjohnlev unsigned long event_callback_eip; 1435084Sjohnlev unsigned long failsafe_callback_eip; 1446144Srab #ifdef __XEN__ 1456144Srab union { 1466144Srab unsigned long syscall_callback_eip; 1476144Srab struct { 1486144Srab unsigned int event_callback_cs; /* compat CS of event cb */ 1496144Srab unsigned int failsafe_callback_cs; /* compat CS of failsafe cb */ 1506144Srab }; 1516144Srab }; 1526144Srab #else 1535084Sjohnlev unsigned long syscall_callback_eip; 1545084Sjohnlev #endif 1556144Srab #endif 1565084Sjohnlev unsigned long vm_assist; /* VMASST_TYPE_* bitmap */ 1575084Sjohnlev #ifdef __x86_64__ 1585084Sjohnlev /* Segment base addresses. */ 1595084Sjohnlev uint64_t fs_base; 1605084Sjohnlev uint64_t gs_base_kernel; 1615084Sjohnlev uint64_t gs_base_user; 1625084Sjohnlev #endif 1635084Sjohnlev }; 1645084Sjohnlev typedef struct vcpu_guest_context vcpu_guest_context_t; 1655084Sjohnlev DEFINE_XEN_GUEST_HANDLE(vcpu_guest_context_t); 1665084Sjohnlev 1675084Sjohnlev struct arch_shared_info { 1685084Sjohnlev unsigned long max_pfn; /* max pfn that appears in table */ 1695084Sjohnlev /* Frame containing list of mfns containing list of mfns containing p2m. */ 1705084Sjohnlev xen_pfn_t pfn_to_mfn_frame_list_list; 1715084Sjohnlev unsigned long nmi_reason; 1725084Sjohnlev uint64_t pad[32]; 1735084Sjohnlev }; 1745084Sjohnlev typedef struct arch_shared_info arch_shared_info_t; 1755084Sjohnlev 176*10175SStuart.Maybee@Sun.COM #define MCA_PANICDATA_MAGIC 0x5044 /* "PD" */ 177*10175SStuart.Maybee@Sun.COM #define MCA_PANICDATA_VERS 1 1787532SSean.Ye@Sun.COM 1797532SSean.Ye@Sun.COM typedef struct xpv_mca_panic_data { 1807532SSean.Ye@Sun.COM uint16_t mpd_magic; 1817532SSean.Ye@Sun.COM uint16_t mpd_version; 1827532SSean.Ye@Sun.COM int mpd_fwdptr_offset; 1837532SSean.Ye@Sun.COM int mpd_revptr_offset; 1847532SSean.Ye@Sun.COM int mpd_dataptr_offset; 1857532SSean.Ye@Sun.COM void *mpd_urgent_processing; 1867532SSean.Ye@Sun.COM void *mpd_urgent_dangling; 1877532SSean.Ye@Sun.COM void *mpd_urgent_committed; 1887532SSean.Ye@Sun.COM void *mpd_nonurgent_processing; 1897532SSean.Ye@Sun.COM void *mpd_nonurgent_dangling; 1907532SSean.Ye@Sun.COM void *mpd_nonurgent_committed; 1917532SSean.Ye@Sun.COM } xpv_mca_panic_data_t; 1927532SSean.Ye@Sun.COM 1935084Sjohnlev typedef struct panic_regs panic_regs_t; 1945084Sjohnlev struct panic_info { 1955084Sjohnlev int pi_version; /* panic_info format version */ 1965084Sjohnlev panic_regs_t *pi_regs; /* register state */ 1975084Sjohnlev void *pi_apic; /* local APIC address */ 1985084Sjohnlev char *pi_panicstr; /* panic message */ 1995084Sjohnlev void *pi_ram_start; /* Start of all-RAM mapping region */ 2005084Sjohnlev void *pi_ram_end; /* End of all-RAM mapping region */ 2016144Srab void *pi_xen_start; /* Start of Xen's text/heap */ 2026144Srab void *pi_xen_end; /* End of Xen's text/heap */ 2035084Sjohnlev void *pi_stktop; /* Top of current Xen stack */ 2045084Sjohnlev struct domain *pi_domain; /* Panicking domain */ 2055084Sjohnlev struct vcpu *pi_vcpu; /* Panicking vcpu */ 2065084Sjohnlev int pi_dom0cpu; /* cpu number - if a dom0 panic */ 2077532SSean.Ye@Sun.COM xpv_mca_panic_data_t pi_mca; /* Machine check error telemetry */ 2085084Sjohnlev }; 2095084Sjohnlev 2105084Sjohnlev struct panic_frame { 2115084Sjohnlev unsigned long pf_fp; 2125084Sjohnlev unsigned long pf_pc; 2135084Sjohnlev }; 2145084Sjohnlev 2157532SSean.Ye@Sun.COM #define PANIC_INFO_VERSION 3 2165084Sjohnlev 2175084Sjohnlev #endif /* !__ASSEMBLY__ */ 2185084Sjohnlev 2195084Sjohnlev /* 2205084Sjohnlev * Prefix forces emulation of some non-trapping instructions. 2215084Sjohnlev * Currently only CPUID. 2225084Sjohnlev */ 2235084Sjohnlev #ifdef __ASSEMBLY__ 2245084Sjohnlev #define XEN_EMULATE_PREFIX .byte 0x0f,0x0b,0x78,0x65,0x6e ; 2255084Sjohnlev #define XEN_CPUID XEN_EMULATE_PREFIX cpuid 2265084Sjohnlev #else 2275084Sjohnlev #define XEN_EMULATE_PREFIX ".byte 0x0f,0x0b,0x78,0x65,0x6e ; " 2285084Sjohnlev #define XEN_CPUID XEN_EMULATE_PREFIX "cpuid" 2295084Sjohnlev #endif 2305084Sjohnlev 2315084Sjohnlev #endif /* __XEN_PUBLIC_ARCH_X86_XEN_H__ */ 2325084Sjohnlev 2335084Sjohnlev /* 2345084Sjohnlev * Local variables: 2355084Sjohnlev * mode: C 2365084Sjohnlev * c-set-style: "BSD" 2375084Sjohnlev * c-basic-offset: 4 2385084Sjohnlev * tab-width: 4 2395084Sjohnlev * indent-tabs-mode: nil 2405084Sjohnlev * End: 2415084Sjohnlev */ 242