pspsdk-1.0+beta2
elftypes.h
Go to the documentation of this file.
1 /*
2  * PSP Software Development Kit - http://www.pspdev.org
3  * -----------------------------------------------------------------------
4  * Licensed under the BSD license, see LICENSE in PSPSDK root for details.
5  *
6  * elftypes.h - Definitions for the different ELF types.
7  *
8  * Copyright (c) 2005 James Forshaw <tyranid@gmail.com>
9  *
10  * $Id: elftypes.h 1520 2005-12-04 20:09:36Z tyranid $
11  */
12 
13 #ifndef __ELF_TYPES_H__
14 #define __ELF_TYPES_H__
15 
16 #include "types.h"
17 
18 #define ELF_MACHINE_MIPS 0x0008
19 #define ELF_SH_STRTAB ".shstrtab"
20 
21 #define ELF_SECT_MAX_NAME 128
22 
23 /* Structure defining a single elf section */
24 struct ElfSection
25 {
26  /* Name index */
28  /* Type of section */
30  /* Section flags */
32  /* Addr of section when loaded */
34  /* Offset of the section in the elf */
36  /* Size of the sections data */
38  /* Link info */
40  /* Info */
42  /* Address alignment */
44  /* Entry size */
46 
47  /* Aliased pointer to the data (in the original Elf) */
49  /* Name of the section */
51  /* Index */
52  int iIndex;
53  /* Section Ref. Used for relocations */
54  struct ElfSection *pRef;
55  /* Indicates if this section is to be outputted */
56  int blOutput;
57 };
58 
59 struct ElfProgram
60 {
69 
70  /* Aliased pointer to the data (in the original Elf)*/
72 };
73 
74 /* Structure to hold elf header data, in native format */
75 struct ElfHeader
76 {
94 };
95 
96 struct ElfReloc
97 {
98  /* Pointer to the section name */
99  const char* secname;
100  /* Base address */
102  /* Type */
104  /* Symbol (if known) */
106  /* Offset into the file */
108  /* New Address for the relocation (to do with what you will) */
110 };
111 
112 /* Define ELF types */
113 typedef u32 Elf32_Addr;
114 typedef u16 Elf32_Half;
115 typedef u32 Elf32_Off;
116 typedef s32 Elf32_Sword;
117 typedef u32 Elf32_Word;
118 
119 #define ELF_MAGIC 0x464C457F
120 
121 #define ELF_EXEC_TYPE 0x0002
122 #define ELF_PRX_TYPE 0xFFA0
123 
124 #define SHT_NULL 0
125 #define SHT_PROGBITS 1
126 #define SHT_SYMTAB 2
127 #define SHT_STRTAB 3
128 #define SHT_RELA 4
129 #define SHT_HASH 5
130 #define SHT_DYNAMIC 6
131 #define SHT_NOTE 7
132 #define SHT_NOBITS 8
133 #define SHT_REL 9
134 #define SHT_SHLIB 10
135 #define SHT_DYNSYM 11
136 #define SHT_LOPROC 0x70000000
137 #define SHT_HIPROC 0x7fffffff
138 #define SHT_LOUSER 0x80000000
139 #define SHT_HIUSER 0xffffffff
140 
141 #define SHT_PRXRELOC (SHT_LOPROC | 0xA0)
142 
143 // MIPS Reloc Entry Types
144 #define R_MIPS_NONE 0
145 #define R_MIPS_16 1
146 #define R_MIPS_32 2
147 #define R_MIPS_REL32 3
148 #define R_MIPS_26 4
149 #define R_MIPS_HI16 5
150 #define R_MIPS_LO16 6
151 #define R_MIPS_GPREL16 7
152 #define R_MIPS_LITERAL 8
153 #define R_MIPS_GOT16 9
154 #define R_MIPS_PC16 10
155 #define R_MIPS_CALL16 11
156 #define R_MIPS_GPREL32 12
157 
158 #define SHF_WRITE 1
159 #define SHF_ALLOC 2
160 #define SHF_EXECINSTR 4
161 
162 #define PT_NULL 0
163 #define PT_LOAD 1
164 #define PT_DYNAMIC 2
165 #define PT_INTERP 3
166 #define PT_NOTE 4
167 #define PT_SHLIB 5
168 #define PT_PHDR 6
169 #define PT_LOPROC 0x70000000
170 #define PT_HIPROC 0x7fffffff
171 
172 /* ELF file header */
173 typedef struct {
178  u8 e_pad[9];
192 } __attribute__((packed)) Elf32_Ehdr;
193 
194 /* ELF section header */
195 typedef struct {
206 } __attribute__((packed)) Elf32_Shdr;
207 
208 typedef struct {
217 } Elf32_Phdr;
218 
219 #define ELF32_R_SYM(i) ((i)>>8)
220 #define ELF32_R_TYPE(i) ((u8)(i&0xFF))
221 
222 typedef struct {
225 } Elf32_Rel;
226 
227 typedef struct {
231  unsigned char st_info;
232  unsigned char st_other;
234 } __attribute__((packed)) Elf32_Sym;
235 
236 #define STB_LOCAL 0
237 #define STB_GLOBAL 1
238 #define STB_WEAK 2
239 #define STB_LOPROC 13
240 #define STB_HIPROC 15
241 
242 #define ELF32_ST_BIND(i) ((i)>>4)
243 #define ELF32_ST_TYPE(i) ((i)&0xf)
244 #define ELF32_ST_INFO(b,t) (((b)<<4)+((t)&0xf))
245 
246 #endif