ia64/xen-unstable

changeset 14111:3dac99b6034e

Xen coredump format: ELF formatified with note section.
added PFN-GMFN table for non-auto translated physmap
added PFN table for auto translated physmap.
HVM domain support.
IA64 support

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>

Use the guest's own p2m table instead of xc_get_pfn_list(), which
cannot handle PFNs with no MFN.
Dump a zeroed page for PFNs with no MFN.
Clearly deprecate xc_get_pfn_list().
Do not include a P2M table with HVM domains.
Refuse to dump HVM until we can map its pages with PFNs.

Signed-off-by: John Levon <john.levon@sun.com>
author Keir Fraser <keir@xensource.com>
date Sat Feb 24 14:31:42 2007 +0000 (2007-02-24)
parents f61992cb82fe
children e2e6830269f7
files tools/libxc/Makefile tools/libxc/xc_core.c tools/libxc/xc_core.h tools/libxc/xc_core_ia64.c tools/libxc/xc_core_ia64.h tools/libxc/xc_core_x86.c tools/libxc/xc_core_x86.h tools/libxc/xc_efi.h tools/libxc/xenctrl.h xen/include/public/elfnote.h
line diff
     1.1 --- a/tools/libxc/Makefile	Sat Feb 24 14:19:42 2007 +0000
     1.2 +++ b/tools/libxc/Makefile	Sat Feb 24 14:31:42 2007 +0000
     1.3 @@ -6,6 +6,8 @@ MINOR    = 0
     1.4  
     1.5  CTRL_SRCS-y       :=
     1.6  CTRL_SRCS-y       += xc_core.c
     1.7 +CTRL_SRCS-$(CONFIG_X86) += xc_core_x86.c
     1.8 +CTRL_SRCS-$(CONFIG_IA64) += xc_core_ia64.c
     1.9  CTRL_SRCS-y       += xc_domain.c
    1.10  CTRL_SRCS-y       += xc_evtchn.c
    1.11  CTRL_SRCS-y       += xc_misc.c
     2.1 --- a/tools/libxc/xc_core.c	Sat Feb 24 14:19:42 2007 +0000
     2.2 +++ b/tools/libxc/xc_core.c	Sat Feb 24 14:31:42 2007 +0000
     2.3 @@ -1,10 +1,62 @@
     2.4 +/*
     2.5 + * Elf format, (pfn, gmfn) table, IA64 support.
     2.6 + * Copyright (c) 2007 Isaku Yamahata <yamahata at valinux co jp>
     2.7 + *                    VA Linux Systems Japan K.K.
     2.8 + *
     2.9 + * xen dump-core file format follows ELF format specification.
    2.10 + * Analisys tools shouldn't depends on the order of sections.
    2.11 + * They should follow elf header and check section names.
    2.12 + *
    2.13 + *  +--------------------------------------------------------+
    2.14 + *  |ELF header                                              |
    2.15 + *  +--------------------------------------------------------+
    2.16 + *  |section headers                                         |
    2.17 + *  |    null section header                                 |
    2.18 + *  |    .shstrtab                                           |
    2.19 + *  |    .note.Xen                                           |
    2.20 + *  |    .xen_prstatus                                       |
    2.21 + *  |    .xen_ia64_mmapped_regs if ia64                      |
    2.22 + *  |    .xen_shared_info if present                         |
    2.23 + *  |    .xen_p2m or .xen_pfn                                |
    2.24 + *  |    .xen_pages                                          |
    2.25 + *  +--------------------------------------------------------+
    2.26 + *  |.note.Xen:note section                                  |
    2.27 + *  |    "Xen" is used as note name,                         |
    2.28 + *  |    types are defined in xen/include/public/elfnote.h   |
    2.29 + *  |    and descriptors are defined in xc_core.h.           |
    2.30 + *  |    dumpcore none                                       |
    2.31 + *  |    dumpcore header                                     |
    2.32 + *  |    dumpcore xen version                                |
    2.33 + *  |    dumpcore format version                             |
    2.34 + *  +--------------------------------------------------------+
    2.35 + *  |.xen_prstatus                                           |
    2.36 + *  |       vcpu_guest_context_t[nr_vcpus]                   |
    2.37 + *  +--------------------------------------------------------+
    2.38 + *  |.xen_ia64_mmapped_regs if ia64                          |
    2.39 + *  |       mmapped_regs_t[nr_vcpus]                         |
    2.40 + *  +--------------------------------------------------------+
    2.41 + *  |.xen_shared_info if possible                            |
    2.42 + *  +--------------------------------------------------------+
    2.43 + *  |.xen_p2m or .xen_pfn                                    |
    2.44 + *  |    .xen_p2m: struct xen_dumpcore_p2m[nr_pages]         |
    2.45 + *  |    .xen_pfn: uint64_t[nr_pages]                        |
    2.46 + *  +--------------------------------------------------------+
    2.47 + *  |.xen_pages                                              |
    2.48 + *  |    page * nr_pages                                     |
    2.49 + *  +--------------------------------------------------------+
    2.50 + *  |.shstrtab: section header string table                  |
    2.51 + *  +--------------------------------------------------------+
    2.52 + *
    2.53 + */
    2.54 +
    2.55  #include "xg_private.h"
    2.56 +#include "xc_core.h"
    2.57 +#include "xc_dom.h"
    2.58  #include <stdlib.h>
    2.59  #include <unistd.h>
    2.60  
    2.61  /* number of pages to write at a time */
    2.62  #define DUMP_INCREMENT (4 * 1024)
    2.63 -#define round_pgup(_p)    (((_p)+(PAGE_SIZE-1))&PAGE_MASK)
    2.64  
    2.65  static int
    2.66  copy_from_domain_page(int xc_handle,
    2.67 @@ -21,107 +73,712 @@ copy_from_domain_page(int xc_handle,
    2.68      return 0;
    2.69  }
    2.70  
    2.71 +/* string table */
    2.72 +struct xc_core_strtab {
    2.73 +    char       *strings;
    2.74 +    uint16_t    current;
    2.75 +    uint16_t    max;
    2.76 +};
    2.77 +
    2.78 +static struct xc_core_strtab*
    2.79 +xc_core_strtab_init(void)
    2.80 +{
    2.81 +    struct xc_core_strtab *strtab;
    2.82 +    char *strings;
    2.83 +    strtab = malloc(sizeof(strtab));
    2.84 +    if ( strtab == NULL )
    2.85 +        return NULL;
    2.86 +
    2.87 +    strings = malloc(PAGE_SIZE);
    2.88 +    if ( strings == NULL )
    2.89 +    {
    2.90 +        PERROR("Could not allocate string table init");
    2.91 +        free(strtab);
    2.92 +        return NULL;
    2.93 +    }
    2.94 +    strtab->strings = strings;
    2.95 +    strtab->max = PAGE_SIZE;
    2.96 +
    2.97 +    /* index 0 represents none */
    2.98 +    strtab->strings[0] = '\0';
    2.99 +    strtab->current = 1;
   2.100 +
   2.101 +    return strtab;
   2.102 +}
   2.103 +
   2.104 +static void
   2.105 +xc_core_strtab_free(struct xc_core_strtab *strtab)
   2.106 +{
   2.107 +    free(strtab->strings);
   2.108 +    free(strtab);
   2.109 +}
   2.110 +
   2.111 +static uint16_t
   2.112 +xc_core_strtab_get(struct xc_core_strtab *strtab, const char *name)
   2.113 +{
   2.114 +    uint16_t ret = 0;
   2.115 +    uint16_t len = strlen(name) + 1;
   2.116 +
   2.117 +    if ( strtab->current + len > strtab->max )
   2.118 +    {
   2.119 +        char *tmp;
   2.120 +        if ( strtab->max * 2 < strtab->max )
   2.121 +        {
   2.122 +            PERROR("too long string table");
   2.123 +            errno = ENOMEM;
   2.124 +            return ret;
   2.125 +        }
   2.126 +
   2.127 +
   2.128 +        tmp = realloc(strtab->strings, strtab->max * 2);
   2.129 +        if ( tmp == NULL )
   2.130 +        {
   2.131 +            PERROR("Could not allocate string table");
   2.132 +            return ret;
   2.133 +        }
   2.134 +
   2.135 +        strtab->strings = tmp;
   2.136 +        strtab->max *= 2;
   2.137 +    }
   2.138 +
   2.139 +    ret = strtab->current;
   2.140 +    strcpy(strtab->strings + strtab->current, name);
   2.141 +    strtab->current += len;
   2.142 +    return ret;
   2.143 +}
   2.144 +
   2.145 +
   2.146 +/* section headers */
   2.147 +struct xc_core_section_headers {
   2.148 +    uint16_t    num;
   2.149 +    uint16_t    num_max;
   2.150 +
   2.151 +    Elf_Shdr   *shdrs;
   2.152 +};
   2.153 +#define SHDR_INIT       16
   2.154 +#define SHDR_INC        4
   2.155 +
   2.156 +static struct xc_core_section_headers*
   2.157 +xc_core_shdr_init(void)
   2.158 +{
   2.159 +    struct xc_core_section_headers *sheaders;
   2.160 +    sheaders = malloc(sizeof(*sheaders));
   2.161 +    if ( sheaders == NULL )
   2.162 +        return NULL;
   2.163 +
   2.164 +    sheaders->num = 0;
   2.165 +    sheaders->num_max = SHDR_INIT;
   2.166 +    sheaders->shdrs = malloc(sizeof(sheaders->shdrs[0]) * sheaders->num_max);
   2.167 +    if ( sheaders->shdrs == NULL )
   2.168 +    {
   2.169 +        free(sheaders);
   2.170 +        return NULL;
   2.171 +    }
   2.172 +    return sheaders;
   2.173 +}
   2.174 +
   2.175 +static void
   2.176 +xc_core_shdr_free(struct xc_core_section_headers *sheaders)
   2.177 +{
   2.178 +    free(sheaders->shdrs);
   2.179 +    free(sheaders);
   2.180 +}
   2.181 +
   2.182 +Elf_Shdr*
   2.183 +xc_core_shdr_get(struct xc_core_section_headers *sheaders)
   2.184 +{
   2.185 +    Elf_Shdr *shdr;
   2.186 +
   2.187 +    if ( sheaders->num == sheaders->num_max )
   2.188 +    {
   2.189 +        Elf_Shdr *shdrs;
   2.190 +        if ( sheaders->num_max + SHDR_INC < sheaders->num_max )
   2.191 +        {
   2.192 +            errno = E2BIG;
   2.193 +            return NULL;
   2.194 +        }
   2.195 +        sheaders->num_max += SHDR_INC;
   2.196 +        shdrs = realloc(sheaders->shdrs,
   2.197 +                        sizeof(sheaders->shdrs[0]) * sheaders->num_max);
   2.198 +        if ( shdrs == NULL )
   2.199 +            return NULL;
   2.200 +        sheaders->shdrs = shdrs;
   2.201 +    }
   2.202 +
   2.203 +    shdr = &sheaders->shdrs[sheaders->num];
   2.204 +    sheaders->num++;
   2.205 +    memset(shdr, 0, sizeof(*shdr));
   2.206 +    return shdr;
   2.207 +}
   2.208 +
   2.209 +int
   2.210 +xc_core_shdr_set(Elf_Shdr *shdr,
   2.211 +                 struct xc_core_strtab *strtab,
   2.212 +                 const char *name, uint32_t type,
   2.213 +                 uint64_t offset, uint64_t size,
   2.214 +                 uint64_t addralign, uint64_t entsize)
   2.215 +{
   2.216 +    uint64_t name_idx = xc_core_strtab_get(strtab, name);
   2.217 +    if ( name_idx == 0 )
   2.218 +        return -1;
   2.219 +
   2.220 +    shdr->sh_name = name_idx;
   2.221 +    shdr->sh_type = type;
   2.222 +    shdr->sh_offset = offset;
   2.223 +    shdr->sh_size = size;
   2.224 +    shdr->sh_addralign = addralign;
   2.225 +    shdr->sh_entsize = entsize;
   2.226 +    return 0;
   2.227 +}
   2.228 +
   2.229 +static int
   2.230 +elfnote_fill_xen_version(int xc_handle,
   2.231 +                         struct xen_dumpcore_elfnote_xen_version_desc
   2.232 +                         *xen_version)
   2.233 +{
   2.234 +    int rc;
   2.235 +    memset(xen_version, 0, sizeof(*xen_version));
   2.236 +
   2.237 +    rc = xc_version(xc_handle, XENVER_version, NULL);
   2.238 +    if ( rc < 0 )
   2.239 +        return rc;
   2.240 +    xen_version->major_version = rc >> 16;
   2.241 +    xen_version->minor_version = rc & ((1 << 16) - 1);
   2.242 +
   2.243 +    rc = xc_version(xc_handle, XENVER_extraversion,
   2.244 +                    &xen_version->extra_version);
   2.245 +    if ( rc < 0 )
   2.246 +        return rc;
   2.247 +
   2.248 +    rc = xc_version(xc_handle, XENVER_compile_info,
   2.249 +                    &xen_version->compile_info);
   2.250 +    if ( rc < 0 )
   2.251 +        return rc;
   2.252 +
   2.253 +    rc = xc_version(xc_handle,
   2.254 +                    XENVER_capabilities, &xen_version->capabilities);
   2.255 +    if ( rc < 0 )
   2.256 +        return rc;
   2.257 +
   2.258 +    rc = xc_version(xc_handle, XENVER_changeset, &xen_version->changeset);
   2.259 +    if ( rc < 0 )
   2.260 +        return rc;
   2.261 +
   2.262 +    rc = xc_version(xc_handle, XENVER_platform_parameters,
   2.263 +                    &xen_version->platform_parameters);
   2.264 +    if ( rc < 0 )
   2.265 +        return rc;
   2.266 +
   2.267 +    rc = xc_version(xc_handle, XENVER_pagesize, NULL);
   2.268 +    if ( rc < 0 )
   2.269 +        return rc;
   2.270 +    xen_version->pagesize = rc;
   2.271 +
   2.272 +    return 0;
   2.273 +}
   2.274 +
   2.275 +static int
   2.276 +elfnote_fill_format_version(struct xen_dumpcore_elfnote_format_version_desc
   2.277 +                            *format_version)
   2.278 +{
   2.279 +    format_version->version = XEN_DUMPCORE_FORMAT_VERSION_CURRENT;
   2.280 +    return 0;
   2.281 +}
   2.282 +
   2.283  int
   2.284  xc_domain_dumpcore_via_callback(int xc_handle,
   2.285                                  uint32_t domid,
   2.286                                  void *args,
   2.287                                  dumpcore_rtn_t dump_rtn)
   2.288  {
   2.289 -    unsigned long nr_pages;
   2.290 -    uint64_t *page_array = NULL;
   2.291      xc_dominfo_t info;
   2.292 -    int i, nr_vcpus = 0;
   2.293 +    shared_info_t *live_shinfo = NULL;
   2.294 +
   2.295 +    int nr_vcpus = 0;
   2.296      char *dump_mem, *dump_mem_start = NULL;
   2.297 -    struct xc_core_header header;
   2.298      vcpu_guest_context_t  ctxt[MAX_VIRT_CPUS];
   2.299 +    struct xc_core_arch_context arch_ctxt;
   2.300      char dummy[PAGE_SIZE];
   2.301      int dummy_len;
   2.302 -    int sts;
   2.303 +    int sts = -1;
   2.304 +
   2.305 +    unsigned long i;
   2.306 +    unsigned long j;
   2.307 +    unsigned long nr_pages;
   2.308 +
   2.309 +    xc_core_memory_map_t *memory_map = NULL;
   2.310 +    unsigned int nr_memory_map;
   2.311 +    unsigned int map_idx;
   2.312 +
   2.313 +    int auto_translated_physmap;
   2.314 +    xen_pfn_t *p2m = NULL;
   2.315 +    unsigned long max_pfn = 0;
   2.316 +    struct xen_dumpcore_p2m *p2m_array = NULL;
   2.317 +
   2.318 +    uint64_t *pfn_array = NULL;
   2.319  
   2.320 +    Elf_Ehdr ehdr;
   2.321 +    unsigned long filesz;
   2.322 +    unsigned long offset;
   2.323 +    unsigned long fixup;
   2.324 +
   2.325 +    struct xc_core_strtab *strtab = NULL;
   2.326 +    uint16_t strtab_idx;
   2.327 +    struct xc_core_section_headers *sheaders = NULL;
   2.328 +    Elf_Shdr *shdr;
   2.329 +
   2.330 +    /* elf notes */
   2.331 +    struct xen_elfnote elfnote;
   2.332 +    struct xen_dumpcore_elfnote_none_desc none;
   2.333 +    struct xen_dumpcore_elfnote_header_desc header;
   2.334 +    struct xen_dumpcore_elfnote_xen_version_desc xen_version;
   2.335 +    struct xen_dumpcore_elfnote_format_version_desc format_version;
   2.336 +
   2.337 +    xc_core_arch_context_init(&arch_ctxt);
   2.338      if ( (dump_mem_start = malloc(DUMP_INCREMENT*PAGE_SIZE)) == NULL )
   2.339      {
   2.340          PERROR("Could not allocate dump_mem");
   2.341 -        goto error_out;
   2.342 +        goto out;
   2.343      }
   2.344  
   2.345      if ( xc_domain_getinfo(xc_handle, domid, 1, &info) != 1 )
   2.346      {
   2.347          PERROR("Could not get info for domain");
   2.348 -        goto error_out;
   2.349 +        goto out;
   2.350      }
   2.351 +    /* Map the shared info frame */
   2.352 +    live_shinfo = xc_map_foreign_range(xc_handle, domid, PAGE_SIZE,
   2.353 +                                       PROT_READ, info.shared_info_frame);
   2.354 +    if ( !live_shinfo 
   2.355 +#ifdef __ia64__
   2.356 +         && !info.hvm
   2.357 +#endif
   2.358 +        )
   2.359 +    {
   2.360 +        PERROR("Couldn't map live_shinfo");
   2.361 +        goto out;
   2.362 +    }
   2.363 +    auto_translated_physmap = xc_core_arch_auto_translated_physmap(&info);
   2.364  
   2.365      if ( domid != info.domid )
   2.366      {
   2.367          PERROR("Domain %d does not exist", domid);
   2.368 -        goto error_out;
   2.369 +        goto out;
   2.370      }
   2.371  
   2.372      for ( i = 0; i <= info.max_vcpu_id; i++ )
   2.373 -        if ( xc_vcpu_getcontext(xc_handle, domid, i, &ctxt[nr_vcpus]) == 0)
   2.374 +    {
   2.375 +        if ( xc_vcpu_getcontext(xc_handle, domid, i, &ctxt[nr_vcpus]) == 0 )
   2.376 +        {
   2.377 +            if ( xc_core_arch_context_get(&arch_ctxt, &ctxt[nr_vcpus],
   2.378 +                                          xc_handle, domid) )
   2.379 +                continue;
   2.380              nr_vcpus++;
   2.381 +        }
   2.382 +    }
   2.383 +    if ( nr_vcpus == 0 )
   2.384 +    {
   2.385 +        PERROR("No VCPU context could be grabbed");
   2.386 +        goto out;
   2.387 +    }
   2.388 +
   2.389 +    /* obtain memory map */
   2.390 +    sts = xc_core_arch_memory_map_get(xc_handle, &info, live_shinfo,
   2.391 +                                      &memory_map, &nr_memory_map);
   2.392 +    if ( sts != 0 )
   2.393 +        goto out;
   2.394  
   2.395      nr_pages = info.nr_pages;
   2.396 +    if ( !auto_translated_physmap )
   2.397 +    {
   2.398 +        /* obtain p2m table */
   2.399 +        p2m_array = malloc(nr_pages * sizeof(p2m_array[0]));
   2.400 +        if ( p2m_array == NULL )
   2.401 +        {
   2.402 +            PERROR("Could not allocate p2m array");
   2.403 +            goto out;
   2.404 +        }
   2.405  
   2.406 +        sts = xc_core_arch_map_p2m(xc_handle, &info, live_shinfo,
   2.407 +                                   &p2m, &max_pfn);
   2.408 +        if ( sts != 0 )
   2.409 +            goto out;
   2.410 +    }
   2.411 +    else
   2.412 +    {
   2.413 +        pfn_array = malloc(nr_pages * sizeof(pfn_array[0]));
   2.414 +        if ( pfn_array == NULL )
   2.415 +        {
   2.416 +            PERROR("Could not allocate pfn array");
   2.417 +            goto out;
   2.418 +        }
   2.419 +    }
   2.420 +
   2.421 +    /* create .xen_p2m or .xen_pfn */
   2.422 +    j = 0;
   2.423 +    for ( map_idx = 0; map_idx < nr_memory_map; map_idx++ )
   2.424 +    {
   2.425 +        uint64_t pfn_start;
   2.426 +        uint64_t pfn_end;
   2.427 +
   2.428 +        pfn_start = memory_map[map_idx].addr >> PAGE_SHIFT;
   2.429 +        pfn_end = pfn_start + (memory_map[map_idx].size >> PAGE_SHIFT);
   2.430 +        for ( i = pfn_start; i < pfn_end; i++ )
   2.431 +        {
   2.432 +            if ( !auto_translated_physmap )
   2.433 +            {
   2.434 +                if ( p2m[i] == INVALID_P2M_ENTRY )
   2.435 +                    continue;
   2.436 +                p2m_array[j].pfn = i;
   2.437 +                p2m_array[j].gmfn = p2m[i];
   2.438 +            }
   2.439 +            else
   2.440 +            {
   2.441 +                /* try to map page to determin wheter it has underlying page */
   2.442 +                void *vaddr = xc_map_foreign_range(xc_handle, domid,
   2.443 +                                                   PAGE_SIZE, PROT_READ, i);
   2.444 +                if ( vaddr == NULL )
   2.445 +                    continue;
   2.446 +                munmap(vaddr, PAGE_SIZE);
   2.447 +                pfn_array[j] = i;
   2.448 +            }
   2.449 +
   2.450 +            j++;
   2.451 +        }
   2.452 +    }
   2.453 +    if ( j != nr_pages )
   2.454 +    {
   2.455 +        PERROR("j (%ld) != nr_pages (%ld)", j , nr_pages);
   2.456 +        /* When live dump-mode (-L option) is specified,
   2.457 +         * guest domain may change its mapping.
   2.458 +         */
   2.459 +        nr_pages = j;
   2.460 +    }
   2.461 +
   2.462 +    memset(&ehdr, 0, sizeof(ehdr));
   2.463 +    ehdr.e_ident[EI_MAG0] = ELFMAG0;
   2.464 +    ehdr.e_ident[EI_MAG1] = ELFMAG1;
   2.465 +    ehdr.e_ident[EI_MAG2] = ELFMAG2;
   2.466 +    ehdr.e_ident[EI_MAG3] = ELFMAG3;
   2.467 +    ehdr.e_ident[EI_CLASS] = ELFCLASS;
   2.468 +    ehdr.e_ident[EI_DATA] = ELF_ARCH_DATA;
   2.469 +    ehdr.e_ident[EI_VERSION] = EV_CURRENT;
   2.470 +    ehdr.e_ident[EI_OSABI] = ELFOSABI_SYSV;
   2.471 +    ehdr.e_ident[EI_ABIVERSION] = EV_CURRENT;
   2.472 +
   2.473 +    ehdr.e_type = ET_CORE;
   2.474 +    ehdr.e_machine = ELF_ARCH_MACHINE;
   2.475 +    ehdr.e_version = EV_CURRENT;
   2.476 +    ehdr.e_entry = 0;
   2.477 +    ehdr.e_phoff = 0;
   2.478 +    ehdr.e_shoff = sizeof(ehdr);
   2.479 +    ehdr.e_flags = ELF_CORE_EFLAGS;
   2.480 +    ehdr.e_ehsize = sizeof(ehdr);
   2.481 +    ehdr.e_phentsize = sizeof(Elf_Phdr);
   2.482 +    ehdr.e_phnum = 0;
   2.483 +    ehdr.e_shentsize = sizeof(Elf_Shdr);
   2.484 +    /* ehdr.e_shnum and ehdr.e_shstrndx aren't known here yet. fill it later*/
   2.485 +
   2.486 +    /* create section header */
   2.487 +    strtab = xc_core_strtab_init();
   2.488 +    if ( strtab == NULL )
   2.489 +    {
   2.490 +        PERROR("Could not allocate string table");
   2.491 +        goto out;
   2.492 +    }
   2.493 +    sheaders = xc_core_shdr_init();
   2.494 +    if ( sheaders == NULL )
   2.495 +    {
   2.496 +        PERROR("Could not allocate section headers");
   2.497 +        goto out;
   2.498 +    }
   2.499 +    /* null section */
   2.500 +    shdr = xc_core_shdr_get(sheaders);
   2.501 +    if ( shdr == NULL )
   2.502 +    {
   2.503 +        PERROR("Could not get section header for null section");
   2.504 +        goto out;
   2.505 +    }
   2.506 +
   2.507 +    /* .shstrtab */
   2.508 +    shdr = xc_core_shdr_get(sheaders);
   2.509 +    if ( shdr == NULL )
   2.510 +    {
   2.511 +        PERROR("Could not get section header for shstrtab");
   2.512 +        goto out;
   2.513 +    }
   2.514 +    strtab_idx = shdr - sheaders->shdrs;
   2.515 +    /* strtab_shdr.sh_offset, strtab_shdr.sh_size aren't unknown.
   2.516 +     * fill it later
   2.517 +     */
   2.518 +    sts = xc_core_shdr_set(shdr, strtab, ELF_SHSTRTAB, SHT_STRTAB, 0, 0, 0, 0);
   2.519 +    if ( sts != 0 )
   2.520 +        goto out;
   2.521 +
   2.522 +    /* elf note section */
   2.523 +    /* here the number of section header is unknown. fix up offset later. */
   2.524 +    offset = sizeof(ehdr);
   2.525 +    filesz =
   2.526 +        sizeof(struct xen_dumpcore_elfnote_none) +         /* none */
   2.527 +        sizeof(struct xen_dumpcore_elfnote_header) +       /* core header */
   2.528 +        sizeof(struct xen_dumpcore_elfnote_xen_version) +  /* xen version */
   2.529 +        sizeof(struct xen_dumpcore_elfnote_format_version);/* format version */
   2.530 +    shdr = xc_core_shdr_get(sheaders);
   2.531 +    if ( shdr == NULL )
   2.532 +    {
   2.533 +        PERROR("Could not get section header for note section");
   2.534 +        goto out;
   2.535 +    }
   2.536 +    sts = xc_core_shdr_set(shdr, strtab, XEN_DUMPCORE_SEC_NOTE, SHT_NOTE,
   2.537 +                           offset, filesz, 0, 0);
   2.538 +    if ( sts != 0 )
   2.539 +        goto out;
   2.540 +    offset += filesz;
   2.541 +
   2.542 +    /* prstatus */
   2.543 +    shdr = xc_core_shdr_get(sheaders);
   2.544 +    if ( shdr == NULL )
   2.545 +    {
   2.546 +        PERROR("Could not get section header for .xen_prstatus");
   2.547 +        goto out;
   2.548 +    }
   2.549 +    filesz = sizeof(ctxt[0]) * nr_vcpus;
   2.550 +    sts = xc_core_shdr_set(shdr, strtab, XEN_DUMPCORE_SEC_PRSTATUS,
   2.551 +                           SHT_PROGBITS, offset, filesz,
   2.552 +                           __alignof__(ctxt[0]), sizeof(ctxt[0]));
   2.553 +    if ( sts != 0 )
   2.554 +        goto out;
   2.555 +    offset += filesz;
   2.556 +
   2.557 +    /* arch context */
   2.558 +    sts = xc_core_arch_context_get_shdr(&arch_ctxt, sheaders, strtab,
   2.559 +                                        &filesz, offset);
   2.560 +    if ( sts != 0)
   2.561 +        goto out;
   2.562 +    offset += filesz;
   2.563 +
   2.564 +    /* shared_info */
   2.565 +    if ( live_shinfo != NULL )
   2.566 +    {
   2.567 +        shdr = xc_core_shdr_get(sheaders);
   2.568 +        if ( shdr == NULL )
   2.569 +        {
   2.570 +            PERROR("Could not get section header for .xen_shared_info");
   2.571 +            goto out;
   2.572 +        }
   2.573 +        filesz = PAGE_SIZE;
   2.574 +        sts = xc_core_shdr_set(shdr, strtab, XEN_DUMPCORE_SEC_SHARED_INFO,
   2.575 +                               SHT_PROGBITS, offset, filesz,
   2.576 +                               __alignof__(*live_shinfo), PAGE_SIZE);
   2.577 +        if ( sts != 0 )
   2.578 +            goto out;
   2.579 +        offset += filesz;
   2.580 +    }
   2.581 +
   2.582 +    /* p2m/pfn table */
   2.583 +    shdr = xc_core_shdr_get(sheaders);
   2.584 +    if ( shdr == NULL )
   2.585 +    {
   2.586 +        PERROR("Could not get section header for .xen_{p2m, pfn} table");
   2.587 +        goto out;
   2.588 +    }
   2.589 +    if ( !auto_translated_physmap )
   2.590 +    {
   2.591 +        filesz = nr_pages * sizeof(p2m_array[0]);
   2.592 +        sts = xc_core_shdr_set(shdr, strtab, XEN_DUMPCORE_SEC_P2M,
   2.593 +                               SHT_PROGBITS,
   2.594 +                               offset, filesz, __alignof__(p2m_array[0]),
   2.595 +                               sizeof(p2m_array[0]));
   2.596 +        if ( sts != 0 )
   2.597 +            goto out;
   2.598 +    }
   2.599 +    else
   2.600 +    {
   2.601 +        filesz = nr_pages * sizeof(pfn_array[0]);
   2.602 +        sts = xc_core_shdr_set(shdr, strtab, XEN_DUMPCORE_SEC_PFN,
   2.603 +                               SHT_PROGBITS,
   2.604 +                               offset, filesz, __alignof__(pfn_array[0]),
   2.605 +                               sizeof(pfn_array[0]));
   2.606 +        if ( sts != 0 )
   2.607 +            goto out;
   2.608 +    }
   2.609 +    offset += filesz;
   2.610 +
   2.611 +    /* pages */
   2.612 +    shdr = xc_core_shdr_get(sheaders);
   2.613 +    if ( shdr == NULL )
   2.614 +    {
   2.615 +        PERROR("could not get section headers for .xen_pages");
   2.616 +        goto out;
   2.617 +    }
   2.618 +
   2.619 +    /*
   2.620 +     * pages are the last section to allocate section headers
   2.621 +     * so that we know the number of section headers here.
   2.622 +     */
   2.623 +    fixup = sheaders->num * sizeof(*shdr);
   2.624 +    /* zeroth section should have zero offset */
   2.625 +    for ( i = 1; i < sheaders->num; i++ )
   2.626 +        sheaders->shdrs[i].sh_offset += fixup;
   2.627 +    offset += fixup;
   2.628 +    dummy_len = ROUNDUP(offset, PAGE_SHIFT) - offset; /* padding length */
   2.629 +    offset += dummy_len;
   2.630 +
   2.631 +    filesz = nr_pages * PAGE_SIZE;
   2.632 +    sts = xc_core_shdr_set(shdr, strtab, XEN_DUMPCORE_SEC_PAGES, SHT_PROGBITS,
   2.633 +                           offset, filesz, PAGE_SIZE, PAGE_SIZE);
   2.634 +    if ( sts != 0 )
   2.635 +        goto out;
   2.636 +    offset += filesz;
   2.637 +
   2.638 +    /* fixing up section header string table section header */
   2.639 +    filesz = strtab->current;
   2.640 +    sheaders->shdrs[strtab_idx].sh_offset = offset;
   2.641 +    sheaders->shdrs[strtab_idx].sh_size = filesz;
   2.642 +
   2.643 +    /* write out elf header */
   2.644 +    ehdr.e_shnum = sheaders->num;
   2.645 +    ehdr.e_shstrndx = strtab_idx;
   2.646 +    sts = dump_rtn(args, (char*)&ehdr, sizeof(ehdr));
   2.647 +    if ( sts != 0 )
   2.648 +        goto out;
   2.649 +
   2.650 +    /* section headers */
   2.651 +    sts = dump_rtn(args, (char*)sheaders->shdrs,
   2.652 +                   sheaders->num * sizeof(sheaders->shdrs[0]));
   2.653 +    if ( sts != 0 )
   2.654 +        goto out;
   2.655 +
   2.656 +    /* elf note section */
   2.657 +    memset(&elfnote, 0, sizeof(elfnote));
   2.658 +    elfnote.namesz = strlen(XEN_DUMPCORE_ELFNOTE_NAME) + 1;
   2.659 +    strncpy(elfnote.name, XEN_DUMPCORE_ELFNOTE_NAME, sizeof(elfnote.name));
   2.660 +
   2.661 +    /* elf note section:xen core header */
   2.662 +    elfnote.descsz = sizeof(none);
   2.663 +    elfnote.type = XEN_ELFNOTE_DUMPCORE_NONE;
   2.664 +    sts = dump_rtn(args, (char*)&elfnote, sizeof(elfnote));
   2.665 +    if ( sts != 0 )
   2.666 +        goto out;
   2.667 +    sts = dump_rtn(args, (char*)&none, sizeof(none));
   2.668 +    if ( sts != 0 )
   2.669 +        goto out;
   2.670 +
   2.671 +    /* elf note section:xen core header */
   2.672 +    elfnote.descsz = sizeof(header);
   2.673 +    elfnote.type = XEN_ELFNOTE_DUMPCORE_HEADER;
   2.674      header.xch_magic = info.hvm ? XC_CORE_MAGIC_HVM : XC_CORE_MAGIC;
   2.675      header.xch_nr_vcpus = nr_vcpus;
   2.676      header.xch_nr_pages = nr_pages;
   2.677 -    header.xch_ctxt_offset = sizeof(struct xc_core_header);
   2.678 -    header.xch_index_offset = sizeof(struct xc_core_header) +
   2.679 -        sizeof(vcpu_guest_context_t)*nr_vcpus;
   2.680 -    dummy_len = (sizeof(struct xc_core_header) +
   2.681 -                 (sizeof(vcpu_guest_context_t) * nr_vcpus) +
   2.682 -                 (nr_pages * sizeof(*page_array)));
   2.683 -    header.xch_pages_offset = round_pgup(dummy_len);
   2.684 +    header.xch_page_size = PAGE_SIZE;
   2.685 +    sts = dump_rtn(args, (char*)&elfnote, sizeof(elfnote));
   2.686 +    if ( sts != 0 )
   2.687 +        goto out;
   2.688 +    sts = dump_rtn(args, (char*)&header, sizeof(header));
   2.689 +    if ( sts != 0 )
   2.690 +        goto out;
   2.691  
   2.692 -    sts = dump_rtn(args, (char *)&header, sizeof(struct xc_core_header));
   2.693 +    /* elf note section: xen version */
   2.694 +    elfnote.descsz = sizeof(xen_version);
   2.695 +    elfnote.type = XEN_ELFNOTE_DUMPCORE_XEN_VERSION;
   2.696 +    elfnote_fill_xen_version(xc_handle, &xen_version);
   2.697 +    sts = dump_rtn(args, (char*)&elfnote, sizeof(elfnote));
   2.698 +    if ( sts != 0 )
   2.699 +        goto out;
   2.700 +    sts = dump_rtn(args, (char*)&xen_version, sizeof(xen_version));
   2.701      if ( sts != 0 )
   2.702 -        goto error_out;
   2.703 +        goto out;
   2.704  
   2.705 +    /* elf note section: format version */
   2.706 +    elfnote.descsz = sizeof(format_version);
   2.707 +    elfnote.type = XEN_ELFNOTE_DUMPCORE_FORMAT_VERSION;
   2.708 +    elfnote_fill_format_version(&format_version);
   2.709 +    sts = dump_rtn(args, (char*)&elfnote, sizeof(elfnote));
   2.710 +    if ( sts != 0 )
   2.711 +        goto out;
   2.712 +    sts = dump_rtn(args, (char*)&format_version, sizeof(format_version));
   2.713 +    if ( sts != 0 )
   2.714 +        goto out;
   2.715 +
   2.716 +    /* prstatus: .xen_prstatus */
   2.717      sts = dump_rtn(args, (char *)&ctxt, sizeof(ctxt[0]) * nr_vcpus);
   2.718      if ( sts != 0 )
   2.719 -        goto error_out;
   2.720 +        goto out;
   2.721  
   2.722 -    if ( (page_array = malloc(nr_pages * sizeof(*page_array))) == NULL )
   2.723 +    if ( live_shinfo != NULL )
   2.724      {
   2.725 -        IPRINTF("Could not allocate memory\n");
   2.726 -        goto error_out;
   2.727 +        /* shared_info: .xen_shared_info */
   2.728 +        sts = dump_rtn(args, (char*)live_shinfo, PAGE_SIZE);
   2.729 +        if ( sts != 0 )
   2.730 +            goto out;
   2.731      }
   2.732 -    if ( xc_get_pfn_list(xc_handle, domid, page_array, nr_pages) != nr_pages )
   2.733 -    {
   2.734 -        IPRINTF("Could not get the page frame list\n");
   2.735 -        goto error_out;
   2.736 -    }
   2.737 -    sts = dump_rtn(args, (char *)page_array, nr_pages * sizeof(*page_array));
   2.738 +
   2.739 +    /* arch specific context */
   2.740 +    sts = xc_core_arch_context_dump(&arch_ctxt, args, dump_rtn);
   2.741      if ( sts != 0 )
   2.742 -        goto error_out;
   2.743 +        goto out;
   2.744 +
   2.745 +    /* p2m/pfn table: .xen_p2m/.xen_pfn */
   2.746 +    if ( !auto_translated_physmap )
   2.747 +        sts = dump_rtn(args, (char *)p2m_array,
   2.748 +                       sizeof(p2m_array[0]) * nr_pages);
   2.749 +    else
   2.750 +        sts = dump_rtn(args, (char *)pfn_array,
   2.751 +                       sizeof(pfn_array[0]) * nr_pages);
   2.752 +    if ( sts != 0 )
   2.753 +        goto out;
   2.754  
   2.755      /* Pad the output data to page alignment. */
   2.756      memset(dummy, 0, PAGE_SIZE);
   2.757 -    sts = dump_rtn(args, dummy, header.xch_pages_offset - dummy_len);
   2.758 +    sts = dump_rtn(args, dummy, dummy_len);
   2.759      if ( sts != 0 )
   2.760 -        goto error_out;
   2.761 +        goto out;
   2.762  
   2.763 +    /* dump pages: .xen_pages */
   2.764      for ( dump_mem = dump_mem_start, i = 0; i < nr_pages; i++ )
   2.765      {
   2.766 -        copy_from_domain_page(xc_handle, domid, page_array[i], dump_mem);
   2.767 +        uint64_t gmfn;
   2.768 +        if ( !auto_translated_physmap )
   2.769 +            gmfn = p2m_array[i].gmfn;
   2.770 +        else
   2.771 +            gmfn = pfn_array[i];
   2.772 +
   2.773 +        copy_from_domain_page(xc_handle, domid, gmfn, dump_mem);
   2.774          dump_mem += PAGE_SIZE;
   2.775          if ( ((i + 1) % DUMP_INCREMENT == 0) || ((i + 1) == nr_pages) )
   2.776          {
   2.777              sts = dump_rtn(args, dump_mem_start, dump_mem - dump_mem_start);
   2.778              if ( sts != 0 )
   2.779 -                goto error_out;
   2.780 +                goto out;
   2.781              dump_mem = dump_mem_start;
   2.782          }
   2.783      }
   2.784  
   2.785 -    free(dump_mem_start);
   2.786 -    free(page_array);
   2.787 -    return 0;
   2.788 +    /* elf section header string table: .shstrtab */
   2.789 +    sts = dump_rtn(args, strtab->strings, strtab->current);
   2.790 +    if ( sts != 0 )
   2.791 +        goto out;
   2.792 +
   2.793 +    sts = 0;
   2.794  
   2.795 - error_out:
   2.796 -    free(dump_mem_start);
   2.797 -    free(page_array);
   2.798 -    return -1;
   2.799 +out:
   2.800 +    if ( p2m != NULL )
   2.801 +        munmap(p2m, PAGE_SIZE * P2M_FL_ENTRIES);
   2.802 +    if ( p2m_array != NULL )
   2.803 +        free(p2m_array);
   2.804 +    if ( pfn_array != NULL )
   2.805 +        free(pfn_array);
   2.806 +    if ( sheaders != NULL )
   2.807 +        xc_core_shdr_free(sheaders);
   2.808 +    if ( strtab != NULL )
   2.809 +        xc_core_strtab_free(strtab);
   2.810 +    if ( dump_mem_start != NULL )
   2.811 +        free(dump_mem_start);
   2.812 +    if ( live_shinfo != NULL )
   2.813 +        munmap(live_shinfo, PAGE_SIZE);
   2.814 +    xc_core_arch_context_free(&arch_ctxt);
   2.815 +
   2.816 +    return sts;
   2.817  }
   2.818  
   2.819  /* Callback args for writing to a local dump file. */
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/tools/libxc/xc_core.h	Sat Feb 24 14:31:42 2007 +0000
     3.3 @@ -0,0 +1,165 @@
     3.4 +/*
     3.5 + * Copyright (c) 2006 Isaku Yamahata <yamahata at valinux co jp>
     3.6 + *                    VA Linux Systems Japan K.K.
     3.7 + *
     3.8 + * This program is free software; you can redistribute it and/or modify
     3.9 + * it under the terms of the GNU General Public License as published by
    3.10 + * the Free Software Foundation; either version 2 of the License, or
    3.11 + * (at your option) any later version.
    3.12 + *
    3.13 + * This program is distributed in the hope that it will be useful,
    3.14 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    3.15 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    3.16 + * GNU General Public License for more details.
    3.17 + *
    3.18 + * You should have received a copy of the GNU General Public License
    3.19 + * along with this program; if not, write to the Free Software
    3.20 + * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    3.21 + *
    3.22 + */
    3.23 +
    3.24 +#ifndef XC_CORE_H
    3.25 +#define XC_CORE_H
    3.26 +
    3.27 +#include "xen/version.h"
    3.28 +#include "xg_private.h"
    3.29 +#include "xen/elfstructs.h"
    3.30 +
    3.31 +/* section names */
    3.32 +#define XEN_DUMPCORE_SEC_NOTE                   ".note.Xen"
    3.33 +#define XEN_DUMPCORE_SEC_PRSTATUS               ".xen_prstatus"
    3.34 +#define XEN_DUMPCORE_SEC_SHARED_INFO            ".xen_shared_info"
    3.35 +#define XEN_DUMPCORE_SEC_P2M                    ".xen_p2m"
    3.36 +#define XEN_DUMPCORE_SEC_PFN                    ".xen_pfn"
    3.37 +#define XEN_DUMPCORE_SEC_PAGES                  ".xen_pages"
    3.38 +
    3.39 +#define XEN_DUMPCORE_SEC_IA64_MAPPED_REGS       ".xen_ia64_mapped_regs"
    3.40 +
    3.41 +/* elf note name */
    3.42 +#define XEN_DUMPCORE_ELFNOTE_NAME               "Xen"
    3.43 +/* note numbers are defined in xen/elfnote.h */
    3.44 +
    3.45 +struct xen_elfnote {
    3.46 +    uint32_t    namesz; /* Elf_Note note; */
    3.47 +    uint32_t    descsz;
    3.48 +    uint32_t    type;
    3.49 +    char        name[4]; /* sizeof("Xen") = 4
    3.50 +                          * Fotunately this is 64bit aligned so that
    3.51 +                          * we can use same structore for both 32/64bit
    3.52 +                          */
    3.53 +};
    3.54 +
    3.55 +struct xen_dumpcore_elfnote_none_desc {
    3.56 +    /* nothing */
    3.57 +};
    3.58 +
    3.59 +struct xen_dumpcore_elfnote_header_desc {
    3.60 +    uint64_t    xch_magic;
    3.61 +    uint64_t    xch_nr_vcpus;
    3.62 +    uint64_t    xch_nr_pages;
    3.63 +    uint64_t    xch_page_size;
    3.64 +};
    3.65 +
    3.66 +struct xen_dumpcore_elfnote_xen_version_desc {
    3.67 +    uint64_t                    major_version;
    3.68 +    uint64_t                    minor_version;
    3.69 +    xen_extraversion_t          extra_version;
    3.70 +    xen_compile_info_t          compile_info;
    3.71 +    xen_capabilities_info_t     capabilities;
    3.72 +    xen_changeset_info_t        changeset;
    3.73 +    xen_platform_parameters_t   platform_parameters;
    3.74 +    uint64_t                    pagesize;
    3.75 +};
    3.76 +
    3.77 +#define XEN_DUMPCORE_FORMAT_VERSION(major, minor)  \
    3.78 +    ((major) << 32) | ((minor) & 0xffffffff)
    3.79 +#define XEN_DUMPCORE_FORMAT_MAJOR(version)      ((major) >> 32)
    3.80 +#define XEN_DUMPCORE_FORMAT_MINOR(version)      ((minor) & 0xffffffff)
    3.81 +
    3.82 +#define XEN_DUMPCORE_FORMAT_MAJOR_CURRENT       ((uint64_t)0)
    3.83 +#define XEN_DUMPCORE_FORMAT_MINOR_CURRENT       ((uint64_t)1)
    3.84 +#define XEN_DUMPCORE_FORMAT_VERSION_CURRENT                         \
    3.85 +    XEN_DUMPCORE_FORMAT_VERSION(XEN_DUMPCORE_FORMAT_MAJOR_CURRENT,  \
    3.86 +                                XEN_DUMPCORE_FORMAT_MINOR_CURRENT)
    3.87 +
    3.88 +struct xen_dumpcore_elfnote_format_version_desc {
    3.89 +    uint64_t    version;
    3.90 +};
    3.91 +
    3.92 +
    3.93 +struct xen_dumpcore_elfnote_none {
    3.94 +    struct xen_elfnote                          elfnote;
    3.95 +    struct xen_dumpcore_elfnote_none_desc       none;
    3.96 +};
    3.97 +
    3.98 +struct xen_dumpcore_elfnote_header {
    3.99 +    struct xen_elfnote                          elfnote;
   3.100 +    struct xen_dumpcore_elfnote_header_desc     header;
   3.101 +};
   3.102 +
   3.103 +struct xen_dumpcore_elfnote_xen_version {
   3.104 +    struct xen_elfnote                                  elfnote;
   3.105 +    struct xen_dumpcore_elfnote_xen_version_desc        xen_version;
   3.106 +};
   3.107 +
   3.108 +struct xen_dumpcore_elfnote_format_version {
   3.109 +    struct xen_elfnote                                  elfnote;
   3.110 +    struct xen_dumpcore_elfnote_format_version_desc     format_version;
   3.111 +};
   3.112 +
   3.113 +struct xen_dumpcore_p2m {
   3.114 +    uint64_t    pfn;
   3.115 +    uint64_t    gmfn;
   3.116 +};
   3.117 +
   3.118 +
   3.119 +struct xc_core_strtab;
   3.120 +struct xc_core_section_headers;
   3.121 +
   3.122 +Elf_Shdr*
   3.123 +xc_core_shdr_get(struct xc_core_section_headers *sheaders);
   3.124 +int
   3.125 +xc_core_shdr_set(Elf_Shdr *shdr,
   3.126 +                 struct xc_core_strtab *strtab,
   3.127 +                 const char *name, uint32_t type,
   3.128 +                 uint64_t offset, uint64_t size,
   3.129 +                 uint64_t addralign, uint64_t entsize);
   3.130 +
   3.131 +struct xc_core_memory_map {
   3.132 +    uint64_t    addr;
   3.133 +    uint64_t    size;
   3.134 +};
   3.135 +typedef struct xc_core_memory_map xc_core_memory_map_t;
   3.136 +int xc_core_arch_auto_translated_physmap(const xc_dominfo_t *info);
   3.137 +int xc_core_arch_memory_map_get(int xc_handle, xc_dominfo_t *info,
   3.138 +                                shared_info_t *live_shinfo,
   3.139 +                                xc_core_memory_map_t **mapp,
   3.140 +                                unsigned int *nr_entries);
   3.141 +int xc_core_arch_map_p2m(int xc_handle, xc_dominfo_t *info,
   3.142 +                         shared_info_t *live_shinfo, xen_pfn_t **live_p2m,
   3.143 +                         unsigned long *pfnp);
   3.144 +
   3.145 +
   3.146 +#if defined (__i386__) || defined (__x86_64__)
   3.147 +# include "xc_core_x86.h"
   3.148 +#elif defined (__ia64__)
   3.149 +# include "xc_core_ia64.h"
   3.150 +#else
   3.151 +# error "unsupported architecture"
   3.152 +#endif
   3.153 +
   3.154 +#ifndef ELF_CORE_EFLAGS
   3.155 +# define ELF_CORE_EFLAGS 0
   3.156 +#endif
   3.157 +
   3.158 +#endif /* XC_CORE_H */
   3.159 +
   3.160 +/*
   3.161 + * Local variables:
   3.162 + * mode: C
   3.163 + * c-set-style: "BSD"
   3.164 + * c-basic-offset: 4
   3.165 + * tab-width: 4
   3.166 + * indent-tabs-mode: nil
   3.167 + * End:
   3.168 + */
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/tools/libxc/xc_core_ia64.c	Sat Feb 24 14:31:42 2007 +0000
     4.3 @@ -0,0 +1,315 @@
     4.4 +/*
     4.5 + * This program is free software; you can redistribute it and/or modify
     4.6 + * it under the terms of the GNU General Public License as published by
     4.7 + * the Free Software Foundation; either version 2 of the License, or
     4.8 + * (at your option) any later version.
     4.9 + *
    4.10 + * This program is distributed in the hope that it will be useful,
    4.11 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    4.12 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    4.13 + * GNU General Public License for more details.
    4.14 + *
    4.15 + * You should have received a copy of the GNU General Public License
    4.16 + * along with this program; if not, write to the Free Software
    4.17 + * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    4.18 + *
    4.19 + * Copyright (c) 2007 Isaku Yamahata <yamahata at valinux co jp>
    4.20 + *                    VA Linux Systems Japan K.K.
    4.21 + *
    4.22 + */
    4.23 +
    4.24 +#include "xg_private.h"
    4.25 +#include "xc_core.h"
    4.26 +#include "xc_efi.h"
    4.27 +#include "xc_dom.h"
    4.28 +
    4.29 +int
    4.30 +xc_core_arch_auto_translated_physmap(const xc_dominfo_t *info)
    4.31 +{
    4.32 +    /*
    4.33 +     * on ia64, both paravirtualize domain and hvm domain are
    4.34 +     * auto_translated_physmap mode
    4.35 +     */
    4.36 +    return 1;
    4.37 +}
    4.38 +
    4.39 +/* see setup_guest() @ xc_linux_build.c */
    4.40 +static int
    4.41 +memory_map_get_old_domu(int xc_handle, xc_dominfo_t *info,
    4.42 +                        shared_info_t *live_shinfo,
    4.43 +                        xc_core_memory_map_t **mapp, unsigned int *nr_entries)
    4.44 +{
    4.45 +    xc_core_memory_map_t *map = NULL;
    4.46 +
    4.47 +    map = malloc(sizeof(*map));
    4.48 +    if ( map == NULL )
    4.49 +    {
    4.50 +        PERROR("Could not allocate memory");
    4.51 +        goto out;
    4.52 +    }
    4.53 +
    4.54 +    map->addr = 0;
    4.55 +    map->size = info->max_memkb * 1024;
    4.56 +
    4.57 +    *mapp = map;
    4.58 +    *nr_entries = 1;
    4.59 +    return 0;
    4.60 +
    4.61 +out:
    4.62 +    if ( map != NULL )
    4.63 +        free(map);
    4.64 +    return -1;
    4.65 +}
    4.66 +
    4.67 +/* see setup_guest() @ xc_ia64_hvm_build.c */
    4.68 +static int
    4.69 +memory_map_get_old_hvm(int xc_handle, xc_dominfo_t *info, 
    4.70 +                       shared_info_t *live_shinfo,
    4.71 +                       xc_core_memory_map_t **mapp, unsigned int *nr_entries)
    4.72 +{
    4.73 +    const xc_core_memory_map_t gfw_map[] = {
    4.74 +        {IO_PAGE_START, IO_PAGE_SIZE},
    4.75 +        {STORE_PAGE_START, STORE_PAGE_SIZE},
    4.76 +        {BUFFER_IO_PAGE_START, BUFFER_IO_PAGE_SIZE},
    4.77 +        {GFW_START, GFW_SIZE},
    4.78 +    };
    4.79 +    const unsigned int nr_gfw_map = sizeof(gfw_map)/sizeof(gfw_map[0]);
    4.80 +    xc_core_memory_map_t *map = NULL;
    4.81 +    unsigned int i;
    4.82 +    
    4.83 +#define VGA_IO_END      (VGA_IO_START + VGA_IO_SIZE)
    4.84 +    /* [0, VGA_IO_START) [VGA_IO_END, 3GB), [4GB, ...) + gfw_map */
    4.85 +    map = malloc((3 + nr_gfw_map) * sizeof(*map));
    4.86 +    if ( map == NULL )
    4.87 +    {
    4.88 +        PERROR("Could not allocate memory");
    4.89 +        goto out;
    4.90 +    }
    4.91 +
    4.92 +    for ( i = 0; i < nr_gfw_map; i++ )
    4.93 +        map[i] = gfw_map[i];
    4.94 +    map[i].addr = 0;
    4.95 +    map[i].size = info->max_memkb * 1024;
    4.96 +    i++;
    4.97 +    if ( map[i - 1].size < VGA_IO_END )
    4.98 +    {
    4.99 +        map[i - 1].size = VGA_IO_START;
   4.100 +    }
   4.101 +    else
   4.102 +    {
   4.103 +        map[i].addr = VGA_IO_END;
   4.104 +        map[i].size = map[i - 1].size - VGA_IO_END;
   4.105 +        map[i - 1].size = VGA_IO_START;
   4.106 +        i++;
   4.107 +        if ( map[i - 1].addr + map[i - 1].size > MMIO_START )
   4.108 +        {
   4.109 +            map[i].addr = MMIO_START + 1 * MEM_G;
   4.110 +            map[i].size = map[i - 1].addr + map[i - 1].size - MMIO_START;
   4.111 +            map[i - 1].size = MMIO_START - map[i - 1].addr;
   4.112 +            i++;
   4.113 +        }
   4.114 +    }
   4.115 +    *mapp = map;
   4.116 +    *nr_entries = i;
   4.117 +    return 0;
   4.118 +
   4.119 +out:
   4.120 +    if ( map != NULL )
   4.121 +        free(map);
   4.122 +    return -1;
   4.123 +}
   4.124 +
   4.125 +static int
   4.126 +memory_map_get_old(int xc_handle, xc_dominfo_t *info, 
   4.127 +                   shared_info_t *live_shinfo,
   4.128 +                   xc_core_memory_map_t **mapp, unsigned int *nr_entries)
   4.129 +{
   4.130 +    if ( info->hvm )
   4.131 +        return memory_map_get_old_hvm(xc_handle, info, live_shinfo,
   4.132 +                                      mapp, nr_entries);
   4.133 +    if ( live_shinfo == NULL )
   4.134 +        return -1;
   4.135 +    return memory_map_get_old_domu(xc_handle, info, live_shinfo,
   4.136 +                                   mapp, nr_entries);
   4.137 +}
   4.138 +
   4.139 +int
   4.140 +xc_core_arch_memory_map_get(int xc_handle, xc_dominfo_t *info,
   4.141 +                            shared_info_t *live_shinfo,
   4.142 +                            xc_core_memory_map_t **mapp,
   4.143 +                            unsigned int *nr_entries)
   4.144 +{
   4.145 +#ifdef notyet
   4.146 +    int ret = -1;
   4.147 +    xen_ia64_memmap_info_t *memmap_info;
   4.148 +    xc_core_memory_map_t *map;
   4.149 +    char *start;
   4.150 +    char *end;
   4.151 +    char *p;
   4.152 +    efi_memory_desc_t *md;
   4.153 +
   4.154 +    if  ( live_shinfo == NULL || live_shinfo->arch.memmap_info_pfn == 0 )
   4.155 +        goto old;
   4.156 +
   4.157 +    memmap_info = xc_map_foreign_range(xc_handle, info->domid,
   4.158 +                                       PAGE_SIZE, PROT_READ,
   4.159 +                                       live_shinfo->arch.memmap_info_pfn);
   4.160 +    if ( memmap_info == NULL )
   4.161 +    {
   4.162 +        PERROR("Could not map memmap info.");
   4.163 +        return -1;
   4.164 +    }
   4.165 +    if ( memmap_info->efi_memdesc_size != sizeof(*md) ||
   4.166 +         (memmap_info->efi_memmap_size / memmap_info->efi_memdesc_size) == 0 ||
   4.167 +         memmap_info->efi_memmap_size > PAGE_SIZE - sizeof(memmap_info) ||
   4.168 +         memmap_info->efi_memdesc_version != EFI_MEMORY_DESCRIPTOR_VERSION )
   4.169 +    {
   4.170 +        PERROR("unknown memmap header. defaulting to compat mode.");
   4.171 +        munmap(memmap_info, PAGE_SIZE);
   4.172 +        goto old;
   4.173 +    }
   4.174 +
   4.175 +    *nr_entries = memmap_info->efi_memmap_size / memmap_info->efi_memdesc_size;
   4.176 +    map = malloc(*nr_entries * sizeof(*md));
   4.177 +    if ( map == NULL )
   4.178 +    {
   4.179 +        PERROR("Could not allocate memory for memmap.");
   4.180 +        goto out;
   4.181 +    }
   4.182 +    *mapp = map;
   4.183 +
   4.184 +    *nr_entries = 0;
   4.185 +    start = (char*)&memmap_info->memdesc;
   4.186 +    end = start + memmap_info->efi_memmap_size;
   4.187 +    for ( p = start; p < end; p += memmap_info->efi_memdesc_size )
   4.188 +    {
   4.189 +        md = (efi_memory_desc_t*)p;
   4.190 +        if ( md->type != EFI_CONVENTIONAL_MEMORY ||
   4.191 +             md->attribute != EFI_MEMORY_WB ||
   4.192 +             md->num_pages == 0 )
   4.193 +            continue;
   4.194 +
   4.195 +        map[*nr_entries].addr = md->phys_addr;
   4.196 +        map[*nr_entries].size = md->num_pages << EFI_PAGE_SHIFT;
   4.197 +        (*nr_entries)++;
   4.198 +    }
   4.199 +    ret = 0;
   4.200 +out:
   4.201 +    munmap(memmap_info, PAGE_SIZE);
   4.202 +    return ret;
   4.203 +    
   4.204 +old:
   4.205 +#endif
   4.206 +    return memory_map_get_old(xc_handle, info, live_shinfo, mapp, nr_entries);
   4.207 +}
   4.208 +
   4.209 +int
   4.210 +xc_core_arch_map_p2m(int xc_handle, xc_dominfo_t *info,
   4.211 +                     shared_info_t *live_shinfo, xen_pfn_t **live_p2m,
   4.212 +                     unsigned long *pfnp)
   4.213 +{
   4.214 +    /*
   4.215 +     * on ia64, both paravirtualize domain and hvm domain are
   4.216 +     * auto_translated_physmap mode
   4.217 +     */
   4.218 +    errno = ENOSYS;
   4.219 +    return -1;
   4.220 +}
   4.221 +
   4.222 +void
   4.223 +xc_core_arch_context_init(struct xc_core_arch_context* arch_ctxt)
   4.224 +{
   4.225 +    int i;
   4.226 +
   4.227 +    arch_ctxt->mapped_regs_size =
   4.228 +        (XMAPPEDREGS_SIZE < PAGE_SIZE) ? PAGE_SIZE: XMAPPEDREGS_SIZE;
   4.229 +    arch_ctxt->nr_vcpus = 0;
   4.230 +    for ( i = 0; i < MAX_VIRT_CPUS; i++ )
   4.231 +        arch_ctxt->mapped_regs[i] = NULL;
   4.232 +}
   4.233 +
   4.234 +void
   4.235 +xc_core_arch_context_free(struct xc_core_arch_context* arch_ctxt)
   4.236 +{
   4.237 +    int i;
   4.238 +    for ( i = 0; i < arch_ctxt->nr_vcpus; i++ )
   4.239 +        if ( arch_ctxt->mapped_regs[i] != NULL )
   4.240 +            munmap(arch_ctxt->mapped_regs[i], arch_ctxt->mapped_regs_size);
   4.241 +}
   4.242 +
   4.243 +int
   4.244 +xc_core_arch_context_get(struct xc_core_arch_context* arch_ctxt,
   4.245 +                         vcpu_guest_context_t* ctxt,
   4.246 +                         int xc_handle, uint32_t domid)
   4.247 +{
   4.248 +    mapped_regs_t* mapped_regs;
   4.249 +    if ( ctxt->privregs_pfn == INVALID_P2M_ENTRY )
   4.250 +    {
   4.251 +        PERROR("Could not get mmapped privregs gmfn");
   4.252 +        errno = ENOENT;
   4.253 +        return -1;
   4.254 +    }
   4.255 +    mapped_regs = xc_map_foreign_range(xc_handle, domid,
   4.256 +                                       arch_ctxt->mapped_regs_size,
   4.257 +                                       PROT_READ, ctxt->privregs_pfn);
   4.258 +    if ( mapped_regs == NULL )
   4.259 +    {
   4.260 +        PERROR("Could not map mapped privregs");
   4.261 +        return -1;
   4.262 +    }
   4.263 +    arch_ctxt->mapped_regs[arch_ctxt->nr_vcpus] = mapped_regs;
   4.264 +    arch_ctxt->nr_vcpus++;
   4.265 +    return 0;
   4.266 +}
   4.267 +
   4.268 +int
   4.269 +xc_core_arch_context_get_shdr(struct xc_core_arch_context *arch_ctxt, 
   4.270 +                              struct xc_core_section_headers *sheaders,
   4.271 +                              struct xc_core_strtab *strtab,
   4.272 +                              unsigned long *filesz, unsigned long offset)
   4.273 +{
   4.274 +    int sts = -1;
   4.275 +    Elf_Shdr *shdr;
   4.276 +
   4.277 +    /* mmapped priv regs */
   4.278 +    shdr = xc_core_shdr_get(sheaders);
   4.279 +    if ( shdr == NULL )
   4.280 +    {
   4.281 +        PERROR("Could not get section header for .xen_ia64_mapped_regs");
   4.282 +        return sts;
   4.283 +    }
   4.284 +    *filesz = arch_ctxt->mapped_regs_size * arch_ctxt->nr_vcpus;
   4.285 +    sts = xc_core_shdr_set(shdr, strtab, XEN_DUMPCORE_SEC_IA64_MAPPED_REGS,
   4.286 +                           SHT_PROGBITS, offset, *filesz,
   4.287 +                           __alignof__(*arch_ctxt->mapped_regs[0]),
   4.288 +                           arch_ctxt->mapped_regs_size);
   4.289 +    return sts;
   4.290 +}
   4.291 +
   4.292 +int
   4.293 +xc_core_arch_context_dump(struct xc_core_arch_context* arch_ctxt,
   4.294 +                          void* args, dumpcore_rtn_t dump_rtn)
   4.295 +{
   4.296 +    int sts = 0;
   4.297 +    int i;
   4.298 +    
   4.299 +    /* ia64 mapped_regs: .xen_ia64_mapped_regs */
   4.300 +    for ( i = 0; i < arch_ctxt->nr_vcpus; i++ )
   4.301 +    {
   4.302 +        sts = dump_rtn(args, (char*)arch_ctxt->mapped_regs[i],
   4.303 +                       arch_ctxt->mapped_regs_size);
   4.304 +        if ( sts != 0 )
   4.305 +            break;
   4.306 +    }
   4.307 +    return sts;
   4.308 +}
   4.309 +
   4.310 +/*
   4.311 + * Local variables:
   4.312 + * mode: C
   4.313 + * c-set-style: "BSD"
   4.314 + * c-basic-offset: 4
   4.315 + * tab-width: 4
   4.316 + * indent-tabs-mode: nil
   4.317 + * End:
   4.318 + */
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/tools/libxc/xc_core_ia64.h	Sat Feb 24 14:31:42 2007 +0000
     5.3 @@ -0,0 +1,60 @@
     5.4 +/*
     5.5 + * This program is free software; you can redistribute it and/or modify
     5.6 + * it under the terms of the GNU General Public License as published by
     5.7 + * the Free Software Foundation; either version 2 of the License, or
     5.8 + * (at your option) any later version.
     5.9 + *
    5.10 + * This program is distributed in the hope that it will be useful,
    5.11 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    5.12 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    5.13 + * GNU General Public License for more details.
    5.14 + *
    5.15 + * You should have received a copy of the GNU General Public License
    5.16 + * along with this program; if not, write to the Free Software
    5.17 + * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    5.18 + *
    5.19 + * Copyright (c) 2007 Isaku Yamahata <yamahata at valinux co jp>
    5.20 + *                    VA Linux Systems Japan K.K.
    5.21 + *
    5.22 + */
    5.23 +
    5.24 +#ifndef XC_CORE_IA64_H
    5.25 +#define XC_CORE_IA64_H
    5.26 +
    5.27 +#define ELF_ARCH_DATA           ELFDATA2LSB
    5.28 +#define ELF_ARCH_MACHINE        EM_IA_64
    5.29 +
    5.30 +struct xc_core_arch_context {
    5.31 +    size_t mapped_regs_size;
    5.32 +    int nr_vcpus;
    5.33 +    mapped_regs_t* mapped_regs[MAX_VIRT_CPUS];
    5.34 +};
    5.35 +
    5.36 +void
    5.37 +xc_core_arch_context_init(struct xc_core_arch_context* arch_ctxt);
    5.38 +void
    5.39 +xc_core_arch_context_free(struct xc_core_arch_context* arch_ctxt);
    5.40 +int
    5.41 +xc_core_arch_context_get(struct xc_core_arch_context* arch_ctxt,
    5.42 +                         vcpu_guest_context_t* ctxt,
    5.43 +                         int xc_handle, uint32_t domid);
    5.44 +int
    5.45 +xc_core_arch_context_get_shdr(struct xc_core_arch_context* arch_ctxt, 
    5.46 +                              struct xc_core_section_headers *sheaders,
    5.47 +                              struct xc_core_strtab *strtab,
    5.48 +                              unsigned long *filesz, unsigned long offset);
    5.49 +int
    5.50 +xc_core_arch_context_dump(struct xc_core_arch_context* arch_ctxt,
    5.51 +                          void* args, dumpcore_rtn_t dump_rtn);
    5.52 +
    5.53 +#endif /* XC_CORE_IA64_H */
    5.54 +
    5.55 +/*
    5.56 + * Local variables:
    5.57 + * mode: C
    5.58 + * c-set-style: "BSD"
    5.59 + * c-basic-offset: 4
    5.60 + * tab-width: 4
    5.61 + * indent-tabs-mode: nil
    5.62 + * End:
    5.63 + */
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/tools/libxc/xc_core_x86.c	Sat Feb 24 14:31:42 2007 +0000
     6.3 @@ -0,0 +1,136 @@
     6.4 +/*
     6.5 + * This program is free software; you can redistribute it and/or modify
     6.6 + * it under the terms of the GNU General Public License as published by
     6.7 + * the Free Software Foundation; either version 2 of the License, or
     6.8 + * (at your option) any later version.
     6.9 + *
    6.10 + * This program is distributed in the hope that it will be useful,
    6.11 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    6.12 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    6.13 + * GNU General Public License for more details.
    6.14 + *
    6.15 + * You should have received a copy of the GNU General Public License
    6.16 + * along with this program; if not, write to the Free Software
    6.17 + * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    6.18 + *
    6.19 + * Copyright (c) 2007 Isaku Yamahata <yamahata at valinux co jp>
    6.20 + *                    VA Linux Systems Japan K.K.
    6.21 + *
    6.22 + */
    6.23 +
    6.24 +#include "xg_private.h"
    6.25 +#include "xc_core.h"
    6.26 +
    6.27 +int
    6.28 +xc_core_arch_auto_translated_physmap(const xc_dominfo_t *info)
    6.29 +{
    6.30 +    if ( info->hvm )
    6.31 +        return 1;
    6.32 +    return 0;
    6.33 +}
    6.34 +
    6.35 +int
    6.36 +xc_core_arch_memory_map_get(int xc_handle, xc_dominfo_t *info,
    6.37 +                            shared_info_t *live_shinfo,
    6.38 +                            xc_core_memory_map_t **mapp,
    6.39 +                            unsigned int *nr_entries)
    6.40 +{
    6.41 +    unsigned long max_pfn = live_shinfo->arch.max_pfn;
    6.42 +    xc_core_memory_map_t *map = NULL;
    6.43 +
    6.44 +    map = malloc(sizeof(*map));
    6.45 +    if ( !map )
    6.46 +    {
    6.47 +        PERROR("Could not allocate memory");
    6.48 +        goto out;
    6.49 +    }
    6.50 +
    6.51 +    map->addr = 0;
    6.52 +    map->size = max_pfn << PAGE_SHIFT;
    6.53 +
    6.54 +    *mapp = map;
    6.55 +    *nr_entries = 1;
    6.56 +    return 0;
    6.57 +
    6.58 +out:
    6.59 +    if ( map )
    6.60 +        free(map);
    6.61 +    return -1;
    6.62 +}
    6.63 +
    6.64 +int
    6.65 +xc_core_arch_map_p2m(int xc_handle, xc_dominfo_t *info,
    6.66 +                     shared_info_t *live_shinfo, xen_pfn_t **live_p2m,
    6.67 +                     unsigned long *pfnp)
    6.68 +{
    6.69 +    /* Double and single indirect references to the live P2M table */
    6.70 +    xen_pfn_t *live_p2m_frame_list_list = NULL;
    6.71 +    xen_pfn_t *live_p2m_frame_list = NULL;
    6.72 +    uint32_t dom = info->domid;
    6.73 +    unsigned long max_pfn = live_shinfo->arch.max_pfn;
    6.74 +    int ret = -1;
    6.75 +    int err;
    6.76 +
    6.77 +    if ( max_pfn < info->nr_pages  )
    6.78 +    {
    6.79 +        ERROR("max_pfn < nr_pages -1 (%lx < %lx", max_pfn, info->nr_pages - 1);
    6.80 +        goto out;
    6.81 +    }
    6.82 +
    6.83 +    live_p2m_frame_list_list =
    6.84 +        xc_map_foreign_range(xc_handle, dom, PAGE_SIZE, PROT_READ,
    6.85 +                             live_shinfo->arch.pfn_to_mfn_frame_list_list);
    6.86 +
    6.87 +    if ( !live_p2m_frame_list_list )
    6.88 +    {
    6.89 +        PERROR("Couldn't map p2m_frame_list_list (errno %d)", errno);
    6.90 +        goto out;
    6.91 +    }
    6.92 +
    6.93 +    live_p2m_frame_list =
    6.94 +        xc_map_foreign_batch(xc_handle, dom, PROT_READ,
    6.95 +                             live_p2m_frame_list_list,
    6.96 +                             P2M_FLL_ENTRIES);
    6.97 +
    6.98 +    if ( !live_p2m_frame_list )
    6.99 +    {
   6.100 +        PERROR("Couldn't map p2m_frame_list");
   6.101 +        goto out;
   6.102 +    }
   6.103 +
   6.104 +    *live_p2m = xc_map_foreign_batch(xc_handle, dom, PROT_READ,
   6.105 +                                    live_p2m_frame_list,
   6.106 +                                    P2M_FL_ENTRIES);
   6.107 +
   6.108 +    if ( !*live_p2m )
   6.109 +    {
   6.110 +        PERROR("Couldn't map p2m table");
   6.111 +        goto out;
   6.112 +    }
   6.113 +
   6.114 +    *pfnp = max_pfn;
   6.115 +
   6.116 +    ret = 0;
   6.117 +
   6.118 +out:
   6.119 +    err = errno;
   6.120 +
   6.121 +    if ( live_p2m_frame_list_list )
   6.122 +        munmap(live_p2m_frame_list_list, PAGE_SIZE);
   6.123 +
   6.124 +    if ( live_p2m_frame_list )
   6.125 +        munmap(live_p2m_frame_list, P2M_FLL_ENTRIES * PAGE_SIZE);
   6.126 +
   6.127 +    errno = err;
   6.128 +    return ret;
   6.129 +}
   6.130 +
   6.131 +/*
   6.132 + * Local variables:
   6.133 + * mode: C
   6.134 + * c-set-style: "BSD"
   6.135 + * c-basic-offset: 4
   6.136 + * tab-width: 4
   6.137 + * indent-tabs-mode: nil
   6.138 + * End:
   6.139 + */
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/tools/libxc/xc_core_x86.h	Sat Feb 24 14:31:42 2007 +0000
     7.3 @@ -0,0 +1,64 @@
     7.4 +/*
     7.5 + * This program is free software; you can redistribute it and/or modify
     7.6 + * it under the terms of the GNU General Public License as published by
     7.7 + * the Free Software Foundation; either version 2 of the License, or
     7.8 + * (at your option) any later version.
     7.9 + *
    7.10 + * This program is distributed in the hope that it will be useful,
    7.11 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    7.12 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    7.13 + * GNU General Public License for more details.
    7.14 + *
    7.15 + * You should have received a copy of the GNU General Public License
    7.16 + * along with this program; if not, write to the Free Software
    7.17 + * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    7.18 + *
    7.19 + * Copyright (c) 2007 Isaku Yamahata <yamahata at valinux co jp>
    7.20 + *                    VA Linux Systems Japan K.K.
    7.21 + *
    7.22 + */
    7.23 +
    7.24 +#ifndef XC_CORE_X86_H
    7.25 +#define XC_CORE_X86_H
    7.26 +
    7.27 +#if defined(__i386__) || defined(__x86_64__)
    7.28 +#define ELF_ARCH_DATA           ELFDATA2LSB
    7.29 +#if defined (__i386__)
    7.30 +# define ELF_ARCH_MACHINE       EM_386
    7.31 +#else
    7.32 +# define ELF_ARCH_MACHINE       EM_X86_64
    7.33 +#endif
    7.34 +#endif /* __i386__ or __x86_64__ */
    7.35 +
    7.36 +
    7.37 +struct xc_core_arch_context {
    7.38 +    /* nothing */
    7.39 +};
    7.40 +
    7.41 +#define xc_core_arch_context_init(arch_ctxt)            do {} while (0)
    7.42 +#define xc_core_arch_context_free(arch_ctxt)            do {} while (0)
    7.43 +#define xc_core_arch_context_get(arch_ctxt, ctxt, xc_handle, domid) \
    7.44 +                                                                (0)
    7.45 +#define xc_core_arch_context_dump(arch_ctxt, args, dump_rtn)    (0)
    7.46 +
    7.47 +static inline int
    7.48 +xc_core_arch_context_get_shdr(struct xc_core_arch_context *arch_ctxt, 
    7.49 +                              struct xc_core_section_headers *sheaders,
    7.50 +                              struct xc_core_strtab *strtab,
    7.51 +                              unsigned long *filesz, unsigned long offset)
    7.52 +{
    7.53 +    *filesz = 0;
    7.54 +    return 0;
    7.55 +}
    7.56 +
    7.57 +#endif /* XC_CORE_X86_H */
    7.58 +
    7.59 +/*
    7.60 + * Local variables:
    7.61 + * mode: C
    7.62 + * c-set-style: "BSD"
    7.63 + * c-basic-offset: 4
    7.64 + * tab-width: 4
    7.65 + * indent-tabs-mode: nil
    7.66 + * End:
    7.67 + */
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/tools/libxc/xc_efi.h	Sat Feb 24 14:31:42 2007 +0000
     8.3 @@ -0,0 +1,68 @@
     8.4 +#ifndef XC_EFI_H
     8.5 +#define XC_EFI_H
     8.6 +
     8.7 +/* definitions from xen/include/asm-ia64/linux-xen/linux/efi.h */
     8.8 +
     8.9 +/*
    8.10 + * Extensible Firmware Interface
    8.11 + * Based on 'Extensible Firmware Interface Specification' version 0.9, April 30, 1999
    8.12 + *
    8.13 + * Copyright (C) 1999 VA Linux Systems
    8.14 + * Copyright (C) 1999 Walt Drummond <drummond@valinux.com>
    8.15 + * Copyright (C) 1999, 2002-2003 Hewlett-Packard Co.
    8.16 + *	David Mosberger-Tang <davidm@hpl.hp.com>
    8.17 + *	Stephane Eranian <eranian@hpl.hp.com>
    8.18 + */
    8.19 +
    8.20 +/*
    8.21 + * Memory map descriptor:
    8.22 + */
    8.23 +
    8.24 +/* Memory types: */
    8.25 +#define EFI_RESERVED_TYPE                0
    8.26 +#define EFI_LOADER_CODE                  1
    8.27 +#define EFI_LOADER_DATA                  2
    8.28 +#define EFI_BOOT_SERVICES_CODE           3
    8.29 +#define EFI_BOOT_SERVICES_DATA           4
    8.30 +#define EFI_RUNTIME_SERVICES_CODE        5
    8.31 +#define EFI_RUNTIME_SERVICES_DATA        6
    8.32 +#define EFI_CONVENTIONAL_MEMORY          7
    8.33 +#define EFI_UNUSABLE_MEMORY              8
    8.34 +#define EFI_ACPI_RECLAIM_MEMORY          9
    8.35 +#define EFI_ACPI_MEMORY_NVS             10
    8.36 +#define EFI_MEMORY_MAPPED_IO            11
    8.37 +#define EFI_MEMORY_MAPPED_IO_PORT_SPACE 12
    8.38 +#define EFI_PAL_CODE                    13
    8.39 +#define EFI_MAX_MEMORY_TYPE             14
    8.40 +
    8.41 +/* Attribute values: */
    8.42 +#define EFI_MEMORY_UC           ((uint64_t)0x0000000000000001ULL)    /* uncached */
    8.43 +#define EFI_MEMORY_WC           ((uint64_t)0x0000000000000002ULL)    /* write-coalescing */
    8.44 +#define EFI_MEMORY_WT           ((uint64_t)0x0000000000000004ULL)    /* write-through */
    8.45 +#define EFI_MEMORY_WB           ((uint64_t)0x0000000000000008ULL)    /* write-back */
    8.46 +#define EFI_MEMORY_WP           ((uint64_t)0x0000000000001000ULL)    /* write-protect */
    8.47 +#define EFI_MEMORY_RP           ((uint64_t)0x0000000000002000ULL)    /* read-protect */
    8.48 +#define EFI_MEMORY_XP           ((uint64_t)0x0000000000004000ULL)    /* execute-protect */
    8.49 +#define EFI_MEMORY_RUNTIME      ((uint64_t)0x8000000000000000ULL)    /* range requires runtime mapping */
    8.50 +#define EFI_MEMORY_DESCRIPTOR_VERSION   1
    8.51 +
    8.52 +#define EFI_PAGE_SHIFT          12
    8.53 +
    8.54 +/*
    8.55 + * For current x86 implementations of EFI, there is
    8.56 + * additional padding in the mem descriptors.  This is not
    8.57 + * the case in ia64.  Need to have this fixed in the f/w.
    8.58 + */
    8.59 +typedef struct {
    8.60 +        uint32_t type;
    8.61 +        uint32_t pad;
    8.62 +        uint64_t phys_addr;
    8.63 +        uint64_t virt_addr;
    8.64 +        uint64_t num_pages;
    8.65 +        uint64_t attribute;
    8.66 +#if defined (__i386__)
    8.67 +        uint64_t pad1;
    8.68 +#endif
    8.69 +} efi_memory_desc_t;
    8.70 +
    8.71 +#endif /* XC_EFI_H */
     9.1 --- a/tools/libxc/xenctrl.h	Sat Feb 24 14:19:42 2007 +0000
     9.2 +++ b/tools/libxc/xenctrl.h	Sat Feb 24 14:31:42 2007 +0000
     9.3 @@ -570,6 +570,11 @@ void *xc_map_foreign_batch(int xc_handle
     9.4  unsigned long xc_translate_foreign_address(int xc_handle, uint32_t dom,
     9.5                                             int vcpu, unsigned long long virt);
     9.6  
     9.7 +
     9.8 +/**
     9.9 + * DEPRECATED.  Avoid using this, as it does not correctly account for PFNs
    9.10 + * without a backing MFN.
    9.11 + */
    9.12  int xc_get_pfn_list(int xc_handle, uint32_t domid, uint64_t *pfn_buf,
    9.13                      unsigned long max_pfns);
    9.14  
    10.1 --- a/xen/include/public/elfnote.h	Sat Feb 24 14:19:42 2007 +0000
    10.2 +++ b/xen/include/public/elfnote.h	Sat Feb 24 14:31:42 2007 +0000
    10.3 @@ -175,6 +175,41 @@
    10.4   */
    10.5  #define XEN_ELFNOTE_CRASH_REGS 0x1000002
    10.6  
    10.7 +
    10.8 +/*
    10.9 + * xen dump-core none note.
   10.10 + * xm dump-core code will create one XEN_ELFNOTE_DUMPCORE_NONE
   10.11 + * in its dump file to indicate that the file is xen dump-core
   10.12 + * file. This note doesn't have any other information.
   10.13 + * See tools/libxc/xc_core.h for more information.
   10.14 + */
   10.15 +#define XEN_ELFNOTE_DUMPCORE_NONE               0x2000000
   10.16 +
   10.17 +/*
   10.18 + * xen dump-core header note.
   10.19 + * xm dump-core code will create one XEN_ELFNOTE_DUMPCORE_HEADER
   10.20 + * in its dump file.
   10.21 + * See tools/libxc/xc_core.h for more information.
   10.22 + */
   10.23 +#define XEN_ELFNOTE_DUMPCORE_HEADER             0x2000001
   10.24 +
   10.25 +/*
   10.26 + * xen dump-core xen version note.
   10.27 + * xm dump-core code will create one XEN_ELFNOTE_DUMPCORE_XEN_VERSION
   10.28 + * in its dump file. It contains the xen version obtained via the
   10.29 + * XENVER hypercall.
   10.30 + * See tools/libxc/xc_core.h for more information.
   10.31 + */
   10.32 +#define XEN_ELFNOTE_DUMPCORE_XEN_VERSION        0x2000002
   10.33 +
   10.34 +/*
   10.35 + * xen dump-core format version note.
   10.36 + * xm dump-core code will create one XEN_ELFNOTE_DUMPCORE_FORMAT_VERSION
   10.37 + * in its dump file. It contains a format version identifier.
   10.38 + * See tools/libxc/xc_core.h for more information.
   10.39 + */
   10.40 +#define XEN_ELFNOTE_DUMPCORE_FORMAT_VERSION     0x2000003
   10.41 +
   10.42  #endif /* __XEN_PUBLIC_ELFNOTE_H__ */
   10.43  
   10.44  /*