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

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