direct-io.hg

changeset 14419:5a198ae89051

hvmloader: More simplification of highmem bios relocation code.
Signed-off-by: Keir Fraser <keir@xensource.com>
author Keir Fraser <keir@xensource.com>
date Fri Mar 16 23:56:26 2007 +0000 (2007-03-16)
parents cf32c9e54c8f
children 0e0fdba35503
files tools/firmware/hvmloader/32bitbios_support.c tools/firmware/hvmloader/util.h
line diff
     1.1 --- a/tools/firmware/hvmloader/32bitbios_support.c	Fri Mar 16 23:34:24 2007 +0000
     1.2 +++ b/tools/firmware/hvmloader/32bitbios_support.c	Fri Mar 16 23:56:26 2007 +0000
     1.3 @@ -31,18 +31,15 @@
     1.4  #include "../rombios/32bit/jumptable.h"
     1.5  
     1.6  /* Relocate ELF file of type ET_REL */
     1.7 -static int relocate_elf(char *elfarray)
     1.8 +static void relocate_elf(char *elfarray)
     1.9  {
    1.10      Elf32_Ehdr *ehdr = (Elf32_Ehdr *)elfarray;
    1.11      Elf32_Shdr *shdr = (Elf32_Shdr *)&elfarray[ehdr->e_shoff];
    1.12 -    int i;
    1.13 -
    1.14 -    if ( ehdr->e_type != ET_REL )
    1.15 -    {
    1.16 -        printf("Not a relocatable BIOS object file. Has type %d, need %d\n",
    1.17 -               ehdr->e_type, ET_REL);
    1.18 -        return -1;
    1.19 -    }
    1.20 +    Elf32_Sym  *syms, *sym;
    1.21 +    Elf32_Rel  *rels;
    1.22 +    char       *code;
    1.23 +    uint32_t   *loc, fix;
    1.24 +    int i, j;
    1.25  
    1.26      for ( i = 0; i < ehdr->e_shnum; i++ )
    1.27          shdr[i].sh_addr = (Elf32_Addr)&elfarray[shdr[i].sh_offset];
    1.28 @@ -50,43 +47,33 @@ static int relocate_elf(char *elfarray)
    1.29      for ( i = 0; i < ehdr->e_shnum; i++ )
    1.30      {
    1.31          if ( shdr[i].sh_type == SHT_RELA )
    1.32 -            return -2;
    1.33 -
    1.34 -        if ( shdr[i].sh_type == SHT_REL )
    1.35 -        {
    1.36 -            Elf32_Shdr *targetsec = (Elf32_Shdr *)&(shdr[shdr[i].sh_info]);
    1.37 -            Elf32_Shdr *symtabsec = (Elf32_Shdr *)&(shdr[shdr[i].sh_link]);
    1.38 -            Elf32_Sym  *syms      = (Elf32_Sym *)symtabsec->sh_addr;
    1.39 -            Elf32_Rel  *rels      = (Elf32_Rel *)shdr[i].sh_addr;
    1.40 -            char *code            = (char *)targetsec->sh_addr;
    1.41 -            int j;
    1.42 -
    1.43 -            /* must not have been stripped */
    1.44 -            if ( shdr[i].sh_size == 0 )
    1.45 -                return -6;
    1.46 +            printf("Unsupported section type SHT_RELA\n");
    1.47  
    1.48 -            for ( j = 0; j < shdr[i].sh_size / sizeof(Elf32_Rel); j++ )
    1.49 -            {
    1.50 -                int idx           = ELF32_R_SYM(rels[j].r_info);
    1.51 -                Elf32_Sym *symbol = &syms[idx];
    1.52 -                uint32_t *loc     = (uint32_t *)&code[rels[j].r_offset];
    1.53 -                uint32_t fix      = shdr[symbol->st_shndx].sh_addr +
    1.54 -                                    symbol->st_value;
    1.55 +        if ( shdr[i].sh_type != SHT_REL )
    1.56 +            continue;
    1.57  
    1.58 -                switch ( ELF32_R_TYPE(rels[j].r_info) )
    1.59 -                {
    1.60 -                    case R_386_PC32:
    1.61 -                        *loc += (fix - (uint32_t)loc);
    1.62 -                    break;
    1.63 +        syms = (Elf32_Sym *)shdr[shdr[i].sh_link].sh_addr;
    1.64 +        rels = (Elf32_Rel *)shdr[i].sh_addr;
    1.65 +        code = (char      *)shdr[shdr[i].sh_info].sh_addr;
    1.66  
    1.67 -                    case R_386_32:
    1.68 -                        *loc += fix;
    1.69 -                    break;
    1.70 -                }
    1.71 +        for ( j = 0; j < shdr[i].sh_size / sizeof(Elf32_Rel); j++ )
    1.72 +        {
    1.73 +            sym = &syms[ELF32_R_SYM(rels[j].r_info)];
    1.74 +            loc = (uint32_t *)&code[rels[j].r_offset];
    1.75 +            fix = shdr[sym->st_shndx].sh_addr + sym->st_value;
    1.76 +
    1.77 +            switch ( ELF32_R_TYPE(rels[j].r_info) )
    1.78 +            {
    1.79 +            case R_386_PC32:
    1.80 +                *loc += fix - (uint32_t)loc;
    1.81 +                break;
    1.82 +
    1.83 +            case R_386_32:
    1.84 +                *loc += fix;
    1.85 +                break;
    1.86              }
    1.87          }
    1.88      }
    1.89 -    return 0;
    1.90  }
    1.91  
    1.92  /* Scan the rombios for the destination of the jump table. */
    1.93 @@ -97,27 +84,21 @@ static char *get_jump_table_start(void)
    1.94      for ( bios_mem = (char *)ROMBIOS_BEGIN;
    1.95            bios_mem != (char *)ROMBIOS_END;
    1.96            bios_mem++ )
    1.97 -    {
    1.98 -        if ( strncmp(bios_mem, "___JMPT", 7) == 0 )
    1.99 +        if ( !strncmp(bios_mem, "___JMPT", 7) )
   1.100              return bios_mem;
   1.101 -    }
   1.102  
   1.103      return NULL;
   1.104  }
   1.105  
   1.106  /* Copy relocated jumptable into the rombios. */
   1.107 -static int copy_jumptable(char *elfarray)
   1.108 +static void copy_jumptable(char *elfarray)
   1.109  {
   1.110      Elf32_Ehdr *ehdr = (Elf32_Ehdr *)elfarray;
   1.111      Elf32_Shdr *shdr = (Elf32_Shdr *)&elfarray[ehdr->e_shoff];
   1.112 -    Elf32_Shdr *shdr_strings = (Elf32_Shdr *)&shdr[ehdr->e_shstrndx];
   1.113 -    char *secstrings = (char *)&elfarray[shdr_strings->sh_offset];
   1.114 -    uint32_t *rombiosjumptable = (uint32_t *)get_jump_table_start();
   1.115 +    char *secstrings = &elfarray[shdr[ehdr->e_shstrndx].sh_offset];
   1.116 +    char *jump_table = get_jump_table_start();
   1.117      int i;
   1.118  
   1.119 -    if ( rombiosjumptable == NULL )
   1.120 -        return -3;
   1.121 -
   1.122      /* Find the section with the jump table and copy to lower BIOS memory. */
   1.123      for ( i = 0; i < ehdr->e_shnum; i++ )
   1.124          if ( !strcmp(JUMPTABLE_SECTION_NAME, secstrings + shdr[i].sh_name) )
   1.125 @@ -126,38 +107,39 @@ static int copy_jumptable(char *elfarray
   1.126      if ( i == ehdr->e_shnum )
   1.127      {
   1.128          printf("Could not find " JUMPTABLE_SECTION_NAME " section in file.\n");
   1.129 -        return -4;
   1.130 +        return;
   1.131      }
   1.132  
   1.133 -    memcpy(rombiosjumptable, (uint32_t *)shdr[i].sh_addr, shdr[i].sh_size);
   1.134 +    if ( jump_table == NULL )
   1.135 +    {
   1.136 +        printf("Could not find jump table in file.\n");
   1.137 +        return;
   1.138 +    }
   1.139  
   1.140 -    return 0;
   1.141 +    memcpy(jump_table, (char *)shdr[i].sh_addr, shdr[i].sh_size);
   1.142  }
   1.143  
   1.144 -static int relocate_32bitbios(char *elfarray, uint32_t elfarraysize)
   1.145 +static void relocate_32bitbios(char *elfarray, uint32_t elfarraysize)
   1.146  {
   1.147      uint32_t mask = (64 * 1024) - 1;
   1.148      char *highbiosarea;
   1.149 -    int rc;
   1.150  
   1.151      highbiosarea = (char *)(long)
   1.152          e820_malloc((elfarraysize + mask) & ~mask, /* round to 64kb */
   1.153                      E820_RESERVED,
   1.154                      (uint64_t)0xffffffff);
   1.155 -
   1.156      if ( highbiosarea == NULL )
   1.157 -        return -5;
   1.158 +    {
   1.159 +        printf("No available memory for BIOS high memory area\n");
   1.160 +        return;
   1.161 +    }
   1.162  
   1.163      memcpy(highbiosarea, elfarray, elfarraysize);
   1.164 -    rc = relocate_elf(highbiosarea);
   1.165 -    if ( rc == 0 )
   1.166 -        rc = copy_jumptable(highbiosarea);
   1.167 -
   1.168 -    return rc;
   1.169 +    relocate_elf(highbiosarea);
   1.170 +    copy_jumptable(highbiosarea);
   1.171  }
   1.172  
   1.173 -int highbios_setup(void)
   1.174 +void highbios_setup(void)
   1.175  {
   1.176 -    return relocate_32bitbios((char *)highbios_array,
   1.177 -                              sizeof(highbios_array));
   1.178 +    relocate_32bitbios((char *)highbios_array, sizeof(highbios_array));
   1.179  }
     2.1 --- a/tools/firmware/hvmloader/util.h	Fri Mar 16 23:34:24 2007 +0000
     2.2 +++ b/tools/firmware/hvmloader/util.h	Fri Mar 16 23:56:26 2007 +0000
     2.3 @@ -88,7 +88,7 @@ uint64_t e820_malloc(uint64_t size, uint
     2.4  #define E820_MAP    ((struct e820entry *)(E820_MAP_PAGE + E820_MAP_OFFSET))
     2.5  
     2.6  /* Prepare the 32bit BIOS */
     2.7 -int highbios_setup(void);
     2.8 +void highbios_setup(void);
     2.9  
    2.10  #define isdigit(c) ((c) >= '0' && (c) <= '9')
    2.11