Elf to memory image for simulation

0

I am writing a C++ simulation model of Sparc V8. Memory is modelled simply as an array. I need to read an elf-executable generated by a cross compiler and use it to initialise the memory. I am planning to do it as follows.

sparc-elf-readelf --hex-dump=.text --hex-dump=.rodata --hex-dump=.data <elf-file> > dump.txt
grep "0x" dump.txt >dump2.txt

This produces an (address, word, word word) format text file that looks like this:

  0x00000000 88100000 09000000 81c120b0 01000000 .......... .....
  0x00000010 91d02000 01000000 01000000 01000000 .. .............
  0x00000020 91d02000 01000000 01000000 01000000 .. .............
  0x00000030 91d02000 01000000 01000000 01000000 .. .............
  0x00000040 91d02000 01000000 01000000 01000000 .. .............
  0x00000050 a1480000 29000000 81c521a8 01000000 .H..).....!.....
  0x00000060 a1480000 29000000 81c52220 01000000 .H..)....." ....
  0x00000070 91d02000 01000000 01000000 01000000 .. .............
  ...

Q: What are all the dots in the last column?

Q: Is there a better way to generate a memory image from the elf executable? I think I need to copy only the .text, .rodata and .data sections

thanks for any suggestions

simulation
elf
readelf

1 Answer

2

Q: What are all the dots in the last column?

As Ernest says, they are unprintable characters. That is, each one is a byte that does not fit in 7 bits (not ASCII) or it is lower than 0x20 (control ASCII character).

Q: Is there a better way to generate a memory image from the elf executable? I think I need to copy only the .text, .rodata and .data sections

Your approach will simply not work. The ELF format is not just about providing information about where sections will go in memory; it also contains instructions for resolving dynamic symbols and relocations. What you need, is a memory image after the loader activities has taken place.

I suggest you read the ELF specification and the addendum applicable to SPARC. If you are not embarking into this project for just educational purposes, I also suggest you rather use any of the existing platform and application emulators like QEMU .


User contributions licensed under CC BY-SA 3.0