3018a895adea0c67e23e6878ebf0b273f3c10d11
[tpg/acess2.git] / Usermode / Libraries / ld-acess.so_src / elf32.h
1 /**
2  Acess v1
3  \file elf32.h
4  \brief ELF Exeutable Loader
5 */
6 #ifndef _ELF32_H
7 #define _ELF32_H
8
9 #include <stdint.h>
10
11 typedef uint16_t        Elf32_Half;
12 typedef uint32_t        Elf32_Addr;
13 typedef uint32_t        Elf32_Off;
14 typedef uint32_t        Elf32_Word;
15 typedef int32_t         Elf32_Sword;
16
17 #define ELFCLASS32      1
18
19 #define EM_NONE 0
20 #define EM_386  3
21 #define EM_ARM  40
22
23 /**
24  \struct elf_header_s
25  \brief ELF File Header
26 */
27 struct sElf32_Ehdr {
28         uint8_t e_ident[16];    //!< Identifier Bytes
29         Elf32_Half      filetype;       //!< File Type
30         Elf32_Half      machine;        //!< Machine / Arch
31         Elf32_Word      version;        //!< Version (File?)
32         Elf32_Addr      entrypoint;     //!< Entry Point
33         Elf32_Off       phoff;  //!< Program Header Offset
34         Elf32_Word      shoff;  //!< Section Header Offset
35         Elf32_Word      flags;  //!< Flags
36         Elf32_Half      headersize;     //!< Header Size
37         Elf32_Half      phentsize;      //!< Program Header Entry Size
38         Elf32_Half      phentcount;     //!< Program Header Entry Count
39         Elf32_Half      shentsize;      //!< Section Header Entry Size
40         Elf32_Half      shentcount;     //!< Section Header Entry Count
41         Elf32_Half      shstrindex;     //!< Section Header String Table Index
42 };
43
44 /**
45  \name Executable Types
46  \{
47 */
48 #define ET_NONE         0       //!< NULL Type
49 #define ET_REL          1       //!< Relocatable (Object)
50 #define ET_EXEC         2       //!< Executable
51 #define ET_DYN          3       //!< Dynamic Library
52 #define ET_CORE         4       //!< Core?
53 #define ET_LOPROC       0xFF00  //!< Low Impl Defined
54 #define ET_HIPROC       0xFFFF  //!< High Impl Defined
55 //! \}
56
57 /**
58  \name Section IDs
59  \{
60 */
61 #define SHN_UNDEF               0       //!< Undefined Section
62 #define SHN_LORESERVE   0xFF00  //!< Low Reserved
63 #define SHN_LOPROC              0xFF00  //!< Low Impl Defined
64 #define SHN_HIPROC              0xFF1F  //!< High Impl Defined
65 #define SHN_ABS                 0xFFF1  //!< Absolute Address (Base: 0, Size: -1)
66 #define SHN_COMMON              0xFFF2  //!< Common
67 #define SHN_HIRESERVE   0xFFFF  //!< High Reserved
68 //! \}
69
70 /**
71  \enum eElfSectionTypes
72  \brief ELF Section Types
73 */
74 enum eElfSectionTypes {
75         SHT_NULL,       //0
76         SHT_PROGBITS,   //1
77         SHT_SYMTAB,     //2
78         SHT_STRTAB,     //3
79         SHT_RELA,       //4
80         SHT_HASH,       //5
81         SHT_DYNAMIC,    //6
82         SHT_NOTE,       //7
83         SHT_NOBITS,     //8
84         SHT_REL,        //9
85         SHT_SHLIB,      //A
86         SHT_DYNSYM,     //B
87         SHT_LAST,       //C
88         SHT_LOPROC = 0x70000000,
89         SHT_HIPROC = 0x7fffffff,
90         SHT_LOUSER = 0x80000000,
91         SHT_HIUSER = 0xffffffff
92 };
93
94 #if 0
95 #define SHF_WRITE       0x1
96 #define SHF_ALLOC       0x2
97 #define SHF_EXECINSTR   0x4
98 #define SHF_MASKPROC    0xf0000000
99
100 struct sElf32_Shent {
101         Uint32  name;
102         Uint32  type;
103         Uint32  flags;
104         Uint32  address;
105         Uint32  offset;
106         Uint32  size;
107         Uint32  link;
108         Uint32  info;
109         Uint32  addralign;
110         Uint32  entsize;
111 };      //sizeof = 40
112 #endif
113
114 struct elf_sym_s {
115         Elf32_Word      nameOfs;
116         Elf32_Addr      value;  //Address
117         Elf32_Word      size;
118         uint8_t info;
119         uint8_t other;
120         Elf32_Half      shndx;
121 };
122 #define STN_UNDEF       0       // Undefined Symbol
123
124 enum {
125         PT_NULL,        //0
126         PT_LOAD,        //1
127         PT_DYNAMIC,     //2
128         PT_INTERP,      //3
129         PT_NOTE,        //4
130         PT_SHLIB,       //5
131         PT_PHDR,        //6
132         PT_LOPROC = 0x70000000,
133         PT_HIPROC = 0x7fffffff
134 };
135
136 struct sElf32_Phdr {
137         Elf32_Word      Type;
138         Elf32_Off       Offset;
139         Elf32_Addr      VAddr;
140         Elf32_Addr      PAddr;
141         Elf32_Word      FileSize;
142         Elf32_Word      MemSize;
143         Elf32_Word      Flags;
144         Elf32_Word      Align;
145 };
146
147 struct elf32_rel_s {
148         Elf32_Addr      r_offset;
149         Elf32_Word      r_info;
150 };
151
152 struct elf32_rela_s {
153         Elf32_Addr      r_offset;
154         Elf32_Word      r_info;
155         Elf32_Sword     r_addend;
156 };
157
158 enum {
159         R_386_NONE=0,   // none
160         R_386_32,       // S+A
161         R_386_PC32,     // S+A-P
162         R_386_GOT32,    // G+A-P
163         R_386_PLT32,    // L+A-P
164         R_386_COPY,     // none
165         R_386_GLOB_DAT, // S
166         R_386_JMP_SLOT, // S
167         R_386_RELATIVE, // B+A
168         R_386_GOTOFF,   // S+A-GOT
169         R_386_GOTPC,    // GOT+A-P
170         R_386_LAST      // none
171 };
172
173 // NOTES:
174 //  'T' means the thumb bit
175 //  'B(S)' Origin of a symbol
176 enum {
177         R_ARM_NONE,     //  0 No action
178         R_ARM_PC24,     //  1 ((S + A) | T) - P
179         R_ARM_ABS32,    //  2 (S + A) | T
180         R_ARM_REL32,    //  3 ((S + A) | T) - P
181         R_ARM_LDR_PC_G0,        //  4 S + A - P
182         R_ARM_ABS16,    //  5 S + A
183         R_ARM_ABS12,    //  6 S + A
184         R_ARM_THM_ABS5, //  7 S + A
185         R_ARM_ABS8,     //  8 S + A
186         R_ARM_SBREL32,  //  9 ((S + A) | T) - B(S)
187         R_ARM_THM_CALL, // 10 ((S + A) | T) - P
188         R_ARM_THM_PC8,  // 11 S + A - Pa,
189         R_ARM_BREL_ADJ, // 12 ΔB(S) + A
190         R_ARM_TLS_DESC, // 13 --
191         R_ARM_THM_SWI8, // 14 (Reserved)
192         R_ARM_XPC25,    // 15 (Reserved)
193         R_ARM_THM_XPC22,        // 16 (Reserved)
194         R_ARM_TLS_DTPMOD32,     // 17 Module[S]
195         R_ARM_TLS_DTPOFF32,     // 18 S + A - TLS
196         R_ARM_TLS_TPOFF32,      // 19 S + A - tp
197         R_ARM_COPY,     // 20 Misc
198         R_ARM_GLOB_DAT, // 21 (S + A) | T
199         R_ARM_JUMP_SLOT,        // 22 (S + A) | T
200         R_ARM_RELATIVE, // 23 B(S) + A (extra?)
201         // ... More defined (IHI0044)
202 };
203
204 #define ELF32_R_SYM(i)  ((i)>>8)        // Takes an info value and returns a symbol index
205 #define ELF32_R_TYPE(i) ((i)&0xFF)      // Takes an info value and returns a type
206 #define ELF32_R_INFO(s,t)       (((s)<<8)+((t)&0xFF))   // Takes a type and symbol index and returns an info value
207
208 struct elf32_dyn_s {
209         Elf32_Half      d_tag;
210         Elf32_Word      d_val;  //Also d_ptr
211 };
212
213 enum {
214         DT_NULL,        //!< Marks End of list
215         DT_NEEDED,      //!< Offset in strtab to needed library
216         DT_PLTRELSZ,    //!< Size in bytes of PLT
217         DT_PLTGOT,      //!< Address of PLT/GOT
218         DT_HASH,        //!< Address of symbol hash table
219         DT_STRTAB,      //!< String Table address
220         DT_SYMTAB,      //!< Symbol Table address
221         DT_RELA,        //!< Relocation table address
222         DT_RELASZ,      //!< Size of relocation table
223         DT_RELAENT,     //!< Size of entry in relocation table
224         DT_STRSZ,       //!< Size of string table
225         DT_SYMENT,      //!< Size of symbol table entry
226         DT_INIT,        //!< Address of initialisation function
227         DT_FINI,        //!< Address of termination function
228         DT_SONAME,      //!< String table offset of so name
229         DT_RPATH,       //!< String table offset of library path
230         DT_SYMBOLIC,//!< Reverse order of symbol searching for library, search libs first then executable
231         DT_REL,         //!< Relocation Entries (Elf32_Rel instead of Elf32_Rela)
232         DT_RELSZ,       //!< Size of above table (bytes)
233         DT_RELENT,      //!< Size of entry in above table
234         DT_PLTREL,      //!< Relocation entry of PLT
235         DT_DEBUG,       //!< Debugging Entry - Unknown contents
236         DT_TEXTREL,     //!< Indicates that modifcations to a non-writeable segment may occur
237         DT_JMPREL,      //!< Address of PLT only relocation entries
238         DT_LOPROC = 0x70000000, //!< Low Definable
239         DT_HIPROC = 0x7FFFFFFF  //!< High Definable
240 };
241
242 typedef struct sElf32_Ehdr      Elf32_Ehdr;
243 typedef struct sElf32_Phdr      Elf32_Phdr;
244 typedef struct sElf32_Shent     Elf32_Shent;
245 typedef struct elf_sym_s        elf_symtab;
246 typedef struct elf_sym_s        Elf32_Sym;
247 typedef struct elf32_rel_s      Elf32_Rel;
248 typedef struct elf32_rela_s     Elf32_Rela;
249 typedef struct elf32_dyn_s      Elf32_Dyn;
250
251 #endif  // defined(_EXE_ELF_H)

UCC git Repository :: git.ucc.asn.au