From: Michal Ostrowski Subject: [PATCH][2/4] Cross-compilation enablement. Date: Tue, 30 Aug 2005 08:24:28 -0400 Message-ID: <20050830082428.016725ca@brick.watson.ibm.com> References: <20050830082230.1422f7fa@brick.watson.ibm.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============0369859224==" Return-path: In-Reply-To: <20050830082230.1422f7fa@brick.watson.ibm.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Mime-version: 1.0 Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: xen-devel@lists.xensource.com List-Id: xen-devel@lists.xenproject.org --===============0369859224== Content-Type: multipart/signed; boundary=Signature_Tue__30_Aug_2005_08_24_28_-0400_Ua6kRxX6YbiSurXK; protocol="application/pgp-signature"; micalg=pgp-sha1 --Signature_Tue__30_Aug_2005_08_24_28_-0400_Ua6kRxX6YbiSurXK Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Signed-off-by: Michal Ostrowski changeset: 6335:b8dfe20a5b9d user: mostrows@heater.watson.ibm.com date: Mon Aug 29 18:52:56 2005 -0400 summary: Make mbootpack work on big-endian systems. diff -r 28c822457019 -r b8dfe20a5b9d tools/misc/mbootpack/Makefile --- a/tools/misc/mbootpack/Makefile Mon Aug 29 22:48:06 2005 +++ b/tools/misc/mbootpack/Makefile Mon Aug 29 22:52:56 2005 @@ -20,11 +20,10 @@ INCS :=3D -I. -I- DEFS :=3D=20 LDFLAGS :=3D=20 -CC :=3D gcc CFLAGS :=3D -Wall -Wpointer-arith -Wcast-qual -Wno-unused -Wno-format CFLAGS +=3D -Wmissing-prototypes -#CFLAGS +=3D -pipe -g -O0 -Wcast-align -CFLAGS +=3D -pipe -O3=20 +CFLAGS +=3D -pipe -g -O0 -Wcast-align +#CFLAGS +=3D -pipe -O3=20 =20 # What object files need building for the program OBJS :=3D mbootpack.o buildimage.o @@ -34,7 +33,7 @@ DEPS =3D .*.d =20 mbootpack: $(OBJS) - $(CC) -o $@ $(filter-out %.a, $^) $(LDFLAGS) + $(HOSTCC) -o $@ $(filter-out %.a, $^) $(LDFLAGS) =20 clean: $(RM) mbootpack *.o $(DEPS) bootsect setup bzimage_header.c bin2c @@ -48,20 +47,22 @@ $(LD) -m elf_i386 -Ttext 0x0 -s --oformat binary setup.o -o $@ =20 bin2c: bin2c.o=20 - $(CC) -o $@ $^=20 + $(HOSTCC) -o $@ $^=20 =20 bzimage_header.c: bootsect setup bin2c ./bin2c -n 8 -b1 -a bzimage_bootsect bootsect > bzimage_header.c ./bin2c -n 8 -b1 -a bzimage_setup setup >> bzimage_header.c =20 + buildimage.c: bzimage_header.c @ =20 %.o: %.S - $(CC) $(DEPFLAGS) $(CFLAGS) $(INCS) $(DEFS) -c $< -o $@ + $(HOSTCC) $(DEPFLAGS) $(CFLAGS) $(INCS) $(DEFS) -c $< -o $@ =20 %.o: %.c - $(CC) $(DEPFLAGS) $(CFLAGS) $(INCS) $(DEFS) -c $< -o $@ + $(HOSTCC) $(DEPFLAGS) $(CFLAGS) $(INCS) $(DEFS) -c $< -o $@ + =20 .PHONY: all clean gdb .PRECIOUS: $(OBJS) $(OBJS:.o=3D.c) $(DEPS) diff -r 28c822457019 -r b8dfe20a5b9d tools/misc/mbootpack/buildimage.c --- a/tools/misc/mbootpack/buildimage.c Mon Aug 29 22:48:06 2005 +++ b/tools/misc/mbootpack/buildimage.c Mon Aug 29 22:52:56 2005 @@ -42,6 +42,7 @@ =20 #include "mbootpack.h" #include "mb_header.h" + =20 /* We will build an image that a bzImage-capable bootloader will load lik= e=20 * this: @@ -105,8 +106,8 @@ section_t *s; =20 /* Patch the kernel and mbi addresses into the setup code */ - *(address_t *)(bzimage_setup + BZ_ENTRY_OFFSET) =3D entry; - *(address_t *)(bzimage_setup + BZ_MBI_OFFSET) =3D mbi; + *(address_t *)(bzimage_setup + BZ_ENTRY_OFFSET) =3D eswap(entry); + *(address_t *)(bzimage_setup + BZ_MBI_OFFSET) =3D eswap(mbi); if (!quiet) printf("Kernel entry is %p, MBI is %p.\n", entry, mbi); =20 /* Write out header and trampoline */ diff -r 28c822457019 -r b8dfe20a5b9d tools/misc/mbootpack/mbootpack.c --- a/tools/misc/mbootpack/mbootpack.c Mon Aug 29 22:48:06 2005 +++ b/tools/misc/mbootpack/mbootpack.c Mon Aug 29 22:52:56 2005 @@ -252,20 +252,21 @@ for (i =3D 0; i <=3D MIN(len - 12, MULTIBOOT_SEARCH - 12); i +=3D 4) { mbh =3D (struct multiboot_header *)(headerbuf + i); - if (mbh->magic !=3D MULTIBOOT_MAGIC=20 - || ((mbh->magic+mbh->flags+mbh->checksum) & 0xffffffff)) + if (eswap(mbh->magic) !=3D MULTIBOOT_MAGIC=20 + || ((eswap(mbh->magic)+eswap(mbh->flags)+eswap(mbh->checksum))= =20 + & 0xffffffff)) { /* Not a multiboot header */ continue; } - if (mbh->flags & MULTIBOOT_UNSUPPORTED) { + if (eswap(mbh->flags) & MULTIBOOT_UNSUPPORTED) { /* Requires options we don't support */ printf("Fatal: found a multiboot header, but it " "requires multiboot options that I\n" "don't understand. Sorry.\n"); exit(1); }=20 - if (mbh->flags & MULTIBOOT_VIDEO_MODE) {=20 + if (eswap(mbh->flags) & MULTIBOOT_VIDEO_MODE) {=20 /* Asked for screen mode information */ /* XXX carry on regardless */ printf("Warning: found a multiboot header which asks " @@ -275,22 +276,22 @@ } /* This kernel will do: place and load it */ =20 - if (mbh->flags & MULTIBOOT_AOUT_KLUDGE) { + if (eswap(mbh->flags) & MULTIBOOT_AOUT_KLUDGE) { =20 /* Load using the offsets in the multiboot header */ if(!quiet)=20 printf("Loading %s using multiboot header.\n", filename); =20 /* How much is there? */ - start =3D mbh->load_addr; =20 - if (mbh->load_end_addr !=3D 0)=20 - loadsize =3D mbh->load_end_addr - mbh->load_addr; + start =3D eswap(mbh->load_addr); =20 + if (eswap(mbh->load_end_addr) !=3D 0)=20 + loadsize =3D eswap(mbh->load_end_addr) - eswap(mbh->load_a= ddr); else=20 loadsize =3D sb.st_size; =20 /* How much memory will it take up? */=20 - if (mbh->bss_end_addr !=3D 0) - size =3D mbh->bss_end_addr - mbh->load_addr; + if (eswap(mbh->bss_end_addr) !=3D 0) + size =3D eswap(mbh->bss_end_addr) - eswap(mbh->load_addr); else size =3D loadsize; =20 @@ -335,32 +336,34 @@ =20 /* Done. */ if (!quiet) printf("Loaded kernel from %s\n", filename); - return mbh->entry_addr; + return eswap(mbh->entry_addr); =20 } else { =20 /* Now look for an ELF32 header */ =20 ehdr =3D (Elf32_Ehdr *)headerbuf; - if (*(unsigned long *)ehdr !=3D 0x464c457f=20 + if (*(unsigned long *)ehdr !=3D eswap(0x464c457f) || ehdr->e_ident[EI_DATA] !=3D ELFDATA2LSB || ehdr->e_ident[EI_CLASS] !=3D ELFCLASS32 - || ehdr->e_machine !=3D EM_386) + || eswap(ehdr->e_machine) !=3D EM_386) { printf("Fatal: kernel has neither ELF32/x86 nor multiboot = load" " headers.\n"); exit(1); } - if (ehdr->e_phoff + ehdr->e_phnum*sizeof(*phdr) > HEADERBUF_SI= ZE) { + if (eswap(ehdr->e_phoff) + eswap(ehdr->e_phnum)*sizeof(*phdr)= =20 + > HEADERBUF_SIZE) { /* Don't expect this will happen with sane kernels */ printf("Fatal: too much ELF for me. Try increasing " "HEADERBUF_SIZE in mbootpack.\n"); exit(1); } - if (ehdr->e_phoff + ehdr->e_phnum*sizeof (*phdr) > len) { + if (eswap(ehdr->e_phoff) + eswap(ehdr->e_phnum)*sizeof (*phdr)= =20 + > len) { printf("Fatal: malformed ELF header overruns EOF.\n"); exit(1); } - if (ehdr->e_phnum <=3D 0) { + if (eswap(ehdr->e_phnum) <=3D 0) { printf("Fatal: ELF kernel has no program headers.\n"); exit(1); } @@ -368,22 +371,22 @@ if(!quiet)=20 printf("Loading %s using ELF header.\n", filename); =20 - if (ehdr->e_type !=3D ET_EXEC=20 - || ehdr->e_version !=3D EV_CURRENT - || ehdr->e_phentsize !=3D sizeof (Elf32_Phdr)) { + if (eswap(ehdr->e_type) !=3D ET_EXEC=20 + || eswap(ehdr->e_version) !=3D EV_CURRENT + || eswap(ehdr->e_phentsize) !=3D sizeof (Elf32_Phdr)) { printf("Warning: funny-looking ELF header.\n"); } - phdr =3D (Elf32_Phdr *)(headerbuf + ehdr->e_phoff); + phdr =3D (Elf32_Phdr *)(headerbuf + eswap(ehdr->e_phoff)); =20 /* Obey the program headers to load the kernel */ - for(i =3D 0; i < ehdr->e_phnum; i++) { - - start =3D phdr[i].p_paddr; - size =3D phdr[i].p_memsz; - if (phdr[i].p_type !=3D PT_LOAD)=20 + for(i =3D 0; i < eswap(ehdr->e_phnum); i++) { + + start =3D eswap(phdr[i].p_paddr); + size =3D eswap(phdr[i].p_memsz); + if (eswap(phdr[i].p_type) !=3D PT_LOAD)=20 loadsize =3D 0; else=20 - loadsize =3D MIN((long int)phdr[i].p_filesz, size); + loadsize =3D MIN((long int)eswap(phdr[i].p_filesz), si= ze); =20 if ((buffer =3D malloc(size)) =3D=3D NULL) { printf("Fatal: malloc() for kernel load failed: %s\n", @@ -396,7 +399,7 @@ =20 /* Load section from file */=20 if (loadsize > 0) { - if (fseek(fp, phdr[i].p_offset, SEEK_SET) !=3D 0) { + if (fseek(fp, eswap(phdr[i].p_offset), SEEK_SET) !=3D = 0) { printf("Fatal: seek failed in %s\n", strerror(errno)); exit(1); @@ -452,7 +455,7 @@ =20 /* Done! */ if (!quiet) printf("Loaded kernel from %s\n", filename); - return ehdr->e_entry; + return eswap(ehdr->e_entry); } =20 } @@ -568,12 +571,12 @@ /* Command line */ p =3D (char *)(mbi + 1); sprintf(p, "%s %s", imagename, command_line); - mbi->cmdline =3D ((address_t)p) + mbi_reloc_offset; + mbi->cmdline =3D eswap(((address_t)p) + mbi_reloc_offset); p +=3D command_line_len; =20 /* Bootloader ID */ sprintf(p, version_string); - mbi->boot_loader_name =3D ((address_t)p) + mbi_reloc_offset; + mbi->boot_loader_name =3D eswap(((address_t)p) + mbi_reloc_offset); p +=3D strlen(version_string) + 1; =20 /* Next is space for the module command lines */ @@ -582,17 +585,17 @@ /* Last come the module info structs */ modp =3D (struct mod_list *) ((((address_t)p + mod_command_line_space) + 3) & ~3); - mbi->mods_count =3D modules; - mbi->mods_addr =3D ((address_t)modp) + mbi_reloc_offset; + mbi->mods_count =3D eswap(modules); + mbi->mods_addr =3D eswap(((address_t)modp) + mbi_reloc_offset); =20 /* Memory information will be added at boot time, by setup.S=20 * or trampoline.S. */ - mbi->flags =3D MB_INFO_CMDLINE | MB_INFO_BOOT_LOADER_NAME; + mbi->flags =3D eswap(MB_INFO_CMDLINE | MB_INFO_BOOT_LOADER_NAME); =20 =20 /* Load the modules */ if (modules) { - mbi->flags |=3D MB_INFO_MODS; + mbi->flags =3D eswap(eswap(mbi->flags) | MB_INFO_MODS); =20 /* Go back and parse the module command lines */ optind =3D opterr =3D 1; @@ -652,10 +655,10 @@ if (p !=3D NULL) *p =3D ' '; =20 /* Fill in the module info struct */ - modp->mod_start =3D start; - modp->mod_end =3D start + size; - modp->cmdline =3D (address_t)mod_clp + mbi_reloc_offset; - modp->pad =3D 0; + modp->mod_start =3D eswap(start); + modp->mod_end =3D eswap(start + size); + modp->cmdline =3D eswap((address_t)mod_clp + mbi_reloc_offset); + modp->pad =3D eswap(0); modp++; =20 /* Store the module command line */ diff -r 28c822457019 -r b8dfe20a5b9d tools/misc/mbootpack/mbootpack.h --- a/tools/misc/mbootpack/mbootpack.h Mon Aug 29 22:48:06 2005 +++ b/tools/misc/mbootpack/mbootpack.h Mon Aug 29 22:52:56 2005 @@ -31,6 +31,24 @@ =20 #undef NDEBUG #include + +#include +#include +#if __BYTE_ORDER =3D=3D __LITTLE_ENDIAN +#define eswap(x) (x) +#else=20 +#define eswap(x) \ + ({ \ + typeof(x) y =3D (x); \ + switch(sizeof(y)) \ + { \ + case 2: y =3D __bswap_16(y); break; \ + case 4: y =3D __bswap_32(y); break; \ + case 8: y =3D __bswap_64(y); break; \ + } \ + y; \ + })=09 +#endif =09 =20 /* Flags */ extern int quiet; --Signature_Tue__30_Aug_2005_08_24_28_-0400_Ua6kRxX6YbiSurXK Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.5 (GNU/Linux) iD8DBQFDFE/8DMDCqU5zPMARAjR5AJ9bV5FIoM4uQ8KQFHBUPXma923bJwCffU/1 eAdOxQ0jTm9MPjUk89KKiFk= =wHxN -----END PGP SIGNATURE----- --Signature_Tue__30_Aug_2005_08_24_28_-0400_Ua6kRxX6YbiSurXK-- --===============0369859224== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --===============0369859224==--