debuggers.hg
changeset 13656:3c9926aadec5
libelf: use for x86 dom0 builder.
This patch switches the x86 dom0 builder over to libelf.
Signed-off-by: Gerd Hoffmann <kraxel@suse.de>
---
xen/arch/ia64/xen/domain.c | 79 +++++------
xen/arch/x86/domain_build.c | 303 +++++++++++++++-----------------------------
xen/common/Makefile | 4
3 files changed, 148 insertions(+), 238 deletions(-)
This patch switches the x86 dom0 builder over to libelf.
Signed-off-by: Gerd Hoffmann <kraxel@suse.de>
---
xen/arch/ia64/xen/domain.c | 79 +++++------
xen/arch/x86/domain_build.c | 303 +++++++++++++++-----------------------------
xen/common/Makefile | 4
3 files changed, 148 insertions(+), 238 deletions(-)
author | Emmanuel Ackaouy <ack@xensource.com> |
---|---|
date | Thu Jan 25 22:16:52 2007 +0000 (2007-01-25) |
parents | db3d03dfe92f |
children | a754192ffce6 |
files | xen/arch/ia64/xen/domain.c xen/arch/x86/domain_build.c xen/common/Makefile |
line diff
1.1 --- a/xen/arch/ia64/xen/domain.c Thu Jan 25 22:16:52 2007 +0000 1.2 +++ b/xen/arch/ia64/xen/domain.c Thu Jan 25 22:16:52 2007 +0000 1.3 @@ -31,7 +31,7 @@ 1.4 #include <xen/event.h> 1.5 #include <xen/console.h> 1.6 #include <xen/version.h> 1.7 -#include <xen/elf.h> 1.8 +#include <public/libelf.h> 1.9 #include <asm/pgalloc.h> 1.10 #include <asm/offsets.h> /* for IA64_THREAD_INFO_SIZE */ 1.11 #include <asm/vcpu.h> /* for function declarations */ 1.12 @@ -871,38 +871,23 @@ int shadow_mode_control(struct domain *d 1.13 #define privify_memory(x,y) do {} while(0) 1.14 #endif 1.15 1.16 -// see arch/x86/xxx/domain_build.c 1.17 -int elf_sanity_check(const Elf_Ehdr *ehdr) 1.18 +static void loaddomainelfimage(struct domain *d, struct elf_binary *elf) 1.19 { 1.20 - if (!(IS_ELF(*ehdr))) 1.21 - { 1.22 - printk("DOM0 image is not a Xen-compatible Elf image.\n"); 1.23 - return 0; 1.24 - } 1.25 - return 1; 1.26 -} 1.27 - 1.28 -static void loaddomainelfimage(struct domain *d, unsigned long image_start) 1.29 -{ 1.30 - char *elfbase = (char *) image_start; 1.31 - Elf_Ehdr ehdr; 1.32 - Elf_Phdr phdr; 1.33 - int h, filesz, memsz; 1.34 + const elf_phdr *phdr; 1.35 + int phnum, h, filesz, memsz; 1.36 unsigned long elfaddr, dom_mpaddr, dom_imva; 1.37 struct page_info *p; 1.38 - 1.39 - memcpy(&ehdr, (void *) image_start, sizeof(Elf_Ehdr)); 1.40 - for ( h = 0; h < ehdr.e_phnum; h++ ) { 1.41 - memcpy(&phdr, 1.42 - elfbase + ehdr.e_phoff + (h*ehdr.e_phentsize), 1.43 - sizeof(Elf_Phdr)); 1.44 - if ((phdr.p_type != PT_LOAD)) 1.45 + 1.46 + phnum = elf_uval(elf, elf->ehdr, e_phnum); 1.47 + for (h = 0; h < phnum; h++) { 1.48 + phdr = elf_phdr_by_index(elf, h); 1.49 + if (!elf_phdr_is_loadable(elf, phdr)) 1.50 continue; 1.51 1.52 - filesz = phdr.p_filesz; 1.53 - memsz = phdr.p_memsz; 1.54 - elfaddr = (unsigned long) elfbase + phdr.p_offset; 1.55 - dom_mpaddr = phdr.p_paddr; 1.56 + filesz = elf_uval(elf, phdr, p_filesz); 1.57 + memsz = elf_uval(elf, phdr, p_memsz); 1.58 + elfaddr = (unsigned long) elf->image + elf_uval(elf, phdr, p_offset); 1.59 + dom_mpaddr = elf_uval(elf, phdr, p_paddr); 1.60 1.61 while (memsz > 0) { 1.62 p = assign_new_domain_page(d,dom_mpaddr); 1.63 @@ -922,7 +907,7 @@ static void loaddomainelfimage(struct do 1.64 PAGE_SIZE-filesz); 1.65 } 1.66 //FIXME: This test for code seems to find a lot more than objdump -x does 1.67 - if (phdr.p_flags & PF_X) { 1.68 + if (elf_uval(elf, phdr, p_flags) & PF_X) { 1.69 privify_memory(dom_imva,PAGE_SIZE); 1.70 flush_icache_range(dom_imva, 1.71 dom_imva+PAGE_SIZE); 1.72 @@ -985,7 +970,8 @@ int construct_dom0(struct domain *d, 1.73 struct vcpu *v = d->vcpu[0]; 1.74 unsigned long max_pages; 1.75 1.76 - struct domain_setup_info dsi; 1.77 + struct elf_binary elf; 1.78 + struct elf_dom_parms parms; 1.79 unsigned long p_start; 1.80 unsigned long pkern_start; 1.81 unsigned long pkern_entry; 1.82 @@ -1009,18 +995,31 @@ int construct_dom0(struct domain *d, 1.83 BUG_ON(d->vcpu[0] == NULL); 1.84 BUG_ON(test_bit(_VCPUF_initialised, &v->vcpu_flags)); 1.85 1.86 - memset(&dsi, 0, sizeof(struct domain_setup_info)); 1.87 - 1.88 printk("*** LOADING DOMAIN 0 ***\n"); 1.89 1.90 max_pages = dom0_size / PAGE_SIZE; 1.91 d->max_pages = max_pages; 1.92 d->tot_pages = 0; 1.93 - dsi.image_addr = (unsigned long)image_start; 1.94 - dsi.image_len = image_len; 1.95 - rc = parseelfimage(&dsi); 1.96 + 1.97 + rc = elf_init(&elf, (void*)image_start, image_len); 1.98 if ( rc != 0 ) 1.99 return rc; 1.100 +#ifdef VERBOSE 1.101 + elf_set_verbose(&elf); 1.102 +#endif 1.103 + elf_parse_binary(&elf); 1.104 + if (0 != (elf_xen_parse(&elf, &parms))) 1.105 + return rc; 1.106 + 1.107 + printk(" Dom0 kernel: %s, %s, paddr 0x%" PRIx64 " -> 0x%" PRIx64 "\n", 1.108 + elf_64bit(&elf) ? "64-bit" : "32-bit", 1.109 + elf_msb(&elf) ? "msb" : "lsb", 1.110 + elf.pstart, elf.pend); 1.111 + if (!elf_64bit(&elf) || 1.112 + elf_uval(&elf, elf.ehdr, e_machine) != EM_IA_64) { 1.113 + printk("Incompatible kernel binary\n"); 1.114 + return -1; 1.115 + } 1.116 1.117 #ifdef VALIDATE_VT 1.118 /* Temp workaround */ 1.119 @@ -1039,10 +1038,10 @@ int construct_dom0(struct domain *d, 1.120 } 1.121 #endif 1.122 1.123 - p_start = dsi.v_start; 1.124 - pkern_start = dsi.v_kernstart; 1.125 - pkern_end = dsi.v_kernend; 1.126 - pkern_entry = dsi.v_kernentry; 1.127 + p_start = parms.virt_base; 1.128 + pkern_start = parms.virt_kstart; 1.129 + pkern_end = parms.virt_kend; 1.130 + pkern_entry = parms.virt_entry; 1.131 1.132 //printk("p_start=%lx, pkern_start=%lx, pkern_end=%lx, pkern_entry=%lx\n",p_start,pkern_start,pkern_end,pkern_entry); 1.133 1.134 @@ -1113,7 +1112,7 @@ int construct_dom0(struct domain *d, 1.135 panic("Cannot allocate dom0 vcpu %d\n", i); 1.136 1.137 /* Copy the OS image. */ 1.138 - loaddomainelfimage(d,image_start); 1.139 + loaddomainelfimage(d,&elf); 1.140 1.141 BUILD_BUG_ON(sizeof(start_info_t) + sizeof(dom0_vga_console_info_t) + 1.142 sizeof(struct ia64_boot_param) > PAGE_SIZE);
2.1 --- a/xen/arch/x86/domain_build.c Thu Jan 25 22:16:52 2007 +0000 2.2 +++ b/xen/arch/x86/domain_build.c Thu Jan 25 22:16:52 2007 +0000 2.3 @@ -13,7 +13,6 @@ 2.4 #include <xen/delay.h> 2.5 #include <xen/event.h> 2.6 #include <xen/console.h> 2.7 -#include <xen/elf.h> 2.8 #include <xen/kernel.h> 2.9 #include <xen/domain.h> 2.10 #include <xen/version.h> 2.11 @@ -29,7 +28,7 @@ 2.12 #include <asm/shadow.h> 2.13 2.14 #include <public/version.h> 2.15 -#include <public/elfnote.h> 2.16 +#include <public/libelf.h> 2.17 2.18 extern unsigned long initial_images_nrpages(void); 2.19 extern void discard_initial_images(void); 2.20 @@ -190,69 +189,12 @@ static void process_dom0_ioports_disable 2.21 } 2.22 } 2.23 2.24 -static const char *feature_names[XENFEAT_NR_SUBMAPS*32] = { 2.25 - [XENFEAT_writable_page_tables] = "writable_page_tables", 2.26 - [XENFEAT_writable_descriptor_tables] = "writable_descriptor_tables", 2.27 - [XENFEAT_auto_translated_physmap] = "auto_translated_physmap", 2.28 - [XENFEAT_supervisor_mode_kernel] = "supervisor_mode_kernel", 2.29 - [XENFEAT_pae_pgdir_above_4gb] = "pae_pgdir_above_4gb" 2.30 -}; 2.31 - 2.32 -static void parse_features( 2.33 - const char *feats, 2.34 - uint32_t supported[XENFEAT_NR_SUBMAPS], 2.35 - uint32_t required[XENFEAT_NR_SUBMAPS]) 2.36 -{ 2.37 - const char *end, *p; 2.38 - int i, req; 2.39 - 2.40 - if ( (end = strchr(feats, ',')) == NULL ) 2.41 - end = feats + strlen(feats); 2.42 - 2.43 - while ( feats < end ) 2.44 - { 2.45 - p = strchr(feats, '|'); 2.46 - if ( (p == NULL) || (p > end) ) 2.47 - p = end; 2.48 - 2.49 - req = (*feats == '!'); 2.50 - if ( req ) 2.51 - feats++; 2.52 - 2.53 - for ( i = 0; i < XENFEAT_NR_SUBMAPS*32; i++ ) 2.54 - { 2.55 - if ( feature_names[i] == NULL ) 2.56 - continue; 2.57 - 2.58 - if ( strncmp(feature_names[i], feats, p-feats) == 0 ) 2.59 - { 2.60 - set_bit(i, supported); 2.61 - if ( req ) 2.62 - set_bit(i, required); 2.63 - break; 2.64 - } 2.65 - } 2.66 - 2.67 - if ( i == XENFEAT_NR_SUBMAPS*32 ) 2.68 - { 2.69 - printk("Unknown kernel feature \"%.*s\".\n", 2.70 - (int)(p-feats), feats); 2.71 - if ( req ) 2.72 - panic("Domain 0 requires an unknown hypervisor feature.\n"); 2.73 - } 2.74 - 2.75 - feats = p; 2.76 - if ( *feats == '|' ) 2.77 - feats++; 2.78 - } 2.79 -} 2.80 - 2.81 int construct_dom0(struct domain *d, 2.82 unsigned long _image_start, unsigned long image_len, 2.83 unsigned long _initrd_start, unsigned long initrd_len, 2.84 char *cmdline) 2.85 { 2.86 - int i, rc, dom0_pae, xen_pae, order; 2.87 + int i, rc, compatible, compat32, order, machine; 2.88 struct cpu_user_regs *regs; 2.89 unsigned long pfn, mfn; 2.90 unsigned long nr_pages; 2.91 @@ -263,9 +205,7 @@ int construct_dom0(struct domain *d, 2.92 struct page_info *page = NULL; 2.93 start_info_t *si; 2.94 struct vcpu *v = d->vcpu[0]; 2.95 - const char *p; 2.96 unsigned long long value; 2.97 - int value_defined; 2.98 #if defined(__i386__) 2.99 char *image_start = (char *)_image_start; /* use lowmem mappings */ 2.100 char *initrd_start = (char *)_initrd_start; /* use lowmem mappings */ 2.101 @@ -287,7 +227,10 @@ int construct_dom0(struct domain *d, 2.102 * *_start address are page-aligned, except v_start (and v_end) which are 2.103 * superpage-aligned. 2.104 */ 2.105 - struct domain_setup_info dsi; 2.106 + struct elf_binary elf; 2.107 + struct elf_dom_parms parms; 2.108 + unsigned long vkern_start; 2.109 + unsigned long vkern_end; 2.110 unsigned long vinitrd_start; 2.111 unsigned long vinitrd_end; 2.112 unsigned long vphysmap_start; 2.113 @@ -298,6 +241,7 @@ int construct_dom0(struct domain *d, 2.114 unsigned long vstack_end; 2.115 unsigned long vpt_start; 2.116 unsigned long vpt_end; 2.117 + unsigned long v_start; 2.118 unsigned long v_end; 2.119 2.120 /* Machine address of next candidate page-table page. */ 2.121 @@ -312,21 +256,71 @@ int construct_dom0(struct domain *d, 2.122 BUG_ON(d->vcpu[0] == NULL); 2.123 BUG_ON(test_bit(_VCPUF_initialised, &v->vcpu_flags)); 2.124 2.125 - memset(&dsi, 0, sizeof(struct domain_setup_info)); 2.126 - dsi.image_addr = (unsigned long)image_start; 2.127 - dsi.image_len = image_len; 2.128 - 2.129 printk("*** LOADING DOMAIN 0 ***\n"); 2.130 2.131 d->max_pages = ~0U; 2.132 2.133 nr_pages = compute_dom0_nr_pages(); 2.134 2.135 - rc = parseelfimage(&dsi); 2.136 + if (0 != (rc = elf_init(&elf, image_start, image_len))) 2.137 + return rc; 2.138 +#ifdef VERBOSE 2.139 + elf_set_verbose(&elf); 2.140 +#endif 2.141 + elf_parse_binary(&elf); 2.142 + if (0 != (elf_xen_parse(&elf, &parms))) 2.143 + return rc; 2.144 + 2.145 + /* compatibility check */ 2.146 + compatible = 0; 2.147 + compat32 = 0; 2.148 + machine = elf_uval(&elf, elf.ehdr, e_machine); 2.149 + switch (CONFIG_PAGING_LEVELS) { 2.150 + case 2: /* x86_32 */ 2.151 + if (parms.pae == PAEKERN_bimodal) 2.152 + parms.pae = PAEKERN_no; 2.153 + printk(" Xen kernel: 32-bit, lsb\n"); 2.154 + if (elf_32bit(&elf) && !parms.pae && machine == EM_386) 2.155 + compatible = 1; 2.156 + break; 2.157 + case 3: /* x86_32p */ 2.158 + if (parms.pae == PAEKERN_bimodal) 2.159 + parms.pae = PAEKERN_extended_cr3; 2.160 + printk(" Xen kernel: 32-bit, PAE, lsb\n"); 2.161 + if (elf_32bit(&elf) && parms.pae && machine == EM_386) 2.162 + compatible = 1; 2.163 + break; 2.164 + case 4: /* x86_64 */ 2.165 +#ifndef CONFIG_COMPAT 2.166 + printk(" Xen kernel: 64-bit, lsb\n"); 2.167 +#else 2.168 + printk(" Xen kernel: 64-bit, lsb, compat32\n"); 2.169 + if (elf_32bit(&elf) && parms.pae == PAEKERN_bimodal) 2.170 + parms.pae = PAEKERN_extended_cr3; 2.171 + if (elf_32bit(&elf) && parms.pae && machine == EM_386) 2.172 + { 2.173 + compat32 = 1; 2.174 + compatible = 1; 2.175 + } 2.176 +#endif 2.177 + if (elf_64bit(&elf) && machine == EM_X86_64) 2.178 + compatible = 1; 2.179 + break; 2.180 + } 2.181 + printk(" Dom0 kernel: %s%s, %s, paddr 0x%" PRIx64 " -> 0x%" PRIx64 "\n", 2.182 + elf_64bit(&elf) ? "64-bit" : "32-bit", 2.183 + parms.pae ? ", PAE" : "", 2.184 + elf_msb(&elf) ? "msb" : "lsb", 2.185 + elf.pstart, elf.pend); 2.186 + 2.187 + if ( !compatible ) 2.188 + { 2.189 + printk("Mismatch between Xen and DOM0 kernel\n"); 2.190 + return -EINVAL; 2.191 + } 2.192 + 2.193 #ifdef CONFIG_COMPAT 2.194 - if ( rc == -ENOSYS 2.195 - && !compat_disabled 2.196 - && (rc = parseelf32image(&dsi)) == 0 ) 2.197 + if (compat32) 2.198 { 2.199 l1_pgentry_t gdt_l1e; 2.200 2.201 @@ -348,42 +342,10 @@ int construct_dom0(struct domain *d, 2.202 local_flush_tlb_one(GDT_LDT_VIRT_START + FIRST_RESERVED_GDT_BYTE); 2.203 } 2.204 #endif 2.205 - if ( rc != 0) 2.206 - { 2.207 - if ( rc == -ENOSYS ) 2.208 - printk("DOM0 image is not a Xen-compatible Elf image.\n"); 2.209 - return rc; 2.210 - } 2.211 - 2.212 - xen_pae = (CONFIG_PAGING_LEVELS == 3) || IS_COMPAT(d); 2.213 - if (dsi.pae_kernel == PAEKERN_bimodal) 2.214 - dom0_pae = xen_pae; 2.215 - else 2.216 - dom0_pae = (dsi.pae_kernel != PAEKERN_no); 2.217 - if ( dom0_pae != xen_pae ) 2.218 - { 2.219 - printk("PAE mode mismatch between Xen and DOM0 (xen=%s, dom0=%s)\n", 2.220 - xen_pae ? "yes" : "no", dom0_pae ? "yes" : "no"); 2.221 - return -EINVAL; 2.222 - } 2.223 - 2.224 - if ( xen_pae && (dsi.pae_kernel == PAEKERN_extended_cr3 || 2.225 - dsi.pae_kernel == PAEKERN_bimodal) ) 2.226 + if ( parms.pae == PAEKERN_extended_cr3 ) 2.227 set_bit(VMASST_TYPE_pae_extended_cr3, &d->vm_assist); 2.228 2.229 -#ifdef CONFIG_COMPAT 2.230 - if ( IS_COMPAT(d) ) 2.231 - { 2.232 - value = xen_elf32note_numeric(&dsi, XEN_ELFNOTE_HV_START_LOW, &value_defined); 2.233 - p = xen_elf32note_string(&dsi, XEN_ELFNOTE_FEATURES); 2.234 - } 2.235 - else 2.236 -#endif 2.237 - { 2.238 - value = xen_elfnote_numeric(&dsi, XEN_ELFNOTE_HV_START_LOW, &value_defined); 2.239 - p = xen_elfnote_string(&dsi, XEN_ELFNOTE_FEATURES); 2.240 - } 2.241 - if ( value_defined ) 2.242 + if ( UNSET_ADDR != parms.virt_hv_start_low && elf_32bit(&elf) ) 2.243 { 2.244 #if CONFIG_PAGING_LEVELS < 4 2.245 unsigned long mask = (1UL << L2_PAGETABLE_SHIFT) - 1; 2.246 @@ -393,7 +355,7 @@ int construct_dom0(struct domain *d, 2.247 : (1UL << L2_PAGETABLE_SHIFT) - 1; 2.248 #endif 2.249 2.250 - value = (value + mask) & ~mask; 2.251 + value = (parms.virt_hv_start_low + mask) & ~mask; 2.252 #ifdef CONFIG_COMPAT 2.253 HYPERVISOR_COMPAT_VIRT_START(d) = max_t(unsigned int, m2p_compat_vstart, value); 2.254 if ( value > (!IS_COMPAT(d) ? 2.255 @@ -404,21 +366,12 @@ int construct_dom0(struct domain *d, 2.256 #endif 2.257 panic("Domain 0 expects too high a hypervisor start address.\n"); 2.258 } 2.259 - if ( p != NULL ) 2.260 - { 2.261 - parse_features(p, 2.262 - dom0_features_supported, 2.263 - dom0_features_required); 2.264 - printk("Domain 0 kernel supports features = { %08x }.\n", 2.265 - dom0_features_supported[0]); 2.266 - printk("Domain 0 kernel requires features = { %08x }.\n", 2.267 - dom0_features_required[0]); 2.268 - if ( dom0_features_required[0] ) 2.269 + 2.270 + if ( parms.f_required[0] /* Huh? -- kraxel */ ) 2.271 panic("Domain 0 requires an unsupported hypervisor feature.\n"); 2.272 - } 2.273 2.274 /* Align load address to 4MB boundary. */ 2.275 - dsi.v_start &= ~((1UL<<22)-1); 2.276 + v_start = parms.virt_base & ~((1UL<<22)-1); 2.277 2.278 /* 2.279 * Why do we need this? The number of page-table frames depends on the 2.280 @@ -427,7 +380,9 @@ int construct_dom0(struct domain *d, 2.281 * read-only). We have a pair of simultaneous equations in two unknowns, 2.282 * which we solve by exhaustive search. 2.283 */ 2.284 - vinitrd_start = round_pgup(dsi.v_end); 2.285 + vkern_start = parms.virt_kstart; 2.286 + vkern_end = parms.virt_kend; 2.287 + vinitrd_start = round_pgup(vkern_end); 2.288 vinitrd_end = vinitrd_start + initrd_len; 2.289 vphysmap_start = round_pgup(vinitrd_end); 2.290 vphysmap_end = vphysmap_start + (nr_pages * (!IS_COMPAT(d) ? 2.291 @@ -447,12 +402,12 @@ int construct_dom0(struct domain *d, 2.292 if ( (v_end - vstack_end) < (512UL << 10) ) 2.293 v_end += 1UL << 22; /* Add extra 4MB to get >= 512kB padding. */ 2.294 #if defined(__i386__) && !defined(CONFIG_X86_PAE) 2.295 - if ( (((v_end - dsi.v_start + ((1UL<<L2_PAGETABLE_SHIFT)-1)) >> 2.296 + if ( (((v_end - v_start + ((1UL<<L2_PAGETABLE_SHIFT)-1)) >> 2.297 L2_PAGETABLE_SHIFT) + 1) <= nr_pt_pages ) 2.298 break; 2.299 #elif defined(__i386__) && defined(CONFIG_X86_PAE) 2.300 /* 5 pages: 1x 3rd + 4x 2nd level */ 2.301 - if ( (((v_end - dsi.v_start + ((1UL<<L2_PAGETABLE_SHIFT)-1)) >> 2.302 + if ( (((v_end - v_start + ((1UL<<L2_PAGETABLE_SHIFT)-1)) >> 2.303 L2_PAGETABLE_SHIFT) + 5) <= nr_pt_pages ) 2.304 break; 2.305 #elif defined(__x86_64__) 2.306 @@ -460,17 +415,17 @@ int construct_dom0(struct domain *d, 2.307 (((((_h) + ((1UL<<(_s))-1)) & ~((1UL<<(_s))-1)) - \ 2.308 ((_l) & ~((1UL<<(_s))-1))) >> (_s)) 2.309 if ( (1 + /* # L4 */ 2.310 - NR(dsi.v_start, v_end, L4_PAGETABLE_SHIFT) + /* # L3 */ 2.311 + NR(v_start, v_end, L4_PAGETABLE_SHIFT) + /* # L3 */ 2.312 (!IS_COMPAT(d) ? 2.313 - NR(dsi.v_start, v_end, L3_PAGETABLE_SHIFT) : /* # L2 */ 2.314 + NR(v_start, v_end, L3_PAGETABLE_SHIFT) : /* # L2 */ 2.315 4) + /* # compat L2 */ 2.316 - NR(dsi.v_start, v_end, L2_PAGETABLE_SHIFT)) /* # L1 */ 2.317 + NR(v_start, v_end, L2_PAGETABLE_SHIFT)) /* # L1 */ 2.318 <= nr_pt_pages ) 2.319 break; 2.320 #endif 2.321 } 2.322 2.323 - order = get_order_from_bytes(v_end - dsi.v_start); 2.324 + order = get_order_from_bytes(v_end - v_start); 2.325 if ( (1UL << order) > nr_pages ) 2.326 panic("Domain 0 allocation is too small for kernel image.\n"); 2.327 2.328 @@ -497,24 +452,24 @@ int construct_dom0(struct domain *d, 2.329 " Page tables: %p->%p\n" 2.330 " Boot stack: %p->%p\n" 2.331 " TOTAL: %p->%p\n", 2.332 - _p(dsi.v_kernstart), _p(dsi.v_kernend), 2.333 + _p(vkern_start), _p(vkern_end), 2.334 _p(vinitrd_start), _p(vinitrd_end), 2.335 _p(vphysmap_start), _p(vphysmap_end), 2.336 _p(vstartinfo_start), _p(vstartinfo_end), 2.337 _p(vpt_start), _p(vpt_end), 2.338 _p(vstack_start), _p(vstack_end), 2.339 - _p(dsi.v_start), _p(v_end)); 2.340 - printk(" ENTRY ADDRESS: %p\n", _p(dsi.v_kernentry)); 2.341 + _p(v_start), _p(v_end)); 2.342 + printk(" ENTRY ADDRESS: %p\n", _p(parms.virt_entry)); 2.343 2.344 - if ( ((v_end - dsi.v_start)>>PAGE_SHIFT) > nr_pages ) 2.345 + if ( ((v_end - v_start)>>PAGE_SHIFT) > nr_pages ) 2.346 { 2.347 printk("Initial guest OS requires too much space\n" 2.348 "(%luMB is greater than %luMB limit)\n", 2.349 - (v_end-dsi.v_start)>>20, nr_pages>>(20-PAGE_SHIFT)); 2.350 + (v_end-v_start)>>20, nr_pages>>(20-PAGE_SHIFT)); 2.351 return -ENOMEM; 2.352 } 2.353 2.354 - mpt_alloc = (vpt_start - dsi.v_start) + 2.355 + mpt_alloc = (vpt_start - v_start) + 2.356 (unsigned long)pfn_to_paddr(alloc_spfn); 2.357 2.358 #if defined(__i386__) 2.359 @@ -522,7 +477,7 @@ int construct_dom0(struct domain *d, 2.360 * Protect the lowest 1GB of memory. We use a temporary mapping there 2.361 * from which we copy the kernel and ramdisk images. 2.362 */ 2.363 - if ( dsi.v_start < (1UL<<30) ) 2.364 + if ( v_start < (1UL<<30) ) 2.365 { 2.366 printk("Initial loading isn't allowed to lowest 1GB of memory.\n"); 2.367 return -EINVAL; 2.368 @@ -552,9 +507,9 @@ int construct_dom0(struct domain *d, 2.369 l2e_from_page(virt_to_page(d->arch.mm_perdomain_pt) + i, 2.370 __PAGE_HYPERVISOR); 2.371 2.372 - l2tab += l2_linear_offset(dsi.v_start); 2.373 + l2tab += l2_linear_offset(v_start); 2.374 mfn = alloc_spfn; 2.375 - for ( count = 0; count < ((v_end-dsi.v_start)>>PAGE_SHIFT); count++ ) 2.376 + for ( count = 0; count < ((v_end-v_start)>>PAGE_SHIFT); count++ ) 2.377 { 2.378 if ( !((unsigned long)l1tab & (PAGE_SIZE-1)) ) 2.379 { 2.380 @@ -564,7 +519,7 @@ int construct_dom0(struct domain *d, 2.381 l2tab++; 2.382 clear_page(l1tab); 2.383 if ( count == 0 ) 2.384 - l1tab += l1_table_offset(dsi.v_start); 2.385 + l1tab += l1_table_offset(v_start); 2.386 } 2.387 *l1tab = l1e_from_pfn(mfn, L1_PROT); 2.388 l1tab++; 2.389 @@ -654,7 +609,7 @@ int construct_dom0(struct domain *d, 2.390 2.391 /* Overlap with Xen protected area? */ 2.392 if ( !IS_COMPAT(d) ? 2.393 - ((dsi.v_start < HYPERVISOR_VIRT_END) && 2.394 + ((v_start < HYPERVISOR_VIRT_END) && 2.395 (v_end > HYPERVISOR_VIRT_START)) : 2.396 (v_end > HYPERVISOR_COMPAT_VIRT_START(d)) ) 2.397 { 2.398 @@ -694,9 +649,9 @@ int construct_dom0(struct domain *d, 2.399 panic("Not enough RAM for domain 0 hypercall argument translation.\n"); 2.400 } 2.401 2.402 - l4tab += l4_table_offset(dsi.v_start); 2.403 + l4tab += l4_table_offset(v_start); 2.404 mfn = alloc_spfn; 2.405 - for ( count = 0; count < ((v_end-dsi.v_start)>>PAGE_SHIFT); count++ ) 2.406 + for ( count = 0; count < ((v_end-v_start)>>PAGE_SHIFT); count++ ) 2.407 { 2.408 if ( !((unsigned long)l1tab & (PAGE_SIZE-1)) ) 2.409 { 2.410 @@ -704,14 +659,14 @@ int construct_dom0(struct domain *d, 2.411 l1start = l1tab = __va(mpt_alloc); mpt_alloc += PAGE_SIZE; 2.412 clear_page(l1tab); 2.413 if ( count == 0 ) 2.414 - l1tab += l1_table_offset(dsi.v_start); 2.415 + l1tab += l1_table_offset(v_start); 2.416 if ( !((unsigned long)l2tab & (PAGE_SIZE-1)) ) 2.417 { 2.418 maddr_to_page(mpt_alloc)->u.inuse.type_info = PGT_l2_page_table; 2.419 l2start = l2tab = __va(mpt_alloc); mpt_alloc += PAGE_SIZE; 2.420 clear_page(l2tab); 2.421 if ( count == 0 ) 2.422 - l2tab += l2_table_offset(dsi.v_start); 2.423 + l2tab += l2_table_offset(v_start); 2.424 if ( !((unsigned long)l3tab & (PAGE_SIZE-1)) ) 2.425 { 2.426 maddr_to_page(mpt_alloc)->u.inuse.type_info = 2.427 @@ -719,7 +674,7 @@ int construct_dom0(struct domain *d, 2.428 l3start = l3tab = __va(mpt_alloc); mpt_alloc += PAGE_SIZE; 2.429 clear_page(l3tab); 2.430 if ( count == 0 ) 2.431 - l3tab += l3_table_offset(dsi.v_start); 2.432 + l3tab += l3_table_offset(v_start); 2.433 *l4tab = l4e_from_paddr(__pa(l3start), L4_PROT); 2.434 l4tab++; 2.435 } 2.436 @@ -832,30 +787,20 @@ int construct_dom0(struct domain *d, 2.437 write_ptbase(v); 2.438 2.439 /* Copy the OS image and free temporary buffer. */ 2.440 -#ifdef CONFIG_COMPAT 2.441 - if ( IS_COMPAT(d) ) 2.442 + elf.dest = (void*)vkern_start; 2.443 + elf_load_binary(&elf); 2.444 + 2.445 + if ( UNSET_ADDR != parms.virt_hypercall ) 2.446 { 2.447 - (void)loadelf32image(&dsi); 2.448 - value = 2.449 - xen_elf32note_numeric(&dsi, XEN_ELFNOTE_HYPERCALL_PAGE, &value_defined); 2.450 - } 2.451 - else 2.452 -#endif 2.453 - { 2.454 - (void)loadelfimage(&dsi); 2.455 - value = 2.456 - xen_elfnote_numeric(&dsi, XEN_ELFNOTE_HYPERCALL_PAGE, &value_defined); 2.457 - } 2.458 - if ( value_defined ) 2.459 - { 2.460 - if ( (value < dsi.v_start) || (value >= v_end) ) 2.461 + if ( (parms.virt_hypercall < v_start) || 2.462 + (parms.virt_hypercall >= v_end) ) 2.463 { 2.464 write_ptbase(current); 2.465 local_irq_enable(); 2.466 printk("Invalid HYPERCALL_PAGE field in ELF notes.\n"); 2.467 return -1; 2.468 } 2.469 - hypercall_page_initialise(d, (void *)(unsigned long)value); 2.470 + hypercall_page_initialise(d, (void *)(unsigned long)parms.virt_hypercall); 2.471 } 2.472 2.473 /* Copy the initial ramdisk. */ 2.474 @@ -878,14 +823,15 @@ int construct_dom0(struct domain *d, 2.475 si->mfn_list = vphysmap_start; 2.476 sprintf(si->magic, "xen-%i.%i-x86_%d%s", 2.477 xen_major_version(), xen_minor_version(), 2.478 - !IS_COMPAT(d) ? BITS_PER_LONG : 32, xen_pae ? "p" : ""); 2.479 + elf_64bit(&elf) ? 64 : 32, 2.480 + parms.pae ? "p" : ""); 2.481 2.482 /* Write the phys->machine and machine->phys table entries. */ 2.483 for ( pfn = 0; pfn < d->tot_pages; pfn++ ) 2.484 { 2.485 mfn = pfn + alloc_spfn; 2.486 #ifndef NDEBUG 2.487 -#define REVERSE_START ((v_end - dsi.v_start) >> PAGE_SHIFT) 2.488 +#define REVERSE_START ((v_end - v_start) >> PAGE_SHIFT) 2.489 if ( pfn > REVERSE_START ) 2.490 mfn = alloc_epfn - (pfn - REVERSE_START); 2.491 #endif 2.492 @@ -966,7 +912,7 @@ int construct_dom0(struct domain *d, 2.493 : FLAT_COMPAT_KERNEL_DS; 2.494 regs->ss = !IS_COMPAT(d) ? FLAT_KERNEL_SS : FLAT_COMPAT_KERNEL_SS; 2.495 regs->cs = !IS_COMPAT(d) ? FLAT_KERNEL_CS : FLAT_COMPAT_KERNEL_CS; 2.496 - regs->eip = dsi.v_kernentry; 2.497 + regs->eip = parms.virt_entry; 2.498 regs->esp = vstack_end; 2.499 regs->esi = vstartinfo_start; 2.500 regs->eflags = X86_EFLAGS_IF; 2.501 @@ -1037,41 +983,6 @@ int construct_dom0(struct domain *d, 2.502 return 0; 2.503 } 2.504 2.505 -int elf_sanity_check(const Elf_Ehdr *ehdr) 2.506 -{ 2.507 - if ( !IS_ELF(*ehdr) || 2.508 -#if defined(__i386__) 2.509 - (ehdr->e_ident[EI_CLASS] != ELFCLASS32) || 2.510 - (ehdr->e_machine != EM_386) || 2.511 -#elif defined(__x86_64__) 2.512 - (ehdr->e_ident[EI_CLASS] != ELFCLASS64) || 2.513 - (ehdr->e_machine != EM_X86_64) || 2.514 -#endif 2.515 - (ehdr->e_ident[EI_DATA] != ELFDATA2LSB) || 2.516 - (ehdr->e_type != ET_EXEC) ) 2.517 - { 2.518 - return 0; 2.519 - } 2.520 - 2.521 - return 1; 2.522 -} 2.523 - 2.524 -#ifdef CONFIG_COMPAT 2.525 -int elf32_sanity_check(const Elf32_Ehdr *ehdr) 2.526 -{ 2.527 - if ( !IS_ELF(*ehdr) || 2.528 - (ehdr->e_ident[EI_CLASS] != ELFCLASS32) || 2.529 - (ehdr->e_machine != EM_386) || 2.530 - (ehdr->e_ident[EI_DATA] != ELFDATA2LSB) || 2.531 - (ehdr->e_type != ET_EXEC) ) 2.532 - { 2.533 - return 0; 2.534 - } 2.535 - 2.536 - return 1; 2.537 -} 2.538 -#endif 2.539 - 2.540 /* 2.541 * Local variables: 2.542 * mode: C
3.1 --- a/xen/common/Makefile Thu Jan 25 22:16:52 2007 +0000 3.2 +++ b/xen/common/Makefile Thu Jan 25 22:16:52 2007 +0000 3.3 @@ -2,8 +2,8 @@ obj-y += acm_ops.o 3.4 obj-y += bitmap.o 3.5 obj-y += domctl.o 3.6 obj-y += domain.o 3.7 -obj-y += elf.o 3.8 -obj-$(CONFIG_COMPAT) += elf32.o 3.9 +#obj-y += elf.o 3.10 +#obj-$(CONFIG_COMPAT) += elf32.o 3.11 obj-y += event_channel.o 3.12 obj-y += grant_table.o 3.13 obj-y += kernel.o