Advertisement
Guest User

Untitled

a guest
Nov 11th, 2015
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 1.64 KB | None | 0 0
  1. diff --git a/cores/elf-loader/elf-loader.c b/cores/elf-loader/elf-loader.c
  2. index e11aa55..a5ca2e3 100644
  3. --- a/cores/elf-loader/elf-loader.c
  4. +++ b/cores/elf-loader/elf-loader.c
  5. @@ -26,6 +26,8 @@
  6.  #include <gelf.h>
  7.  #include <fcntl.h>
  8.  
  9. +uint8_t big_endian;
  10. +
  11.  uint8_t *dump_program_data(Elf *elf_object, int *size)
  12.  {
  13.     uint8_t *buffer = NULL;
  14. @@ -132,6 +134,7 @@ uint8_t *dump_section_data(Elf *elf_object, int *size)
  15.  uint8_t *load_elf_file(char *elf_file_name, int *size)
  16.  {
  17.     uint8_t *buf = NULL;
  18. +   char *id;
  19.  
  20.     if (elf_version(EV_CURRENT) == EV_NONE)
  21.         return NULL;
  22. @@ -156,6 +159,21 @@ uint8_t *load_elf_file(char *elf_file_name, int *size)
  23.         return NULL;
  24.     }
  25.  
  26. +   if (( id = elf_getident (elf_object , NULL )) == NULL )
  27. +       printf (" getident () failed : % s . " ,
  28. +       elf_errmsg ( -1));
  29. +
  30. +   if (id[EI_DATA] == ELFDATA2LSB)
  31. +       big_endian = 0;
  32. +   else if (id[EI_DATA] == ELFDATA2MSB)
  33. +       big_endian = 1;
  34. +   else {
  35. +       printf("%s has unknown endianness '%d'\n", elf_file_name, id[EI_DATA]);
  36. +       elf_end(elf_object);
  37. +       close(fd);
  38. +       return NULL;
  39. +   }
  40. +
  41.     buf = dump_program_data(elf_object, size);
  42.  
  43.     if (buf == NULL)
  44. @@ -169,8 +187,12 @@ uint8_t *load_elf_file(char *elf_file_name, int *size)
  45.  
  46.  unsigned int read_32(uint8_t *bin_file, unsigned int address)
  47.  {
  48. +  if(big_endian)
  49.     return (bin_file[address] << 24) | (bin_file[address + 1] << 16) |
  50.            (bin_file[address + 2] << 8) | (bin_file[address + 3]);
  51. +  else
  52. +   return (bin_file[address+3] << 24) | (bin_file[address + 2] << 16) |
  53. +          (bin_file[address + 1] << 8) | (bin_file[address + 0]);
  54.  }
  55.  
  56.  unsigned short read_16(uint8_t *bin_file, unsigned int address)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement