00001 /* 00002 * PSP Software Development Kit - http://www.pspdev.org 00003 * ----------------------------------------------------------------------- 00004 * Licensed under the BSD license, see LICENSE in PSPSDK root for details. 00005 * 00006 * elftypes.h - Definitions for the different ELF types. 00007 * 00008 * Copyright (c) 2005 James Forshaw <tyranid@gmail.com> 00009 * 00010 * $Id: elftypes.h 1095 2005-09-27 21:02:16Z jim $ 00011 */ 00012 00013 #ifndef __ELF_TYPES_H__ 00014 #define __ELF_TYPES_H__ 00015 00016 #include "types.h" 00017 00018 #define ELF_MACHINE_MIPS 0x0008 00019 #define ELF_SH_STRTAB ".shstrtab" 00020 00021 #define ELF_SECT_MAX_NAME 128 00022 00023 /* Structure defining a single elf section */ 00024 struct ElfSection 00025 { 00026 /* Name index */ 00027 u32 iName; 00028 /* Type of section */ 00029 u32 iType; 00030 /* Section flags */ 00031 u32 iFlags; 00032 /* Addr of section when loaded */ 00033 u32 iAddr; 00034 /* Offset of the section in the elf */ 00035 u32 iOffset; 00036 /* Size of the sections data */ 00037 u32 iSize; 00038 /* Link info */ 00039 u32 iLink; 00040 /* Info */ 00041 u32 iInfo; 00042 /* Address alignment */ 00043 u32 iAddralign; 00044 /* Entry size */ 00045 u32 iEntsize; 00046 00047 /* Aliased pointer to the data (in the original Elf) */ 00048 u8 *pData; 00049 /* Name of the section */ 00050 char szName[ELF_SECT_MAX_NAME]; 00051 /* Index */ 00052 int iIndex; 00053 /* Section Ref. Used for relocations */ 00054 struct ElfSection *pRef; 00055 /* Indicates if this section is to be outputted */ 00056 int blOutput; 00057 }; 00058 00059 struct ElfProgram 00060 { 00061 u32 iType; 00062 u32 iOffset; 00063 u32 iVaddr; 00064 u32 iPaddr; 00065 u32 iFilesz; 00066 u32 iMemsz; 00067 u32 iFlags; 00068 u32 iAlign; 00069 00070 /* Aliased pointer to the data (in the original Elf)*/ 00071 u8 *pData; 00072 }; 00073 00074 /* Structure to hold elf header data, in native format */ 00075 struct ElfHeader 00076 { 00077 u32 iMagic; 00078 u32 iClass; 00079 u32 iData; 00080 u32 iIdver; 00081 u32 iType; 00082 u32 iMachine; 00083 u32 iVersion; 00084 u32 iEntry; 00085 u32 iPhoff; 00086 u32 iShoff; 00087 u32 iFlags; 00088 u32 iEhsize; 00089 u32 iPhentsize; 00090 u32 iPhnum; 00091 u32 iShentsize; 00092 u32 iShnum; 00093 u32 iShstrndx; 00094 }; 00095 00096 struct ElfReloc 00097 { 00098 /* Pointer to the section name */ 00099 const char* secname; 00100 /* Base address */ 00101 u32 base; 00102 /* Type */ 00103 u32 type; 00104 /* Symbol (if known) */ 00105 u32 symbol; 00106 /* Offset into the file */ 00107 u32 offset; 00108 /* New Address for the relocation (to do with what you will) */ 00109 u32 addr; 00110 }; 00111 00112 /* Define ELF types */ 00113 typedef u32 Elf32_Addr; 00114 typedef u16 Elf32_Half; 00115 typedef u32 Elf32_Off; 00116 typedef s32 Elf32_Sword; 00117 typedef u32 Elf32_Word; 00118 00119 #define ELF_MAGIC 0x464C457F 00120 00121 #define ELF_EXEC_TYPE 0x0002 00122 #define ELF_PRX_TYPE 0xFFA0 00123 00124 #define SHT_NULL 0 00125 #define SHT_PROGBITS 1 00126 #define SHT_SYMTAB 2 00127 #define SHT_STRTAB 3 00128 #define SHT_RELA 4 00129 #define SHT_HASH 5 00130 #define SHT_DYNAMIC 6 00131 #define SHT_NOTE 7 00132 #define SHT_NOBITS 8 00133 #define SHT_REL 9 00134 #define SHT_SHLIB 10 00135 #define SHT_DYNSYM 11 00136 #define SHT_LOPROC 0x70000000 00137 #define SHT_HIPROC 0x7fffffff 00138 #define SHT_LOUSER 0x80000000 00139 #define SHT_HIUSER 0xffffffff 00140 00141 #define SHT_PRXRELOC (SHT_LOPROC | 0xA0) 00142 00143 // MIPS Reloc Entry Types 00144 #define R_MIPS_NONE 0 00145 #define R_MIPS_16 1 00146 #define R_MIPS_32 2 00147 #define R_MIPS_REL32 3 00148 #define R_MIPS_26 4 00149 #define R_MIPS_HI16 5 00150 #define R_MIPS_LO16 6 00151 #define R_MIPS_GPREL16 7 00152 #define R_MIPS_LITERAL 8 00153 #define R_MIPS_GOT16 9 00154 #define R_MIPS_PC16 10 00155 #define R_MIPS_CALL16 11 00156 #define R_MIPS_GPREL32 12 00157 00158 #define SHF_WRITE 1 00159 #define SHF_ALLOC 2 00160 #define SHF_EXECINSTR 4 00161 00162 #define PT_NULL 0 00163 #define PT_LOAD 1 00164 #define PT_DYNAMIC 2 00165 #define PT_INTERP 3 00166 #define PT_NOTE 4 00167 #define PT_SHLIB 5 00168 #define PT_PHDR 6 00169 #define PT_LOPROC 0x70000000 00170 #define PT_HIPROC 0x7fffffff 00171 00172 /* ELF file header */ 00173 typedef struct { 00174 Elf32_Word e_magic; 00175 u8 e_class; 00176 u8 e_data; 00177 u8 e_idver; 00178 u8 e_pad[9]; 00179 Elf32_Half e_type; 00180 Elf32_Half e_machine; 00181 Elf32_Word e_version; 00182 Elf32_Addr e_entry; 00183 Elf32_Off e_phoff; 00184 Elf32_Off e_shoff; 00185 Elf32_Word e_flags; 00186 Elf32_Half e_ehsize; 00187 Elf32_Half e_phentsize; 00188 Elf32_Half e_phnum; 00189 Elf32_Half e_shentsize; 00190 Elf32_Half e_shnum; 00191 Elf32_Half e_shstrndx; 00192 } __attribute__((packed)) Elf32_Ehdr; 00193 00194 /* ELF section header */ 00195 typedef struct { 00196 Elf32_Word sh_name; 00197 Elf32_Word sh_type; 00198 Elf32_Word sh_flags; 00199 Elf32_Addr sh_addr; 00200 Elf32_Off sh_offset; 00201 Elf32_Word sh_size; 00202 Elf32_Word sh_link; 00203 Elf32_Word sh_info; 00204 Elf32_Word sh_addralign; 00205 Elf32_Word sh_entsize; 00206 } __attribute__((packed)) Elf32_Shdr; 00207 00208 typedef struct { 00209 Elf32_Word p_type; 00210 Elf32_Off p_offset; 00211 Elf32_Addr p_vaddr; 00212 Elf32_Addr p_paddr; 00213 Elf32_Word p_filesz; 00214 Elf32_Word p_memsz; 00215 Elf32_Word p_flags; 00216 Elf32_Word p_align; 00217 } Elf32_Phdr; 00218 00219 #define ELF32_R_SYM(i) ((i)>>8) 00220 #define ELF32_R_TYPE(i) ((u8)(i&0xFF)) 00221 00222 typedef struct { 00223 Elf32_Addr r_offset; 00224 Elf32_Word r_info; 00225 } Elf32_Rel; 00226 00227 typedef struct { 00228 Elf32_Word st_name; 00229 Elf32_Addr st_value; 00230 Elf32_Word st_size; 00231 unsigned char st_info; 00232 unsigned char st_other; 00233 Elf32_Half st_shndx; 00234 } __attribute__((packed)) Elf32_Sym; 00235 00236 #endif