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

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