linux/arch/powerpc/boot/elf.h
<<
>>
Prefs
   1/* SPDX-License-Identifier: GPL-2.0 */
   2#ifndef _PPC_BOOT_ELF_H_
   3#define _PPC_BOOT_ELF_H_
   4
   5/* 32-bit ELF base types. */
   6typedef unsigned int Elf32_Addr;
   7typedef unsigned short Elf32_Half;
   8typedef unsigned int Elf32_Off;
   9typedef signed int Elf32_Sword;
  10typedef unsigned int Elf32_Word;
  11
  12/* 64-bit ELF base types. */
  13typedef unsigned long long Elf64_Addr;
  14typedef unsigned short Elf64_Half;
  15typedef signed short Elf64_SHalf;
  16typedef unsigned long long Elf64_Off;
  17typedef signed int Elf64_Sword;
  18typedef unsigned int Elf64_Word;
  19typedef unsigned long long Elf64_Xword;
  20typedef signed long long Elf64_Sxword;
  21
  22/* These constants are for the segment types stored in the image headers */
  23#define PT_NULL    0
  24#define PT_LOAD    1
  25#define PT_DYNAMIC 2
  26#define PT_INTERP  3
  27#define PT_NOTE    4
  28#define PT_SHLIB   5
  29#define PT_PHDR    6
  30#define PT_TLS     7            /* Thread local storage segment */
  31#define PT_LOOS    0x60000000   /* OS-specific */
  32#define PT_HIOS    0x6fffffff   /* OS-specific */
  33#define PT_LOPROC  0x70000000
  34#define PT_HIPROC  0x7fffffff
  35#define PT_GNU_EH_FRAME         0x6474e550
  36
  37#define PT_GNU_STACK    (PT_LOOS + 0x474e551)
  38
  39/* These constants define the different elf file types */
  40#define ET_NONE   0
  41#define ET_REL    1
  42#define ET_EXEC   2
  43#define ET_DYN    3
  44#define ET_CORE   4
  45#define ET_LOPROC 0xff00
  46#define ET_HIPROC 0xffff
  47
  48/* These constants define the various ELF target machines */
  49#define EM_NONE  0
  50#define EM_PPC         20       /* PowerPC */
  51#define EM_PPC64       21       /* PowerPC64 */
  52
  53#define EI_NIDENT       16
  54
  55typedef struct elf32_hdr {
  56        unsigned char e_ident[EI_NIDENT];
  57        Elf32_Half e_type;
  58        Elf32_Half e_machine;
  59        Elf32_Word e_version;
  60        Elf32_Addr e_entry;     /* Entry point */
  61        Elf32_Off e_phoff;
  62        Elf32_Off e_shoff;
  63        Elf32_Word e_flags;
  64        Elf32_Half e_ehsize;
  65        Elf32_Half e_phentsize;
  66        Elf32_Half e_phnum;
  67        Elf32_Half e_shentsize;
  68        Elf32_Half e_shnum;
  69        Elf32_Half e_shstrndx;
  70} Elf32_Ehdr;
  71
  72typedef struct elf64_hdr {
  73        unsigned char e_ident[16];      /* ELF "magic number" */
  74        Elf64_Half e_type;
  75        Elf64_Half e_machine;
  76        Elf64_Word e_version;
  77        Elf64_Addr e_entry;     /* Entry point virtual address */
  78        Elf64_Off e_phoff;      /* Program header table file offset */
  79        Elf64_Off e_shoff;      /* Section header table file offset */
  80        Elf64_Word e_flags;
  81        Elf64_Half e_ehsize;
  82        Elf64_Half e_phentsize;
  83        Elf64_Half e_phnum;
  84        Elf64_Half e_shentsize;
  85        Elf64_Half e_shnum;
  86        Elf64_Half e_shstrndx;
  87} Elf64_Ehdr;
  88
  89/* These constants define the permissions on sections in the program
  90   header, p_flags. */
  91#define PF_R            0x4
  92#define PF_W            0x2
  93#define PF_X            0x1
  94
  95typedef struct elf32_phdr {
  96        Elf32_Word p_type;
  97        Elf32_Off p_offset;
  98        Elf32_Addr p_vaddr;
  99        Elf32_Addr p_paddr;
 100        Elf32_Word p_filesz;
 101        Elf32_Word p_memsz;
 102        Elf32_Word p_flags;
 103        Elf32_Word p_align;
 104} Elf32_Phdr;
 105
 106typedef struct elf64_phdr {
 107        Elf64_Word p_type;
 108        Elf64_Word p_flags;
 109        Elf64_Off p_offset;     /* Segment file offset */
 110        Elf64_Addr p_vaddr;     /* Segment virtual address */
 111        Elf64_Addr p_paddr;     /* Segment physical address */
 112        Elf64_Xword p_filesz;   /* Segment size in file */
 113        Elf64_Xword p_memsz;    /* Segment size in memory */
 114        Elf64_Xword p_align;    /* Segment alignment, file & memory */
 115} Elf64_Phdr;
 116
 117#define EI_MAG0         0       /* e_ident[] indexes */
 118#define EI_MAG1         1
 119#define EI_MAG2         2
 120#define EI_MAG3         3
 121#define EI_CLASS        4
 122#define EI_DATA         5
 123#define EI_VERSION      6
 124#define EI_OSABI        7
 125#define EI_PAD          8
 126
 127#define ELFMAG0         0x7f    /* EI_MAG */
 128#define ELFMAG1         'E'
 129#define ELFMAG2         'L'
 130#define ELFMAG3         'F'
 131#define ELFMAG          "\177ELF"
 132#define SELFMAG         4
 133
 134#define ELFCLASSNONE    0       /* EI_CLASS */
 135#define ELFCLASS32      1
 136#define ELFCLASS64      2
 137#define ELFCLASSNUM     3
 138
 139#define ELFDATANONE     0       /* e_ident[EI_DATA] */
 140#define ELFDATA2LSB     1
 141#define ELFDATA2MSB     2
 142
 143#define EV_NONE         0       /* e_version, EI_VERSION */
 144#define EV_CURRENT      1
 145#define EV_NUM          2
 146
 147#define ELFOSABI_NONE   0
 148#define ELFOSABI_LINUX  3
 149
 150struct elf_info {
 151        unsigned long loadsize;
 152        unsigned long memsize;
 153        unsigned long elfoffset;
 154};
 155int parse_elf64(void *hdr, struct elf_info *info);
 156int parse_elf32(void *hdr, struct elf_info *info);
 157
 158#endif                          /* _PPC_BOOT_ELF_H_ */
 159