ia64/xen-unstable

changeset 3635:10b8afffe96b

bitkeeper revision 1.1159.240.1 (42025e61IuxB-TOGFWNyIT0-7gRIuw)

More x86_64 progress: currently churning through construct_dom0.
Then will need a few extensions to entry.S and I can jump to ring 3.
To get hypercalls working I will need a SYSCALL entry point and also
to add uaccess.h/usercopy.S functionality.
Signed-off-by: keir.fraser@cl.cam.ac.uk
author kaf24@scramble.cl.cam.ac.uk
date Thu Feb 03 17:24:49 2005 +0000 (2005-02-03)
parents 1c43dbcfc46f
children 8710698e57e1
files xen/arch/x86/setup.c xen/arch/x86/x86_32/domain_build.c xen/arch/x86/x86_64/domain_build.c xen/common/elf.c xen/include/xen/elf.h xen/include/xen/sched.h
line diff
     1.1 --- a/xen/arch/x86/setup.c	Thu Feb 03 17:03:05 2005 +0000
     1.2 +++ b/xen/arch/x86/setup.c	Thu Feb 03 17:24:49 2005 +0000
     1.3 @@ -625,10 +625,10 @@ void __init __start_xen(multiboot_info_t
     1.4       * above our heap. The second module, if present, is an initrd ramdisk.
     1.5       */
     1.6      if ( construct_dom0(dom0, dom0_memory_start, dom0_memory_end,
     1.7 -                        (char *)initial_images_start, 
     1.8 +                        initial_images_start, 
     1.9                          mod[0].mod_end-mod[0].mod_start,
    1.10                          (mbi->mods_count == 1) ? 0 :
    1.11 -                        (char *)initial_images_start + 
    1.12 +                        initial_images_start + 
    1.13                          (mod[1].mod_start-mod[0].mod_start),
    1.14                          (mbi->mods_count == 1) ? 0 :
    1.15                          mod[mbi->mods_count-1].mod_end - mod[1].mod_start,
     2.1 --- a/xen/arch/x86/x86_32/domain_build.c	Thu Feb 03 17:03:05 2005 +0000
     2.2 +++ b/xen/arch/x86/x86_32/domain_build.c	Thu Feb 03 17:24:49 2005 +0000
     2.3 @@ -27,11 +27,11 @@
     2.4  #define round_pgup(_p)    (((_p)+(PAGE_SIZE-1))&PAGE_MASK)
     2.5  #define round_pgdown(_p)  ((_p)&PAGE_MASK)
     2.6  
     2.7 -int construct_dom0(struct domain *p, 
     2.8 +int construct_dom0(struct domain *d,
     2.9                     unsigned long alloc_start,
    2.10                     unsigned long alloc_end,
    2.11 -                   char *image_start, unsigned long image_len, 
    2.12 -                   char *initrd_start, unsigned long initrd_len,
    2.13 +                   unsigned long _image_start, unsigned long image_len, 
    2.14 +                   unsigned long _initrd_start, unsigned long initrd_len,
    2.15                     char *cmdline)
    2.16  {
    2.17      char *dst;
    2.18 @@ -44,7 +44,9 @@ int construct_dom0(struct domain *p,
    2.19      l1_pgentry_t *l1tab = NULL, *l1start = NULL;
    2.20      struct pfn_info *page = NULL;
    2.21      start_info_t *si;
    2.22 -    struct exec_domain *ed = p->exec_domain[0];
    2.23 +    struct exec_domain *ed = d->exec_domain[0];
    2.24 +    char *image_start  = (char *)_image_start;  /* use lowmem mappings */
    2.25 +    char *initrd_start = (char *)_initrd_start; /* use lowmem mappings */
    2.26  
    2.27      /*
    2.28       * This fully describes the memory layout of the initial domain. All 
    2.29 @@ -70,9 +72,9 @@ int construct_dom0(struct domain *p,
    2.30      extern void physdev_init_dom0(struct domain *);
    2.31  
    2.32      /* Sanity! */
    2.33 -    if ( p->id != 0 ) 
    2.34 +    if ( d->id != 0 ) 
    2.35          BUG();
    2.36 -    if ( test_bit(DF_CONSTRUCTED, &p->d_flags) ) 
    2.37 +    if ( test_bit(DF_CONSTRUCTED, &d->d_flags) ) 
    2.38          BUG();
    2.39  
    2.40      memset(&dsi, 0, sizeof(struct domain_setup_info));
    2.41 @@ -97,13 +99,10 @@ int construct_dom0(struct domain *p,
    2.42  
    2.43      /* Set up domain options */
    2.44      if ( dsi.use_writable_pagetables )
    2.45 -        vm_assist(p, VMASST_CMD_enable, VMASST_TYPE_writable_pagetables);
    2.46 +        vm_assist(d, VMASST_CMD_enable, VMASST_TYPE_writable_pagetables);
    2.47  
    2.48 -    if ( (dsi.v_start & (PAGE_SIZE-1)) != 0 )
    2.49 -    {
    2.50 -        printk("Initial guest OS must load to a page boundary.\n");
    2.51 -        return -EINVAL;
    2.52 -    }
    2.53 +    /* Align load address to 4MB boundary. */
    2.54 +    dsi.v_start &= ~((1UL<<22)-1);
    2.55  
    2.56      /*
    2.57       * Why do we need this? The number of page-table frames depends on the 
    2.58 @@ -124,10 +123,10 @@ int construct_dom0(struct domain *p,
    2.59          vstartinfo_end   = vstartinfo_start + PAGE_SIZE;
    2.60          vstack_start     = vstartinfo_end;
    2.61          vstack_end       = vstack_start + PAGE_SIZE;
    2.62 -        v_end            = (vstack_end + (1<<22)-1) & ~((1<<22)-1);
    2.63 -        if ( (v_end - vstack_end) < (512 << 10) )
    2.64 -            v_end += 1 << 22; /* Add extra 4MB to get >= 512kB padding. */
    2.65 -        if ( (((v_end - dsi.v_start + ((1<<L2_PAGETABLE_SHIFT)-1)) >> 
    2.66 +        v_end            = (vstack_end + (1UL<<22)-1) & ~((1UL<<22)-1);
    2.67 +        if ( (v_end - vstack_end) < (512UL << 10) )
    2.68 +            v_end += 1UL << 22; /* Add extra 4MB to get >= 512kB padding. */
    2.69 +        if ( (((v_end - dsi.v_start + ((1UL<<L2_PAGETABLE_SHIFT)-1)) >> 
    2.70                 L2_PAGETABLE_SHIFT) + 1) <= nr_pt_pages )
    2.71              break;
    2.72      }
    2.73 @@ -135,18 +134,18 @@ int construct_dom0(struct domain *p,
    2.74      printk("PHYSICAL MEMORY ARRANGEMENT:\n"
    2.75             " Kernel image:  %p->%p\n"
    2.76             " Initrd image:  %p->%p\n"
    2.77 -           " Dom0 alloc.:   %08lx->%08lx\n",
    2.78 -           image_start, image_start + image_len,
    2.79 -           initrd_start, initrd_start + initrd_len,
    2.80 +           " Dom0 alloc.:   %p->%p\n",
    2.81 +           _image_start, _image_start + image_len,
    2.82 +           _initrd_start, _initrd_start + initrd_len,
    2.83             alloc_start, alloc_end);
    2.84      printk("VIRTUAL MEMORY ARRANGEMENT:\n"
    2.85 -           " Loaded kernel: %08lx->%08lx\n"
    2.86 -           " Init. ramdisk: %08lx->%08lx\n"
    2.87 -           " Phys-Mach map: %08lx->%08lx\n"
    2.88 -           " Page tables:   %08lx->%08lx\n"
    2.89 -           " Start info:    %08lx->%08lx\n"
    2.90 -           " Boot stack:    %08lx->%08lx\n"
    2.91 -           " TOTAL:         %08lx->%08lx\n",
    2.92 +           " Loaded kernel: %p->%p\n"
    2.93 +           " Init. ramdisk: %p->%p\n"
    2.94 +           " Phys-Mach map: %p->%p\n"
    2.95 +           " Page tables:   %p->%p\n"
    2.96 +           " Start info:    %p->%p\n"
    2.97 +           " Boot stack:    %p->%p\n"
    2.98 +           " TOTAL:         %p->%p\n",
    2.99             dsi.v_kernstart, dsi.v_kernend, 
   2.100             vinitrd_start, vinitrd_end,
   2.101             vphysmap_start, vphysmap_end,
   2.102 @@ -154,7 +153,7 @@ int construct_dom0(struct domain *p,
   2.103             vstartinfo_start, vstartinfo_end,
   2.104             vstack_start, vstack_end,
   2.105             dsi.v_start, v_end);
   2.106 -    printk(" ENTRY ADDRESS: %08lx\n", dsi.v_kernentry);
   2.107 +    printk(" ENTRY ADDRESS: %p\n", dsi.v_kernentry);
   2.108  
   2.109      if ( (v_end - dsi.v_start) > (nr_pages * PAGE_SIZE) )
   2.110      {
   2.111 @@ -168,7 +167,7 @@ int construct_dom0(struct domain *p,
   2.112       * Protect the lowest 1GB of memory. We use a temporary mapping there
   2.113       * from which we copy the kernel and ramdisk images.
   2.114       */
   2.115 -    if ( dsi.v_start < (1<<30) )
   2.116 +    if ( dsi.v_start < (1UL<<30) )
   2.117      {
   2.118          printk("Initial loading isn't allowed to lowest 1GB of memory.\n");
   2.119          return -EINVAL;
   2.120 @@ -201,11 +200,11 @@ int construct_dom0(struct domain *p,
   2.121            mfn++ )
   2.122      {
   2.123          page = &frame_table[mfn];
   2.124 -        page_set_owner(page, p);
   2.125 +        page_set_owner(page, d);
   2.126          page->u.inuse.type_info = 0;
   2.127          page->count_info        = PGC_allocated | 1;
   2.128 -        list_add_tail(&page->list, &p->page_list);
   2.129 -        p->tot_pages++; p->max_pages++;
   2.130 +        list_add_tail(&page->list, &d->page_list);
   2.131 +        d->tot_pages++; d->max_pages++;
   2.132      }
   2.133  
   2.134      mpt_alloc = (vpt_start - dsi.v_start) + alloc_start;
   2.135 @@ -229,7 +228,7 @@ int construct_dom0(struct domain *p,
   2.136      l2tab[LINEAR_PT_VIRT_START >> L2_PAGETABLE_SHIFT] =
   2.137          mk_l2_pgentry((unsigned long)l2start | __PAGE_HYPERVISOR);
   2.138      l2tab[PERDOMAIN_VIRT_START >> L2_PAGETABLE_SHIFT] =
   2.139 -        mk_l2_pgentry(__pa(p->mm_perdomain_pt) | __PAGE_HYPERVISOR);
   2.140 +        mk_l2_pgentry(__pa(d->mm_perdomain_pt) | __PAGE_HYPERVISOR);
   2.141      ed->mm.pagetable = mk_pagetable((unsigned long)l2start);
   2.142  
   2.143      l2tab += l2_table_offset(dsi.v_start);
   2.144 @@ -248,7 +247,7 @@ int construct_dom0(struct domain *p,
   2.145          *l1tab++ = mk_l1_pgentry((mfn << PAGE_SHIFT) | L1_PROT);
   2.146          
   2.147          page = &frame_table[mfn];
   2.148 -        if ( !get_page_and_type(page, p, PGT_writable_page) )
   2.149 +        if ( !get_page_and_type(page, d, PGT_writable_page) )
   2.150              BUG();
   2.151  
   2.152          mfn++;
   2.153 @@ -273,10 +272,10 @@ int construct_dom0(struct domain *p,
   2.154               * Installed as CR3: increment both the ref_count and type_count.
   2.155               * Net: just increment the ref_count.
   2.156               */
   2.157 -            get_page(page, p); /* an extra ref because of readable mapping */
   2.158 +            get_page(page, d); /* an extra ref because of readable mapping */
   2.159  
   2.160              /* Get another ref to L2 page so that it can be pinned. */
   2.161 -            if ( !get_page_and_type(page, p, PGT_l2_page_table) )
   2.162 +            if ( !get_page_and_type(page, d, PGT_l2_page_table) )
   2.163                  BUG();
   2.164              set_bit(_PGT_pinned, &page->u.inuse.type_info);
   2.165          }
   2.166 @@ -293,7 +292,7 @@ int construct_dom0(struct domain *p,
   2.167               * increment both the ref_count and type_count.
   2.168               * Net: just increment the ref_count.
   2.169               */
   2.170 -            get_page(page, p); /* an extra ref because of readable mapping */
   2.171 +            get_page(page, d); /* an extra ref because of readable mapping */
   2.172          }
   2.173          l1tab++;
   2.174          if( !((unsigned long)l1tab & (PAGE_SIZE - 1)) )
   2.175 @@ -301,12 +300,12 @@ int construct_dom0(struct domain *p,
   2.176      }
   2.177  
   2.178      /* Set up shared-info area. */
   2.179 -    update_dom_time(p);
   2.180 -    p->shared_info->domain_time = 0;
   2.181 +    update_dom_time(d);
   2.182 +    d->shared_info->domain_time = 0;
   2.183      /* Mask all upcalls... */
   2.184      for ( i = 0; i < MAX_VIRT_CPUS; i++ )
   2.185 -        p->shared_info->vcpu_data[i].evtchn_upcall_mask = 1;
   2.186 -    p->shared_info->n_vcpu = smp_num_cpus;
   2.187 +        d->shared_info->vcpu_data[i].evtchn_upcall_mask = 1;
   2.188 +    d->shared_info->n_vcpu = smp_num_cpus;
   2.189  
   2.190      /* Install the new page tables. */
   2.191      __cli();
   2.192 @@ -322,15 +321,15 @@ int construct_dom0(struct domain *p,
   2.193      /* Set up start info area. */
   2.194      si = (start_info_t *)vstartinfo_start;
   2.195      memset(si, 0, PAGE_SIZE);
   2.196 -    si->nr_pages     = p->tot_pages;
   2.197 -    si->shared_info  = virt_to_phys(p->shared_info);
   2.198 +    si->nr_pages     = d->tot_pages;
   2.199 +    si->shared_info  = virt_to_phys(d->shared_info);
   2.200      si->flags        = SIF_PRIVILEGED | SIF_INITDOMAIN;
   2.201      si->pt_base      = vpt_start;
   2.202      si->nr_pt_frames = nr_pt_pages;
   2.203      si->mfn_list     = vphysmap_start;
   2.204  
   2.205      /* Write the phys->machine and machine->phys table entries. */
   2.206 -    for ( pfn = 0; pfn < p->tot_pages; pfn++ )
   2.207 +    for ( pfn = 0; pfn < d->tot_pages; pfn++ )
   2.208      {
   2.209          mfn = pfn + (alloc_start>>PAGE_SHIFT);
   2.210  #ifndef NDEBUG
   2.211 @@ -346,7 +345,7 @@ int construct_dom0(struct domain *p,
   2.212      {
   2.213          si->mod_start = vinitrd_start;
   2.214          si->mod_len   = initrd_len;
   2.215 -        printk("Initrd len 0x%lx, start at 0x%08lx\n",
   2.216 +        printk("Initrd len 0x%lx, start at 0x%p\n",
   2.217                 si->mod_len, si->mod_start);
   2.218      }
   2.219  
   2.220 @@ -373,17 +372,32 @@ int construct_dom0(struct domain *p,
   2.221      zap_low_mappings(); /* Do the same for the idle page tables. */
   2.222      
   2.223      /* DOM0 gets access to everything. */
   2.224 -    physdev_init_dom0(p);
   2.225 +    physdev_init_dom0(d);
   2.226  
   2.227 -    set_bit(DF_CONSTRUCTED, &p->d_flags);
   2.228 +    set_bit(DF_CONSTRUCTED, &d->d_flags);
   2.229  
   2.230      new_thread(ed, dsi.v_kernentry, vstack_end, vstartinfo_start);
   2.231  
   2.232  #if 0 /* XXXXX DO NOT CHECK IN ENABLED !!! (but useful for testing so leave) */
   2.233 -    shadow_lock(&p->mm);
   2.234 -    shadow_mode_enable(p, SHM_test); 
   2.235 -    shadow_unlock(&p->mm);
   2.236 +    shadow_lock(&d->mm);
   2.237 +    shadow_mode_enable(d, SHM_test); 
   2.238 +    shadow_unlock(&d->mm);
   2.239  #endif
   2.240  
   2.241      return 0;
   2.242  }
   2.243 +
   2.244 +int elf_sanity_check(Elf_Ehdr *ehdr)
   2.245 +{
   2.246 +    if ( !IS_ELF(*ehdr) ||
   2.247 +         (ehdr->e_ident[EI_CLASS] != ELFCLASS32) ||
   2.248 +         (ehdr->e_ident[EI_DATA] != ELFDATA2LSB) ||
   2.249 +         (ehdr->e_type != ET_EXEC) ||
   2.250 +         (ehdr->e_machine != EM_386) )
   2.251 +    {
   2.252 +        printk("DOM0 image is not i386-compatible executable Elf image.\n");
   2.253 +        return 0;
   2.254 +    }
   2.255 +
   2.256 +    return 1;
   2.257 +}
     3.1 --- a/xen/arch/x86/x86_64/domain_build.c	Thu Feb 03 17:03:05 2005 +0000
     3.2 +++ b/xen/arch/x86/x86_64/domain_build.c	Thu Feb 03 17:24:49 2005 +0000
     3.3 @@ -29,11 +29,11 @@
     3.4  #define round_pgup(_p)    (((_p)+(PAGE_SIZE-1))&PAGE_MASK)
     3.5  #define round_pgdown(_p)  ((_p)&PAGE_MASK)
     3.6  
     3.7 -int construct_dom0(struct domain *p, 
     3.8 +int construct_dom0(struct domain *d,
     3.9                     unsigned long alloc_start,
    3.10                     unsigned long alloc_end,
    3.11 -                   char *image_start, unsigned long image_len, 
    3.12 -                   char *initrd_start, unsigned long initrd_len,
    3.13 +                   unsigned long _image_start, unsigned long image_len, 
    3.14 +                   unsigned long _initrd_start, unsigned long initrd_len,
    3.15                     char *cmdline)
    3.16  {
    3.17      char *dst;
    3.18 @@ -46,7 +46,9 @@ int construct_dom0(struct domain *p,
    3.19      l1_pgentry_t *l1tab = NULL, *l1start = NULL;
    3.20      struct pfn_info *page = NULL;
    3.21      start_info_t *si;
    3.22 -    struct exec_domain *ed = p->exec_domain[0];
    3.23 +    struct exec_domain *ed = d->exec_domain[0];
    3.24 +    char *image_start  = __va(_image_start);
    3.25 +    char *initrd_start = __va(_initrd_start);
    3.26  
    3.27      /*
    3.28       * This fully describes the memory layout of the initial domain. All 
    3.29 @@ -72,9 +74,9 @@ int construct_dom0(struct domain *p,
    3.30      extern void physdev_init_dom0(struct domain *);
    3.31  
    3.32      /* Sanity! */
    3.33 -    if ( p->id != 0 ) 
    3.34 +    if ( d->id != 0 ) 
    3.35          BUG();
    3.36 -    if ( test_bit(DF_CONSTRUCTED, &p->d_flags) ) 
    3.37 +    if ( test_bit(DF_CONSTRUCTED, &d->d_flags) ) 
    3.38          BUG();
    3.39  
    3.40      memset(&dsi, 0, sizeof(struct domain_setup_info));
    3.41 @@ -99,13 +101,10 @@ int construct_dom0(struct domain *p,
    3.42  
    3.43      /* Set up domain options */
    3.44      if ( dsi.use_writable_pagetables )
    3.45 -        vm_assist(p, VMASST_CMD_enable, VMASST_TYPE_writable_pagetables);
    3.46 +        vm_assist(d, VMASST_CMD_enable, VMASST_TYPE_writable_pagetables);
    3.47  
    3.48 -    if ( (dsi.v_start & (PAGE_SIZE-1)) != 0 )
    3.49 -    {
    3.50 -        printk("Initial guest OS must load to a page boundary.\n");
    3.51 -        return -EINVAL;
    3.52 -    }
    3.53 +    /* Align load address to 4MB boundary. */
    3.54 +    dsi.v_start &= ~((1UL<<22)-1);
    3.55  
    3.56      /*
    3.57       * Why do we need this? The number of page-table frames depends on the 
    3.58 @@ -126,10 +125,10 @@ int construct_dom0(struct domain *p,
    3.59          vstartinfo_end   = vstartinfo_start + PAGE_SIZE;
    3.60          vstack_start     = vstartinfo_end;
    3.61          vstack_end       = vstack_start + PAGE_SIZE;
    3.62 -        v_end            = (vstack_end + (1<<22)-1) & ~((1<<22)-1);
    3.63 -        if ( (v_end - vstack_end) < (512 << 10) )
    3.64 -            v_end += 1 << 22; /* Add extra 4MB to get >= 512kB padding. */
    3.65 -        if ( (((v_end - dsi.v_start + ((1<<L2_PAGETABLE_SHIFT)-1)) >> 
    3.66 +        v_end            = (vstack_end + (1UL<<22)-1) & ~((1UL<<22)-1);
    3.67 +        if ( (v_end - vstack_end) < (512UL << 10) )
    3.68 +            v_end += 1UL << 22; /* Add extra 4MB to get >= 512kB padding. */
    3.69 +        if ( (((v_end - dsi.v_start + ((1UL<<L2_PAGETABLE_SHIFT)-1)) >> 
    3.70                 L2_PAGETABLE_SHIFT) + 1) <= nr_pt_pages )
    3.71              break;
    3.72      }
    3.73 @@ -137,18 +136,18 @@ int construct_dom0(struct domain *p,
    3.74      printk("PHYSICAL MEMORY ARRANGEMENT:\n"
    3.75             " Kernel image:  %p->%p\n"
    3.76             " Initrd image:  %p->%p\n"
    3.77 -           " Dom0 alloc.:   %08lx->%08lx\n",
    3.78 -           image_start, image_start + image_len,
    3.79 -           initrd_start, initrd_start + initrd_len,
    3.80 +           " Dom0 alloc.:   %p->%p\n",
    3.81 +           _image_start, _image_start + image_len,
    3.82 +           _initrd_start, _initrd_start + initrd_len,
    3.83             alloc_start, alloc_end);
    3.84      printk("VIRTUAL MEMORY ARRANGEMENT:\n"
    3.85 -           " Loaded kernel: %08lx->%08lx\n"
    3.86 -           " Init. ramdisk: %08lx->%08lx\n"
    3.87 -           " Phys-Mach map: %08lx->%08lx\n"
    3.88 -           " Page tables:   %08lx->%08lx\n"
    3.89 -           " Start info:    %08lx->%08lx\n"
    3.90 -           " Boot stack:    %08lx->%08lx\n"
    3.91 -           " TOTAL:         %08lx->%08lx\n",
    3.92 +           " Loaded kernel: %p->%p\n"
    3.93 +           " Init. ramdisk: %p->%p\n"
    3.94 +           " Phys-Mach map: %p->%p\n"
    3.95 +           " Page tables:   %p->%p\n"
    3.96 +           " Start info:    %p->%p\n"
    3.97 +           " Boot stack:    %p->%p\n"
    3.98 +           " TOTAL:         %p->%p\n",
    3.99             dsi.v_kernstart, dsi.v_kernend, 
   3.100             vinitrd_start, vinitrd_end,
   3.101             vphysmap_start, vphysmap_end,
   3.102 @@ -156,7 +155,7 @@ int construct_dom0(struct domain *p,
   3.103             vstartinfo_start, vstartinfo_end,
   3.104             vstack_start, vstack_end,
   3.105             dsi.v_start, v_end);
   3.106 -    printk(" ENTRY ADDRESS: %08lx\n", dsi.v_kernentry);
   3.107 +    printk(" ENTRY ADDRESS: %p\n", dsi.v_kernentry);
   3.108  
   3.109      if ( (v_end - dsi.v_start) > (nr_pages * PAGE_SIZE) )
   3.110      {
   3.111 @@ -166,32 +165,30 @@ int construct_dom0(struct domain *p,
   3.112          return -ENOMEM;
   3.113      }
   3.114  
   3.115 -    /*
   3.116 -     * Protect the lowest 1GB of memory. We use a temporary mapping there
   3.117 -     * from which we copy the kernel and ramdisk images.
   3.118 -     */
   3.119 -    if ( dsi.v_start < (1<<30) )
   3.120 +    /* Overlap with Xen protected area? */
   3.121 +    if ( (dsi.v_start < HYPERVISOR_VIRT_END) &&
   3.122 +         (v_end > HYPERVISOR_VIRT_START) )
   3.123      {
   3.124 -        printk("Initial loading isn't allowed to lowest 1GB of memory.\n");
   3.125 +        printk("DOM0 image overlaps with Xen private area.\n");
   3.126          return -EINVAL;
   3.127      }
   3.128  
   3.129      /* Paranoia: scrub DOM0's memory allocation. */
   3.130      printk("Scrubbing DOM0 RAM: ");
   3.131 -    dst = (char *)alloc_start;
   3.132 -    while ( dst < (char *)alloc_end )
   3.133 +    dst = __va(alloc_start);
   3.134 +    while ( __pa(dst) < alloc_end )
   3.135      {
   3.136  #define SCRUB_BYTES (100 * 1024 * 1024) /* 100MB */
   3.137          printk(".");
   3.138          touch_nmi_watchdog();
   3.139 -        if ( ((char *)alloc_end - dst) > SCRUB_BYTES )
   3.140 +        if ( (alloc_end - __pa(dst)) > SCRUB_BYTES )
   3.141          {
   3.142              memset(dst, 0, SCRUB_BYTES);
   3.143              dst += SCRUB_BYTES;
   3.144          }
   3.145          else
   3.146          {
   3.147 -            memset(dst, 0, (char *)alloc_end - dst);
   3.148 +            memset(dst, 0, alloc_end - __pa(dst));
   3.149              break;
   3.150          }
   3.151      }
   3.152 @@ -203,11 +200,11 @@ int construct_dom0(struct domain *p,
   3.153            mfn++ )
   3.154      {
   3.155          page = &frame_table[mfn];
   3.156 -        page_set_owner(page, p);
   3.157 +        page_set_owner(page, d);
   3.158          page->u.inuse.type_info = 0;
   3.159          page->count_info        = PGC_allocated | 1;
   3.160 -        list_add_tail(&page->list, &p->page_list);
   3.161 -        p->tot_pages++; p->max_pages++;
   3.162 +        list_add_tail(&page->list, &d->page_list);
   3.163 +        d->tot_pages++; d->max_pages++;
   3.164      }
   3.165  
   3.166      mpt_alloc = (vpt_start - dsi.v_start) + alloc_start;
   3.167 @@ -231,7 +228,7 @@ int construct_dom0(struct domain *p,
   3.168      l2tab[LINEAR_PT_VIRT_START >> L2_PAGETABLE_SHIFT] =
   3.169          mk_l2_pgentry((unsigned long)l2start | __PAGE_HYPERVISOR);
   3.170      l2tab[PERDOMAIN_VIRT_START >> L2_PAGETABLE_SHIFT] =
   3.171 -        mk_l2_pgentry(__pa(p->mm_perdomain_pt) | __PAGE_HYPERVISOR);
   3.172 +        mk_l2_pgentry(__pa(d->mm_perdomain_pt) | __PAGE_HYPERVISOR);
   3.173      ed->mm.pagetable = mk_pagetable((unsigned long)l2start);
   3.174  
   3.175      l2tab += l2_table_offset(dsi.v_start);
   3.176 @@ -250,7 +247,7 @@ int construct_dom0(struct domain *p,
   3.177          *l1tab++ = mk_l1_pgentry((mfn << PAGE_SHIFT) | L1_PROT);
   3.178          
   3.179          page = &frame_table[mfn];
   3.180 -        if ( !get_page_and_type(page, p, PGT_writable_page) )
   3.181 +        if ( !get_page_and_type(page, d, PGT_writable_page) )
   3.182              BUG();
   3.183  
   3.184          mfn++;
   3.185 @@ -275,10 +272,10 @@ int construct_dom0(struct domain *p,
   3.186               * Installed as CR3: increment both the ref_count and type_count.
   3.187               * Net: just increment the ref_count.
   3.188               */
   3.189 -            get_page(page, p); /* an extra ref because of readable mapping */
   3.190 +            get_page(page, d); /* an extra ref because of readable mapping */
   3.191  
   3.192              /* Get another ref to L2 page so that it can be pinned. */
   3.193 -            if ( !get_page_and_type(page, p, PGT_l2_page_table) )
   3.194 +            if ( !get_page_and_type(page, d, PGT_l2_page_table) )
   3.195                  BUG();
   3.196              set_bit(_PGT_pinned, &page->u.inuse.type_info);
   3.197          }
   3.198 @@ -295,7 +292,7 @@ int construct_dom0(struct domain *p,
   3.199               * increment both the ref_count and type_count.
   3.200               * Net: just increment the ref_count.
   3.201               */
   3.202 -            get_page(page, p); /* an extra ref because of readable mapping */
   3.203 +            get_page(page, d); /* an extra ref because of readable mapping */
   3.204          }
   3.205          l1tab++;
   3.206          if( !((unsigned long)l1tab & (PAGE_SIZE - 1)) )
   3.207 @@ -303,12 +300,12 @@ int construct_dom0(struct domain *p,
   3.208      }
   3.209  
   3.210      /* Set up shared-info area. */
   3.211 -    update_dom_time(p);
   3.212 -    p->shared_info->domain_time = 0;
   3.213 +    update_dom_time(d);
   3.214 +    d->shared_info->domain_time = 0;
   3.215      /* Mask all upcalls... */
   3.216      for ( i = 0; i < MAX_VIRT_CPUS; i++ )
   3.217 -        p->shared_info->vcpu_data[i].evtchn_upcall_mask = 1;
   3.218 -    p->shared_info->n_vcpu = smp_num_cpus;
   3.219 +        d->shared_info->vcpu_data[i].evtchn_upcall_mask = 1;
   3.220 +    d->shared_info->n_vcpu = smp_num_cpus;
   3.221  
   3.222      /* Install the new page tables. */
   3.223      __cli();
   3.224 @@ -324,15 +321,15 @@ int construct_dom0(struct domain *p,
   3.225      /* Set up start info area. */
   3.226      si = (start_info_t *)vstartinfo_start;
   3.227      memset(si, 0, PAGE_SIZE);
   3.228 -    si->nr_pages     = p->tot_pages;
   3.229 -    si->shared_info  = virt_to_phys(p->shared_info);
   3.230 +    si->nr_pages     = d->tot_pages;
   3.231 +    si->shared_info  = virt_to_phys(d->shared_info);
   3.232      si->flags        = SIF_PRIVILEGED | SIF_INITDOMAIN;
   3.233      si->pt_base      = vpt_start;
   3.234      si->nr_pt_frames = nr_pt_pages;
   3.235      si->mfn_list     = vphysmap_start;
   3.236  
   3.237      /* Write the phys->machine and machine->phys table entries. */
   3.238 -    for ( pfn = 0; pfn < p->tot_pages; pfn++ )
   3.239 +    for ( pfn = 0; pfn < d->tot_pages; pfn++ )
   3.240      {
   3.241          mfn = pfn + (alloc_start>>PAGE_SHIFT);
   3.242  #ifndef NDEBUG
   3.243 @@ -348,7 +345,7 @@ int construct_dom0(struct domain *p,
   3.244      {
   3.245          si->mod_start = vinitrd_start;
   3.246          si->mod_len   = initrd_len;
   3.247 -        printk("Initrd len 0x%lx, start at 0x%08lx\n",
   3.248 +        printk("Initrd len 0x%lx, start at 0x%p\n",
   3.249                 si->mod_len, si->mod_start);
   3.250      }
   3.251  
   3.252 @@ -375,17 +372,32 @@ int construct_dom0(struct domain *p,
   3.253      zap_low_mappings(); /* Do the same for the idle page tables. */
   3.254      
   3.255      /* DOM0 gets access to everything. */
   3.256 -    physdev_init_dom0(p);
   3.257 +    physdev_init_dom0(d);
   3.258  
   3.259 -    set_bit(DF_CONSTRUCTED, &p->d_flags);
   3.260 +    set_bit(DF_CONSTRUCTED, &d->d_flags);
   3.261  
   3.262      new_thread(ed, dsi.v_kernentry, vstack_end, vstartinfo_start);
   3.263  
   3.264  #if 0 /* XXXXX DO NOT CHECK IN ENABLED !!! (but useful for testing so leave) */
   3.265 -    shadow_lock(&p->mm);
   3.266 +    shadow_lock(&d->mm);
   3.267      shadow_mode_enable(p, SHM_test); 
   3.268 -    shadow_unlock(&p->mm);
   3.269 +    shadow_unlock(&d->mm);
   3.270  #endif
   3.271  
   3.272      return 0;
   3.273  }
   3.274 +
   3.275 +int elf_sanity_check(Elf_Ehdr *ehdr)
   3.276 +{
   3.277 +    if ( !IS_ELF(*ehdr) ||
   3.278 +         (ehdr->e_ident[EI_CLASS] != ELFCLASS64) ||
   3.279 +         (ehdr->e_ident[EI_DATA] != ELFDATA2LSB) ||
   3.280 +         (ehdr->e_type != ET_EXEC) ||
   3.281 +         (ehdr->e_machine != EM_X86_64) )
   3.282 +    {
   3.283 +        printk("DOM0 image is not x86/64-compatible executable Elf image.\n");
   3.284 +        return 0;
   3.285 +    }
   3.286 +
   3.287 +    return 1;
   3.288 +}
     4.1 --- a/xen/common/elf.c	Thu Feb 03 17:03:05 2005 +0000
     4.2 +++ b/xen/common/elf.c	Thu Feb 03 17:24:49 2005 +0000
     4.3 @@ -35,11 +35,8 @@ int parseelfimage(char *elfbase,
     4.4      char *shstrtab, *guestinfo=NULL, *p;
     4.5      int h;
     4.6  
     4.7 -    if ( !IS_ELF(*ehdr) )
     4.8 -    {
     4.9 -        printk("Kernel image does not have an ELF header.\n");
    4.10 +    if ( !elf_sanity_check(ehdr) )
    4.11          return -EINVAL;
    4.12 -    }
    4.13  
    4.14      if ( (ehdr->e_phoff + (ehdr->e_phnum * ehdr->e_phentsize)) > elfsize )
    4.15      {
     5.1 --- a/xen/include/xen/elf.h	Thu Feb 03 17:03:05 2005 +0000
     5.2 +++ b/xen/include/xen/elf.h	Thu Feb 03 17:24:49 2005 +0000
     5.3 @@ -528,4 +528,8 @@ struct domain_setup_info;
     5.4  extern int loadelfimage(char *);
     5.5  extern int parseelfimage(char *, unsigned long, struct domain_setup_info *);
     5.6  
     5.7 +#ifdef Elf_Ehdr
     5.8 +extern int elf_sanity_check(Elf_Ehdr *ehdr);
     5.9 +#endif
    5.10 +
    5.11  #endif /* __XEN_ELF_H__ */
     6.1 --- a/xen/include/xen/sched.h	Thu Feb 03 17:03:05 2005 +0000
     6.2 +++ b/xen/include/xen/sched.h	Thu Feb 03 17:24:49 2005 +0000
     6.3 @@ -216,8 +216,8 @@ extern struct domain *do_createdomain(
     6.4  extern int construct_dom0(struct domain *d, 
     6.5                            unsigned long alloc_start,
     6.6                            unsigned long alloc_end,
     6.7 -                          char *image_start, unsigned long image_len, 
     6.8 -                          char *initrd_start, unsigned long initrd_len,
     6.9 +                          unsigned long image_start, unsigned long image_len, 
    6.10 +                          unsigned long initrd_start, unsigned long initrd_len,
    6.11                            char *cmdline);
    6.12  extern int final_setup_guestos(struct domain *d, dom0_builddomain_t *);
    6.13