win-pvdrivers

changeset 147:2efec00dd95f

updates for AMD64 - may have broken 32 bit...
author James Harper <james.harper@bendigoit.com.au>
date Wed Jan 23 23:07:47 2008 +1100 (2008-01-23)
parents b474e898b409
children c3f70f8c913e f9e747698949
files common/include/public/arch-x86/xen.h common/include/xen_public.h common/include/xen_windows.h xenpci/evtchn.c xenpci/gnttbl.c xenpci/hypercall_amd64.h xenpci/sources xenpci/xenpci.c xenpci/xenpci.h
line diff
     1.1 --- a/common/include/public/arch-x86/xen.h	Wed Jan 23 13:01:20 2008 +1100
     1.2 +++ b/common/include/public/arch-x86/xen.h	Wed Jan 23 23:07:47 2008 +1100
     1.3 @@ -1,212 +1,212 @@
     1.4 -/******************************************************************************
     1.5 - * arch-x86/xen.h
     1.6 - * 
     1.7 - * Guest OS interface to x86 Xen.
     1.8 - * 
     1.9 - * Permission is hereby granted, free of charge, to any person obtaining a copy
    1.10 - * of this software and associated documentation files (the "Software"), to
    1.11 - * deal in the Software without restriction, including without limitation the
    1.12 - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
    1.13 - * sell copies of the Software, and to permit persons to whom the Software is
    1.14 - * furnished to do so, subject to the following conditions:
    1.15 - *
    1.16 - * The above copyright notice and this permission notice shall be included in
    1.17 - * all copies or substantial portions of the Software.
    1.18 - *
    1.19 - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    1.20 - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    1.21 - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    1.22 - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    1.23 - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
    1.24 - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
    1.25 - * DEALINGS IN THE SOFTWARE.
    1.26 - *
    1.27 - * Copyright (c) 2004-2006, K A Fraser
    1.28 - */
    1.29 -
    1.30 -#ifndef __XEN_PUBLIC_ARCH_X86_XEN_H__
    1.31 -#define __XEN_PUBLIC_ARCH_X86_XEN_H__
    1.32 -
    1.33 -/* Structural guest handles introduced in 0x00030201. */
    1.34 -#if __XEN_INTERFACE_VERSION__ >= 0x00030201
    1.35 -#define __DEFINE_XEN_GUEST_HANDLE(name, type) \
    1.36 -    typedef struct { type *p; } __guest_handle_ ## name
    1.37 -#else
    1.38 -#define __DEFINE_XEN_GUEST_HANDLE(name, type) \
    1.39 -    typedef type * __guest_handle_ ## name
    1.40 -#endif
    1.41 -
    1.42 -#define DEFINE_XEN_GUEST_HANDLE(name)   __DEFINE_XEN_GUEST_HANDLE(name, name)
    1.43 -#define __XEN_GUEST_HANDLE(name)        __guest_handle_ ## name
    1.44 -#define XEN_GUEST_HANDLE(name)          __XEN_GUEST_HANDLE(name)
    1.45 -#define set_xen_guest_handle(hnd, val)  do { (hnd).p = val; } while (0)
    1.46 -#ifdef __XEN_TOOLS__
    1.47 -#define get_xen_guest_handle(val, hnd)  do { val = (hnd).p; } while (0)
    1.48 -#endif
    1.49 -
    1.50 -#if defined(__i386__)
    1.51 -#include "xen-x86_32.h"
    1.52 -#elif defined(__x86_64__)
    1.53 -#include "xen-x86_64.h"
    1.54 -#endif
    1.55 -
    1.56 -#ifndef __ASSEMBLY__
    1.57 -/* Guest handles for primitive C types. */
    1.58 -__DEFINE_XEN_GUEST_HANDLE(uchar, unsigned char);
    1.59 -__DEFINE_XEN_GUEST_HANDLE(uint,  unsigned int);
    1.60 -__DEFINE_XEN_GUEST_HANDLE(ulong, xen_ulong_t);
    1.61 -DEFINE_XEN_GUEST_HANDLE(char);
    1.62 -DEFINE_XEN_GUEST_HANDLE(int);
    1.63 -DEFINE_XEN_GUEST_HANDLE(long);
    1.64 -DEFINE_XEN_GUEST_HANDLE(void);
    1.65 -
    1.66 -typedef xen_ulong_t xen_pfn_t;
    1.67 -DEFINE_XEN_GUEST_HANDLE(xen_pfn_t);
    1.68 -#define PRI_xen_pfn "lx"
    1.69 -#endif
    1.70 -
    1.71 -/*
    1.72 - * SEGMENT DESCRIPTOR TABLES
    1.73 - */
    1.74 -/*
    1.75 - * A number of GDT entries are reserved by Xen. These are not situated at the
    1.76 - * start of the GDT because some stupid OSes export hard-coded selector values
    1.77 - * in their ABI. These hard-coded values are always near the start of the GDT,
    1.78 - * so Xen places itself out of the way, at the far end of the GDT.
    1.79 - */
    1.80 -#define FIRST_RESERVED_GDT_PAGE  14
    1.81 -#define FIRST_RESERVED_GDT_BYTE  (FIRST_RESERVED_GDT_PAGE * 4096)
    1.82 -#define FIRST_RESERVED_GDT_ENTRY (FIRST_RESERVED_GDT_BYTE / 8)
    1.83 -
    1.84 -/* Maximum number of virtual CPUs in multi-processor guests. */
    1.85 -#define MAX_VIRT_CPUS 32
    1.86 -
    1.87 -#ifndef __ASSEMBLY__
    1.88 -
    1.89 -#if defined(_AMD64_)
    1.90 -/* Under windows _AMD64_, sizeof(long) != sizeof(void *)
    1.91 -typedef long long xen_long_t;
    1.92 -typedef unsigned long long xen_ulong_t;
    1.93 -#else
    1.94 -typedef xen_ulong_t xen_long_t;
    1.95 -typedef xen_ulong_t xen_ulong_t;
    1.96 -#endif
    1.97 -
    1.98 -/*
    1.99 - * Send an array of these to HYPERVISOR_set_trap_table().
   1.100 - * The privilege level specifies which modes may enter a trap via a software
   1.101 - * interrupt. On x86/64, since rings 1 and 2 are unavailable, we allocate
   1.102 - * privilege levels as follows:
   1.103 - *  Level == 0: Noone may enter
   1.104 - *  Level == 1: Kernel may enter
   1.105 - *  Level == 2: Kernel may enter
   1.106 - *  Level == 3: Everyone may enter
   1.107 - */
   1.108 -#define TI_GET_DPL(_ti)      ((_ti)->flags & 3)
   1.109 -#define TI_GET_IF(_ti)       ((_ti)->flags & 4)
   1.110 -#define TI_SET_DPL(_ti,_dpl) ((_ti)->flags |= (_dpl))
   1.111 -#define TI_SET_IF(_ti,_if)   ((_ti)->flags |= ((!!(_if))<<2))
   1.112 -struct trap_info {
   1.113 -    uint8_t       vector;  /* exception vector                              */
   1.114 -    uint8_t       flags;   /* 0-3: privilege level; 4: clear event enable?  */
   1.115 -    uint16_t      cs;      /* code selector                                 */
   1.116 -    xen_ulong_t address; /* code offset                                   */
   1.117 -};
   1.118 -typedef struct trap_info trap_info_t;
   1.119 -DEFINE_XEN_GUEST_HANDLE(trap_info_t);
   1.120 -
   1.121 -typedef uint64_t tsc_timestamp_t; /* RDTSC timestamp */
   1.122 -
   1.123 -/*
   1.124 - * The following is all CPU context. Note that the fpu_ctxt block is filled 
   1.125 - * in by FXSAVE if the CPU has feature FXSR; otherwise FSAVE is used.
   1.126 - */
   1.127 -struct vcpu_guest_context {
   1.128 -    /* FPU registers come first so they can be aligned for FXSAVE/FXRSTOR. */
   1.129 -    struct { char x[512]; } fpu_ctxt;       /* User-level FPU registers     */
   1.130 -#define VGCF_I387_VALID                (1<<0)
   1.131 -#define VGCF_IN_KERNEL                 (1<<2)
   1.132 -#define _VGCF_i387_valid               0
   1.133 -#define VGCF_i387_valid                (1<<_VGCF_i387_valid)
   1.134 -#define _VGCF_in_kernel                2
   1.135 -#define VGCF_in_kernel                 (1<<_VGCF_in_kernel)
   1.136 -#define _VGCF_failsafe_disables_events 3
   1.137 -#define VGCF_failsafe_disables_events  (1<<_VGCF_failsafe_disables_events)
   1.138 -#define _VGCF_syscall_disables_events  4
   1.139 -#define VGCF_syscall_disables_events   (1<<_VGCF_syscall_disables_events)
   1.140 -#define _VGCF_online                   5
   1.141 -#define VGCF_online                    (1<<_VGCF_online)
   1.142 -    xen_ulong_t flags;                    /* VGCF_* flags                 */
   1.143 -    struct cpu_user_regs user_regs;         /* User-level CPU registers     */
   1.144 -    struct trap_info trap_ctxt[256];        /* Virtual IDT                  */
   1.145 -    xen_ulong_t ldt_base, ldt_ents;       /* LDT (linear address, # ents) */
   1.146 -    xen_ulong_t gdt_frames[16], gdt_ents; /* GDT (machine frames, # ents) */
   1.147 -    xen_ulong_t kernel_ss, kernel_sp;     /* Virtual TSS (only SS1/SP1)   */
   1.148 -    /* NB. User pagetable on x86/64 is placed in ctrlreg[1]. */
   1.149 -    xen_ulong_t ctrlreg[8];               /* CR0-CR7 (control registers)  */
   1.150 -    xen_ulong_t debugreg[8];              /* DB0-DB7 (debug registers)    */
   1.151 -#ifdef __i386__
   1.152 -    xen_ulong_t event_callback_cs;        /* CS:EIP of event callback     */
   1.153 -    xen_ulong_t event_callback_eip;
   1.154 -    xen_ulong_t failsafe_callback_cs;     /* CS:EIP of failsafe callback  */
   1.155 -    xen_ulong_t failsafe_callback_eip;
   1.156 -#else
   1.157 -    xen_ulong_t event_callback_eip;
   1.158 -    xen_ulong_t failsafe_callback_eip;
   1.159 -#ifdef __XEN__
   1.160 -    union {
   1.161 -        xen_ulong_t syscall_callback_eip;
   1.162 -        struct {
   1.163 -            unsigned int event_callback_cs;    /* compat CS of event cb     */
   1.164 -            unsigned int failsafe_callback_cs; /* compat CS of failsafe cb  */
   1.165 -        };
   1.166 -    };
   1.167 -#else
   1.168 -    xen_ulong_t syscall_callback_eip;
   1.169 -#endif
   1.170 -#endif
   1.171 -    xen_ulong_t vm_assist;                /* VMASST_TYPE_* bitmap */
   1.172 -#ifdef __x86_64__
   1.173 -    /* Segment base addresses. */
   1.174 -    uint64_t      fs_base;
   1.175 -    uint64_t      gs_base_kernel;
   1.176 -    uint64_t      gs_base_user;
   1.177 -#endif
   1.178 -};
   1.179 -typedef struct vcpu_guest_context vcpu_guest_context_t;
   1.180 -DEFINE_XEN_GUEST_HANDLE(vcpu_guest_context_t);
   1.181 -
   1.182 -struct arch_shared_info {
   1.183 -    xen_ulong_t max_pfn;                  /* max pfn that appears in table */
   1.184 -    /* Frame containing list of mfns containing list of mfns containing p2m. */
   1.185 -    xen_pfn_t     pfn_to_mfn_frame_list_list;
   1.186 -    xen_ulong_t nmi_reason;
   1.187 -    uint64_t pad[32];
   1.188 -};
   1.189 -typedef struct arch_shared_info arch_shared_info_t;
   1.190 -
   1.191 -#endif /* !__ASSEMBLY__ */
   1.192 -
   1.193 -/*
   1.194 - * Prefix forces emulation of some non-trapping instructions.
   1.195 - * Currently only CPUID.
   1.196 - */
   1.197 -#ifdef __ASSEMBLY__
   1.198 -#define XEN_EMULATE_PREFIX .byte 0x0f,0x0b,0x78,0x65,0x6e ;
   1.199 -#define XEN_CPUID          XEN_EMULATE_PREFIX cpuid
   1.200 -#else
   1.201 -#define XEN_EMULATE_PREFIX ".byte 0x0f,0x0b,0x78,0x65,0x6e ; "
   1.202 -#define XEN_CPUID          XEN_EMULATE_PREFIX "cpuid"
   1.203 -#endif
   1.204 -
   1.205 -#endif /* __XEN_PUBLIC_ARCH_X86_XEN_H__ */
   1.206 -
   1.207 -/*
   1.208 - * Local variables:
   1.209 - * mode: C
   1.210 - * c-set-style: "BSD"
   1.211 - * c-basic-offset: 4
   1.212 - * tab-width: 4
   1.213 - * indent-tabs-mode: nil
   1.214 - * End:
   1.215 - */
   1.216 +/******************************************************************************
   1.217 + * arch-x86/xen.h
   1.218 + * 
   1.219 + * Guest OS interface to x86 Xen.
   1.220 + * 
   1.221 + * Permission is hereby granted, free of charge, to any person obtaining a copy
   1.222 + * of this software and associated documentation files (the "Software"), to
   1.223 + * deal in the Software without restriction, including without limitation the
   1.224 + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
   1.225 + * sell copies of the Software, and to permit persons to whom the Software is
   1.226 + * furnished to do so, subject to the following conditions:
   1.227 + *
   1.228 + * The above copyright notice and this permission notice shall be included in
   1.229 + * all copies or substantial portions of the Software.
   1.230 + *
   1.231 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
   1.232 + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
   1.233 + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
   1.234 + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
   1.235 + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
   1.236 + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
   1.237 + * DEALINGS IN THE SOFTWARE.
   1.238 + *
   1.239 + * Copyright (c) 2004-2006, K A Fraser
   1.240 + */
   1.241 +
   1.242 +#ifndef __XEN_PUBLIC_ARCH_X86_XEN_H__
   1.243 +#define __XEN_PUBLIC_ARCH_X86_XEN_H__
   1.244 +
   1.245 +/* Structural guest handles introduced in 0x00030201. */
   1.246 +#if __XEN_INTERFACE_VERSION__ >= 0x00030201
   1.247 +#define __DEFINE_XEN_GUEST_HANDLE(name, type) \
   1.248 +    typedef struct { type *p; } __guest_handle_ ## name
   1.249 +#else
   1.250 +#define __DEFINE_XEN_GUEST_HANDLE(name, type) \
   1.251 +    typedef type * __guest_handle_ ## name
   1.252 +#endif
   1.253 +
   1.254 +#define DEFINE_XEN_GUEST_HANDLE(name)   __DEFINE_XEN_GUEST_HANDLE(name, name)
   1.255 +#define __XEN_GUEST_HANDLE(name)        __guest_handle_ ## name
   1.256 +#define XEN_GUEST_HANDLE(name)          __XEN_GUEST_HANDLE(name)
   1.257 +#define set_xen_guest_handle(hnd, val)  do { (hnd).p = val; } while (0)
   1.258 +#ifdef __XEN_TOOLS__
   1.259 +#define get_xen_guest_handle(val, hnd)  do { val = (hnd).p; } while (0)
   1.260 +#endif
   1.261 +
   1.262 +#if defined(_AMD64_)
   1.263 +/* Under windows _AMD64_, sizeof(long) != sizeof(void *) */
   1.264 +typedef long xen_long_t;
   1.265 +typedef unsigned long long xen_ulong_t;
   1.266 +#else
   1.267 +typedef long xen_long_t;
   1.268 +typedef unsigned long long xen_ulong_t;
   1.269 +#endif
   1.270 +
   1.271 +#if defined(__i386__)
   1.272 +#include "xen-x86_32.h"
   1.273 +#elif defined(__x86_64__)
   1.274 +#include "xen-x86_64.h"
   1.275 +#endif
   1.276 +
   1.277 +#ifndef __ASSEMBLY__
   1.278 +/* Guest handles for primitive C types. */
   1.279 +__DEFINE_XEN_GUEST_HANDLE(uchar, unsigned char);
   1.280 +__DEFINE_XEN_GUEST_HANDLE(uint,  unsigned int);
   1.281 +__DEFINE_XEN_GUEST_HANDLE(ulong, xen_ulong_t);
   1.282 +DEFINE_XEN_GUEST_HANDLE(char);
   1.283 +DEFINE_XEN_GUEST_HANDLE(int);
   1.284 +DEFINE_XEN_GUEST_HANDLE(long);
   1.285 +DEFINE_XEN_GUEST_HANDLE(void);
   1.286 +
   1.287 +typedef xen_ulong_t xen_pfn_t;
   1.288 +DEFINE_XEN_GUEST_HANDLE(xen_pfn_t);
   1.289 +#define PRI_xen_pfn "lx"
   1.290 +#endif
   1.291 +
   1.292 +/*
   1.293 + * SEGMENT DESCRIPTOR TABLES
   1.294 + */
   1.295 +/*
   1.296 + * A number of GDT entries are reserved by Xen. These are not situated at the
   1.297 + * start of the GDT because some stupid OSes export hard-coded selector values
   1.298 + * in their ABI. These hard-coded values are always near the start of the GDT,
   1.299 + * so Xen places itself out of the way, at the far end of the GDT.
   1.300 + */
   1.301 +#define FIRST_RESERVED_GDT_PAGE  14
   1.302 +#define FIRST_RESERVED_GDT_BYTE  (FIRST_RESERVED_GDT_PAGE * 4096)
   1.303 +#define FIRST_RESERVED_GDT_ENTRY (FIRST_RESERVED_GDT_BYTE / 8)
   1.304 +
   1.305 +/* Maximum number of virtual CPUs in multi-processor guests. */
   1.306 +#define MAX_VIRT_CPUS 32
   1.307 +
   1.308 +#ifndef __ASSEMBLY__
   1.309 +
   1.310 +/*
   1.311 + * Send an array of these to HYPERVISOR_set_trap_table().
   1.312 + * The privilege level specifies which modes may enter a trap via a software
   1.313 + * interrupt. On x86/64, since rings 1 and 2 are unavailable, we allocate
   1.314 + * privilege levels as follows:
   1.315 + *  Level == 0: Noone may enter
   1.316 + *  Level == 1: Kernel may enter
   1.317 + *  Level == 2: Kernel may enter
   1.318 + *  Level == 3: Everyone may enter
   1.319 + */
   1.320 +#define TI_GET_DPL(_ti)      ((_ti)->flags & 3)
   1.321 +#define TI_GET_IF(_ti)       ((_ti)->flags & 4)
   1.322 +#define TI_SET_DPL(_ti,_dpl) ((_ti)->flags |= (_dpl))
   1.323 +#define TI_SET_IF(_ti,_if)   ((_ti)->flags |= ((!!(_if))<<2))
   1.324 +struct trap_info {
   1.325 +    uint8_t       vector;  /* exception vector                              */
   1.326 +    uint8_t       flags;   /* 0-3: privilege level; 4: clear event enable?  */
   1.327 +    uint16_t      cs;      /* code selector                                 */
   1.328 +    xen_ulong_t address; /* code offset                                   */
   1.329 +};
   1.330 +typedef struct trap_info trap_info_t;
   1.331 +DEFINE_XEN_GUEST_HANDLE(trap_info_t);
   1.332 +
   1.333 +typedef uint64_t tsc_timestamp_t; /* RDTSC timestamp */
   1.334 +
   1.335 +/*
   1.336 + * The following is all CPU context. Note that the fpu_ctxt block is filled 
   1.337 + * in by FXSAVE if the CPU has feature FXSR; otherwise FSAVE is used.
   1.338 + */
   1.339 +struct vcpu_guest_context {
   1.340 +    /* FPU registers come first so they can be aligned for FXSAVE/FXRSTOR. */
   1.341 +    struct { char x[512]; } fpu_ctxt;       /* User-level FPU registers     */
   1.342 +#define VGCF_I387_VALID                (1<<0)
   1.343 +#define VGCF_IN_KERNEL                 (1<<2)
   1.344 +#define _VGCF_i387_valid               0
   1.345 +#define VGCF_i387_valid                (1<<_VGCF_i387_valid)
   1.346 +#define _VGCF_in_kernel                2
   1.347 +#define VGCF_in_kernel                 (1<<_VGCF_in_kernel)
   1.348 +#define _VGCF_failsafe_disables_events 3
   1.349 +#define VGCF_failsafe_disables_events  (1<<_VGCF_failsafe_disables_events)
   1.350 +#define _VGCF_syscall_disables_events  4
   1.351 +#define VGCF_syscall_disables_events   (1<<_VGCF_syscall_disables_events)
   1.352 +#define _VGCF_online                   5
   1.353 +#define VGCF_online                    (1<<_VGCF_online)
   1.354 +    xen_ulong_t flags;                    /* VGCF_* flags                 */
   1.355 +    struct cpu_user_regs user_regs;         /* User-level CPU registers     */
   1.356 +    struct trap_info trap_ctxt[256];        /* Virtual IDT                  */
   1.357 +    xen_ulong_t ldt_base, ldt_ents;       /* LDT (linear address, # ents) */
   1.358 +    xen_ulong_t gdt_frames[16], gdt_ents; /* GDT (machine frames, # ents) */
   1.359 +    xen_ulong_t kernel_ss, kernel_sp;     /* Virtual TSS (only SS1/SP1)   */
   1.360 +    /* NB. User pagetable on x86/64 is placed in ctrlreg[1]. */
   1.361 +    xen_ulong_t ctrlreg[8];               /* CR0-CR7 (control registers)  */
   1.362 +    xen_ulong_t debugreg[8];              /* DB0-DB7 (debug registers)    */
   1.363 +#ifdef __i386__
   1.364 +    xen_ulong_t event_callback_cs;        /* CS:EIP of event callback     */
   1.365 +    xen_ulong_t event_callback_eip;
   1.366 +    xen_ulong_t failsafe_callback_cs;     /* CS:EIP of failsafe callback  */
   1.367 +    xen_ulong_t failsafe_callback_eip;
   1.368 +#else
   1.369 +    xen_ulong_t event_callback_eip;
   1.370 +    xen_ulong_t failsafe_callback_eip;
   1.371 +#ifdef __XEN__
   1.372 +    union {
   1.373 +        xen_ulong_t syscall_callback_eip;
   1.374 +        struct {
   1.375 +            unsigned int event_callback_cs;    /* compat CS of event cb     */
   1.376 +            unsigned int failsafe_callback_cs; /* compat CS of failsafe cb  */
   1.377 +        };
   1.378 +    };
   1.379 +#else
   1.380 +    xen_ulong_t syscall_callback_eip;
   1.381 +#endif
   1.382 +#endif
   1.383 +    xen_ulong_t vm_assist;                /* VMASST_TYPE_* bitmap */
   1.384 +#ifdef __x86_64__
   1.385 +    /* Segment base addresses. */
   1.386 +    uint64_t      fs_base;
   1.387 +    uint64_t      gs_base_kernel;
   1.388 +    uint64_t      gs_base_user;
   1.389 +#endif
   1.390 +};
   1.391 +typedef struct vcpu_guest_context vcpu_guest_context_t;
   1.392 +DEFINE_XEN_GUEST_HANDLE(vcpu_guest_context_t);
   1.393 +
   1.394 +struct arch_shared_info {
   1.395 +    xen_ulong_t max_pfn;                  /* max pfn that appears in table */
   1.396 +    /* Frame containing list of mfns containing list of mfns containing p2m. */
   1.397 +    xen_pfn_t     pfn_to_mfn_frame_list_list;
   1.398 +    xen_ulong_t nmi_reason;
   1.399 +    uint64_t pad[32];
   1.400 +};
   1.401 +typedef struct arch_shared_info arch_shared_info_t;
   1.402 +
   1.403 +#endif /* !__ASSEMBLY__ */
   1.404 +
   1.405 +/*
   1.406 + * Prefix forces emulation of some non-trapping instructions.
   1.407 + * Currently only CPUID.
   1.408 + */
   1.409 +#ifdef __ASSEMBLY__
   1.410 +#define XEN_EMULATE_PREFIX .byte 0x0f,0x0b,0x78,0x65,0x6e ;
   1.411 +#define XEN_CPUID          XEN_EMULATE_PREFIX cpuid
   1.412 +#else
   1.413 +#define XEN_EMULATE_PREFIX ".byte 0x0f,0x0b,0x78,0x65,0x6e ; "
   1.414 +#define XEN_CPUID          XEN_EMULATE_PREFIX "cpuid"
   1.415 +#endif
   1.416 +
   1.417 +#endif /* __XEN_PUBLIC_ARCH_X86_XEN_H__ */
   1.418 +
   1.419 +/*
   1.420 + * Local variables:
   1.421 + * mode: C
   1.422 + * c-set-style: "BSD"
   1.423 + * c-basic-offset: 4
   1.424 + * tab-width: 4
   1.425 + * indent-tabs-mode: nil
   1.426 + * End:
   1.427 + */
   1.428 \ No newline at end of file
     2.1 --- a/common/include/xen_public.h	Wed Jan 23 13:01:20 2008 +1100
     2.2 +++ b/common/include/xen_public.h	Wed Jan 23 23:07:47 2008 +1100
     2.3 @@ -20,10 +20,6 @@ Foundation, Inc., 51 Franklin Street, Fi
     2.4  #if !defined(_XEN_PUBLIC_H_)
     2.5  #define _XEN_PUBLIC_H_
     2.6  
     2.7 -//#include <evtchn_public.h>
     2.8 -//#include <xenbus_public.h>
     2.9 -//#include <gnttbl_public.h>
    2.10 -
    2.11  DEFINE_GUID( GUID_XEN_IFACE, 0x5C568AC5, 0x9DDF, 0x4FA5, 0xA9, 0x4A, 0x39, 0xD6, 0x70, 0x77, 0x81, 0x9C);
    2.12  //{5C568AC5-9DDF-4FA5-A94A-39D67077819C}
    2.13  
    2.14 @@ -52,7 +48,7 @@ typedef evtchn_port_t
    2.15  (*PXEN_EVTCHN_ALLOCUNBOUND)(PVOID Context, domid_t Domain);
    2.16  
    2.17  typedef grant_ref_t
    2.18 -(*PXEN_GNTTBL_GRANTACCESS)(WDFDEVICE Device, domid_t domid, unsigned long frame, int readonly);
    2.19 +(*PXEN_GNTTBL_GRANTACCESS)(WDFDEVICE Device, domid_t domid, uint32_t frame, int readonly);
    2.20  typedef BOOLEAN
    2.21  (*PXEN_GNTTBL_ENDACCESS)(WDFDEVICE Device, grant_ref_t ref);
    2.22  
     3.1 --- a/common/include/xen_windows.h	Wed Jan 23 13:01:20 2008 +1100
     3.2 +++ b/common/include/xen_windows.h	Wed Jan 23 23:07:47 2008 +1100
     3.3 @@ -25,7 +25,7 @@ typedef UINT16 uint16_t;
     3.4  typedef INT32 int32_t;
     3.5  typedef UINT32 uint32_t;
     3.6  typedef UINT64 uint64_t;
     3.7 -typedef unsigned long pgentry_t;
     3.8 +//typedef unsigned long pgentry_t;
     3.9  
    3.10  #include <xen.h>
    3.11  
     4.1 --- a/xenpci/evtchn.c	Wed Jan 23 13:01:20 2008 +1100
     4.2 +++ b/xenpci/evtchn.c	Wed Jan 23 23:07:47 2008 +1100
     4.3 @@ -19,6 +19,18 @@ Foundation, Inc., 51 Franklin Street, Fi
     4.4  
     4.5  #include "xenpci.h"
     4.6  
     4.7 +#if defined(__X86__)
     4.8 +  #define xchg(p1, p2) _InterlockedExchange(p1, p2)
     4.9 +  #define synch_clear_bit(p1, p2) _interlockedbittestandreset(p2, p1)
    4.10 +  #define synch_set_bit(p1, p2) _interlockedbittestandset(p2, p1)
    4.11 +  #define bit_scan_forward(p1, p2) _BitScanForward(p1, p2)
    4.12 +#else
    4.13 +  #define xchg(p1, p2) _InterlockedExchange64(p1, p2)
    4.14 +  #define synch_clear_bit(p1, p2) _interlockedbittestandreset64(p2, p1)
    4.15 +  #define synch_set_bit(p1, p2) _interlockedbittestandset64(p2, p1)
    4.16 +  #define bit_scan_forward(p1, p2) _BitScanForward64(p1, p2)
    4.17 +#endif
    4.18 +
    4.19  static VOID
    4.20  EvtChn_DpcBounce(WDFDPC Dpc)
    4.21  {
    4.22 @@ -35,12 +47,13 @@ EvtChn_Interrupt(WDFINTERRUPT Interrupt,
    4.23    vcpu_info_t *vcpu_info;
    4.24    PXENPCI_DEVICE_DATA xpdd = GetDeviceData(WdfInterruptGetDevice(Interrupt));
    4.25    shared_info_t *shared_info_area = xpdd->shared_info_area;
    4.26 -  unsigned long evt_words, evt_word;
    4.27 +  xen_ulong_t evt_words;
    4.28 +  unsigned long evt_word;
    4.29    unsigned long evt_bit;
    4.30 -  unsigned long port;
    4.31 +  unsigned int port;
    4.32    ev_action_t *ev_action;
    4.33  
    4.34 -//  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ " (cpu = %d)\n", cpu));
    4.35 +  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ " (cpu = %d)\n", cpu));
    4.36  
    4.37    UNREFERENCED_PARAMETER(MessageID);
    4.38  
    4.39 @@ -48,12 +61,12 @@ EvtChn_Interrupt(WDFINTERRUPT Interrupt,
    4.40  
    4.41    vcpu_info->evtchn_upcall_pending = 0;
    4.42  
    4.43 -  evt_words = _InterlockedExchange((volatile LONG *)&vcpu_info->evtchn_pending_sel, 0);
    4.44 +  evt_words = xchg((volatile xen_ulong_t *)&vcpu_info->evtchn_pending_sel, 0);
    4.45    
    4.46 -  while (_BitScanForward(&evt_word, evt_words))
    4.47 +  while (bit_scan_forward(&evt_word, evt_words))
    4.48    {
    4.49      evt_words &= ~(1 << evt_word);
    4.50 -    while (_BitScanForward(&evt_bit, shared_info_area->evtchn_pending[evt_word] & ~shared_info_area->evtchn_mask[evt_word]))
    4.51 +    while (bit_scan_forward(&evt_bit, shared_info_area->evtchn_pending[evt_word] & ~shared_info_area->evtchn_mask[evt_word]))
    4.52      {
    4.53        port = (evt_word << 5) + evt_bit;
    4.54        ev_action = &xpdd->ev_actions[port];
    4.55 @@ -65,7 +78,7 @@ EvtChn_Interrupt(WDFINTERRUPT Interrupt,
    4.56        {
    4.57          if (ev_action->DpcFlag)
    4.58          {
    4.59 -//          KdPrint((__DRIVER_NAME " --- Scheduling Dpc\n"));
    4.60 +          KdPrint((__DRIVER_NAME " --- Scheduling Dpc\n"));
    4.61            WdfDpcEnqueue(ev_action->Dpc);
    4.62          }
    4.63          else
    4.64 @@ -73,11 +86,11 @@ EvtChn_Interrupt(WDFINTERRUPT Interrupt,
    4.65            ev_action->ServiceRoutine(NULL, ev_action->ServiceContext);
    4.66          }
    4.67        }
    4.68 -      _interlockedbittestandreset((volatile LONG *)&shared_info_area->evtchn_pending[0], port);
    4.69 +      synch_clear_bit(port, (volatile xen_ulong_t *)&shared_info_area->evtchn_pending[evt_word]);
    4.70      }
    4.71    }
    4.72  
    4.73 -//  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
    4.74 +  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
    4.75  
    4.76    return FALSE; // This needs to be FALSE so it can fall through to the scsiport ISR.
    4.77  }
    4.78 @@ -171,8 +184,8 @@ EvtChn_Mask(PVOID Context, evtchn_port_t
    4.79    PXENPCI_DEVICE_DATA xpdd = GetDeviceData(Device);
    4.80    //KdPrint((__DRIVER_NAME " --> EvtChn_Mask\n"));
    4.81  
    4.82 -  _interlockedbittestandset(
    4.83 -    (volatile LONG *)&xpdd->shared_info_area->evtchn_mask[0], Port);
    4.84 +  synch_set_bit(Port,
    4.85 +    (volatile xen_ulong_t *)&xpdd->shared_info_area->evtchn_mask[0]);
    4.86  
    4.87    //KdPrint((__DRIVER_NAME " <-- EvtChn_Mask\n"));
    4.88  
    4.89 @@ -186,8 +199,8 @@ EvtChn_Unmask(PVOID Context, evtchn_port
    4.90    PXENPCI_DEVICE_DATA xpdd = GetDeviceData(Device);
    4.91    //KdPrint((__DRIVER_NAME " --> EvtChn_Unmask\n"));
    4.92  
    4.93 -  _interlockedbittestandreset(
    4.94 -    (volatile LONG *)&xpdd->shared_info_area->evtchn_mask[0], Port);
    4.95 +  synch_clear_bit(Port,
    4.96 +    (volatile xen_ulong_t *)&xpdd->shared_info_area->evtchn_mask[0]);
    4.97    // should we kick off pending interrupts here too???
    4.98  
    4.99    //KdPrint((__DRIVER_NAME " <-- EvtChn_Unmask\n"));
   4.100 @@ -232,11 +245,11 @@ EvtChn_GetXenStorePort(WDFDEVICE Device)
   4.101  {
   4.102    evtchn_port_t Port;  
   4.103  
   4.104 -  //KdPrint((__DRIVER_NAME " --> EvtChn_GetStorePort\n"));
   4.105 +  KdPrint((__DRIVER_NAME " --> EvtChn_GetStorePort\n"));
   4.106  
   4.107    Port = (evtchn_port_t)hvm_get_parameter(Device, HVM_PARAM_STORE_EVTCHN);
   4.108  
   4.109 -  //KdPrint((__DRIVER_NAME " <-- EvtChn_GetStorePort\n"));
   4.110 +  KdPrint((__DRIVER_NAME " <-- EvtChn_GetStorePort\n"));
   4.111  
   4.112    return Port;
   4.113  }
   4.114 @@ -247,22 +260,20 @@ EvtChn_GetXenStoreRingAddr(WDFDEVICE Dev
   4.115    PHYSICAL_ADDRESS pa_xen_store_interface;
   4.116    PVOID xen_store_interface;
   4.117  
   4.118 -  ULONG xen_store_mfn;
   4.119 +  xen_ulong_t xen_store_mfn;
   4.120  
   4.121 -  //KdPrint((__DRIVER_NAME " --> EvtChn_GetRingAddr\n"));
   4.122 +  KdPrint((__DRIVER_NAME " --> EvtChn_GetRingAddr\n"));
   4.123  
   4.124 -  xen_store_mfn = (ULONG)hvm_get_parameter(Device, HVM_PARAM_STORE_PFN);
   4.125 +  xen_store_mfn = hvm_get_parameter(Device, HVM_PARAM_STORE_PFN);
   4.126  
   4.127    pa_xen_store_interface.QuadPart = xen_store_mfn << PAGE_SHIFT;
   4.128    xen_store_interface = MmMapIoSpace(pa_xen_store_interface, PAGE_SIZE, MmNonCached);
   4.129  
   4.130 -  //KdPrint((__DRIVER_NAME " xen_store_mfn = %08x\n", xen_store_mfn));
   4.131 +  KdPrint((__DRIVER_NAME " xen_store_mfn = %08x\n", xen_store_mfn));
   4.132    //KdPrint((__DRIVER_NAME " xen_store_evtchn = %08x\n", xen_store_evtchn));
   4.133 -  //KdPrint((__DRIVER_NAME " xen_store_interface = %08x\n", xen_store_interface));
   4.134 +  KdPrint((__DRIVER_NAME " xen_store_interface = %08x\n", xen_store_interface));
   4.135  
   4.136 -  //KeInitializeEvent(&xenbus_waitevent, NotificationEvent, FALSE);
   4.137 -
   4.138 -  //KdPrint((__DRIVER_NAME " <-- EvtChn_GetRingAddr\n"));
   4.139 +  KdPrint((__DRIVER_NAME " <-- EvtChn_GetRingAddr\n"));
   4.140  
   4.141    return xen_store_interface;
   4.142  }
     5.1 --- a/xenpci/gnttbl.c	Wed Jan 23 13:01:20 2008 +1100
     5.2 +++ b/xenpci/gnttbl.c	Wed Jan 23 23:07:47 2008 +1100
     5.3 @@ -101,7 +101,7 @@ grant_ref_t
     5.4  GntTbl_GrantAccess(
     5.5    WDFDEVICE Device,
     5.6    domid_t domid,
     5.7 -  unsigned long frame,
     5.8 +  uint32_t frame,
     5.9    int readonly)
    5.10  {
    5.11    PXENPCI_DEVICE_DATA xpdd = GetDeviceData(Device);
     6.1 --- a/xenpci/hypercall_amd64.h	Wed Jan 23 13:01:20 2008 +1100
     6.2 +++ b/xenpci/hypercall_amd64.h	Wed Jan 23 23:07:47 2008 +1100
     6.3 @@ -108,7 +108,7 @@ HYPERVISOR_mmu_update(WDFDEVICE Device, 
     6.4  static __inline int
     6.5  HYPERVISOR_console_io(WDFDEVICE Device, int cmd, int count, char *string)
     6.6  {
     6.7 -  ASSERTMSG("consoile_io not yet supported under AMD64", FALSE);
     6.8 +  ASSERTMSG("console_io not yet supported under AMD64", FALSE);
     6.9  /*
    6.10    char *hypercall_stubs = GetDeviceData(Device)->hypercall_stubs;
    6.11    long __res;
    6.12 @@ -130,7 +130,7 @@ static __inline int
    6.13  HYPERVISOR_hvm_op(WDFDEVICE Device, int op, struct xen_hvm_param *arg)
    6.14  {
    6.15    PCHAR hvm_op_func = GetDeviceData(Device)->hypercall_stubs;
    6.16 -  hvm_op_func += __HYPERVISOR_memory_op * 32;
    6.17 +  hvm_op_func += __HYPERVISOR_hvm_op * 32;
    6.18    return _hypercall2(hvm_op_func, op, arg);
    6.19  /*
    6.20    char *hypercall_stubs = GetDeviceData(Device)->hypercall_stubs;
    6.21 @@ -179,6 +179,7 @@ hvm_get_parameter(WDFDEVICE Device, int 
    6.22    a.index = hvm_param;
    6.23    retval = HYPERVISOR_hvm_op(Device, HVMOP_get_param, &a);
    6.24    KdPrint((__DRIVER_NAME " hvm_get_parameter retval = %d\n", retval));
    6.25 +  KdPrint((__DRIVER_NAME " hvm_get_parameter value = %ld\n", a.value));
    6.26    KdPrint((__DRIVER_NAME " <-- hvm_get_parameter\n"));
    6.27    return a.value;
    6.28  }
     7.1 --- a/xenpci/sources	Wed Jan 23 13:01:20 2008 +1100
     7.2 +++ b/xenpci/sources	Wed Jan 23 23:07:47 2008 +1100
     7.3 @@ -1,7 +1,7 @@
     7.4  TARGETNAME=XENPCI
     7.5  TARGETTYPE=DRIVER
     7.6  TARGETPATH=..\Target\$(DDK_TARGET_OS)
     7.7 -VERSION=0.6.0.5	
     7.8 +VERSION=0.6.0.15
     7.9  KMDF_VERSION=1
    7.10  MSC_WARNING_LEVEL=/W4
    7.11  INF_NAME=xenpci
     8.1 --- a/xenpci/xenpci.c	Wed Jan 23 13:01:20 2008 +1100
     8.2 +++ b/xenpci/xenpci.c	Wed Jan 23 23:07:47 2008 +1100
     8.3 @@ -24,11 +24,6 @@ Foundation, Inc., 51 Franklin Street, Fi
     8.4  #define SHUTDOWN_PATH "control/shutdown"
     8.5  #define BALLOON_PATH "memory/target"
     8.6  
     8.7 -#if sizeof(long) < sizeof(void *)
     8.8 - #define x 1
     8.9 -#else
    8.10 - #define x 2
    8.11 -#endif
    8.12  DRIVER_INITIALIZE DriverEntry;
    8.13  static NTSTATUS
    8.14  XenPCI_AddDevice(WDFDRIVER Driver, PWDFDEVICE_INIT DeviceInit);
    8.15 @@ -306,18 +301,9 @@ init_xen_info(WDFDEVICE Device)
    8.16    KdPrint((__DRIVER_NAME " gpfn = %d\n", xatp.gpfn));
    8.17    ret = HYPERVISOR_memory_op(Device, XENMEM_add_to_physmap, &xatp);
    8.18    KdPrint((__DRIVER_NAME " hypervisor memory op ret = %d\n", ret));
    8.19 -
    8.20 -  KdPrint((__DRIVER_NAME " %d %d %d", sizeof(short), sizeof(int), sizeof(long)));
    8.21 -  KdPrint((__DRIVER_NAME " sizeof(xen_add_to_physmap) = %d\n", sizeof(struct xen_add_to_physmap)));
    8.22 -  KdPrint((__DRIVER_NAME " FIELD_OFFSET(xen_add_to_physmap, domid) = %d\n", FIELD_OFFSET(struct xen_add_to_physmap, domid)));
    8.23 -  KdPrint((__DRIVER_NAME " FIELD_OFFSET(xen_add_to_physmap, idx) = %d\n", FIELD_OFFSET(struct xen_add_to_physmap, idx)));
    8.24 -  KdPrint((__DRIVER_NAME " FIELD_OFFSET(xen_add_to_physmap, space) = %d\n", FIELD_OFFSET(struct xen_add_to_physmap, space)));
    8.25 -  KdPrint((__DRIVER_NAME " FIELD_OFFSET(xen_add_to_physmap, gpfn) = %d\n", FIELD_OFFSET(struct xen_add_to_physmap, gpfn)));
    8.26 -
    8.27    xpdd->shared_info_area = MmMapIoSpace(shared_info_area_unmapped,
    8.28      PAGE_SIZE, MmCached);
    8.29 -
    8.30 -  return 1;
    8.31 +  return 0;
    8.32  } 
    8.33  
    8.34  static int
    8.35 @@ -527,7 +513,7 @@ XenPCI_PrepareHardware(
    8.36        break;
    8.37      case CmResourceTypeMemory:
    8.38        KdPrint((__DRIVER_NAME "     Memory mapped CSR:(%x:%x) Length:(%d)\n", descriptor->u.Memory.Start.LowPart, descriptor->u.Memory.Start.HighPart, descriptor->u.Memory.Length));
    8.39 -      xpdd->platform_mmio_addr = descriptor->u.Memory.Start; //(ULONG)MmMapIoSpace(descriptor->u.Memory.Start, descriptor->u.Memory.Length, MmNonCached);
    8.40 +      xpdd->platform_mmio_addr = descriptor->u.Memory.Start;
    8.41        xpdd->platform_mmio_len = descriptor->u.Memory.Length;
    8.42        xpdd->platform_mmio_alloc = 0;
    8.43        break;
     9.1 --- a/xenpci/xenpci.h	Wed Jan 23 13:01:20 2008 +1100
     9.2 +++ b/xenpci/xenpci.h	Wed Jan 23 23:07:47 2008 +1100
     9.3 @@ -216,7 +216,7 @@ EvtChn_GetXenStoreRingAddr(WDFDEVICE Dev
     9.4  VOID
     9.5  GntTbl_Init(WDFDEVICE Device);
     9.6  grant_ref_t
     9.7 -GntTbl_GrantAccess(WDFDEVICE Device, domid_t domid, unsigned long frame, int readonly);
     9.8 +GntTbl_GrantAccess(WDFDEVICE Device, domid_t domid, uint32_t, int readonly);
     9.9  BOOLEAN
    9.10  GntTbl_EndAccess(WDFDEVICE Device, grant_ref_t ref);
    9.11