ia64/xen-unstable

changeset 14193:1966270d89d7

[HVM] Builder must know which kind of vcpu context struct to use
when the tools are being run in a compat-mode domain
Signed-off-by: Tim Deegan <Tim.Deegan@xensource.com>
author Tim Deegan <Tim.Deegan@xensource.com>
date Thu Mar 01 11:04:23 2007 +0000 (2007-03-01)
parents b703aa29424f
children 8939727a9d93
files tools/libxc/xc_hvm_build.c
line diff
     1.1 --- a/tools/libxc/xc_hvm_build.c	Thu Mar 01 09:52:40 2007 +0000
     1.2 +++ b/tools/libxc/xc_hvm_build.c	Thu Mar 01 11:04:23 2007 +0000
     1.3 @@ -11,6 +11,8 @@
     1.4  #include "xg_private.h"
     1.5  #include "xc_private.h"
     1.6  
     1.7 +#include <xen/foreign/x86_32.h>
     1.8 +#include <xen/foreign/x86_64.h>
     1.9  #include <xen/hvm/hvm_info_table.h>
    1.10  #include <xen/hvm/params.h>
    1.11  #include <xen/hvm/e820.h>
    1.12 @@ -19,6 +21,15 @@
    1.13  
    1.14  #define SCRATCH_PFN 0xFFFFF
    1.15  
    1.16 +/* Need to provide the right flavour of vcpu context for Xen */
    1.17 +typedef union
    1.18 +{
    1.19 +    vcpu_guest_context_x86_64_t c64;
    1.20 +    vcpu_guest_context_x86_32_t c32;   
    1.21 +    vcpu_guest_context_t c;
    1.22 +} vcpu_guest_context_either_t;
    1.23 +
    1.24 +
    1.25  int xc_set_hvm_param(
    1.26      int handle, domid_t dom, int param, unsigned long value)
    1.27  {
    1.28 @@ -182,7 +193,7 @@ loadelfimage(struct elf_binary *elf, int
    1.29  static int setup_guest(int xc_handle,
    1.30                         uint32_t dom, int memsize,
    1.31                         char *image, unsigned long image_size,
    1.32 -                       vcpu_guest_context_t *ctxt)
    1.33 +                       vcpu_guest_context_either_t *ctxt)
    1.34  {
    1.35      xen_pfn_t *page_array = NULL;
    1.36      unsigned long i, nr_pages = (unsigned long)memsize << (20 - PAGE_SHIFT);
    1.37 @@ -193,6 +204,7 @@ static int setup_guest(int xc_handle,
    1.38      struct elf_binary elf;
    1.39      uint64_t v_start, v_end;
    1.40      int rc;
    1.41 +    xen_capabilities_info_t caps;
    1.42  
    1.43      if (0 != elf_init(&elf, image, image_size))
    1.44          goto error_out;
    1.45 @@ -200,6 +212,12 @@ static int setup_guest(int xc_handle,
    1.46      v_start = 0;
    1.47      v_end = (unsigned long long)memsize << 20;
    1.48  
    1.49 +    if (xc_version(xc_handle, XENVER_capabilities, &caps) != 0)
    1.50 +    {
    1.51 +        PERROR("Could not get Xen capabilities\n");
    1.52 +        goto error_out;
    1.53 +    }
    1.54 +
    1.55      if ( (elf.pstart & (PAGE_SIZE - 1)) != 0 )
    1.56      {
    1.57          PERROR("Guest OS must load to a page boundary.\n");
    1.58 @@ -282,7 +300,11 @@ static int setup_guest(int xc_handle,
    1.59  
    1.60      free(page_array);
    1.61  
    1.62 -    ctxt->user_regs.eip = elf_uval(&elf, elf.ehdr, e_entry);
    1.63 +    /* Set [er]ip in the way that's right for Xen */
    1.64 +    if ( strstr(caps, "x86_64") )
    1.65 +        ctxt->c64.user_regs.rip = elf_uval(&elf, elf.ehdr, e_entry); 
    1.66 +    else
    1.67 +        ctxt->c32.user_regs.eip = elf_uval(&elf, elf.ehdr, e_entry);
    1.68  
    1.69      return 0;
    1.70  
    1.71 @@ -298,7 +320,7 @@ static int xc_hvm_build_internal(int xc_
    1.72                                   unsigned long image_size)
    1.73  {
    1.74      struct xen_domctl launch_domctl;
    1.75 -    vcpu_guest_context_t ctxt;
    1.76 +    vcpu_guest_context_either_t ctxt;
    1.77      int rc;
    1.78  
    1.79      if ( (image == NULL) || (image_size == 0) )
    1.80 @@ -323,7 +345,7 @@ static int xc_hvm_build_internal(int xc_
    1.81      memset(&launch_domctl, 0, sizeof(launch_domctl));
    1.82      launch_domctl.domain = (domid_t)domid;
    1.83      launch_domctl.u.vcpucontext.vcpu   = 0;
    1.84 -    set_xen_guest_handle(launch_domctl.u.vcpucontext.ctxt, &ctxt);
    1.85 +    set_xen_guest_handle(launch_domctl.u.vcpucontext.ctxt, &ctxt.c);
    1.86      launch_domctl.cmd = XEN_DOMCTL_setvcpucontext;
    1.87      rc = xc_domctl(xc_handle, &launch_domctl);
    1.88