2 * Copyright (C) Paul Mackerras 1997.
4 * Updates for PPC64 by Todd Inglett, Dave Engebretsen & Peter Bergner.
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
18 int parse_elf64(void *hdr
, struct elf_info
*info
)
20 Elf64_Ehdr
*elf64
= hdr
;
24 if (!(elf64
->e_ident
[EI_MAG0
] == ELFMAG0
&&
25 elf64
->e_ident
[EI_MAG1
] == ELFMAG1
&&
26 elf64
->e_ident
[EI_MAG2
] == ELFMAG2
&&
27 elf64
->e_ident
[EI_MAG3
] == ELFMAG3
&&
28 elf64
->e_ident
[EI_CLASS
] == ELFCLASS64
&&
29 elf64
->e_ident
[EI_DATA
] == ELFDATA2MSB
&&
30 elf64
->e_type
== ET_EXEC
&&
31 elf64
->e_machine
== EM_PPC64
))
34 elf64ph
= (Elf64_Phdr
*)((unsigned long)elf64
+
35 (unsigned long)elf64
->e_phoff
);
36 for (i
= 0; i
< (unsigned int)elf64
->e_phnum
; i
++, elf64ph
++)
37 if (elf64ph
->p_type
== PT_LOAD
)
39 if (i
>= (unsigned int)elf64
->e_phnum
)
42 info
->loadsize
= (unsigned long)elf64ph
->p_filesz
;
43 info
->memsize
= (unsigned long)elf64ph
->p_memsz
;
44 info
->elfoffset
= (unsigned long)elf64ph
->p_offset
;
49 int parse_elf32(void *hdr
, struct elf_info
*info
)
51 Elf32_Ehdr
*elf32
= hdr
;
55 if (!(elf32
->e_ident
[EI_MAG0
] == ELFMAG0
&&
56 elf32
->e_ident
[EI_MAG1
] == ELFMAG1
&&
57 elf32
->e_ident
[EI_MAG2
] == ELFMAG2
&&
58 elf32
->e_ident
[EI_MAG3
] == ELFMAG3
&&
59 elf32
->e_ident
[EI_CLASS
] == ELFCLASS32
&&
60 elf32
->e_ident
[EI_DATA
] == ELFDATA2MSB
&&
61 elf32
->e_type
== ET_EXEC
&&
62 elf32
->e_machine
== EM_PPC
))
65 elf32ph
= (Elf32_Phdr
*) ((unsigned long)elf32
+ elf32
->e_phoff
);
66 for (i
= 0; i
< elf32
->e_phnum
; i
++, elf32ph
++)
67 if (elf32ph
->p_type
== PT_LOAD
)
69 if (i
>= elf32
->e_phnum
)
72 info
->loadsize
= elf32ph
->p_filesz
;
73 info
->memsize
= elf32ph
->p_memsz
;
74 info
->elfoffset
= elf32ph
->p_offset
;