direct-io.hg

changeset 3913:8a3a22b2096e

bitkeeper revision 1.1236.1.13 (421dacedhaZlzbC4_CN6lMN85qerFQ)

Merge scramble.cl.cam.ac.uk:/local/scratch/kaf24/xen-2.0-testing.bk
into scramble.cl.cam.ac.uk:/local/scratch/kaf24/xen-unstable.bk
author kaf24@scramble.cl.cam.ac.uk
date Thu Feb 24 10:31:09 2005 +0000 (2005-02-24)
parents 2d1350c497e9 ef622cae68c4
children 9a7751095472
files xen/arch/x86/boot/mkelf32.c
line diff
     1.1 --- a/xen/arch/x86/boot/mkelf32.c	Thu Feb 24 09:47:42 2005 +0000
     1.2 +++ b/xen/arch/x86/boot/mkelf32.c	Thu Feb 24 10:31:09 2005 +0000
     1.3 @@ -107,6 +107,94 @@ static Elf32_Shdr out_shdr[] = {
     1.4      }
     1.5  };
     1.6  
     1.7 +#define swap16(_v) ((((u16)(_v)>>8)&0xff)|(((u16)(_v)&0xff)<<8))
     1.8 +#define swap32(_v) (((u32)swap16((u16)(_v))<<16)|(u32)swap16((u32)((_v)>>16)))
     1.9 +#define swap64(_v) (((u64)swap32((u32)(_v))<<32)|(u64)swap32((u32)((_v)>>32)))
    1.10 +
    1.11 +static int big_endian;
    1.12 +
    1.13 +static void endianadjust_ehdr32(Elf32_Ehdr *eh)
    1.14 +{
    1.15 +    if ( !big_endian )
    1.16 +        return;
    1.17 +    eh->e_type      = swap16(eh->e_type);
    1.18 +    eh->e_machine   = swap16(eh->e_machine);
    1.19 +    eh->e_version   = swap32(eh->e_version);
    1.20 +    eh->e_entry     = swap32(eh->e_entry);
    1.21 +    eh->e_phoff     = swap32(eh->e_phoff);
    1.22 +    eh->e_shoff     = swap32(eh->e_shoff);
    1.23 +    eh->e_flags     = swap32(eh->e_flags);
    1.24 +    eh->e_ehsize    = swap16(eh->e_ehsize);
    1.25 +    eh->e_phentsize = swap16(eh->e_phentsize);
    1.26 +    eh->e_phnum     = swap16(eh->e_phnum);
    1.27 +    eh->e_shentsize = swap16(eh->e_shentsize);
    1.28 +    eh->e_shnum     = swap16(eh->e_shnum);
    1.29 +    eh->e_shstrndx  = swap16(eh->e_shstrndx);
    1.30 +}
    1.31 +
    1.32 +static void endianadjust_ehdr64(Elf64_Ehdr *eh)
    1.33 +{
    1.34 +    if ( !big_endian )
    1.35 +        return;
    1.36 +    eh->e_type      = swap16(eh->e_type);
    1.37 +    eh->e_machine   = swap16(eh->e_machine);
    1.38 +    eh->e_version   = swap32(eh->e_version);
    1.39 +    eh->e_entry     = swap64(eh->e_entry);
    1.40 +    eh->e_phoff     = swap64(eh->e_phoff);
    1.41 +    eh->e_shoff     = swap64(eh->e_shoff);
    1.42 +    eh->e_flags     = swap32(eh->e_flags);
    1.43 +    eh->e_ehsize    = swap16(eh->e_ehsize);
    1.44 +    eh->e_phentsize = swap16(eh->e_phentsize);
    1.45 +    eh->e_phnum     = swap16(eh->e_phnum);
    1.46 +    eh->e_shentsize = swap16(eh->e_shentsize);
    1.47 +    eh->e_shnum     = swap16(eh->e_shnum);
    1.48 +    eh->e_shstrndx  = swap16(eh->e_shstrndx);
    1.49 +}
    1.50 +
    1.51 +static void endianadjust_phdr32(Elf32_Phdr *ph)
    1.52 +{
    1.53 +    if ( !big_endian )
    1.54 +        return;
    1.55 +    ph->p_type      = swap32(ph->p_type);
    1.56 +    ph->p_offset    = swap32(ph->p_offset);
    1.57 +    ph->p_vaddr     = swap32(ph->p_vaddr);
    1.58 +    ph->p_paddr     = swap32(ph->p_paddr);
    1.59 +    ph->p_filesz    = swap32(ph->p_filesz);
    1.60 +    ph->p_memsz     = swap32(ph->p_memsz);
    1.61 +    ph->p_flags     = swap32(ph->p_flags);
    1.62 +    ph->p_align     = swap32(ph->p_align);       
    1.63 +}
    1.64 +
    1.65 +static void endianadjust_phdr64(Elf64_Phdr *ph)
    1.66 +{
    1.67 +    if ( !big_endian )
    1.68 +        return;
    1.69 +    ph->p_type      = swap32(ph->p_type);
    1.70 +    ph->p_flags     = swap32(ph->p_flags);
    1.71 +    ph->p_offset    = swap64(ph->p_offset);
    1.72 +    ph->p_vaddr     = swap64(ph->p_vaddr);
    1.73 +    ph->p_paddr     = swap64(ph->p_paddr);
    1.74 +    ph->p_filesz    = swap64(ph->p_filesz);
    1.75 +    ph->p_memsz     = swap64(ph->p_memsz);
    1.76 +    ph->p_align     = swap64(ph->p_align);       
    1.77 +}
    1.78 +
    1.79 +static void endianadjust_shdr32(Elf32_Shdr *sh)
    1.80 +{
    1.81 +    if ( !big_endian )
    1.82 +        return;
    1.83 +    sh->sh_name     = swap32(sh->sh_name);
    1.84 +    sh->sh_type     = swap32(sh->sh_type);
    1.85 +    sh->sh_flags    = swap32(sh->sh_flags);
    1.86 +    sh->sh_addr     = swap32(sh->sh_addr);
    1.87 +    sh->sh_offset   = swap32(sh->sh_offset);
    1.88 +    sh->sh_size     = swap32(sh->sh_size);
    1.89 +    sh->sh_link     = swap32(sh->sh_link);
    1.90 +    sh->sh_info     = swap32(sh->sh_info);
    1.91 +    sh->sh_addralign = swap32(sh->sh_addralign);
    1.92 +    sh->sh_entsize  = swap32(sh->sh_entsize);
    1.93 +}
    1.94 +
    1.95  static void do_write(int fd, void *data, int len)
    1.96  {
    1.97      int   done, left = len;
    1.98 @@ -155,7 +243,7 @@ int main(int argc, char **argv)
    1.99      char      *inimage, *outimage;
   1.100      int        infd, outfd;
   1.101      char       buffer[1024];
   1.102 -    int        bytes, todo;
   1.103 +    int        bytes, todo, i;
   1.104  
   1.105      Elf32_Ehdr in32_ehdr;
   1.106      Elf32_Phdr in32_phdr;
   1.107 @@ -189,6 +277,9 @@ int main(int argc, char **argv)
   1.108          return 1;
   1.109      }
   1.110  
   1.111 +    big_endian = (*(u16 *)in32_ehdr.e_ident == ((ELFMAG0 << 8) | ELFMAG1));
   1.112 +
   1.113 +    endianadjust_ehdr32(&in32_ehdr);
   1.114      switch ( in32_ehdr.e_ident[EI_CLASS] )
   1.115      {
   1.116      case ELFCLASS32:
   1.117 @@ -208,6 +299,7 @@ int main(int argc, char **argv)
   1.118  
   1.119          (void)lseek(infd, in32_ehdr.e_phoff, SEEK_SET);
   1.120          do_read(infd, &in32_phdr, sizeof(in32_phdr));
   1.121 +        endianadjust_phdr32(&in32_phdr);
   1.122  
   1.123          (void)lseek(infd, in32_phdr.p_offset, SEEK_SET);
   1.124          dat_siz = (u32)in32_phdr.p_filesz;
   1.125 @@ -217,6 +309,7 @@ int main(int argc, char **argv)
   1.126      case ELFCLASS64:
   1.127          (void)lseek(infd, 0, SEEK_SET);
   1.128          do_read(infd, &in64_ehdr, sizeof(in64_ehdr));
   1.129 +        endianadjust_ehdr64(&in64_ehdr);
   1.130  
   1.131          if ( in64_ehdr.e_phentsize != sizeof(in64_phdr) )
   1.132          {
   1.133 @@ -234,6 +327,7 @@ int main(int argc, char **argv)
   1.134  
   1.135          (void)lseek(infd, in64_ehdr.e_phoff, SEEK_SET);
   1.136          do_read(infd, &in64_phdr, sizeof(in64_phdr));
   1.137 +        endianadjust_phdr64(&in64_phdr);
   1.138  
   1.139          (void)lseek(infd, in64_phdr.p_offset, SEEK_SET);
   1.140          dat_siz = (u32)in64_phdr.p_filesz;
   1.141 @@ -271,7 +365,10 @@ int main(int argc, char **argv)
   1.142          return 1;
   1.143      }
   1.144  
   1.145 +    endianadjust_ehdr32(&out_ehdr);
   1.146      do_write(outfd, &out_ehdr, sizeof(out_ehdr));
   1.147 +
   1.148 +    endianadjust_phdr32(&out_phdr);
   1.149      do_write(outfd, &out_phdr, sizeof(out_phdr));
   1.150      
   1.151      if ( (bytes = RAW_OFFSET - sizeof(out_ehdr) - sizeof(out_phdr)) < 0 )
   1.152 @@ -289,7 +386,10 @@ int main(int argc, char **argv)
   1.153          do_write(outfd, buffer, todo);
   1.154      }
   1.155  
   1.156 +    for ( i = 0; i < (sizeof(out_shdr) / sizeof(out_shdr[0])); i++ )
   1.157 +        endianadjust_shdr32(&out_shdr[i]);
   1.158      do_write(outfd, &out_shdr[0], sizeof(out_shdr));
   1.159 +
   1.160      do_write(outfd, out_shstrtab, sizeof(out_shstrtab));
   1.161      do_write(outfd, buffer, 4-((sizeof(out_shstrtab)+dat_siz)&3));
   1.162  
   1.163 @@ -298,3 +398,12 @@ int main(int argc, char **argv)
   1.164  
   1.165      return 0;
   1.166  }
   1.167 +
   1.168 +/*
   1.169 + * Local variables:
   1.170 + * mode: C
   1.171 + * c-set-style: "BSD"
   1.172 + * c-basic-offset: 4
   1.173 + * tab-width: 4
   1.174 + * indent-tabs-mode: nil
   1.175 + */