162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 262306a36Sopenharmony_ci#ifndef _PPC_BOOT_ELF_H_ 362306a36Sopenharmony_ci#define _PPC_BOOT_ELF_H_ 462306a36Sopenharmony_ci 562306a36Sopenharmony_ci/* 32-bit ELF base types. */ 662306a36Sopenharmony_citypedef unsigned int Elf32_Addr; 762306a36Sopenharmony_citypedef unsigned short Elf32_Half; 862306a36Sopenharmony_citypedef unsigned int Elf32_Off; 962306a36Sopenharmony_citypedef signed int Elf32_Sword; 1062306a36Sopenharmony_citypedef unsigned int Elf32_Word; 1162306a36Sopenharmony_ci 1262306a36Sopenharmony_ci/* 64-bit ELF base types. */ 1362306a36Sopenharmony_citypedef unsigned long long Elf64_Addr; 1462306a36Sopenharmony_citypedef unsigned short Elf64_Half; 1562306a36Sopenharmony_citypedef signed short Elf64_SHalf; 1662306a36Sopenharmony_citypedef unsigned long long Elf64_Off; 1762306a36Sopenharmony_citypedef signed int Elf64_Sword; 1862306a36Sopenharmony_citypedef unsigned int Elf64_Word; 1962306a36Sopenharmony_citypedef unsigned long long Elf64_Xword; 2062306a36Sopenharmony_citypedef signed long long Elf64_Sxword; 2162306a36Sopenharmony_ci 2262306a36Sopenharmony_ci/* These constants are for the segment types stored in the image headers */ 2362306a36Sopenharmony_ci#define PT_NULL 0 2462306a36Sopenharmony_ci#define PT_LOAD 1 2562306a36Sopenharmony_ci#define PT_DYNAMIC 2 2662306a36Sopenharmony_ci#define PT_INTERP 3 2762306a36Sopenharmony_ci#define PT_NOTE 4 2862306a36Sopenharmony_ci#define PT_SHLIB 5 2962306a36Sopenharmony_ci#define PT_PHDR 6 3062306a36Sopenharmony_ci#define PT_TLS 7 /* Thread local storage segment */ 3162306a36Sopenharmony_ci#define PT_LOOS 0x60000000 /* OS-specific */ 3262306a36Sopenharmony_ci#define PT_HIOS 0x6fffffff /* OS-specific */ 3362306a36Sopenharmony_ci#define PT_LOPROC 0x70000000 3462306a36Sopenharmony_ci#define PT_HIPROC 0x7fffffff 3562306a36Sopenharmony_ci#define PT_GNU_EH_FRAME 0x6474e550 3662306a36Sopenharmony_ci 3762306a36Sopenharmony_ci#define PT_GNU_STACK (PT_LOOS + 0x474e551) 3862306a36Sopenharmony_ci 3962306a36Sopenharmony_ci/* These constants define the different elf file types */ 4062306a36Sopenharmony_ci#define ET_NONE 0 4162306a36Sopenharmony_ci#define ET_REL 1 4262306a36Sopenharmony_ci#define ET_EXEC 2 4362306a36Sopenharmony_ci#define ET_DYN 3 4462306a36Sopenharmony_ci#define ET_CORE 4 4562306a36Sopenharmony_ci#define ET_LOPROC 0xff00 4662306a36Sopenharmony_ci#define ET_HIPROC 0xffff 4762306a36Sopenharmony_ci 4862306a36Sopenharmony_ci/* These constants define the various ELF target machines */ 4962306a36Sopenharmony_ci#define EM_NONE 0 5062306a36Sopenharmony_ci#define EM_PPC 20 /* PowerPC */ 5162306a36Sopenharmony_ci#define EM_PPC64 21 /* PowerPC64 */ 5262306a36Sopenharmony_ci 5362306a36Sopenharmony_ci#define EI_NIDENT 16 5462306a36Sopenharmony_ci 5562306a36Sopenharmony_citypedef struct elf32_hdr { 5662306a36Sopenharmony_ci unsigned char e_ident[EI_NIDENT]; 5762306a36Sopenharmony_ci Elf32_Half e_type; 5862306a36Sopenharmony_ci Elf32_Half e_machine; 5962306a36Sopenharmony_ci Elf32_Word e_version; 6062306a36Sopenharmony_ci Elf32_Addr e_entry; /* Entry point */ 6162306a36Sopenharmony_ci Elf32_Off e_phoff; 6262306a36Sopenharmony_ci Elf32_Off e_shoff; 6362306a36Sopenharmony_ci Elf32_Word e_flags; 6462306a36Sopenharmony_ci Elf32_Half e_ehsize; 6562306a36Sopenharmony_ci Elf32_Half e_phentsize; 6662306a36Sopenharmony_ci Elf32_Half e_phnum; 6762306a36Sopenharmony_ci Elf32_Half e_shentsize; 6862306a36Sopenharmony_ci Elf32_Half e_shnum; 6962306a36Sopenharmony_ci Elf32_Half e_shstrndx; 7062306a36Sopenharmony_ci} Elf32_Ehdr; 7162306a36Sopenharmony_ci 7262306a36Sopenharmony_citypedef struct elf64_hdr { 7362306a36Sopenharmony_ci unsigned char e_ident[16]; /* ELF "magic number" */ 7462306a36Sopenharmony_ci Elf64_Half e_type; 7562306a36Sopenharmony_ci Elf64_Half e_machine; 7662306a36Sopenharmony_ci Elf64_Word e_version; 7762306a36Sopenharmony_ci Elf64_Addr e_entry; /* Entry point virtual address */ 7862306a36Sopenharmony_ci Elf64_Off e_phoff; /* Program header table file offset */ 7962306a36Sopenharmony_ci Elf64_Off e_shoff; /* Section header table file offset */ 8062306a36Sopenharmony_ci Elf64_Word e_flags; 8162306a36Sopenharmony_ci Elf64_Half e_ehsize; 8262306a36Sopenharmony_ci Elf64_Half e_phentsize; 8362306a36Sopenharmony_ci Elf64_Half e_phnum; 8462306a36Sopenharmony_ci Elf64_Half e_shentsize; 8562306a36Sopenharmony_ci Elf64_Half e_shnum; 8662306a36Sopenharmony_ci Elf64_Half e_shstrndx; 8762306a36Sopenharmony_ci} Elf64_Ehdr; 8862306a36Sopenharmony_ci 8962306a36Sopenharmony_ci/* These constants define the permissions on sections in the program 9062306a36Sopenharmony_ci header, p_flags. */ 9162306a36Sopenharmony_ci#define PF_R 0x4 9262306a36Sopenharmony_ci#define PF_W 0x2 9362306a36Sopenharmony_ci#define PF_X 0x1 9462306a36Sopenharmony_ci 9562306a36Sopenharmony_citypedef struct elf32_phdr { 9662306a36Sopenharmony_ci Elf32_Word p_type; 9762306a36Sopenharmony_ci Elf32_Off p_offset; 9862306a36Sopenharmony_ci Elf32_Addr p_vaddr; 9962306a36Sopenharmony_ci Elf32_Addr p_paddr; 10062306a36Sopenharmony_ci Elf32_Word p_filesz; 10162306a36Sopenharmony_ci Elf32_Word p_memsz; 10262306a36Sopenharmony_ci Elf32_Word p_flags; 10362306a36Sopenharmony_ci Elf32_Word p_align; 10462306a36Sopenharmony_ci} Elf32_Phdr; 10562306a36Sopenharmony_ci 10662306a36Sopenharmony_citypedef struct elf64_phdr { 10762306a36Sopenharmony_ci Elf64_Word p_type; 10862306a36Sopenharmony_ci Elf64_Word p_flags; 10962306a36Sopenharmony_ci Elf64_Off p_offset; /* Segment file offset */ 11062306a36Sopenharmony_ci Elf64_Addr p_vaddr; /* Segment virtual address */ 11162306a36Sopenharmony_ci Elf64_Addr p_paddr; /* Segment physical address */ 11262306a36Sopenharmony_ci Elf64_Xword p_filesz; /* Segment size in file */ 11362306a36Sopenharmony_ci Elf64_Xword p_memsz; /* Segment size in memory */ 11462306a36Sopenharmony_ci Elf64_Xword p_align; /* Segment alignment, file & memory */ 11562306a36Sopenharmony_ci} Elf64_Phdr; 11662306a36Sopenharmony_ci 11762306a36Sopenharmony_ci#define EI_MAG0 0 /* e_ident[] indexes */ 11862306a36Sopenharmony_ci#define EI_MAG1 1 11962306a36Sopenharmony_ci#define EI_MAG2 2 12062306a36Sopenharmony_ci#define EI_MAG3 3 12162306a36Sopenharmony_ci#define EI_CLASS 4 12262306a36Sopenharmony_ci#define EI_DATA 5 12362306a36Sopenharmony_ci#define EI_VERSION 6 12462306a36Sopenharmony_ci#define EI_OSABI 7 12562306a36Sopenharmony_ci#define EI_PAD 8 12662306a36Sopenharmony_ci 12762306a36Sopenharmony_ci#define ELFMAG0 0x7f /* EI_MAG */ 12862306a36Sopenharmony_ci#define ELFMAG1 'E' 12962306a36Sopenharmony_ci#define ELFMAG2 'L' 13062306a36Sopenharmony_ci#define ELFMAG3 'F' 13162306a36Sopenharmony_ci#define ELFMAG "\177ELF" 13262306a36Sopenharmony_ci#define SELFMAG 4 13362306a36Sopenharmony_ci 13462306a36Sopenharmony_ci#define ELFCLASSNONE 0 /* EI_CLASS */ 13562306a36Sopenharmony_ci#define ELFCLASS32 1 13662306a36Sopenharmony_ci#define ELFCLASS64 2 13762306a36Sopenharmony_ci#define ELFCLASSNUM 3 13862306a36Sopenharmony_ci 13962306a36Sopenharmony_ci#define ELFDATANONE 0 /* e_ident[EI_DATA] */ 14062306a36Sopenharmony_ci#define ELFDATA2LSB 1 14162306a36Sopenharmony_ci#define ELFDATA2MSB 2 14262306a36Sopenharmony_ci 14362306a36Sopenharmony_ci#define EV_NONE 0 /* e_version, EI_VERSION */ 14462306a36Sopenharmony_ci#define EV_CURRENT 1 14562306a36Sopenharmony_ci#define EV_NUM 2 14662306a36Sopenharmony_ci 14762306a36Sopenharmony_ci#define ELFOSABI_NONE 0 14862306a36Sopenharmony_ci#define ELFOSABI_LINUX 3 14962306a36Sopenharmony_ci 15062306a36Sopenharmony_cistruct elf_info { 15162306a36Sopenharmony_ci unsigned long loadsize; 15262306a36Sopenharmony_ci unsigned long memsize; 15362306a36Sopenharmony_ci unsigned long elfoffset; 15462306a36Sopenharmony_ci}; 15562306a36Sopenharmony_ciint parse_elf64(void *hdr, struct elf_info *info); 15662306a36Sopenharmony_ciint parse_elf32(void *hdr, struct elf_info *info); 15762306a36Sopenharmony_ci 15862306a36Sopenharmony_ci#endif /* _PPC_BOOT_ELF_H_ */ 159