ia64/xen-unstable

changeset 3638:dbc41aaba297

bitkeeper revision 1.1159.212.81 (4202b326JJIfXeNBQXQRsDKmhOvNEw)

Merge ssh://srg//auto/groups/xeno/BK/xeno.bk
into equilibrium.research:/home/irchomes/mwilli2/src/xen-3.0-devel.bk
author mwilli2@equilibrium.research
date Thu Feb 03 23:26:30 2005 +0000 (2005-02-03)
parents d1bedbc0f20a 8710698e57e1
children c5a71e081a54
files xen/arch/x86/setup.c xen/arch/x86/x86_32/domain_build.c xen/arch/x86/x86_32/entry.S 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:23:18 2005 +0000
     1.2 +++ b/xen/arch/x86/setup.c	Thu Feb 03 23:26:30 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:23:18 2005 +0000
     2.2 +++ b/xen/arch/x86/x86_32/domain_build.c	Thu Feb 03 23:26:30 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_32/entry.S	Thu Feb 03 17:23:18 2005 +0000
     3.2 +++ b/xen/arch/x86/x86_32/entry.S	Thu Feb 03 23:26:30 2005 +0000
     3.3 @@ -630,12 +630,12 @@ do_watchdog_tick:
     3.4  defer_nmi:
     3.5          movl  $FIXMAP_apic_base,%eax
     3.6          # apic_wait_icr_idle()
     3.7 -1:      movl  APIC_ICR(%eax),%ebx
     3.8 +1:      movl  %ss:APIC_ICR(%eax),%ebx
     3.9          testl $APIC_ICR_BUSY,%ebx
    3.10          jnz   1b
    3.11          # __send_IPI_shortcut(APIC_DEST_SELF, TRAP_deferred_nmi)
    3.12          movl  $(APIC_DM_FIXED | APIC_DEST_SELF | APIC_DEST_LOGICAL | \
    3.13 -                TRAP_deferred_nmi),APIC_ICR(%eax)
    3.14 +                TRAP_deferred_nmi),%ss:APIC_ICR(%eax)
    3.15          jmp   restore_all_xen
    3.16  
    3.17  nmi_parity_err:
     4.1 --- a/xen/arch/x86/x86_64/domain_build.c	Thu Feb 03 17:23:18 2005 +0000
     4.2 +++ b/xen/arch/x86/x86_64/domain_build.c	Thu Feb 03 23:26:30 2005 +0000
     4.3 @@ -29,11 +29,11 @@
     4.4  #define round_pgup(_p)    (((_p)+(PAGE_SIZE-1))&PAGE_MASK)
     4.5  #define round_pgdown(_p)  ((_p)&PAGE_MASK)
     4.6  
     4.7 -int construct_dom0(struct domain *p, 
     4.8 +int construct_dom0(struct domain *d,
     4.9                     unsigned long alloc_start,
    4.10                     unsigned long alloc_end,
    4.11 -                   char *image_start, unsigned long image_len, 
    4.12 -                   char *initrd_start, unsigned long initrd_len,
    4.13 +                   unsigned long _image_start, unsigned long image_len, 
    4.14 +                   unsigned long _initrd_start, unsigned long initrd_len,
    4.15                     char *cmdline)
    4.16  {
    4.17      char *dst;
    4.18 @@ -46,7 +46,9 @@ int construct_dom0(struct domain *p,
    4.19      l1_pgentry_t *l1tab = NULL, *l1start = NULL;
    4.20      struct pfn_info *page = NULL;
    4.21      start_info_t *si;
    4.22 -    struct exec_domain *ed = p->exec_domain[0];
    4.23 +    struct exec_domain *ed = d->exec_domain[0];
    4.24 +    char *image_start  = __va(_image_start);
    4.25 +    char *initrd_start = __va(_initrd_start);
    4.26  
    4.27      /*
    4.28       * This fully describes the memory layout of the initial domain. All 
    4.29 @@ -72,9 +74,9 @@ int construct_dom0(struct domain *p,
    4.30      extern void physdev_init_dom0(struct domain *);
    4.31  
    4.32      /* Sanity! */
    4.33 -    if ( p->id != 0 ) 
    4.34 +    if ( d->id != 0 ) 
    4.35          BUG();
    4.36 -    if ( test_bit(DF_CONSTRUCTED, &p->d_flags) ) 
    4.37 +    if ( test_bit(DF_CONSTRUCTED, &d->d_flags) ) 
    4.38          BUG();
    4.39  
    4.40      memset(&dsi, 0, sizeof(struct domain_setup_info));
    4.41 @@ -99,13 +101,10 @@ int construct_dom0(struct domain *p,
    4.42  
    4.43      /* Set up domain options */
    4.44      if ( dsi.use_writable_pagetables )
    4.45 -        vm_assist(p, VMASST_CMD_enable, VMASST_TYPE_writable_pagetables);
    4.46 +        vm_assist(d, VMASST_CMD_enable, VMASST_TYPE_writable_pagetables);
    4.47  
    4.48 -    if ( (dsi.v_start & (PAGE_SIZE-1)) != 0 )
    4.49 -    {
    4.50 -        printk("Initial guest OS must load to a page boundary.\n");
    4.51 -        return -EINVAL;
    4.52 -    }
    4.53 +    /* Align load address to 4MB boundary. */
    4.54 +    dsi.v_start &= ~((1UL<<22)-1);
    4.55  
    4.56      /*
    4.57       * Why do we need this? The number of page-table frames depends on the 
    4.58 @@ -126,10 +125,10 @@ int construct_dom0(struct domain *p,
    4.59          vstartinfo_end   = vstartinfo_start + PAGE_SIZE;
    4.60          vstack_start     = vstartinfo_end;
    4.61          vstack_end       = vstack_start + PAGE_SIZE;
    4.62 -        v_end            = (vstack_end + (1<<22)-1) & ~((1<<22)-1);
    4.63 -        if ( (v_end - vstack_end) < (512 << 10) )
    4.64 -            v_end += 1 << 22; /* Add extra 4MB to get >= 512kB padding. */
    4.65 -        if ( (((v_end - dsi.v_start + ((1<<L2_PAGETABLE_SHIFT)-1)) >> 
    4.66 +        v_end            = (vstack_end + (1UL<<22)-1) & ~((1UL<<22)-1);
    4.67 +        if ( (v_end - vstack_end) < (512UL << 10) )
    4.68 +            v_end += 1UL << 22; /* Add extra 4MB to get >= 512kB padding. */
    4.69 +        if ( (((v_end - dsi.v_start + ((1UL<<L2_PAGETABLE_SHIFT)-1)) >> 
    4.70                 L2_PAGETABLE_SHIFT) + 1) <= nr_pt_pages )
    4.71              break;
    4.72      }
    4.73 @@ -137,18 +136,18 @@ int construct_dom0(struct domain *p,
    4.74      printk("PHYSICAL MEMORY ARRANGEMENT:\n"
    4.75             " Kernel image:  %p->%p\n"
    4.76             " Initrd image:  %p->%p\n"
    4.77 -           " Dom0 alloc.:   %08lx->%08lx\n",
    4.78 -           image_start, image_start + image_len,
    4.79 -           initrd_start, initrd_start + initrd_len,
    4.80 +           " Dom0 alloc.:   %p->%p\n",
    4.81 +           _image_start, _image_start + image_len,
    4.82 +           _initrd_start, _initrd_start + initrd_len,
    4.83             alloc_start, alloc_end);
    4.84      printk("VIRTUAL MEMORY ARRANGEMENT:\n"
    4.85 -           " Loaded kernel: %08lx->%08lx\n"
    4.86 -           " Init. ramdisk: %08lx->%08lx\n"
    4.87 -           " Phys-Mach map: %08lx->%08lx\n"
    4.88 -           " Page tables:   %08lx->%08lx\n"
    4.89 -           " Start info:    %08lx->%08lx\n"
    4.90 -           " Boot stack:    %08lx->%08lx\n"
    4.91 -           " TOTAL:         %08lx->%08lx\n",
    4.92 +           " Loaded kernel: %p->%p\n"
    4.93 +           " Init. ramdisk: %p->%p\n"
    4.94 +           " Phys-Mach map: %p->%p\n"
    4.95 +           " Page tables:   %p->%p\n"
    4.96 +           " Start info:    %p->%p\n"
    4.97 +           " Boot stack:    %p->%p\n"
    4.98 +           " TOTAL:         %p->%p\n",
    4.99             dsi.v_kernstart, dsi.v_kernend, 
   4.100             vinitrd_start, vinitrd_end,
   4.101             vphysmap_start, vphysmap_end,
   4.102 @@ -156,7 +155,7 @@ int construct_dom0(struct domain *p,
   4.103             vstartinfo_start, vstartinfo_end,
   4.104             vstack_start, vstack_end,
   4.105             dsi.v_start, v_end);
   4.106 -    printk(" ENTRY ADDRESS: %08lx\n", dsi.v_kernentry);
   4.107 +    printk(" ENTRY ADDRESS: %p\n", dsi.v_kernentry);
   4.108  
   4.109      if ( (v_end - dsi.v_start) > (nr_pages * PAGE_SIZE) )
   4.110      {
   4.111 @@ -166,32 +165,30 @@ int construct_dom0(struct domain *p,
   4.112          return -ENOMEM;
   4.113      }
   4.114  
   4.115 -    /*
   4.116 -     * Protect the lowest 1GB of memory. We use a temporary mapping there
   4.117 -     * from which we copy the kernel and ramdisk images.
   4.118 -     */
   4.119 -    if ( dsi.v_start < (1<<30) )
   4.120 +    /* Overlap with Xen protected area? */
   4.121 +    if ( (dsi.v_start < HYPERVISOR_VIRT_END) &&
   4.122 +         (v_end > HYPERVISOR_VIRT_START) )
   4.123      {
   4.124 -        printk("Initial loading isn't allowed to lowest 1GB of memory.\n");
   4.125 +        printk("DOM0 image overlaps with Xen private area.\n");
   4.126          return -EINVAL;
   4.127      }
   4.128  
   4.129      /* Paranoia: scrub DOM0's memory allocation. */
   4.130      printk("Scrubbing DOM0 RAM: ");
   4.131 -    dst = (char *)alloc_start;
   4.132 -    while ( dst < (char *)alloc_end )
   4.133 +    dst = __va(alloc_start);
   4.134 +    while ( __pa(dst) < alloc_end )
   4.135      {
   4.136  #define SCRUB_BYTES (100 * 1024 * 1024) /* 100MB */
   4.137          printk(".");
   4.138          touch_nmi_watchdog();
   4.139 -        if ( ((char *)alloc_end - dst) > SCRUB_BYTES )
   4.140 +        if ( (alloc_end - __pa(dst)) > SCRUB_BYTES )
   4.141          {
   4.142              memset(dst, 0, SCRUB_BYTES);
   4.143              dst += SCRUB_BYTES;
   4.144          }
   4.145          else
   4.146          {
   4.147 -            memset(dst, 0, (char *)alloc_end - dst);
   4.148 +            memset(dst, 0, alloc_end - __pa(dst));
   4.149              break;
   4.150          }
   4.151      }
   4.152 @@ -203,11 +200,11 @@ int construct_dom0(struct domain *p,
   4.153            mfn++ )
   4.154      {
   4.155          page = &frame_table[mfn];
   4.156 -        page_set_owner(page, p);
   4.157 +        page_set_owner(page, d);
   4.158          page->u.inuse.type_info = 0;
   4.159          page->count_info        = PGC_allocated | 1;
   4.160 -        list_add_tail(&page->list, &p->page_list);
   4.161 -        p->tot_pages++; p->max_pages++;
   4.162 +        list_add_tail(&page->list, &d->page_list);
   4.163 +        d->tot_pages++; d->max_pages++;
   4.164      }
   4.165  
   4.166      mpt_alloc = (vpt_start - dsi.v_start) + alloc_start;
   4.167 @@ -231,7 +228,7 @@ int construct_dom0(struct domain *p,
   4.168      l2tab[LINEAR_PT_VIRT_START >> L2_PAGETABLE_SHIFT] =
   4.169          mk_l2_pgentry((unsigned long)l2start | __PAGE_HYPERVISOR);
   4.170      l2tab[PERDOMAIN_VIRT_START >> L2_PAGETABLE_SHIFT] =
   4.171 -        mk_l2_pgentry(__pa(p->mm_perdomain_pt) | __PAGE_HYPERVISOR);
   4.172 +        mk_l2_pgentry(__pa(d->mm_perdomain_pt) | __PAGE_HYPERVISOR);
   4.173      ed->mm.pagetable = mk_pagetable((unsigned long)l2start);
   4.174  
   4.175      l2tab += l2_table_offset(dsi.v_start);
   4.176 @@ -250,7 +247,7 @@ int construct_dom0(struct domain *p,
   4.177          *l1tab++ = mk_l1_pgentry((mfn << PAGE_SHIFT) | L1_PROT);
   4.178          
   4.179          page = &frame_table[mfn];
   4.180 -        if ( !get_page_and_type(page, p, PGT_writable_page) )
   4.181 +        if ( !get_page_and_type(page, d, PGT_writable_page) )
   4.182              BUG();
   4.183  
   4.184          mfn++;
   4.185 @@ -275,10 +272,10 @@ int construct_dom0(struct domain *p,
   4.186               * Installed as CR3: increment both the ref_count and type_count.
   4.187               * Net: just increment the ref_count.
   4.188               */
   4.189 -            get_page(page, p); /* an extra ref because of readable mapping */
   4.190 +            get_page(page, d); /* an extra ref because of readable mapping */
   4.191  
   4.192              /* Get another ref to L2 page so that it can be pinned. */
   4.193 -            if ( !get_page_and_type(page, p, PGT_l2_page_table) )
   4.194 +            if ( !get_page_and_type(page, d, PGT_l2_page_table) )
   4.195                  BUG();
   4.196              set_bit(_PGT_pinned, &page->u.inuse.type_info);
   4.197          }
   4.198 @@ -295,7 +292,7 @@ int construct_dom0(struct domain *p,
   4.199               * increment both the ref_count and type_count.
   4.200               * Net: just increment the ref_count.
   4.201               */
   4.202 -            get_page(page, p); /* an extra ref because of readable mapping */
   4.203 +            get_page(page, d); /* an extra ref because of readable mapping */
   4.204          }
   4.205          l1tab++;
   4.206          if( !((unsigned long)l1tab & (PAGE_SIZE - 1)) )
   4.207 @@ -303,12 +300,12 @@ int construct_dom0(struct domain *p,
   4.208      }
   4.209  
   4.210      /* Set up shared-info area. */
   4.211 -    update_dom_time(p);
   4.212 -    p->shared_info->domain_time = 0;
   4.213 +    update_dom_time(d);
   4.214 +    d->shared_info->domain_time = 0;
   4.215      /* Mask all upcalls... */
   4.216      for ( i = 0; i < MAX_VIRT_CPUS; i++ )
   4.217 -        p->shared_info->vcpu_data[i].evtchn_upcall_mask = 1;
   4.218 -    p->shared_info->n_vcpu = smp_num_cpus;
   4.219 +        d->shared_info->vcpu_data[i].evtchn_upcall_mask = 1;
   4.220 +    d->shared_info->n_vcpu = smp_num_cpus;
   4.221  
   4.222      /* Install the new page tables. */
   4.223      __cli();
   4.224 @@ -324,15 +321,15 @@ int construct_dom0(struct domain *p,
   4.225      /* Set up start info area. */
   4.226      si = (start_info_t *)vstartinfo_start;
   4.227      memset(si, 0, PAGE_SIZE);
   4.228 -    si->nr_pages     = p->tot_pages;
   4.229 -    si->shared_info  = virt_to_phys(p->shared_info);
   4.230 +    si->nr_pages     = d->tot_pages;
   4.231 +    si->shared_info  = virt_to_phys(d->shared_info);
   4.232      si->flags        = SIF_PRIVILEGED | SIF_INITDOMAIN;
   4.233      si->pt_base      = vpt_start;
   4.234      si->nr_pt_frames = nr_pt_pages;
   4.235      si->mfn_list     = vphysmap_start;
   4.236  
   4.237      /* Write the phys->machine and machine->phys table entries. */
   4.238 -    for ( pfn = 0; pfn < p->tot_pages; pfn++ )
   4.239 +    for ( pfn = 0; pfn < d->tot_pages; pfn++ )
   4.240      {
   4.241          mfn = pfn + (alloc_start>>PAGE_SHIFT);
   4.242  #ifndef NDEBUG
   4.243 @@ -348,7 +345,7 @@ int construct_dom0(struct domain *p,
   4.244      {
   4.245          si->mod_start = vinitrd_start;
   4.246          si->mod_len   = initrd_len;
   4.247 -        printk("Initrd len 0x%lx, start at 0x%08lx\n",
   4.248 +        printk("Initrd len 0x%lx, start at 0x%p\n",
   4.249                 si->mod_len, si->mod_start);
   4.250      }
   4.251  
   4.252 @@ -375,17 +372,32 @@ int construct_dom0(struct domain *p,
   4.253      zap_low_mappings(); /* Do the same for the idle page tables. */
   4.254      
   4.255      /* DOM0 gets access to everything. */
   4.256 -    physdev_init_dom0(p);
   4.257 +    physdev_init_dom0(d);
   4.258  
   4.259 -    set_bit(DF_CONSTRUCTED, &p->d_flags);
   4.260 +    set_bit(DF_CONSTRUCTED, &d->d_flags);
   4.261  
   4.262      new_thread(ed, dsi.v_kernentry, vstack_end, vstartinfo_start);
   4.263  
   4.264  #if 0 /* XXXXX DO NOT CHECK IN ENABLED !!! (but useful for testing so leave) */
   4.265 -    shadow_lock(&p->mm);
   4.266 +    shadow_lock(&d->mm);
   4.267      shadow_mode_enable(p, SHM_test); 
   4.268 -    shadow_unlock(&p->mm);
   4.269 +    shadow_unlock(&d->mm);
   4.270  #endif
   4.271  
   4.272      return 0;
   4.273  }
   4.274 +
   4.275 +int elf_sanity_check(Elf_Ehdr *ehdr)
   4.276 +{
   4.277 +    if ( !IS_ELF(*ehdr) ||
   4.278 +         (ehdr->e_ident[EI_CLASS] != ELFCLASS64) ||
   4.279 +         (ehdr->e_ident[EI_DATA] != ELFDATA2LSB) ||
   4.280 +         (ehdr->e_type != ET_EXEC) ||
   4.281 +         (ehdr->e_machine != EM_X86_64) )
   4.282 +    {
   4.283 +        printk("DOM0 image is not x86/64-compatible executable Elf image.\n");
   4.284 +        return 0;
   4.285 +    }
   4.286 +
   4.287 +    return 1;
   4.288 +}
     5.1 --- a/xen/common/elf.c	Thu Feb 03 17:23:18 2005 +0000
     5.2 +++ b/xen/common/elf.c	Thu Feb 03 23:26:30 2005 +0000
     5.3 @@ -35,11 +35,8 @@ int parseelfimage(char *elfbase,
     5.4      char *shstrtab, *guestinfo=NULL, *p;
     5.5      int h;
     5.6  
     5.7 -    if ( !IS_ELF(*ehdr) )
     5.8 -    {
     5.9 -        printk("Kernel image does not have an ELF header.\n");
    5.10 +    if ( !elf_sanity_check(ehdr) )
    5.11          return -EINVAL;
    5.12 -    }
    5.13  
    5.14      if ( (ehdr->e_phoff + (ehdr->e_phnum * ehdr->e_phentsize)) > elfsize )
    5.15      {
     6.1 --- a/xen/include/xen/elf.h	Thu Feb 03 17:23:18 2005 +0000
     6.2 +++ b/xen/include/xen/elf.h	Thu Feb 03 23:26:30 2005 +0000
     6.3 @@ -528,4 +528,8 @@ struct domain_setup_info;
     6.4  extern int loadelfimage(char *);
     6.5  extern int parseelfimage(char *, unsigned long, struct domain_setup_info *);
     6.6  
     6.7 +#ifdef Elf_Ehdr
     6.8 +extern int elf_sanity_check(Elf_Ehdr *ehdr);
     6.9 +#endif
    6.10 +
    6.11  #endif /* __XEN_ELF_H__ */
     7.1 --- a/xen/include/xen/sched.h	Thu Feb 03 17:23:18 2005 +0000
     7.2 +++ b/xen/include/xen/sched.h	Thu Feb 03 23:26:30 2005 +0000
     7.3 @@ -216,8 +216,8 @@ extern struct domain *do_createdomain(
     7.4  extern int construct_dom0(struct domain *d, 
     7.5                            unsigned long alloc_start,
     7.6                            unsigned long alloc_end,
     7.7 -                          char *image_start, unsigned long image_len, 
     7.8 -                          char *initrd_start, unsigned long initrd_len,
     7.9 +                          unsigned long image_start, unsigned long image_len, 
    7.10 +                          unsigned long initrd_start, unsigned long initrd_len,
    7.11                            char *cmdline);
    7.12  extern int final_setup_guestos(struct domain *d, dom0_builddomain_t *);
    7.13