aboutsummaryrefslogtreecommitdiffstats
path: root/src/ortho/mcode/elf_common.ads
blob: 28186d0949618605d45f9442ed9617e51730fd34 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
--  ELF definitions.
--  Copyright (C) 2006 Tristan Gingold
--
--  GHDL is free software; you can redistribute it and/or modify it under
--  the terms of the GNU General Public License as published by the Free
--  Software Foundation; either version 2, or (at your option) any later
--  version.
--
--  GHDL is distributed in the hope that it will be useful, but WITHOUT ANY
--  WARRANTY; without even the implied warranty of MERCHANTABILITY or
--  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
--  for more details.
--
--  You should have received a copy of the GNU General Public License
--  along with GCC; see the file COPYING.  If not, write to the Free
--  Software Foundation, 59 Temple Place - Suite 330, Boston, MA
--  02111-1307, USA.
with Interfaces; use Interfaces;

package Elf_Common is
   subtype Elf_Half  is Unsigned_16;
   subtype Elf_Sword is Integer_32;
   subtype Elf_Word  is Unsigned_32;
   subtype Elf_Uchar is Unsigned_8;

   EI_NIDENT : constant Natural := 16;
   type E_Ident_Type is array (Natural range 0 .. EI_NIDENT - 1)
     of Elf_Uchar;

   --  e_type values.
   ET_NONE   : constant Elf_Half := 0;        --  No file type
   ET_REL    : constant Elf_Half := 1;        --  Relocatable file
   ET_EXEC   : constant Elf_Half := 2;        --  Executable file
   ET_DYN    : constant Elf_Half := 3;        --  Shared object file
   ET_CORE   : constant Elf_Half := 4;        --  Core file
   ET_LOPROC : constant Elf_Half := 16#Ff00#; --  Processor-specific
   ET_HIPROC : constant Elf_Half := 16#Ffff#; --  Processor-specific

   --  e_machine values.
   EM_NONE        : constant Elf_Half := 0;  --  No machine
   EM_M32         : constant Elf_Half := 1;  --  AT&T WE 32100
   EM_SPARC       : constant Elf_Half := 2;  --  SPARC
   EM_386         : constant Elf_Half := 3;  --  Intel Architecture
   EM_68K         : constant Elf_Half := 4;  --  Motorola 68000
   EM_88K         : constant Elf_Half := 5;  --  Motorola 88000
   EM_860         : constant Elf_Half := 7;  --  Intel 80860
   EM_MIPS        : constant Elf_Half := 8;  --  MIPS RS3000 Big-Endian
   EM_MIPS_RS4_BE : constant Elf_Half := 10; --  MIPS RS4000 Big-Endian
   -- RESERVED : constant Elf_Half := 11; -- -16 Reserved for future use

   --  e_version
   EV_NONE    : constant Elf_Uchar := 0; --  Invalid versionn
   EV_CURRENT : constant Elf_Uchar := 1; --  Current version

   --  e_ident identification indexes.
   EI_MAG0    : constant Natural := 0;  --  File identification
   EI_MAG1    : constant Natural := 1;  --  File identification
   EI_MAG2    : constant Natural := 2;  --  File identification
   EI_MAG3    : constant Natural := 3;  --  File identification
   EI_CLASS   : constant Natural := 4;  --  File class
   EI_DATA    : constant Natural := 5;  --  Data encoding
   EI_VERSION : constant Natural := 6;  --  File version
   EI_PAD     : constant Natural := 7;  --  Start of padding bytes
   --EI_NIDENT  : constant Natural := 16; --  Size of e_ident[]

   --  Magic values.
   ELFMAG0 : constant Elf_Uchar := 16#7f#; --  e_ident[EI_MAG0]
   ELFMAG1 : constant Elf_Uchar := Character'Pos ('E'); --  e_ident[EI_MAG1]
   ELFMAG2 : constant Elf_Uchar := Character'Pos ('L'); --  e_ident[EI_MAG2]
   ELFMAG3 : constant Elf_Uchar := Character'Pos ('F'); --  e_ident[EI_MAG3]

   ELFCLASSNONE : constant Elf_Uchar := 0; --  Invalid class
   ELFCLASS32   : constant Elf_Uchar := 1; --  32-bit objects
   ELFCLASS64   : constant Elf_Uchar := 2; --  64-bit objects

   ELFDATANONE : constant Elf_Uchar := 0; --  Invalid data encoding
   ELFDATA2LSB : constant Elf_Uchar := 1; --  See below
   ELFDATA2MSB : constant Elf_Uchar := 2; --  See below

   SHN_UNDEF     : constant Elf_Half := 0; --
   SHN_LORESERVE : constant Elf_Half := 16#Ff00#; --
   SHN_LOPROC    : constant Elf_Half := 16#ff00#; --
   SHN_HIPROC    : constant Elf_Half := 16#ff1f#; --
   SHN_ABS       : constant Elf_Half := 16#fff1#; --
   SHN_COMMON    : constant Elf_Half := 16#fff2#; --
   SHN_HIRESERVE : constant Elf_Half := 16#ffff#; --

   -- Sh_type.
   SHT_NULL          : constant Elf_Word := 0;
   SHT_PROGBITS      : constant Elf_Word := 1;
   SHT_SYMTAB        : constant Elf_Word := 2;
   SHT_STRTAB        : constant Elf_Word := 3;
   SHT_RELA          : constant Elf_Word := 4;
   SHT_HASH          : constant Elf_Word := 5;
   SHT_DYNAMIC       : constant Elf_Word := 6;
   SHT_NOTE          : constant Elf_Word := 7;
   SHT_NOBITS        : constant Elf_Word := 8;
   SHT_REL           : constant Elf_Word := 9;
   SHT_SHLIB         : constant Elf_Word := 10;
   SHT_DYNSYM        : constant Elf_Word := 11;
   SHT_INIT_ARRAY    : constant Elf_Word := 14;
   SHT_FINI_ARRAY    : constant Elf_Word := 15;
   SHT_PREINIT_ARRAY : constant Elf_Word := 16;
   SHT_GROUP         : constant Elf_Word := 17;
   SHT_SYMTAB_SHNDX  : constant Elf_Word := 18;
   SHT_NUM           : constant Elf_Word := 19;
   SHT_LOOS          : constant Elf_Word := 16#60000000#;
   SHT_GNU_LIBLIST   : constant Elf_Word := 16#6ffffff7#;
   SHT_CHECKSUM      : constant Elf_Word := 16#6ffffff8#;
   SHT_LOSUNW        : constant Elf_Word := 16#6ffffffa#;
   SHT_SUNW_Move     : constant Elf_Word := 16#6ffffffa#;
   SHT_SUNW_COMDAT   : constant Elf_Word := 16#6ffffffb#;
   SHT_SUNW_Syminfo  : constant Elf_Word := 16#6ffffffc#;
   SHT_GNU_Verdef    : constant Elf_Word := 16#6ffffffd#;
   SHT_GNU_Verneed   : constant Elf_Word := 16#6ffffffe#;
   SHT_GNU_Versym    : constant Elf_Word := 16#6fffffff#;
   SHT_HISUNW        : constant Elf_Word := 16#6fffffff#;
   SHT_HIOS          : constant Elf_Word := 16#6fffffff#;
   SHT_LOPROC        : constant Elf_Word := 16#70000000#;
   SHT_HIPROC        : constant Elf_Word := 16#7fffffff#;
   SHT_LOUSER        : constant Elf_Word := 16#80000000#;
   SHT_HIUSER        : constant Elf_Word := 16#ffffffff#;


   SHF_WRITE     : constant := 16#1#;
   SHF_ALLOC     : constant := 16#2#;
   SHF_EXECINSTR : constant := 16#4#;
   SHF_MASKPROC  : constant := 16#F0000000#;

   function Elf_St_Bind (Info : Elf_Uchar) return Elf_Uchar;
   function Elf_St_Type (Info : Elf_Uchar) return Elf_Uchar;
   function Elf_St_Info (B, T : Elf_Uchar) return Elf_Uchar;
   pragma Inline (Elf_St_Bind);
   pragma Inline (Elf_St_Type);
   pragma Inline (Elf_St_Info);

   --  Symbol binding.
   STB_LOCAL  : constant Elf_Uchar := 0;
   STB_GLOBAL : constant Elf_Uchar := 1;
   STB_WEAK   : constant Elf_Uchar := 2;
   STB_LOPROC : constant Elf_Uchar := 13;
   STB_HIPROC : constant Elf_Uchar := 15;

   --  Symbol types.
   STT_NOTYPE  : constant Elf_Uchar := 0;
   STT_OBJECT  : constant Elf_Uchar := 1;
   STT_FUNC    : constant Elf_Uchar := 2;
   STT_SECTION : constant Elf_Uchar := 3;
   STT_FILE    : constant Elf_Uchar := 4;
   STT_LOPROC  : constant Elf_Uchar := 13;
   STT_HIPROC  : constant Elf_Uchar := 15;


   PT_NULL         : constant Elf_Word := 0;
   PT_LOAD         : constant Elf_Word := 1;
   PT_DYNAMIC      : constant Elf_Word := 2;
   PT_INTERP       : constant Elf_Word := 3;
   PT_NOTE         : constant Elf_Word := 4;
   PT_SHLIB        : constant Elf_Word := 5;
   PT_PHDR         : constant Elf_Word := 6;
   PT_TLS          : constant Elf_Word := 7;
   PT_NUM          : constant Elf_Word := 8;
   PT_LOOS         : constant Elf_Word := 16#60000000#;
   PT_GNU_EH_FRAME : constant Elf_Word := 16#6474e550#;
   PT_LOSUNW       : constant Elf_Word := 16#6ffffffa#;
   PT_SUNWBSS      : constant Elf_Word := 16#6ffffffa#;
   PT_SUNWSTACK    : constant Elf_Word := 16#6ffffffb#;
   PT_HISUNW       : constant Elf_Word := 16#6fffffff#;
   PT_HIOS         : constant Elf_Word := 16#6fffffff#;
   PT_LOPROC       : constant Elf_Word := 16#70000000#;
   PT_HIPROC       : constant Elf_Word := 16#7fffffff#;

   PF_X : constant Elf_Word := 1;
   PF_W : constant Elf_Word := 2;
   PF_R : constant Elf_Word := 4;

   DT_NULL            : constant Elf_Word := 0;
   DT_NEEDED          : constant Elf_Word := 1;
   DT_PLTRELSZ        : constant Elf_Word := 2;
   DT_PLTGOT          : constant Elf_Word := 3;
   DT_HASH            : constant Elf_Word := 4;
   DT_STRTAB          : constant Elf_Word := 5;
   DT_SYMTAB          : constant Elf_Word := 6;
   DT_RELA            : constant Elf_Word := 7;
   DT_RELASZ          : constant Elf_Word := 8;
   DT_RELAENT         : constant Elf_Word := 9;
   DT_STRSZ           : constant Elf_Word := 10;
   DT_SYMENT          : constant Elf_Word := 11;
   DT_INIT            : constant Elf_Word := 12;
   DT_FINI            : constant Elf_Word := 13;
   DT_SONAME          : constant Elf_Word := 14;
   DT_RPATH           : constant Elf_Word := 15;
   DT_SYMBOLIC        : constant Elf_Word := 16;
   DT_REL             : constant Elf_Word := 17;
   DT_RELSZ           : constant Elf_Word := 18;
   DT_RELENT          : constant Elf_Word := 19;
   DT_PLTREL          : constant Elf_Word := 20;
   DT_DEBUG           : constant Elf_Word := 21;
   DT_TEXTREL         : constant Elf_Word := 22;
   DT_JMPREL          : constant Elf_Word := 23;
   DT_BIND_NOW        : constant Elf_Word := 24;
   DT_INIT_ARRAY      : constant Elf_Word := 25;
   DT_FINI_ARRAY      : constant Elf_Word := 26;
   DT_INIT_ARRAYSZ    : constant Elf_Word := 27;
   DT_FINI_ARRAYSZ    : constant Elf_Word := 28;
   DT_RUNPATH         : constant Elf_Word := 29;
   DT_FLAGS           : constant Elf_Word := 30;
   DT_ENCODING        : constant Elf_Word := 32;
   DT_PREINIT_ARRAY   : constant Elf_Word := 32;
   DT_PREINIT_ARRAYSZ : constant Elf_Word := 33;
   DT_NUM             : constant Elf_Word := 34;
   DT_LOOS            : constant Elf_Word := 16#60000000#;
   DT_HIOS            : constant Elf_Word := 16#6fffffff#;
   DT_LOPROC          : constant Elf_Word := 16#70000000#;
   DT_HIPROC          : constant Elf_Word := 16#7fffffff#;
   DT_VALRNGLO        : constant Elf_Word := 16#6ffffd00#;
   DT_GNU_PRELINKED   : constant Elf_Word := 16#6ffffdf5#;
   DT_GNU_CONFLICTSZ  : constant Elf_Word := 16#6ffffdf6#;
   DT_GNU_LIBLISTSZ   : constant Elf_Word := 16#6ffffdf7#;
   DT_CHECKSUM        : constant Elf_Word := 16#6ffffdf8#;
   DT_PLTPADSZ        : constant Elf_Word := 16#6ffffdf9#;
   DT_MOVEENT         : constant Elf_Word := 16#6ffffdfa#;
   DT_MOVESZ          : constant Elf_Word := 16#6ffffdfb#;
   DT_FEATURE_1       : constant Elf_Word := 16#6ffffdfc#;
   DT_POSFLAG_1       : constant Elf_Word := 16#6ffffdfd#;
   DT_SYMINSZ         : constant Elf_Word := 16#6ffffdfe#;
   DT_SYMINENT        : constant Elf_Word := 16#6ffffdff#;
   DT_VALRNGHI        : constant Elf_Word := 16#6ffffdff#;
   DT_ADDRRNGLO       : constant Elf_Word := 16#6ffffe00#;
   DT_GNU_CONFLICT    : constant Elf_Word := 16#6ffffef8#;
   DT_GNU_LIBLIST     : constant Elf_Word := 16#6ffffef9#;
   DT_CONFIG          : constant Elf_Word := 16#6ffffefa#;
   DT_DEPAUDIT        : constant Elf_Word := 16#6ffffefb#;
   DT_AUDIT           : constant Elf_Word := 16#6ffffefc#;
   DT_PLTPAD          : constant Elf_Word := 16#6ffffefd#;
   DT_MOVETAB         : constant Elf_Word := 16#6ffffefe#;
   DT_SYMINFO         : constant Elf_Word := 16#6ffffeff#;
   DT_ADDRRNGHI       : constant Elf_Word := 16#6ffffeff#;
   DT_VERSYM          : constant Elf_Word := 16#6ffffff0#;
   DT_RELACOUNT       : constant Elf_Word := 16#6ffffff9#;
   DT_RELCOUNT        : constant Elf_Word := 16#6ffffffa#;
   DT_FLAGS_1         : constant Elf_Word := 16#6ffffffb#;
   DT_VERDEF          : constant Elf_Word := 16#6ffffffc#;
   DT_VERDEFNUM       : constant Elf_Word := 16#6ffffffd#;
   DT_VERNEED         : constant Elf_Word := 16#6ffffffe#;
   DT_VERNEEDNUM      : constant Elf_Word := 16#6fffffff#;
   DT_AUXILIARY       : constant Elf_Word := 16#7ffffffd#;
   DT_FILTER          : constant Elf_Word := 16#7fffffff#;

end Elf_Common;