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

Subversion Repositories or1k

[/] [or1k/] [tags/] [nog_patch_47/] [or1ksim/] [cpu/] [common/] [elf.h] - Blame information for rev 815

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

Line No. Rev Author Line
1 815 simons
#ifndef _LINUX_ELF_H
2
#define _LINUX_ELF_H
3
 
4
#include <asm/elf.h>
5
 
6
/* Load a short int from the following tables with big-endian formats */
7
#define ELF_SHORT_H(ps) ((((unsigned short)(ps) >> 8) & 0xff) |\
8
                         (((unsigned short)(ps) << 8) & 0xff00))
9
 
10
/* Load a long int from the following tables with big-endian formats */
11
#define ELF_LONG_H(ps) ((((unsigned long)(ps) >> 24) & 0xff) |\
12
                         (((unsigned long)(ps) >> 8) & 0xff00)|\
13
                         (((unsigned long)(ps) << 8) & 0xff0000)|\
14
                         (((unsigned long)(ps) << 24) & 0xff000000))
15
 
16
typedef unsigned long   Elf32_Addr;
17
typedef unsigned short  Elf32_Half;
18
typedef unsigned long   Elf32_Off;
19
typedef long            Elf32_Sword;
20
typedef unsigned long   Elf32_Word;
21
 
22
/* These constants are for the segment types stored in the image headers */
23
#define PT_NULL    0
24
#define PT_LOAD    1
25
#define PT_DYNAMIC 2
26
#define PT_INTERP  3
27
#define PT_NOTE    4
28
#define PT_SHLIB   5
29
#define PT_PHDR    6
30
#define PT_LOPROC  0x70000000
31
#define PT_HIPROC  0x7fffffff
32
 
33
/* These constants define the different elf file types */
34
#define ET_NONE   0
35
#define ET_REL    1
36
#define ET_EXEC   2
37
#define ET_DYN    3
38
#define ET_CORE   4
39
#define ET_LOPROC 5
40
#define ET_HIPROC 6
41
 
42
/* These constants define the various ELF target machines */
43
#define EM_NONE  0
44
#define EM_M32   1
45
#define EM_SPARC 2
46
#define EM_386   3
47
#define EM_68K   4
48
#define EM_88K   5
49
#define EM_486   6   /* Perhaps disused */
50
#define EM_860   7
51
 
52
#define EM_MIPS         8       /* MIPS R3000 (officially, big-endian only) */
53
 
54
#define EM_MIPS_RS4_BE 10       /* MIPS R4000 big-endian */
55
 
56
#define EM_SPARC64     11       /* SPARC v9 (not official) 64-bit */
57
 
58
#define EM_PARISC      15       /* HPPA */
59
 
60
#define EM_SPARC32PLUS 18       /* Sun's "v8plus" */
61
 
62
#define EM_PPC         20       /* PowerPC */
63
 
64
/*
65
 * This is an interim value that we will use until the committee comes
66
 * up with a final number.
67
 */
68
#define EM_ALPHA        0x9026
69
 
70
 
71
/* This is the info that is needed to parse the dynamic section of the file */
72
#define DT_NULL         0
73
#define DT_NEEDED       1
74
#define DT_PLTRELSZ     2
75
#define DT_PLTGOT       3
76
#define DT_HASH         4
77
#define DT_STRTAB       5
78
#define DT_SYMTAB       6
79
#define DT_RELA         7
80
#define DT_RELASZ       8
81
#define DT_RELAENT      9
82
#define DT_STRSZ        10
83
#define DT_SYMENT       11
84
#define DT_INIT         12
85
#define DT_FINI         13
86
#define DT_SONAME       14
87
#define DT_RPATH        15
88
#define DT_SYMBOLIC     16
89
#define DT_REL          17
90
#define DT_RELSZ        18
91
#define DT_RELENT       19
92
#define DT_PLTREL       20
93
#define DT_DEBUG        21
94
#define DT_TEXTREL      22
95
#define DT_JMPREL       23
96
#define DT_LOPROC       0x70000000
97
#define DT_HIPROC       0x7fffffff
98
 
99
/* This info is needed when parsing the symbol table */
100
#define STB_LOCAL  0
101
#define STB_GLOBAL 1
102
#define STB_WEAK   2
103
 
104
#define STT_NOTYPE  0
105
#define STT_OBJECT  1
106
#define STT_FUNC    2
107
#define STT_SECTION 3
108
#define STT_FILE    4
109
 
110
#define ELF32_ST_BIND(x) ((x) >> 4)
111
#define ELF32_ST_TYPE(x) (((unsigned int) x) & 0xf)
112
 
113
/* Symbolic values for the entries in the auxiliary table
114
   put on the initial stack */
115
#define AT_NULL   0     /* end of vector */
116
#define AT_IGNORE 1     /* entry should be ignored */
117
#define AT_EXECFD 2     /* file descriptor of program */
118
#define AT_PHDR   3     /* program headers for program */
119
#define AT_PHENT  4     /* size of program header entry */
120
#define AT_PHNUM  5     /* number of program headers */
121
#define AT_PAGESZ 6     /* system page size */
122
#define AT_BASE   7     /* base address of interpreter */
123
#define AT_FLAGS  8     /* flags */
124
#define AT_ENTRY  9     /* entry point of program */
125
#define AT_NOTELF 10    /* program is not ELF */
126
#define AT_UID    11    /* real uid */
127
#define AT_EUID   12    /* effective uid */
128
#define AT_GID    13    /* real gid */
129
#define AT_EGID   14    /* effective gid */
130
 
131
 
132
typedef struct dynamic{
133
  Elf32_Sword d_tag;
134
  union{
135
    Elf32_Sword d_val;
136
    Elf32_Addr  d_ptr;
137
  } d_un;
138
} Elf32_Dyn;
139
 
140
typedef struct {
141
  unsigned long long d_tag;             /* entry tag value */
142
  union {
143
    unsigned long long d_val;
144
    unsigned long long d_ptr;
145
  } d_un;
146
} Elf64_Dyn;
147
 
148
/* The following are used with relocations */
149
#define ELF32_R_SYM(x) ((x) >> 8)
150
#define ELF32_R_TYPE(x) ((x) & 0xff)
151
 
152
#define R_386_NONE      0
153
#define R_386_32        1
154
#define R_386_PC32      2
155
#define R_386_GOT32     3
156
#define R_386_PLT32     4
157
#define R_386_COPY      5
158
#define R_386_GLOB_DAT  6
159
#define R_386_JMP_SLOT  7
160
#define R_386_RELATIVE  8
161
#define R_386_GOTOFF    9
162
#define R_386_GOTPC     10
163
#define R_386_NUM       11
164
 
165
#define R_68K_NONE      0
166
#define R_68K_32        1
167
#define R_68K_16        2
168
#define R_68K_8         3
169
#define R_68K_PC32      4
170
#define R_68K_PC16      5
171
#define R_68K_PC8       6
172
#define R_68K_GOT32     7
173
#define R_68K_GOT16     8
174
#define R_68K_GOT8      9
175
#define R_68K_GOT32O    10
176
#define R_68K_GOT16O    11
177
#define R_68K_GOT8O     12
178
#define R_68K_PLT32     13
179
#define R_68K_PLT16     14
180
#define R_68K_PLT8      15
181
#define R_68K_PLT32O    16
182
#define R_68K_PLT16O    17
183
#define R_68K_PLT8O     18
184
#define R_68K_COPY      19
185
#define R_68K_GLOB_DAT  20
186
#define R_68K_JMP_SLOT  21
187
#define R_68K_RELATIVE  22
188
 
189
typedef struct elf32_rel {
190
  Elf32_Addr    r_offset;
191
  Elf32_Word    r_info;
192
} Elf32_Rel;
193
 
194
typedef struct elf64_rel {
195
  unsigned long long r_offset;  /* Location at which to apply the action */
196
  unsigned long long r_info;    /* index and type of relocation */
197
} Elf64_Rel;
198
 
199
typedef struct elf32_rela{
200
  Elf32_Addr    r_offset;
201
  Elf32_Word    r_info;
202
  Elf32_Sword   r_addend;
203
} Elf32_Rela;
204
 
205
typedef struct elf64_rela {
206
  unsigned long long r_offset;  /* Location at which to apply the action */
207
  unsigned long long r_info;    /* index and type of relocation */
208
  unsigned long long r_addend;  /* Constant addend used to compute value */
209
} Elf64_Rela;
210
 
211
typedef struct elf32_sym{
212
  Elf32_Word    st_name;
213
  Elf32_Addr    st_value;
214
  Elf32_Word    st_size;
215
  unsigned char st_info;
216
  unsigned char st_other;
217
  Elf32_Half    st_shndx;
218
} Elf32_Sym;
219
 
220
typedef struct elf64_sym {
221
  unsigned int  st_name;                /* Symbol name, index in string tbl */
222
  unsigned char st_info;                /* Type and binding attributes */
223
  unsigned char st_other;               /* No defined meaning, 0 */
224
  unsigned short st_shndx;              /* Associated section index */
225
  unsigned long long st_value;          /* Value of the symbol */
226
  unsigned long long st_size;           /* Associated symbol size */
227
} Elf64_Sym;
228
 
229
 
230
#define EI_NIDENT       16
231
 
232
typedef struct elf32_hdr{
233
  unsigned char e_ident[EI_NIDENT];
234
  Elf32_Half    e_type;
235
  Elf32_Half    e_machine;
236
  Elf32_Word    e_version;
237
  Elf32_Addr    e_entry;  /* Entry point */
238
  Elf32_Off     e_phoff;
239
  Elf32_Off     e_shoff;
240
  Elf32_Word    e_flags;
241
  Elf32_Half    e_ehsize;
242
  Elf32_Half    e_phentsize;
243
  Elf32_Half    e_phnum;
244
  Elf32_Half    e_shentsize;
245
  Elf32_Half    e_shnum;
246
  Elf32_Half    e_shstrndx;
247
} Elf32_Ehdr;
248
 
249
typedef struct elf64_hdr {
250
  unsigned char e_ident[16];            /* ELF "magic number" */
251
  short int e_type;
252
  short unsigned int e_machine;
253
  int   e_version;
254
  unsigned long long e_entry;           /* Entry point virtual address */
255
  unsigned long long e_phoff;           /* Program header table file offset */
256
  unsigned long long e_shoff;           /* Section header table file offset */
257
  int   e_flags;
258
  short int e_ehsize;
259
  short int e_phentsize;
260
  short int e_phnum;
261
  short int e_shentsize;
262
  short int e_shnum;
263
  short int e_shstrndx;
264
} Elf64_Ehdr;
265
 
266
/* These constants define the permissions on sections in the program
267
   header, p_flags. */
268
#define PF_R            0x4
269
#define PF_W            0x2
270
#define PF_X            0x1
271
 
272
typedef struct elf32_phdr{
273
  Elf32_Word    p_type;
274
  Elf32_Off     p_offset;
275
  Elf32_Addr    p_vaddr;
276
  Elf32_Addr    p_paddr;
277
  Elf32_Word    p_filesz;
278
  Elf32_Word    p_memsz;
279
  Elf32_Word    p_flags;
280
  Elf32_Word    p_align;
281
} Elf32_Phdr;
282
 
283
typedef struct elf64_phdr {
284
  int p_type;
285
  int p_flags;
286
  unsigned long long p_offset;          /* Segment file offset */
287
  unsigned long long p_vaddr;           /* Segment virtual address */
288
  unsigned long long p_paddr;           /* Segment physical address */
289
  unsigned long long p_filesz;          /* Segment size in file */
290
  unsigned long long p_memsz;           /* Segment size in memory */
291
  unsigned long long p_align;           /* Segment alignment, file & memory */
292
} Elf64_Phdr;
293
 
294
/* sh_type */
295
#define SHT_NULL        0
296
#define SHT_PROGBITS    1
297
#define SHT_SYMTAB      2
298
#define SHT_STRTAB      3
299
#define SHT_RELA        4
300
#define SHT_HASH        5
301
#define SHT_DYNAMIC     6
302
#define SHT_NOTE        7
303
#define SHT_NOBITS      8
304
#define SHT_REL         9
305
#define SHT_SHLIB       10
306
#define SHT_DYNSYM      11
307
#define SHT_NUM         12
308
#define SHT_LOPROC      0x70000000
309
#define SHT_HIPROC      0x7fffffff
310
#define SHT_LOUSER      0x80000000
311
#define SHT_HIUSER      0xffffffff
312
 
313
/* sh_flags */
314
#define SHF_WRITE       0x1
315
#define SHF_ALLOC       0x2
316
#define SHF_EXECINSTR   0x4
317
#define SHF_MASKPROC    0xf0000000
318
 
319
/* special section indexes */
320
#define SHN_UNDEF       0
321
#define SHN_LORESERVE   0xff00
322
#define SHN_LOPROC      0xff00
323
#define SHN_HIPROC      0xff1f
324
#define SHN_ABS         0xfff1
325
#define SHN_COMMON      0xfff2
326
#define SHN_HIRESERVE   0xffff
327
 
328
typedef struct elf32_shdr {
329
  Elf32_Word    sh_name;
330
  Elf32_Word    sh_type;
331
  Elf32_Word    sh_flags;
332
  Elf32_Addr    sh_addr;
333
  Elf32_Off     sh_offset;
334
  Elf32_Word    sh_size;
335
  Elf32_Word    sh_link;
336
  Elf32_Word    sh_info;
337
  Elf32_Word    sh_addralign;
338
  Elf32_Word    sh_entsize;
339
} Elf32_Shdr;
340
 
341
typedef struct elf64_shdr {
342
  unsigned int  sh_name;                /* Section name, index in string tbl */
343
  unsigned int  sh_type;                /* Type of section */
344
  unsigned long long sh_flags;          /* Miscellaneous section attributes */
345
  unsigned long long sh_addr;           /* Section virtual addr at execution */
346
  unsigned long long sh_offset;         /* Section file offset */
347
  unsigned long long sh_size;           /* Size of section in bytes */
348
  unsigned int  sh_link;                /* Index of another section */
349
  unsigned int  sh_info;                /* Additional section information */
350
  unsigned long long sh_addralign;      /* Section alignment */
351
  unsigned long long sh_entsize;        /* Entry size if section holds table */
352
} Elf64_Shdr;
353
 
354
#define EI_MAG0         0                /* e_ident[] indexes */
355
#define EI_MAG1         1
356
#define EI_MAG2         2
357
#define EI_MAG3         3
358
#define EI_CLASS        4
359
#define EI_DATA         5
360
#define EI_VERSION      6
361
#define EI_PAD          7
362
 
363
#define ELFMAG0         0x7f            /* EI_MAG */
364
#define ELFMAG1         'E'
365
#define ELFMAG2         'L'
366
#define ELFMAG3         'F'
367
#define ELFMAG          "\177ELF"
368
#define SELFMAG         4
369
 
370
#define ELFCLASSNONE    0                /* EI_CLASS */
371
#define ELFCLASS32      1
372
#define ELFCLASS64      2
373
#define ELFCLASSNUM     3
374
 
375
#define ELFDATANONE     0                /* e_ident[EI_DATA] */
376
#define ELFDATA2LSB     1
377
#define ELFDATA2MSB     2
378
 
379
#define EV_NONE         0                /* e_version, EI_VERSION */
380
#define EV_CURRENT      1
381
#define EV_NUM          2
382
 
383
/* Notes used in ET_CORE */
384
#define NT_PRSTATUS     1
385
#define NT_PRFPREG      2
386
#define NT_PRPSINFO     3
387
#define NT_TASKSTRUCT   4
388
 
389
/* Note header in a PT_NOTE section */
390
typedef struct elf32_note {
391
  Elf32_Word    n_namesz;       /* Name size */
392
  Elf32_Word    n_descsz;       /* Content size */
393
  Elf32_Word    n_type;         /* Content type */
394
} Elf32_Nhdr;
395
 
396
/* Note header in a PT_NOTE section */
397
/*
398
 * For now we use the 32 bit version of the structure until we figure
399
 * out whether we need anything better.  Note - on the Alpha, "unsigned int"
400
 * is only 32 bits.
401
 */
402
typedef struct elf64_note {
403
  unsigned int  n_namesz;       /* Name size */
404
  unsigned int  n_descsz;       /* Content size */
405
  unsigned int  n_type;         /* Content type */
406
} Elf64_Nhdr;
407
 
408
#ifdef __mc68000__
409
#define ELF_START_MMAP 0xC0000000
410
#endif
411
#ifdef __i386__
412
#define ELF_START_MMAP 0x80000000
413
#endif
414
 
415
#if ELF_CLASS == ELFCLASS32
416
 
417
extern Elf32_Dyn _DYNAMIC [];
418
#define elfhdr          elf32_hdr
419
#define elf_phdr        elf32_phdr
420
#define elf_note        elf32_note
421
 
422
#else
423
 
424
extern Elf64_Dyn _DYNAMIC [];
425
#define elfhdr          elf64_hdr
426
#define elf_phdr        elf64_phdr
427
#define elf_note        elf64_note
428
 
429
#endif
430
 
431
 
432
#endif /* _LINUX_ELF_H */

powered by: WebSVN 2.1.0

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