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

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