Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef _PPC_BOOT_ELF_H_
0003 #define _PPC_BOOT_ELF_H_
0004 
0005 /* 32-bit ELF base types. */
0006 typedef unsigned int Elf32_Addr;
0007 typedef unsigned short Elf32_Half;
0008 typedef unsigned int Elf32_Off;
0009 typedef signed int Elf32_Sword;
0010 typedef unsigned int Elf32_Word;
0011 
0012 /* 64-bit ELF base types. */
0013 typedef unsigned long long Elf64_Addr;
0014 typedef unsigned short Elf64_Half;
0015 typedef signed short Elf64_SHalf;
0016 typedef unsigned long long Elf64_Off;
0017 typedef signed int Elf64_Sword;
0018 typedef unsigned int Elf64_Word;
0019 typedef unsigned long long Elf64_Xword;
0020 typedef signed long long Elf64_Sxword;
0021 
0022 /* These constants are for the segment types stored in the image headers */
0023 #define PT_NULL    0
0024 #define PT_LOAD    1
0025 #define PT_DYNAMIC 2
0026 #define PT_INTERP  3
0027 #define PT_NOTE    4
0028 #define PT_SHLIB   5
0029 #define PT_PHDR    6
0030 #define PT_TLS     7        /* Thread local storage segment */
0031 #define PT_LOOS    0x60000000   /* OS-specific */
0032 #define PT_HIOS    0x6fffffff   /* OS-specific */
0033 #define PT_LOPROC  0x70000000
0034 #define PT_HIPROC  0x7fffffff
0035 #define PT_GNU_EH_FRAME     0x6474e550
0036 
0037 #define PT_GNU_STACK    (PT_LOOS + 0x474e551)
0038 
0039 /* These constants define the different elf file types */
0040 #define ET_NONE   0
0041 #define ET_REL    1
0042 #define ET_EXEC   2
0043 #define ET_DYN    3
0044 #define ET_CORE   4
0045 #define ET_LOPROC 0xff00
0046 #define ET_HIPROC 0xffff
0047 
0048 /* These constants define the various ELF target machines */
0049 #define EM_NONE  0
0050 #define EM_PPC         20   /* PowerPC */
0051 #define EM_PPC64       21   /* PowerPC64 */
0052 
0053 #define EI_NIDENT   16
0054 
0055 typedef struct elf32_hdr {
0056     unsigned char e_ident[EI_NIDENT];
0057     Elf32_Half e_type;
0058     Elf32_Half e_machine;
0059     Elf32_Word e_version;
0060     Elf32_Addr e_entry; /* Entry point */
0061     Elf32_Off e_phoff;
0062     Elf32_Off e_shoff;
0063     Elf32_Word e_flags;
0064     Elf32_Half e_ehsize;
0065     Elf32_Half e_phentsize;
0066     Elf32_Half e_phnum;
0067     Elf32_Half e_shentsize;
0068     Elf32_Half e_shnum;
0069     Elf32_Half e_shstrndx;
0070 } Elf32_Ehdr;
0071 
0072 typedef struct elf64_hdr {
0073     unsigned char e_ident[16];  /* ELF "magic number" */
0074     Elf64_Half e_type;
0075     Elf64_Half e_machine;
0076     Elf64_Word e_version;
0077     Elf64_Addr e_entry; /* Entry point virtual address */
0078     Elf64_Off e_phoff;  /* Program header table file offset */
0079     Elf64_Off e_shoff;  /* Section header table file offset */
0080     Elf64_Word e_flags;
0081     Elf64_Half e_ehsize;
0082     Elf64_Half e_phentsize;
0083     Elf64_Half e_phnum;
0084     Elf64_Half e_shentsize;
0085     Elf64_Half e_shnum;
0086     Elf64_Half e_shstrndx;
0087 } Elf64_Ehdr;
0088 
0089 /* These constants define the permissions on sections in the program
0090    header, p_flags. */
0091 #define PF_R        0x4
0092 #define PF_W        0x2
0093 #define PF_X        0x1
0094 
0095 typedef struct elf32_phdr {
0096     Elf32_Word p_type;
0097     Elf32_Off p_offset;
0098     Elf32_Addr p_vaddr;
0099     Elf32_Addr p_paddr;
0100     Elf32_Word p_filesz;
0101     Elf32_Word p_memsz;
0102     Elf32_Word p_flags;
0103     Elf32_Word p_align;
0104 } Elf32_Phdr;
0105 
0106 typedef struct elf64_phdr {
0107     Elf64_Word p_type;
0108     Elf64_Word p_flags;
0109     Elf64_Off p_offset; /* Segment file offset */
0110     Elf64_Addr p_vaddr; /* Segment virtual address */
0111     Elf64_Addr p_paddr; /* Segment physical address */
0112     Elf64_Xword p_filesz;   /* Segment size in file */
0113     Elf64_Xword p_memsz;    /* Segment size in memory */
0114     Elf64_Xword p_align;    /* Segment alignment, file & memory */
0115 } Elf64_Phdr;
0116 
0117 #define EI_MAG0     0   /* e_ident[] indexes */
0118 #define EI_MAG1     1
0119 #define EI_MAG2     2
0120 #define EI_MAG3     3
0121 #define EI_CLASS    4
0122 #define EI_DATA     5
0123 #define EI_VERSION  6
0124 #define EI_OSABI    7
0125 #define EI_PAD      8
0126 
0127 #define ELFMAG0     0x7f    /* EI_MAG */
0128 #define ELFMAG1     'E'
0129 #define ELFMAG2     'L'
0130 #define ELFMAG3     'F'
0131 #define ELFMAG      "\177ELF"
0132 #define SELFMAG     4
0133 
0134 #define ELFCLASSNONE    0   /* EI_CLASS */
0135 #define ELFCLASS32  1
0136 #define ELFCLASS64  2
0137 #define ELFCLASSNUM 3
0138 
0139 #define ELFDATANONE 0   /* e_ident[EI_DATA] */
0140 #define ELFDATA2LSB 1
0141 #define ELFDATA2MSB 2
0142 
0143 #define EV_NONE     0   /* e_version, EI_VERSION */
0144 #define EV_CURRENT  1
0145 #define EV_NUM      2
0146 
0147 #define ELFOSABI_NONE   0
0148 #define ELFOSABI_LINUX  3
0149 
0150 struct elf_info {
0151     unsigned long loadsize;
0152     unsigned long memsize;
0153     unsigned long elfoffset;
0154 };
0155 int parse_elf64(void *hdr, struct elf_info *info);
0156 int parse_elf32(void *hdr, struct elf_info *info);
0157 
0158 #endif              /* _PPC_BOOT_ELF_H_ */