Merge tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost
[cris-mirror.git] / arch / powerpc / boot / elf_util.c
blob316552dea4d8c20e5b279ecde40f8d1e81ffee37
1 /*
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.
11 #include <stdarg.h>
12 #include <stddef.h>
13 #include "elf.h"
14 #include "page.h"
15 #include "string.h"
16 #include "stdio.h"
18 int parse_elf64(void *hdr, struct elf_info *info)
20 Elf64_Ehdr *elf64 = hdr;
21 Elf64_Phdr *elf64ph;
22 unsigned int i;
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 #ifdef __LITTLE_ENDIAN__
30 elf64->e_ident[EI_DATA] == ELFDATA2LSB &&
31 #else
32 elf64->e_ident[EI_DATA] == ELFDATA2MSB &&
33 #endif
34 (elf64->e_type == ET_EXEC ||
35 elf64->e_type == ET_DYN) &&
36 elf64->e_machine == EM_PPC64))
37 return 0;
39 elf64ph = (Elf64_Phdr *)((unsigned long)elf64 +
40 (unsigned long)elf64->e_phoff);
41 for (i = 0; i < (unsigned int)elf64->e_phnum; i++, elf64ph++)
42 if (elf64ph->p_type == PT_LOAD)
43 break;
44 if (i >= (unsigned int)elf64->e_phnum)
45 return 0;
47 info->loadsize = (unsigned long)elf64ph->p_filesz;
48 info->memsize = (unsigned long)elf64ph->p_memsz;
49 info->elfoffset = (unsigned long)elf64ph->p_offset;
51 return 1;
54 int parse_elf32(void *hdr, struct elf_info *info)
56 Elf32_Ehdr *elf32 = hdr;
57 Elf32_Phdr *elf32ph;
58 unsigned int i;
60 if (!(elf32->e_ident[EI_MAG0] == ELFMAG0 &&
61 elf32->e_ident[EI_MAG1] == ELFMAG1 &&
62 elf32->e_ident[EI_MAG2] == ELFMAG2 &&
63 elf32->e_ident[EI_MAG3] == ELFMAG3 &&
64 elf32->e_ident[EI_CLASS] == ELFCLASS32 &&
65 elf32->e_ident[EI_DATA] == ELFDATA2MSB &&
66 (elf32->e_type == ET_EXEC ||
67 elf32->e_type == ET_DYN) &&
68 elf32->e_machine == EM_PPC))
69 return 0;
71 elf32ph = (Elf32_Phdr *) ((unsigned long)elf32 + elf32->e_phoff);
72 for (i = 0; i < elf32->e_phnum; i++, elf32ph++)
73 if (elf32ph->p_type == PT_LOAD)
74 break;
75 if (i >= elf32->e_phnum)
76 return 0;
78 info->loadsize = elf32ph->p_filesz;
79 info->memsize = elf32ph->p_memsz;
80 info->elfoffset = elf32ph->p_offset;
81 return 1;