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

Subversion Repositories c0or1k

[/] [c0or1k/] [trunk/] [loader/] [libs/] [elf/] [include/] [elf/] [elf64.h] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 drasko
/*
2
 * Australian Public Licence B (OZPLB)
3
 *
4
 * Version 1-0
5
 *
6
 * Copyright (c) 2004 University of New South Wales
7
 *
8
 * All rights reserved.
9
 *
10
 * Developed by: Operating Systems and Distributed Systems Group (DiSy)
11
 *               University of New South Wales
12
 *               http://www.disy.cse.unsw.edu.au
13
 *
14
 * Permission is granted by University of New South Wales, free of charge, to
15
 * any person obtaining a copy of this software and any associated
16
 * documentation files (the "Software") to deal with the Software without
17
 * restriction, including (without limitation) the rights to use, copy,
18
 * modify, adapt, merge, publish, distribute, communicate to the public,
19
 * sublicense, and/or sell, lend or rent out copies of the Software, and
20
 * to permit persons to whom the Software is furnished to do so, subject
21
 * to the following conditions:
22
 *
23
 *     * Redistributions of source code must retain the above copyright
24
 *       notice, this list of conditions and the following disclaimers.
25
 *
26
 *     * Redistributions in binary form must reproduce the above
27
 *       copyright notice, this list of conditions and the following
28
 *       disclaimers in the documentation and/or other materials provided
29
 *       with the distribution.
30
 *
31
 *     * Neither the name of University of New South Wales, nor the names of its
32
 *       contributors, may be used to endorse or promote products derived
33
 *       from this Software without specific prior written permission.
34
 *
35
 * EXCEPT AS EXPRESSLY STATED IN THIS LICENCE AND TO THE FULL EXTENT
36
 * PERMITTED BY APPLICABLE LAW, THE SOFTWARE IS PROVIDED "AS-IS", AND
37
 * NATIONAL ICT AUSTRALIA AND ITS CONTRIBUTORS MAKE NO REPRESENTATIONS,
38
 * WARRANTIES OR CONDITIONS OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
39
 * BUT NOT LIMITED TO ANY REPRESENTATIONS, WARRANTIES OR CONDITIONS
40
 * REGARDING THE CONTENTS OR ACCURACY OF THE SOFTWARE, OR OF TITLE,
41
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NONINFRINGEMENT,
42
 * THE ABSENCE OF LATENT OR OTHER DEFECTS, OR THE PRESENCE OR ABSENCE OF
43
 * ERRORS, WHETHER OR NOT DISCOVERABLE.
44
 *
45
 * TO THE FULL EXTENT PERMITTED BY APPLICABLE LAW, IN NO EVENT SHALL
46
 * NATIONAL ICT AUSTRALIA OR ITS CONTRIBUTORS BE LIABLE ON ANY LEGAL
47
 * THEORY (INCLUDING, WITHOUT LIMITATION, IN AN ACTION OF CONTRACT,
48
 * NEGLIGENCE OR OTHERWISE) FOR ANY CLAIM, LOSS, DAMAGES OR OTHER
49
 * LIABILITY, INCLUDING (WITHOUT LIMITATION) LOSS OF PRODUCTION OR
50
 * OPERATION TIME, LOSS, DAMAGE OR CORRUPTION OF DATA OR RECORDS; OR LOSS
51
 * OF ANTICIPATED SAVINGS, OPPORTUNITY, REVENUE, PROFIT OR GOODWILL, OR
52
 * OTHER ECONOMIC LOSS; OR ANY SPECIAL, INCIDENTAL, INDIRECT,
53
 * CONSEQUENTIAL, PUNITIVE OR EXEMPLARY DAMAGES, ARISING OUT OF OR IN
54
 * CONNECTION WITH THIS LICENCE, THE SOFTWARE OR THE USE OF OR OTHER
55
 * DEALINGS WITH THE SOFTWARE, EVEN IF NATIONAL ICT AUSTRALIA OR ITS
56
 * CONTRIBUTORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH CLAIM, LOSS,
57
 * DAMAGES OR OTHER LIABILITY.
58
 *
59
 * If applicable legislation implies representations, warranties, or
60
 * conditions, or imposes obligations or liability on University of New South
61
 * Wales or one of its contributors in respect of the Software that
62
 * cannot be wholly or partly excluded, restricted or modified, the
63
 * liability of University of New South Wales or the contributor is limited, to
64
 * the full extent permitted by the applicable legislation, at its
65
 * option, to:
66
 * a.  in the case of goods, any one or more of the following:
67
 * i.  the replacement of the goods or the supply of equivalent goods;
68
 * ii.  the repair of the goods;
69
 * iii. the payment of the cost of replacing the goods or of acquiring
70
 *  equivalent goods;
71
 * iv.  the payment of the cost of having the goods repaired; or
72
 * b.  in the case of services:
73
 * i.  the supplying of the services again; or
74
 * ii.  the payment of the cost of having the services supplied again.
75
 *
76
 * The construction, validity and performance of this licence is governed
77
 * by the laws in force in New South Wales, Australia.
78
 */
79
#ifndef __LIBELF_64_H__
80
#define __LIBELF_64_H__
81
 
82
#include <stdint.h>
83
 
84
/*
85
 * File header
86
 */
87
struct Elf64_Header {
88
        unsigned char   e_ident[16];
89
        uint16_t        e_type; /* Relocatable=1, Executable=2 (+ some
90
                                 * more ..) */
91
        uint16_t        e_machine;      /* Target architecture: MIPS=8 */
92
        uint32_t        e_version;      /* Elf version (should be 1) */
93
        uint64_t        e_entry;        /* Code entry point */
94
        uint64_t        e_phoff;        /* Program header table */
95
        uint64_t        e_shoff;        /* Section header table */
96
        uint32_t        e_flags;        /* Flags */
97
        uint16_t        e_ehsize;       /* ELF header size */
98
        uint16_t        e_phentsize;    /* Size of one program segment
99
                                         * header */
100
        uint16_t        e_phnum;        /* Number of program segment
101
                                         * headers */
102
        uint16_t        e_shentsize;    /* Size of one section header */
103
        uint16_t        e_shnum;        /* Number of section headers */
104
        uint16_t        e_shstrndx;     /* Section header index of the
105
                                         * string table for section header
106
                                         * * names */
107
};
108
 
109
/*
110
 * Section header
111
*/
112
struct Elf64_Shdr {
113
        uint32_t        sh_name;
114
        uint32_t        sh_type;
115
        uint64_t        sh_flags;
116
        uint64_t        sh_addr;
117
        uint64_t        sh_offset;
118
        uint64_t        sh_size;
119
        uint32_t        sh_link;
120
        uint32_t        sh_info;
121
        uint64_t        sh_addralign;
122
        uint64_t        sh_entsize;
123
};
124
 
125
/*
126
 * Program header
127
 */
128
struct Elf64_Phdr {
129
        uint32_t        p_type; /* Segment type: Loadable segment = 1 */
130
        uint32_t        p_flags;        /* Flags: logical "or" of PF_
131
                                         * constants below */
132
        uint64_t        p_offset;       /* Offset of segment in file */
133
        uint64_t        p_vaddr;        /* Reqd virtual address of segment
134
                                         * when loading */
135
        uint64_t        p_paddr;        /* Reqd physical address of
136
                                         * segment */
137
        uint64_t        p_filesz;       /* How many bytes this segment
138
                                         * occupies in file */
139
        uint64_t        p_memsz;        /* How many bytes this segment
140
                                         * should occupy in * memory (when
141
                                         * * loading, expand the segment
142
                                         * by * concatenating enough zero
143
                                         * bytes to it) */
144
        uint64_t        p_align;        /* Reqd alignment of segment in
145
                                         * memory */
146
};
147
 
148
int elf64_checkFile(void *elfFile);
149
struct Elf64_Phdr * elf64_getProgramSegmentTable(void *elfFile);
150
unsigned elf64_getNumSections(void *elfFile);
151
char * elf64_getStringTable(void *elfFile, int string_segment);
152
char * elf64_getSegmentStringTable(void *elfFile);
153
 
154
static inline struct Elf64_Shdr *
155
elf64_getSectionTable(struct Elf64_Header *file)
156
{
157
        /* Cast heaven! */
158
        return (struct Elf64_Shdr*) (uintptr_t) (((uintptr_t) file) + file->e_shoff);
159
}
160
 
161
/* accessor functions */
162
static inline uint32_t
163
elf64_getSectionType(struct Elf64_Header *file, uint16_t s)
164
{
165
        return elf64_getSectionTable(file)[s].sh_type;
166
}
167
 
168
static inline uint32_t
169
elf64_getSectionFlags(struct Elf64_Header *file, uint16_t s)
170
{
171
        return elf64_getSectionTable(file)[s].sh_flags;
172
}
173
 
174
char * elf64_getSectionName(void *elfFile, int i);
175
uint64_t elf64_getSectionSize(void *elfFile, int i);
176
uint64_t elf64_getSectionAddr(struct Elf64_Header *elfFile, int i);
177
void * elf64_getSection(void *elfFile, int i);
178
void * elf64_getSectionNamed(void *elfFile, char *str);
179
int elf64_getSegmentType (void *elfFile, int segment);
180
void elf64_getSegmentInfo(void *elfFile, int segment, uint64_t *p_vaddr,
181
                          uint64_t *p_paddr, uint64_t *p_filesz,
182
                          uint64_t *p_offset, uint64_t *p_memsz);
183
void elf64_showDetails(void *elfFile, int size, char *name);
184
uint64_t elf64_getEntryPoint (struct Elf64_Header *elfFile);
185
 
186
/* Program Headers functions */
187
/* Program header functions */
188
uint16_t elf64_getNumProgramHeaders(struct Elf64_Header *file);
189
 
190
static inline struct Elf64_Phdr *
191
elf64_getProgramHeaderTable(struct Elf64_Header *file)
192
{
193
        /* Cast hell! */
194
        return (struct Elf64_Phdr*) (uintptr_t) (((uintptr_t) file) + file->e_phoff);
195
}
196
 
197
/* accessor functions */
198
static inline uint32_t
199
elf64_getProgramHeaderFlags(struct Elf64_Header *file, uint16_t ph)
200
{
201
        return elf64_getProgramHeaderTable(file)[ph].p_flags;
202
}
203
 
204
static inline uint32_t
205
elf64_getProgramHeaderType(struct Elf64_Header *file, uint16_t ph)
206
{
207
        return elf64_getProgramHeaderTable(file)[ph].p_type;
208
}
209
 
210
static inline uint64_t
211
elf64_getProgramHeaderFileSize(struct Elf64_Header *file, uint16_t ph)
212
{
213
        return elf64_getProgramHeaderTable(file)[ph].p_filesz;
214
}
215
 
216
static inline uint64_t
217
elf64_getProgramHeaderMemorySize(struct Elf64_Header *file, uint16_t ph)
218
{
219
        return elf64_getProgramHeaderTable(file)[ph].p_memsz;
220
}
221
 
222
static inline uint64_t
223
elf64_getProgramHeaderVaddr(struct Elf64_Header *file, uint16_t ph)
224
{
225
        return elf64_getProgramHeaderTable(file)[ph].p_vaddr;
226
}
227
 
228
static inline uint64_t
229
elf64_getProgramHeaderPaddr(struct Elf64_Header *file, uint16_t ph)
230
{
231
        return elf64_getProgramHeaderTable(file)[ph].p_paddr;
232
}
233
 
234
static inline uint64_t
235
elf64_getProgramHeaderOffset(struct Elf64_Header *file, uint16_t ph)
236
{
237
        return elf64_getProgramHeaderTable(file)[ph].p_offset;
238
}
239
 
240
#endif /* __LIBELF_64_H__ */

powered by: WebSVN 2.1.0

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