This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
ELF, Program Header, convert virtual addresses to physical addresses
- From: Torsten Mohr <tmohr at s dot netic dot de>
- To: binutils at sources dot redhat dot com
- Date: Thu, 18 Aug 2005 19:32:58 +0200
- Subject: ELF, Program Header, convert virtual addresses to physical addresses
Hi,
i try to convert virtual addresses in an ELF file to
physical addresses, all based on the program header
entries with p_type == PT_LOAD.
Such an entry has its members:
p_vaddr
p_paddr
p_filesz
p_memsz
If i have a virtual address X, how do i convert it to
a valid physical address?
I think i first need to check if :
p_vaddr <= X < p_vaddr + p_memsz
Is that correct (especially the bounds)?
My first try to get the physical address P then was:
P = X - p_vaddr + p_paddr
But that failed badly on an ELF file generated by a Greenhills
toolchain for a NEC V850 and its program headers:
readelf -l file.elf:
Program Headers:
Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
LOAD 0x000240 0x00000000 0x00000000 0x00594 0x00594 R E 0
LOAD 0x000840 0x00000600 0x00000000 0x00010 0x00010 R E 0
LOAD 0x000850 0x00000610 0x00000000 0x00010 0x00010 R E 0
LOAD 0x000860 0x00000620 0x00000000 0x00040 0x00040 R E 0
LOAD 0x0008a0 0x00000660 0x00000000 0x070b8 0x070b8 R E 0
LOAD 0x007958 0x00007718 0x00000000 0x007b4 0x007b4 R E 0
LOAD 0x008190 0x00007ecc 0x00000000 0x000b0 0x000b0 R E 0
LOAD 0x00810c 0x00007f7c 0x00000000 0x0001c 0x0001c R E 0
LOAD 0x008128 0x00007f98 0x00000000 0x00007 0x00007 R E 0
LOAD 0x008130 0x00007fa0 0x00000000 0x00006 0x00006 R E 0
LOAD 0x008138 0x00007fa8 0x00000000 0x00054 0x00054 R E 0
LOAD 0x00818c 0x00007ffc 0x00000000 0x00004 0x00004 R E 0
LOAD 0x000000 0xffffa000 0x00000000 0x00000 0x000b0 RWE 0
LOAD 0x000000 0xffffa0b0 0x00000000 0x00000 0x0093c RWE 0
LOAD 0x000000 0xffffa9ec 0x00000000 0x00000 0x00400 RWE 0
LOAD 0x000000 0xffffadf0 0x00000000 0x00000 0x00f00 RWE 0
So now i calculate P like this:
P = X + p_paddr
Is this correct? From the ELF specification i did not get much
useful information.
It would be great if anybody could give me a hint here.
Best regards,
Torsten.