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 1150

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

powered by: WebSVN 2.1.0

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