OpenCores
URL https://opencores.org/ocsvn/forwardcom/forwardcom/trunk

Subversion Repositories forwardcom

[/] [forwardcom/] [bintools/] [elf_forwardcom.h] - Blame information for rev 141

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 32 Agner
/****************************    elf_forwardcom.h    **************************
2
* Author:              Agner Fog
3
* Date created:        2016-06-25
4
* Last modified:       2021-05-28
5
* ForwardCom version:  1.11
6
* Program version:     1.11
7
* Project:             ForwardCom binary tools
8
* Description:         Definition of ELF file format. See below
9
*
10
* To do: define exception handler and stack unwind information
11
* To do: define stack size and heap size information
12
* To do: define memory reservation for runtime linking
13
* To do: define formats for debug information
14
* To do: define access rights of executable file or device driver
15
*
16
* Copyright 2016-2021 GNU General Public License v. 3
17
* http://www.gnu.org/licenses/gpl.html
18
*******************************************************************************
19
 
20
This C/C++ header file contains the official definition of the ForwardCom
21
variant of the ELF file format for object files and executable files.
22
The latest version is stored at https://github.com/ForwardCom/bintools
23
 
24
An executable file contains the following elements:
25
1. ELF file header with the structure ElfFwcEhdr
26
2. Any number of program headers with the structure ElfFwcPhdr
27
3. Raw data. Each section aligned by 8
28
4. Any number of section headers with the structure ElfFwcShdr
29
   The sections can have different types as defined by sh_type, including
30
   code, data, symbol tables, string tables, and relocation records.
31
 
32
The program headers and section headers may point to the same raw data. The
33
program headers are used by the loader and the section headers are used by the
34
linker. An object file has the same format, but with no program headers.
35
 
36
The program headers in an executable file must come in the following order:
37
* const (ip)
38
* code (ip)
39
* data (datap)
40
* bss (datap)
41
* data (threadp)
42
* bss (threadp)
43
There may be any number of headers in each category.
44
The raw data in an executable file must come in the same order as the headers
45
that point to them.
46
These rules are intended to simplify boot loader code in small devices.
47
 
48
 
49
ForwardCom library files have the standard UNIX archive format with a sorted
50
symbol table. The details are described below. Dynamic link libraries and
51
shared objects are not used in the ForwardCom system.
52
 
53
******************************************************************************/
54
 
55
#ifndef ELF_FORW_H
56
#define ELF_FORW_H  111    // version number
57
 
58
 
59
//--------------------------------------------------------------------------
60
//                         ELF FILE HEADER
61
//--------------------------------------------------------------------------
62
 
63
struct ElfFwcEhdr {
64
  uint8_t   e_ident[16];   // Magic number and other info
65
                           // e_ident[EI_CLASS] = ELFCLASS64: file class
66
                           // e_ident[EI_DATA] = ELFDATA2LSB: 2's complement, little endian
67
                           // e_ident[EI_VERSION] = EV_CURRENT: current ELF version
68
                           // e_ident[EI_OSABI] = ELFOSABI_FORWARDCOM
69
                           // e_ident[EI_ABIVERSION] = 0 
70
                           // The rest is unused padding   
71
  uint16_t  e_type;        // Object file type
72
  uint16_t  e_machine;     // Architecture
73
  uint32_t  e_version;     // Object file version
74
  uint64_t  e_entry;       // Entry point virtual address
75
  uint64_t  e_phoff;       // Program header table file offset
76
  uint64_t  e_shoff;       // Section header table file offset
77
  uint32_t  e_flags;       // Processor-specific flags. We may define any values for these flags
78
  uint16_t  e_ehsize;      // ELF header size in bytes
79
  uint16_t  e_phentsize;   // Program header table entry size
80
  uint16_t  e_phnum;       // Program header table entry count
81
  uint16_t  e_shentsize;   // Section header table entry size
82
  uint32_t  e_shnum;       // Section header table entry count (was uint16_t)
83
  uint32_t  e_shstrndx;    // Section header string table index (was uint16_t)
84
  // additional fields for ForwardCom
85
  uint32_t  e_stackvect;   // number of vectors to store on stack. multiply by max vector length and add to stacksize
86
  uint64_t  e_stacksize;   // size of stack for main thread
87
  uint64_t  e_ip_base;     // __ip_base relative to first ip based segment
88
  uint64_t  e_datap_base;  // __datap_base relative to first datap based segment
89
  uint64_t  e_threadp_base;// __threadp_base relative to first threadp based segment
90
};
91
 
92
 
93
// Fields in the e_ident array.  The EI_* macros are indices into the array.  
94
// The macros under each EI_* macro are the values the byte may have. 
95
 
96
// Conglomeration of the identification bytes, for easy testing as a word.
97
//#define ELFMAG        "\177ELF"
98
#define ELFMAG        0x464C457F  // 0x7F 'E' 'L' 'F'
99
 
100
// File class
101
#define EI_CLASS      4    // File class byte index
102
#define ELFCLASSNONE  0    // Invalid class
103
#define ELFCLASS32    1    // 32-bit objects
104
#define ELFCLASS64    2    // 64-bit objects *
105
#define ELFCLASSNUM   3
106
 
107
#define EI_DATA       5    // Data encoding byte index
108
#define ELFDATANONE   0    // Invalid data encoding
109
#define ELFDATA2LSB   1    // 2's complement, little endian *
110
#define ELFDATA2MSB   2    // 2's complement, big endian
111
#define ELFDATANUM    3
112
 
113
#define EI_VERSION    6    // File version byte index
114
 
115
#define EI_OSABI               7  // OS ABI identification
116
#define ELFOSABI_SYSV          0  // UNIX System V ABI
117
#define ELFOSABI_HPUX          1  // HP-UX 
118
#define ELFOSABI_ARM          97  // ARM 
119
#define ELFOSABI_STANDALONE  255  // Standalone (embedded) application
120
#define ELFOSABI_FORWARDCOM  250  // ForwardCom 
121
 
122
#define EI_ABIVERSION    8    // x86 ABI version
123
#define EI_ABIVERSION_FORWARDCOM    1    // ForwardCom ABI version
124
 
125
#define EI_PAD           9    // Byte index of padding bytes
126
 
127
// Legal values for e_type (object file type). 
128
#define ET_NONE          0    // No file type
129
#define ET_REL           1    // Relocatable file
130
#define ET_EXEC          2    // Executable file
131
#define ET_DYN           3    // Shared object file (not used by ForwardCom)
132
#define ET_CORE          4    // Core file 
133
#define ET_NUM           5    // Number of defined types
134
#define ET_LOOS     0xfe00    // OS-specific range start
135
#define ET_HIOS     0xfeff    // OS-specific range end
136
#define ET_LOPROC   0xff00    // Processor-specific range start
137
#define ET_HIPROC   0xffff    // Processor-specific range end
138
 
139
// Legal values for e_machine (architecture)
140
#define EM_NONE          0     // No machine
141
#define EM_M32           1     // AT&T WE 32100
142
#define EM_SPARC         2     // SUN SPARC
143
#define EM_386           3     // Intel 80386
144
#define EM_68K           4     // Motorola m68k family
145
#define EM_88K           5     // Motorola m88k family
146
#define EM_860           7     // Intel 80860
147
#define EM_MIPS          8     // MIPS R3000 big-endian
148
#define EM_S370          9     // IBM System/370
149
#define EM_MIPS_RS3_LE  10     // MIPS R3000 little-endian
150
#define EM_PARISC       15     // HPPA
151
#define EM_VPP500       17     // Fujitsu VPP500
152
#define EM_SPARC32PLUS  18     // Sun's "v8plus"
153
#define EM_960          19     // Intel 80960
154
#define EM_PPC          20     // PowerPC
155
#define EM_PPC64        21     // PowerPC 64-bit
156
#define EM_S390         22     // IBM S390
157
#define EM_V800         36     // NEC V800 series
158
#define EM_FR20         37     // Fujitsu FR20
159
#define EM_RH32         38     // TRW RH-32
160
#define EM_RCE          39     // Motorola RCE
161
#define EM_ARM          40     // ARM
162
#define EM_FAKE_ALPHA   41     // Digital Alpha
163
#define EM_SH           42     // Hitachi SH
164
#define EM_SPARCV9      43     // SPARC v9 64-bit
165
#define EM_TRICORE      44     // Siemens Tricore
166
#define EM_ARC          45     // Argonaut RISC Core
167
#define EM_H8_300       46     // Hitachi H8/300
168
#define EM_H8_300H      47     // Hitachi H8/300H
169
#define EM_H8S          48     // Hitachi H8S
170
#define EM_H8_500       49     // Hitachi H8/500
171
#define EM_IA_64        50     // Intel Merced
172
#define EM_MIPS_X       51     // Stanford MIPS-X
173
#define EM_COLDFIRE     52     // Motorola Coldfire
174
#define EM_68HC12       53     // Motorola M68HC12
175
#define EM_MMA          54     // Fujitsu MMA Multimedia Accelerator
176
#define EM_PCP          55     // Siemens PCP
177
#define EM_NCPU         56     // Sony nCPU embeeded RISC
178
#define EM_NDR1         57     // Denso NDR1 microprocessor
179
#define EM_STARCORE     58     // Motorola Start*Core processor
180
#define EM_ME16         59     // Toyota ME16 processor
181
#define EM_ST100        60     // STMicroelectronic ST100 processor
182
#define EM_TINYJ        61     // Advanced Logic Corp. Tinyj emb.fam
183
#define EM_X86_64       62     // AMD x86-64 architecture
184
#define EM_PDSP         63     // Sony DSP Processor
185
#define EM_FX66         66     // Siemens FX66 microcontroller
186
#define EM_ST9PLUS      67     // STMicroelectronics ST9+ 8/16 mc
187
#define EM_ST7          68     // STmicroelectronics ST7 8 bit mc
188
#define EM_68HC16       69     // Motorola MC68HC16 microcontroller
189
#define EM_68HC11       70     // Motorola MC68HC11 microcontroller
190
#define EM_68HC08       71     // Motorola MC68HC08 microcontroller
191
#define EM_68HC05       72     // Motorola MC68HC05 microcontroller
192
#define EM_SVX          73     // Silicon Graphics SVx
193
#define EM_AT19         74     // STMicroelectronics ST19 8 bit mc
194
#define EM_VAX          75     // Digital VAX
195
#define EM_CRIS         76     // Axis Communications 32-bit embedded processor
196
#define EM_JAVELIN      77     // Infineon Technologies 32-bit embedded processor
197
#define EM_FIREPATH     78     // Element 14 64-bit DSP Processor
198
#define EM_ZSP          79     // LSI Logic 16-bit DSP Processor
199
#define EM_MMIX         80     // Donald Knuth's educational 64-bit processor
200
#define EM_HUANY        81     // Harvard University machine-independent object files
201
#define EM_PRISM        82     // SiTera Prism
202
#define EM_AVR          83     // Atmel AVR 8-bit microcontroller
203
#define EM_FR30         84     // Fujitsu FR30
204
#define EM_D10V         85     // Mitsubishi D10V
205
#define EM_D30V         86     // Mitsubishi D30V
206
#define EM_V850         87     // NEC v850
207
#define EM_M32R         88     // Mitsubishi M32R
208
#define EM_MN10300      89     // Matsushita MN10300
209
#define EM_MN10200      90     // Matsushita MN10200
210
#define EM_PJ           91     // picoJava
211
#define EM_OPENRISC     92     // OpenRISC 32-bit embedded processor
212
#define EM_RISCV        243    // RISC-V
213
#define EM_OR32         0x8472 // Open RISC
214
#define EM_ALPHA        0x9026 // Digital Alpha
215
#define EM_FORWARDCOM   0x6233 // ForwardCom preliminary value (constructed from F=6, W=23, C=3)
216
 
217
// Legal values for e_version (version).
218
#define EV_NONE          0    // Invalid ELF version
219
#define EV_CURRENT       1    // Current version
220
#define EV_NUM           2
221
 
222
// Values for e_flags (file header flags)
223
#define EF_INCOMPLETE            0x01  // Incomplete executable file contains unresolved references
224
#define EF_RELINKABLE            0x02  // Relinking of executable file is possible
225
#define EF_RELOCATE              0x10  // Relocation needed when program is loaded
226
#define EF_POSITION_DEPENDENT    0x20  // Contains position-dependent relocations. Multiple processes cannot share same read-only data and code
227
 
228
 
229
//--------------------------------------------------------------------------
230
//                         SECTION HEADER
231
//--------------------------------------------------------------------------
232
 
233
struct ElfFwcShdr {
234
  uint32_t  sh_name;      // Section name (string table index)
235
  uint32_t  sh_flags;     // Section flags
236
  uint64_t  sh_addr;      // Address relative to section group begin
237
  uint64_t  sh_offset;    // Section file offset
238
  uint64_t  sh_size;      // Section size in bytes
239
  uint32_t  sh_link;      // Link to symbol section or string table
240
  uint32_t  sh_entsize;   // Entry size if section holds table
241
  uint32_t  sh_module;    // Module name in relinkable executable
242
  uint32_t  sh_library;   // Library name in relinkable executable
243
  uint32_t  unused1;      // Alignment filler
244
  uint8_t   sh_type;      // Section type
245
  uint8_t   sh_align;     // Section alignment = 1 << sh_align
246
  uint8_t   sh_relink;    // Commands used during relinking. Unused in file
247
  uint8_t   unused2;      // Unused filler
248
};
249
 
250
// Legal values for sh_type (section type)
251
#define SHT_NULL                    0  // Section header table entry unused
252
#define SHT_SYMTAB                  2  // Symbol table. There can be only one symbol table
253
#define SHT_STRTAB                  3  // String table. There are two string tables, one for symbol names and one for section names
254
#define SHT_RELA                    4  // Relocation entries with addends
255
#define SHT_NOTE                    7  // Notes
256
#define SHT_PROGBITS             0x11  // Program data
257
#define SHT_NOBITS               0x12  // Uninitialized data space (bss)
258
#define SHT_COMDAT               0x14  // Communal data or code. Duplicate and unreferenced sections are removed
259
#define SHT_ALLOCATED            0x10  // Allocated at runtime. This bits indicates SHT_PROGBITS, SHT_NOBITS, SHT_COMDAT
260
#define SHT_LIST                 0x20  // Other list. Not loaded into memory. (unsorted event list, )
261
#define SHT_STACKSIZE            0x41  // Records for calculation of stack size
262
#define SHT_ACCESSRIGHTS         0x42  // Records for indicating desired access rights of executable file or device driver
263
// obsolete types, not belonging to ForwardCom
264
//#define SHT_REL                     9  // Relocation entries, no addends
265
//#define SHT_HASH                    5  // Symbol hash table
266
//#define SHT_DYNAMIC                 6  // Dynamic linking information
267
//#define SHT_DYNSYM                0xB  // Dynamic linker symbol table
268
//#define SHT_SHLIB                 0xA  // Reserved
269
//#define SHT_GROUP                0x11  // Section group
270
 
271
// Legal values for sh_flags (section flags). 
272
#define SHF_EXEC                  0x1  // Executable
273
#define SHF_WRITE                 0x2  // Writable
274
#define SHF_READ                  0x4  // Readable
275
#define SHF_PERMISSIONS          (SHF_EXEC | SHF_WRITE | SHF_READ) // access permissions mask
276
#define SHF_MERGE                0x10  // Elements with same value might be merged
277
#define SHF_STRINGS              0x20  // Contains nul-terminated strings
278
#define SHF_INFO_LINK            0x40  // sh_info contains section header index
279
#define SHF_ALLOC               0x100  // Occupies memory during execution
280
#define SHF_IP                 0x1000  // Addressed relative to IP (executable and read-only sections)
281
#define SHF_DATAP              0x2000  // Addressed relative to DATAP (writeable data sections)
282
#define SHF_THREADP            0x4000  // Addressed relative to THREADP (thread-local data sections)
283
#define SHF_BASEPOINTER      (SHF_IP | SHF_DATAP | SHF_THREADP)  // mask to detect base pointer
284
#define SHF_EVENT_HND        0x100000  // Event handler list, contains ElfFwcEvent structures
285
#define SHF_EXCEPTION_HND    0x200000  // Exception handler and stack unroll information
286
#define SHF_DEBUG_INFO       0x400000  // Debug information
287
#define SHF_COMMENT          0x800000  // Comments, including copyright and required libraries
288
#define SHF_RELINK          0x1000000  // Section in executable file can be relinked
289
#define SHF_FIXED           0x2000000  // Non-relinkable section in relinkable file has fixed address relative to base pointers
290
#define SHF_AUTOGEN         0x4000000  // Section is generated by the linker. remake when relinking
291
 
292
 
293
//--------------------------------------------------------------------------
294
//                         SYMBOL TABLES
295
//--------------------------------------------------------------------------
296
 
297
// Symbol table entry, x64
298
struct Elf64_Sym {
299
    uint32_t  st_name;       // Symbol name (string tbl index)
300
    uint8_t   st_type: 4,    // Symbol type
301
              st_bind: 4;    // Symbol binding
302
    uint8_t   st_other;      // Symbol visibility
303
    uint16_t  st_section;    // Section index
304
    uint64_t  st_value;      // Symbol value
305
    uint64_t  st_size;       // Symbol size
306
};
307
 
308
// Symbol table entry, ForwardCom
309
struct ElfFwcSym {
310
  uint32_t  st_name;       // Symbol name (string table index)
311
  uint8_t   st_type;       // Symbol type
312
  uint8_t   st_bind;       // Symbol binding
313
  uint8_t   unused1, unused2;// Alignment fillers
314
  uint32_t  st_other;      // Symbol visibility and additional type information
315
  uint32_t  st_section;    // Section header index (zero for external symbols)
316
  uint64_t  st_value;      // Symbol value
317
  uint32_t  st_unitsize;   // Size of array elements or data unit. Data type is given by st_unitsize and STV_FLOAT
318
                           // st_unitsize is 4 or more for executable code
319
  uint32_t  st_unitnum;    // Symbol size = st_unitsize * st_unitnum 
320
  uint32_t  st_reguse1;    // Register use. bit 0-31 = r0-r31
321
  uint32_t  st_reguse2;    // Register use. bit 0-31 = v0-v31
322
};
323
 
324
// Values for st_bind: symbol binding
325
#define STB_LOCAL           0     // Local symbol
326
#define STB_GLOBAL          1     // Global symbol
327
#define STB_WEAK            2     // Weak symbol
328
#define STB_WEAK2           6     // Weak public symbol with local reference is both import and export
329
#define STB_UNRESOLVED   0x0A     // Symbol is unresolved. Treat as weak
330
#define STB_IGNORE       0x10     // This value is used only internally in the linker (ignore weak/strong during search; ignore overridden weak symbol)
331
#define STB_EXE          0x80     // This value is used only internally in the linker (copy to executable file)
332
 
333
// Values for st_type: symbol type
334
#define STT_NOTYPE          0     // Symbol type is unspecified
335
#define STT_OBJECT          1     // Symbol is a data object
336
#define STT_FUNC            2     // Symbol is a code object
337
#define STT_SECTION         3     // Symbol is a section begin
338
#define STT_FILE            4     // Symbol's name is file name
339
#define STT_COMMON          5     // Symbol is a common data object. Use STV_COMMON instead!
340
//#define STT_TLS           6     // Thread local data object. Use STV_THREADP instead!
341
#define STT_CONSTANT     0x10     // Symbol is a constant with no address
342
#define STT_VARIABLE     0x11     // Symbol is a variable used during assembly. Should not occur in object file
343
#define STT_EXPRESSION   0x12     // Symbol is an expression used during assembly. Should not occur in object file
344
#define STT_TYPENAME     0x14     // Symbol is a type name used during assembly. Should not occur in object file
345
 
346
// Symbol visibility specification encoded in the st_other field. 
347
#define STV_DEFAULT         0     // Default symbol visibility rules
348
//#define STV_INTERNAL        1     // Processor specific hidden class
349
#define STV_HIDDEN         0x20     // Symbol unavailable in other modules
350
//#define STV_PROTECTED       3     // Not preemptible, not exported
351
// st_other types added for ForwardCom:
352
#define STV_EXEC         SHF_EXEC    // = 0x1. Executable code
353
#define STV_WRITE        SHF_WRITE   // = 0x2. Writable data
354
#define STV_READ         SHF_READ    // = 0x4. Readable data
355
#define STV_IP           SHF_IP      // = 0x1000. Addressed relative to IP (in executable and read-only sections)
356
#define STV_DATAP        SHF_DATAP   // = 0x2000. Addressed relative to DATAP (in writeable data sections)
357
#define STV_THREADP      SHF_THREADP // = 0x4000. Addressed relative to THREADP (in thrad local data sections)
358
#define STV_REGUSE       0x10000     // st_reguse field contains register use information
359
#define STV_FLOAT        0x20000     // st_value is a double precision floating point (with STT_CONSTANT)
360
#define STV_STRING       0x40000     // st_value is an assemble-time string. Should not occur in object file
361
#define STV_COMMON      0x100000     // Symbol is communal. Multiple identical instances can be joined. Unreferenced instances can be removed
362
#define STV_UNWIND      0x400000     // Symbol is a table with exception handling and stack unwind information
363
#define STV_DEBUG       0x800000     // Symbol is a table with debug information
364
#define STV_RELINK    SHF_RELINK     // Symbol in executable file can be relinked
365
#define STV_AUTOGEN   SHF_AUTOGEN    // Symbol is generated by the linker. remake when relinking
366
#define STV_MAIN      0x10000000     // Main entry point in executable file
367
#define STV_EXPORTED  0x20000000     // Exported from executable file
368
#define STV_THREAD    0x40000000     // Thread function. Requires own stack
369
#define STV_SECT_ATTR (SHF_EXEC | SHF_READ | SHF_WRITE | SHF_IP | SHF_DATAP | SHF_THREADP | SHF_RELINK | SHF_AUTOGEN) // section attributes to copy to symbol
370
 
371
 
372
/* Definition of absolute symbols:
373
x86 ELF uses symbols with st_section = SHN_ABS_X86 to indicate a public absolute symbol.
374
ForwardCom uses st_type = STT_CONSTANT and sets st_section to the index of an arbitrary
375
section in the same module as the absolute symbol. This is necessary for indicating which
376
module an absolute symbol belongs to in a relinkable executable file. An object file
377
defining absolute symbols must have at least one section, even if it is empty.
378
*/
379
// Special section indices. not used in ForwardCom
380
#define SHN_UNDEF                     0    // Undefined section. external symbol
381
//#define SHN_LORESERVE  ((int16_t)0xff00) // Start of reserved indices
382
//#define SHN_LOPROC     ((int16_t)0xff00) // Start of processor-specific
383
//#define SHN_HIPROC     ((int16_t)0xff1f) // End of processor-specific
384
//#define SHN_LOOS       ((int16_t)0xff20) // Start of OS-specific
385
//#define SHN_HIOS       ((int16_t)0xff3f) // End of OS-specific
386
#define SHN_ABS_X86      ((int16_t)0xfff1) // Associated symbol is absolute (x86 ELF)
387
//#define SHN_COMMON     ((int16_t)0xfff2) // Associated symbol is common (x86 ELF)
388
//#define SHN_XINDEX     ((int16_t)0xffff) // Index is in extra table
389
//#define SHN_HIRESERVE  ((int16_t)0xffff) // End of reserved indices
390
 
391
 
392
//--------------------------------------------------------------------------
393
//                         RELOCATION TABLES
394
//--------------------------------------------------------------------------
395
 
396
// Relocation table entry with addend, x86-64 in section of type SHT_RELA. Not used in ForwardCom
397
struct Elf64_Rela {
398
    uint64_t  r_offset;           // Address
399
    uint32_t  r_type;             // Relocation type
400
    uint32_t  r_sym;              // Symbol index
401
    int64_t   r_addend;           // Addend
402
};
403
 
404
// Relocation table entry for ForwardCom (in section of type SHT_RELA).
405
struct ElfFwcReloc {
406
    uint64_t  r_offset;           // Address relative to section
407
    uint32_t  r_section;          // Section index
408
    uint32_t  r_type;             // Relocation type
409
    uint32_t  r_sym;              // Symbol index
410
    int32_t   r_addend;           // Addend
411
    uint32_t  r_refsym;           // Reference symbol
412
};
413
 
414
 
415
// AMD x86-64 relocation types
416
#define R_X86_64_NONE       0     // No reloc
417
#define R_X86_64_64         1     // Direct 64 bit 
418
#define R_X86_64_PC32       2     // Self relative 32 bit signed (not RIP relative in the sense used in COFF files)
419
#define R_X86_64_GOT32      3     // 32 bit GOT entry
420
#define R_X86_64_PLT32      4     // 32 bit PLT address
421
#define R_X86_64_COPY       5     // Copy symbol at runtime
422
#define R_X86_64_GLOB_DAT   6     // Create GOT entry
423
#define R_X86_64_JUMP_SLOT  7     // Create PLT entry
424
#define R_X86_64_RELATIVE   8     // Adjust by program base
425
#define R_X86_64_GOTPCREL   9     // 32 bit signed self relative offset to GOT
426
#define R_X86_64_32        10     // Direct 32 bit zero extended
427
#define R_X86_64_32S       11     // Direct 32 bit sign extended
428
#define R_X86_64_16        12     // Direct 16 bit zero extended
429
#define R_X86_64_PC16      13     // 16 bit sign extended self relative
430
#define R_X86_64_8         14     // Direct 8 bit sign extended
431
#define R_X86_64_PC8       15     // 8 bit sign extended self relative
432
#define R_X86_64_IRELATIVE 37     // Reference to PLT entry of indirect function (STT_GNU_IFUNC)
433
 
434
 
435
// ForwardCom relocation types are composed of these three fields:
436
// Relocation type in bit 16-31
437
// Relocation size in bit 8-15
438
// Scale factor in bit 0-7.
439
// The r_type field is composed by OR'ing these three.
440
// The value in the relocation field of the specified size will be multiplied by the scale factor.
441
// All relative relocations use signed values.
442
// Instructions with self-relative (IP-relative) addressing are using the END of the instruction 
443
// as reference point. The r_addend field must compensate for the distance between 
444
// the end of the instruction and the beginning of the address field. This will be -7 for 
445
// instructions with format 2.5.3 and -4 for all other jump and call instructions. 
446
// Any offset of the target may be added to r_addend. The value of r_addend is not scaled.
447
// Relocations relative to an arbitrary reference point can be used in jump tables.
448
// The reference point is indicated by a symbol index in r_refsym.
449
// The system function ID relocations are done by the loader, where r_sym indicates the name
450
// of the function in the string table, and r_addend indicates the name of the module or
451
// device driver.
452
// The value at r_offset is not used in the calculation but overwritten with the calculated 
453
// target address. 
454
 
455
// ForwardCom relocation types
456
#define R_FORW_ABS           0x000000       // Absolute address. Scaling is possible, but rarely used
457
#define R_FORW_SELFREL       0x010000       // Self relative. Scale by 4 for code address
458
#define R_FORW_IP_BASE       0x040000       // Relative to __ip_base. Any scale
459
#define R_FORW_DATAP         0x050000       // Relative to __datap_base. Any scale
460
#define R_FORW_THREADP       0x060000       // Relative to __threadp_base. Any scale
461
#define R_FORW_REFP          0x080000       // Relative to arbitrary reference point. Reference symbol index in high 32 bits of r_addend. Any scale
462
#define R_FORW_SYSFUNC       0x100000       // System function ID for system_call, 16 or 32 bit
463
#define R_FORW_SYSMODUL      0x110000       // System module ID for system_call, 16 or 32 bit
464
#define R_FORW_SYSCALL       0x120000       // Combined system module and function ID for system_call, 32 or 64 bit
465
#define R_FORW_DATASTACK     0x200000       // Calculated size of data stack for function, 32 or 64 bit. Scale by 1 or 8
466
#define R_FORW_CALLSTACK     0x210000       // Calculated size of call stack for function, 32 bit. Scale by 1 or 8
467
#define R_FORW_REGUSE        0x400000       // Register use of function, 64 bit
468
#define R_FORW_RELTYPEMASK   0xFF0000       // Mask for isolating relocation type
469
 
470
// Relocation sizes
471
#define R_FORW_NONE          0x000000       // No relocation
472
#define R_FORW_8             0x000100       // 8  bit relocation size
473
#define R_FORW_16            0x000200       // 16 bit relocation size
474
#define R_FORW_24            0x000300       // 24 bit relocation size
475
#define R_FORW_32            0x000400       // 32 bit relocation size
476
#define R_FORW_32LO          0x000500       // Low  16 of 32 bits relocation
477
#define R_FORW_32HI          0x000600       // High 16 of 32 bits relocation
478
#define R_FORW_64            0x000800       // 64 bit relocation size
479
#define R_FORW_64LO          0x000900       // Low  32 of 64 bits relocation
480
#define R_FORW_64HI          0x000A00       // High 32 of 64 bits relocation
481
#define R_FORW_RELSIZEMASK   0x00FF00       // Mask for isolating relocation size
482
 
483
// Relocation scale factors
484
#define R_FORW_SCALE1        0x000000       // Scale factor 1
485
#define R_FORW_SCALE2        0x000001       // Scale factor 2
486
#define R_FORW_SCALE4        0x000002       // Scale factor 4
487
#define R_FORW_SCALE8        0x000003       // Scale factor 8
488
#define R_FORW_SCALE16       0x000004       // Scale factor 16
489
#define R_FORW_RELSCALEMASK  0x0000FF       // Mask for isolating relocation scale factor
490
 
491
// Relocation options
492
#define R_FORW_RELINK      0x01000000       // Refers to relinkable symbol in executable file
493
#define R_FORW_LOADTIME    0x02000000       // Must be relocated at load time. Records with this bit must come first
494
 
495
 
496
//--------------------------------------------------------------------------
497
//                         PROGRAM HEADER
498
//--------------------------------------------------------------------------
499
 
500
// Program header
501
struct ElfFwcPhdr {
502
  uint32_t  p_type;      // Segment type
503
  uint32_t  p_flags;     // Segment flags
504
  uint64_t  p_offset;    // Segment file offset
505
  uint64_t  p_vaddr;     // Segment virtual address
506
  uint64_t  p_paddr;     // Segment physical address (not used. indicates first section instead)
507
  uint64_t  p_filesz;    // Segment size in file
508
  uint64_t  p_memsz;     // Segment size in memory
509
  uint8_t   p_align;     // Segment alignment
510
  uint8_t   unused[7];
511
};
512
 
513
// Legal values for p_type (segment type). 
514
 
515
#define PT_NULL             0    // Program header table entry unused
516
#define PT_LOAD             1    // Loadable program segment
517
#define PT_DYNAMIC          2    // Dynamic linking information
518
#define PT_INTERP           3    // Program interpreter
519
#define PT_NOTE             4    // Auxiliary information
520
#define PT_SHLIB            5    // Reserved
521
#define PT_PHDR             6    // Entry for header table itself
522
//#define PT_NUM              7    // Number of defined types
523
#define PT_LOOS    0x60000000    // Start of OS-specific
524
#define PT_HIOS    0x6fffffff    // End of OS-specific
525
#define PT_LOPROC        0x10    // Start of processor-specific
526
#define PT_HIPROC  0x5fffffff    // End of processor-specific
527
 
528
// Legal values for p_flags (segment flags) are the same as section flags, 
529
// see sh_flags above
530
 
531
/*
532
// Legal values for note segment descriptor types for core files.
533
#define NT_PRSTATUS    1    // Contains copy of prstatus struct
534
#define NT_FPREGSET    2    // Contains copy of fpregset struct
535
#define NT_PRPSINFO    3    // Contains copy of prpsinfo struct
536
#define NT_PRXREG      4    // Contains copy of prxregset struct
537
#define NT_PLATFORM    5    // String from sysinfo(SI_PLATFORM)
538
#define NT_AUXV        6    // Contains copy of auxv array
539
#define NT_GWINDOWS    7    // Contains copy of gwindows struct
540
#define NT_PSTATUS    10    // Contains copy of pstatus struct
541
#define NT_PSINFO     13    // Contains copy of psinfo struct
542
#define NT_PRCRED     14    // Contains copy of prcred struct
543
#define NT_UTSNAME    15    // Contains copy of utsname struct
544
#define NT_LWPSTATUS  16    // Contains copy of lwpstatus struct
545
#define NT_LWPSINFO   17    // Contains copy of lwpinfo struct
546
#define NT_PRFPXREG   20    // Contains copy of fprxregset struct
547
*/
548
// Legal values for the note segment descriptor types for object files.
549
#define NT_VERSION  1       // Contains a version string.
550
 
551
 
552
// Note section contents.  Each entry in the note section begins with a header of a fixed form.
553
 
554
struct Elf64_Nhdr {
555
  uint32_t n_namesz;      // Length of the note's name
556
  uint32_t n_descsz;      // Length of the note's descriptor
557
  uint32_t n_type;        // Type of the note
558
};
559
 
560
/* Defined note types for GNU systems.  */
561
 
562
/* ABI information.  The descriptor consists of words:
563
   word 0: OS descriptor
564
   word 1: major version of the ABI
565
   word 2: minor version of the ABI
566
   word 3: subminor version of the ABI
567
*/
568
#define ELF_NOTE_ABI    1
569
 
570
/* Known OSes.  These value can appear in word 0 of an ELF_NOTE_ABI
571
   note section entry.  */
572
#define ELF_NOTE_OS_LINUX         0
573
#define ELF_NOTE_OS_GNU           1
574
#define ELF_NOTE_OS_SOLARIS2      2
575
 
576
#define FILE_DATA_ALIGN           3  // section data must be aligned by (1 << FILE_DATA_ALIGN) in ELF file
577
 
578
// Memory map definitions
579
#define MEMORY_MAP_ALIGN          3  // align memory map entries by (1 << MEMORY_MAP_ALIGN)
580
#define DATA_EXTRA_SPACE       0x10  // extra space after const data section and last data section
581
 
582
 
583
//--------------------------------------------------------------------------
584
//                         EVENT HANDLER SYSTEM
585
//--------------------------------------------------------------------------
586
/*
587
 
588
A program module may contain a table of event handler records in a read-only
589
section with the attribute SHF_EVENT_HND. The event handler system may be used
590
for handling events, commands, and messages. It is also used for initialization
591
and clean-up. This replaces the constructors and destructors sections of other
592
systems.
593
 
594
The linker will sort the event records of all modules according to event id, key,
595
and priority. If there is more than one event handler for a particular event,
596
then all the event handlers will be called in the order of priority.
597
*/
598
 
599
// event record
600
struct ElfFwcEvent {
601
    int32_t  functionPtr;              // scaled relative pointer to event handler function = (function_address - __ip_base) / 4
602
    uint32_t priority;                 // priority. Highest values are called first. Normal priority = 0x1000
603
    uint32_t key;                      // keyboard hotkey, menu item, or icon id for user command events
604
    uint32_t event;                    // event ID
605
};
606
 
607
 
608
//--------------------------------------------------------------------------
609
//                         STACK SIZE TABLES
610
//--------------------------------------------------------------------------
611
 
612
// SHT_STACKSIZE stack table entry
613
struct ElfFwcStacksize {
614
  uint32_t  ss_syma;                   // Public symbol index
615
  uint32_t  ss_symb;                   // External symbol index. Zero for frame function or to indicate own stack use
616
  uint64_t  ss_framesize;              // Size of data stack frame in syma when calling symb
617
  uint32_t  ss_numvectors;             // Additional data stack frame size for vectors. Multiply by maximum vector length
618
  uint32_t  ss_calls;                  // Size of call stack when syma calls symb (typically 1). Multiply by stack word size = 8
619
};
620
 
621
 
622
//--------------------------------------------------------------------------
623
//                         MASK BITS
624
//--------------------------------------------------------------------------
625
// Masks are used for conditional execution and for setting options
626
 
627
// Mask bit numbers. These bits are used in instruction masks and NUMCONTR to specify various options
628
 
629
#define MSK_ENABLE                    0     // the instruction is not executed if bit number 0 is 0
630
#define MSKI_OPTIONS                 18     // bit number 18-23 contain instruction-specific options. currently unused
631
#define MSKI_ROUNDING                10     // bit number 10-11 indicate rounding mode:
632
                                            // 00: round to nearest or even
633
                                            // 01: round down
634
                                            // 10: round up
635
                                            // 11: truncate towards zero
636
#define MSKI_EXCEPTIONS               2     // bit number 2-5 enable exceptions for division by zero, overflow, underflow, inexact
637
#define MSK_DIVZERO                   2     // enable NAN exception for floating point division by zero
638
#define MSK_OVERFLOW                  3     // enable NAN exception for floating point overflow
639
#define MSK_UNDERFLOW                 4     // enable NAN exception for floating point underflow
640
#define MSK_INEXACT                   5     // enable NAN exception for floating point inexact
641
#define MSK_SUBNORMAL                13     // enable subnormal numbers for float32 and float64
642
#define MSK_CONST_TIME               31     // constant execution time, independent of data (for cryptographic security)
643
 
644
 
645
//--------------------------------------------------------------------------
646
//                         EXCEPTION INDICATORS (preliminary list)
647
//--------------------------------------------------------------------------
648
 
649
// NAN payloads are used for indicating that floating point exceptions have occurred.
650
// These values are generated in the lower 8 bits of NAN payloads.
651
// The remaining payload bits may contain information about the code address where the exception occurred.
652
 
653
// The nan exception indicators are generated only when the corresponding exceptions are enabled in mask bits:
654
const uint32_t nan_inexact           = 0x01;  // inexact result
655
const uint32_t nan_underflow         = 0x02;  // underflow
656
const uint32_t nan_div0              = 0x03;  // division by 0
657
const uint32_t nan_overflow_div      = 0x04;  // division overflow
658
const uint32_t nan_overflow_mul      = 0x05;  // multiplication overflow
659
const uint32_t nan_overflow_add      = 0x06;  // addition and subtraction overflow
660
const uint32_t nan_overflow_conv     = 0x07;  // conversion overflow
661
const uint32_t nan_overflow_other    = 0x08;  // other overflow
662
 
663
// The nan_invalid indicators are generated in case of invalid operations,
664
// regardless of whether exceptions are enabled or not:
665
const uint32_t nan_invalid_sub       = 0x20;  // inf-inf
666
const uint32_t nan_invalid_0div0     = 0x21;  // 0/0
667
const uint32_t nan_invalid_divinf    = 0x22;  // inf/inf
668
const uint32_t nan_invalid_0mulinf   = 0x23;  // 0*inf
669
const uint32_t nan_invalid_rem       = 0x24;  // inf rem 1, 1 rem 0
670
const uint32_t nan_invalid_sqrt      = 0x25;  // sqrt(-1)
671
const uint32_t nan_invalid_pow       = 0x28;  // pow(-1, 2.3)
672
const uint32_t nan_invalid_log       = 0x29;  // log(-1)
673
 
674
 
675
//--------------------------------------------------------------------------
676
//                         FORMAT FOR LIBRARY FILES
677
//--------------------------------------------------------------------------
678
/*
679
ForwardCom libraries use the standard Unix archive format.
680
The preferred filename extension is .li
681
 
682
The first archive member is a sorted symbol list, using the same format as used
683
by Apple/Mac named "/SYMDEF SORTED/". It contains a sorted list of public symbols.
684
The sort order is determined by the unsigned bytes of the ASCII/UTF-8 string.
685
This format is chosen because it provides the fastest symbol search.
686
 
687
The obsolete archive members with the name "/" containing symbol lists in less
688
efficient formats are not included.
689
 
690
The second archive member is a longnames record named "//" as used in Linux
691
and Windows systems. It contains module names longer than 15 characters.
692
Module names are stored without path so that they can be extracted on another
693
computer that does not have the same file structure.
694
 
695
The remaining modules contain object files in the format described above.
696
--------------------------------------------------------------------------------*/
697
 
698
// Signature defining the start of an archive file
699
#define archiveSignature  "!<arch>\n"
700
 
701
// Each library member starts with a UNIX archive member header:
702
struct SUNIXLibraryHeader {
703
    char name[16];                      // member name, terminated by '/'
704
    char date[12];                      // member date, seconds, decimal ASCII
705
    char userID[6];                     // member User ID, decimal ASCII
706
    char groupID[6];                    // member Group ID, decimal ASCII
707
    char fileMode[8];                   // member file mode, octal ASCII
708
    char fileSize[10];                  // member file size not including header, decimal ASCII
709
    char headerEnd[2];                  // "`\n"
710
};
711
 
712
// Member names no longer than 15 characters are stored in the name field and 
713
// terminated by '/'. Longer names are stored in the longnames record. The name
714
// field contains '/' followed by an index into the longnames string table. 
715
// This index is in decimal ASCII.
716
 
717
// The "/SYMDEF SORTED/" record contains the following:
718
// 1. The size of the symbol list = 8 * n, where n = number of exported symbols
719
//    in the library.
720
// 2. For each symbol: the name as an index into the string table (relative to 
721
//    the start of the sting table), followed by:
722
//    an offset to the module containing this symbol relative to file begin.
723
// 3. The length of the string table.
724
// 4. The string table as a sequence of zero-terminated strings.
725
// 5. Zero-padding to a size divisible by 4.
726
 
727
// All numbers in "/SYMDEF SORTED/" are 32-bit unsigned integers (little endian).
728
 
729
// The longnames record has the name "//". It contains member names as zero-terminated strings.
730
 
731
// All archive members are aligned by 8
732
 
733
#endif // ELF_FORW_H

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.