1181624Skmacy/****************************************************************************** 2181624Skmacy * arch-x86/xen.h 3181624Skmacy * 4181624Skmacy * Guest OS interface to x86 Xen. 5181624Skmacy * 6181624Skmacy * Permission is hereby granted, free of charge, to any person obtaining a copy 7181624Skmacy * of this software and associated documentation files (the "Software"), to 8181624Skmacy * deal in the Software without restriction, including without limitation the 9181624Skmacy * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 10181624Skmacy * sell copies of the Software, and to permit persons to whom the Software is 11181624Skmacy * furnished to do so, subject to the following conditions: 12181624Skmacy * 13181624Skmacy * The above copyright notice and this permission notice shall be included in 14181624Skmacy * all copies or substantial portions of the Software. 15181624Skmacy * 16181624Skmacy * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17181624Skmacy * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18181624Skmacy * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19181624Skmacy * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20181624Skmacy * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21181624Skmacy * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22181624Skmacy * DEALINGS IN THE SOFTWARE. 23181624Skmacy * 24181624Skmacy * Copyright (c) 2004-2006, K A Fraser 25181624Skmacy */ 26181624Skmacy 27181624Skmacy#ifndef __XEN_PUBLIC_ARCH_X86_XEN_H__ 28181624Skmacy#define __XEN_PUBLIC_ARCH_X86_XEN_H__ 29181624Skmacy 30183340Skmacy/* Structural guest handles introduced in 0x00030201. */ 31183340Skmacy#if __XEN_INTERFACE_VERSION__ >= 0x00030201 32183340Skmacy#define ___DEFINE_XEN_GUEST_HANDLE(name, type) \ 33183340Skmacy typedef struct { type *p; } __guest_handle_ ## name 34183340Skmacy#else 35189699Sdfr#error "using old handle" 36189699Sdfr#define ___DEFINE_XEN_GUEST_HANDLE(name, type) \ 37183340Skmacy typedef type * __guest_handle_ ## name 38183340Skmacy#endif 39183340Skmacy 40183340Skmacy#define __DEFINE_XEN_GUEST_HANDLE(name, type) \ 41183340Skmacy ___DEFINE_XEN_GUEST_HANDLE(name, type); \ 42183340Skmacy ___DEFINE_XEN_GUEST_HANDLE(const_##name, const type) 43183340Skmacy#define DEFINE_XEN_GUEST_HANDLE(name) __DEFINE_XEN_GUEST_HANDLE(name, name) 44183340Skmacy#define __XEN_GUEST_HANDLE(name) __guest_handle_ ## name 45183340Skmacy#define XEN_GUEST_HANDLE(name) __XEN_GUEST_HANDLE(name) 46183340Skmacy#define set_xen_guest_handle(hnd, val) do { (hnd).p = val; } while (0) 47183340Skmacy#ifdef __XEN_TOOLS__ 48183340Skmacy#define get_xen_guest_handle(val, hnd) do { val = (hnd).p; } while (0) 49183340Skmacy#endif 50183340Skmacy 51181624Skmacy#if defined(__i386__) 52181624Skmacy#include <xen/interface/arch-x86/xen-x86_32.h> 53181624Skmacy#elif defined(__x86_64__) 54189699Sdfr#include <xen/interface/arch-x86/xen-x86_64.h> 55181624Skmacy#endif 56181624Skmacy 57181624Skmacy#ifndef __ASSEMBLY__ 58181624Skmacytypedef unsigned long xen_pfn_t; 59181624Skmacy#define PRI_xen_pfn "lx" 60181624Skmacy#endif 61181624Skmacy 62181624Skmacy/* 63181624Skmacy * SEGMENT DESCRIPTOR TABLES 64181624Skmacy */ 65181624Skmacy/* 66181624Skmacy * A number of GDT entries are reserved by Xen. These are not situated at the 67181624Skmacy * start of the GDT because some stupid OSes export hard-coded selector values 68181624Skmacy * in their ABI. These hard-coded values are always near the start of the GDT, 69181624Skmacy * so Xen places itself out of the way, at the far end of the GDT. 70181624Skmacy */ 71181624Skmacy#define FIRST_RESERVED_GDT_PAGE 14 72181624Skmacy#define FIRST_RESERVED_GDT_BYTE (FIRST_RESERVED_GDT_PAGE * 4096) 73181624Skmacy#define FIRST_RESERVED_GDT_ENTRY (FIRST_RESERVED_GDT_BYTE / 8) 74181624Skmacy 75181624Skmacy/* Maximum number of virtual CPUs in multi-processor guests. */ 76181624Skmacy#define MAX_VIRT_CPUS 32 77181624Skmacy 78181624Skmacy#ifndef __ASSEMBLY__ 79181624Skmacy 80181624Skmacytypedef unsigned long xen_ulong_t; 81181624Skmacy 82181624Skmacy/* 83181624Skmacy * Send an array of these to HYPERVISOR_set_trap_table(). 84181624Skmacy * The privilege level specifies which modes may enter a trap via a software 85181624Skmacy * interrupt. On x86/64, since rings 1 and 2 are unavailable, we allocate 86181624Skmacy * privilege levels as follows: 87181624Skmacy * Level == 0: Noone may enter 88181624Skmacy * Level == 1: Kernel may enter 89181624Skmacy * Level == 2: Kernel may enter 90181624Skmacy * Level == 3: Everyone may enter 91181624Skmacy */ 92181624Skmacy#define TI_GET_DPL(_ti) ((_ti)->flags & 3) 93181624Skmacy#define TI_GET_IF(_ti) ((_ti)->flags & 4) 94181624Skmacy#define TI_SET_DPL(_ti,_dpl) ((_ti)->flags |= (_dpl)) 95181624Skmacy#define TI_SET_IF(_ti,_if) ((_ti)->flags |= ((!!(_if))<<2)) 96181624Skmacystruct trap_info { 97181624Skmacy uint8_t vector; /* exception vector */ 98181624Skmacy uint8_t flags; /* 0-3: privilege level; 4: clear event enable? */ 99181624Skmacy uint16_t cs; /* code selector */ 100181624Skmacy unsigned long address; /* code offset */ 101181624Skmacy}; 102181624Skmacytypedef struct trap_info trap_info_t; 103181624SkmacyDEFINE_XEN_GUEST_HANDLE(trap_info_t); 104181624Skmacy 105181624Skmacytypedef uint64_t tsc_timestamp_t; /* RDTSC timestamp */ 106181624Skmacy 107181624Skmacy/* 108181624Skmacy * The following is all CPU context. Note that the fpu_ctxt block is filled 109181624Skmacy * in by FXSAVE if the CPU has feature FXSR; otherwise FSAVE is used. 110181624Skmacy */ 111181624Skmacystruct vcpu_guest_context { 112181624Skmacy /* FPU registers come first so they can be aligned for FXSAVE/FXRSTOR. */ 113181624Skmacy struct { char x[512]; } fpu_ctxt; /* User-level FPU registers */ 114181624Skmacy#define VGCF_I387_VALID (1<<0) 115181624Skmacy#define VGCF_IN_KERNEL (1<<2) 116181624Skmacy#define _VGCF_i387_valid 0 117181624Skmacy#define VGCF_i387_valid (1<<_VGCF_i387_valid) 118181624Skmacy#define _VGCF_in_kernel 2 119181624Skmacy#define VGCF_in_kernel (1<<_VGCF_in_kernel) 120181624Skmacy#define _VGCF_failsafe_disables_events 3 121181624Skmacy#define VGCF_failsafe_disables_events (1<<_VGCF_failsafe_disables_events) 122181624Skmacy#define _VGCF_syscall_disables_events 4 123181624Skmacy#define VGCF_syscall_disables_events (1<<_VGCF_syscall_disables_events) 124181624Skmacy#define _VGCF_online 5 125181624Skmacy#define VGCF_online (1<<_VGCF_online) 126181624Skmacy unsigned long flags; /* VGCF_* flags */ 127181624Skmacy struct cpu_user_regs user_regs; /* User-level CPU registers */ 128181624Skmacy struct trap_info trap_ctxt[256]; /* Virtual IDT */ 129181624Skmacy unsigned long ldt_base, ldt_ents; /* LDT (linear address, # ents) */ 130181624Skmacy unsigned long gdt_frames[16], gdt_ents; /* GDT (machine frames, # ents) */ 131181624Skmacy unsigned long kernel_ss, kernel_sp; /* Virtual TSS (only SS1/SP1) */ 132181624Skmacy /* NB. User pagetable on x86/64 is placed in ctrlreg[1]. */ 133181624Skmacy unsigned long ctrlreg[8]; /* CR0-CR7 (control registers) */ 134181624Skmacy unsigned long debugreg[8]; /* DB0-DB7 (debug registers) */ 135181624Skmacy#ifdef __i386__ 136181624Skmacy unsigned long event_callback_cs; /* CS:EIP of event callback */ 137181624Skmacy unsigned long event_callback_eip; 138181624Skmacy unsigned long failsafe_callback_cs; /* CS:EIP of failsafe callback */ 139181624Skmacy unsigned long failsafe_callback_eip; 140181624Skmacy#else 141181624Skmacy unsigned long event_callback_eip; 142181624Skmacy unsigned long failsafe_callback_eip; 143181624Skmacy#ifdef __XEN__ 144181624Skmacy union { 145181624Skmacy unsigned long syscall_callback_eip; 146181624Skmacy struct { 147181624Skmacy unsigned int event_callback_cs; /* compat CS of event cb */ 148181624Skmacy unsigned int failsafe_callback_cs; /* compat CS of failsafe cb */ 149181624Skmacy }; 150181624Skmacy } u; 151181624Skmacy#else 152181624Skmacy unsigned long syscall_callback_eip; 153181624Skmacy#endif 154181624Skmacy#endif 155181624Skmacy unsigned long vm_assist; /* VMASST_TYPE_* bitmap */ 156181624Skmacy#ifdef __x86_64__ 157181624Skmacy /* Segment base addresses. */ 158181624Skmacy uint64_t fs_base; 159181624Skmacy uint64_t gs_base_kernel; 160181624Skmacy uint64_t gs_base_user; 161181624Skmacy#endif 162181624Skmacy}; 163181624Skmacytypedef struct vcpu_guest_context vcpu_guest_context_t; 164181624SkmacyDEFINE_XEN_GUEST_HANDLE(vcpu_guest_context_t); 165181624Skmacy 166181624Skmacystruct arch_shared_info { 167181624Skmacy unsigned long max_pfn; /* max pfn that appears in table */ 168181624Skmacy /* Frame containing list of mfns containing list of mfns containing p2m. */ 169181624Skmacy xen_pfn_t pfn_to_mfn_frame_list_list; 170181624Skmacy unsigned long nmi_reason; 171181624Skmacy uint64_t pad[32]; 172181624Skmacy}; 173181624Skmacytypedef struct arch_shared_info arch_shared_info_t; 174181624Skmacy 175181624Skmacy#endif /* !__ASSEMBLY__ */ 176181624Skmacy 177181624Skmacy/* 178181624Skmacy * Prefix forces emulation of some non-trapping instructions. 179181624Skmacy * Currently only CPUID. 180181624Skmacy */ 181181624Skmacy#ifdef __ASSEMBLY__ 182181624Skmacy#define XEN_EMULATE_PREFIX .byte 0x0f,0x0b,0x78,0x65,0x6e ; 183181624Skmacy#define XEN_CPUID XEN_EMULATE_PREFIX cpuid 184181624Skmacy#else 185181624Skmacy#define XEN_EMULATE_PREFIX ".byte 0x0f,0x0b,0x78,0x65,0x6e ; " 186181624Skmacy#define XEN_CPUID XEN_EMULATE_PREFIX "cpuid" 187181624Skmacy#endif 188181624Skmacy 189181624Skmacy#endif /* __XEN_PUBLIC_ARCH_X86_XEN_H__ */ 190181624Skmacy 191181624Skmacy/* 192181624Skmacy * Local variables: 193181624Skmacy * mode: C 194181624Skmacy * c-set-style: "BSD" 195181624Skmacy * c-basic-offset: 4 196181624Skmacy * tab-width: 4 197181624Skmacy * indent-tabs-mode: nil 198181624Skmacy * End: 199181624Skmacy */ 200