0001
0002 #ifndef _PPC_BOOT_ELF_H_
0003 #define _PPC_BOOT_ELF_H_
0004
0005
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
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
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
0031 #define PT_LOOS 0x60000000
0032 #define PT_HIOS 0x6fffffff
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
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
0049 #define EM_NONE 0
0050 #define EM_PPC 20
0051 #define EM_PPC64 21
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;
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];
0074 Elf64_Half e_type;
0075 Elf64_Half e_machine;
0076 Elf64_Word e_version;
0077 Elf64_Addr e_entry;
0078 Elf64_Off e_phoff;
0079 Elf64_Off e_shoff;
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
0090
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;
0110 Elf64_Addr p_vaddr;
0111 Elf64_Addr p_paddr;
0112 Elf64_Xword p_filesz;
0113 Elf64_Xword p_memsz;
0114 Elf64_Xword p_align;
0115 } Elf64_Phdr;
0116
0117 #define EI_MAG0 0
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
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
0135 #define ELFCLASS32 1
0136 #define ELFCLASS64 2
0137 #define ELFCLASSNUM 3
0138
0139 #define ELFDATANONE 0
0140 #define ELFDATA2LSB 1
0141 #define ELFDATA2MSB 2
0142
0143 #define EV_NONE 0
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