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

Subversion Repositories c0or1k

[/] [c0or1k/] [trunk/] [loader/] [libs/] [elf/] [include/] [elf/] [elf32.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 __ELF_ELF_32_H__
80
#define __ELF_ELF_32_H__
81
 
82
#include <stdint.h>
83
 
84
/*
85
 * File header
86
 */
87
struct Elf32_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
        uint32_t        e_entry;        /* Code entry point */
94
        uint32_t        e_phoff;        /* Program header table */
95
        uint32_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 Elf32_Shdr {
113
        uint32_t        sh_name;
114
        uint32_t        sh_type;
115
        uint32_t        sh_flags;
116
        uint32_t        sh_addr;
117
        uint32_t        sh_offset;
118
        uint32_t        sh_size;
119
        uint32_t        sh_link;
120
        uint32_t        sh_info;
121
        uint32_t        sh_addralign;
122
        uint32_t        sh_entsize;
123
};
124
 
125
/*
126
 * Program header
127
 */
128
struct Elf32_Phdr {
129
        uint32_t p_type;        /* Segment type: Loadable segment = 1 */
130
        uint32_t p_offset;      /* Offset of segment in file */
131
        uint32_t p_vaddr;       /* Reqd virtual address of segment
132
                                         * when loading */
133
        uint32_t p_paddr;       /* Reqd physical address of
134
                                         * segment (ignore) */
135
        uint32_t p_filesz;      /* How many bytes this segment
136
                                         * occupies in file */
137
        uint32_t p_memsz;       /* How many bytes this segment
138
                                         * should occupy in * memory (when
139
                                         * * loading, expand the segment
140
                                         * by * concatenating enough zero
141
                                         * bytes to it) */
142
        uint32_t p_flags;       /* Flags: logical "or" of PF_
143
                                         * constants below */
144
        uint32_t p_align;       /* Reqd alignment of segment in
145
                                         * memory */
146
};
147
 
148
int elf32_checkFile(struct Elf32_Header *file);
149
struct Elf32_Phdr * elf32_getProgramSegmentTable(struct Elf32_Header *file);
150
unsigned elf32_getNumSections(struct Elf32_Header *file);
151
char * elf32_getStringTable(struct Elf32_Header *file);
152
char * elf32_getSegmentStringTable(struct Elf32_Header *file);
153
 
154
static inline struct Elf32_Shdr *
155
elf32_getSectionTable(struct Elf32_Header *file)
156
{
157
        /* Cast heaven! */
158
        return (struct Elf32_Shdr*) (uintptr_t) (((uintptr_t) file) + file->e_shoff);
159
}
160
 
161
/* accessor functions */
162
static inline uint32_t
163
elf32_getSectionType(struct Elf32_Header *file, uint16_t s)
164
{
165
        return elf32_getSectionTable(file)[s].sh_type;
166
}
167
 
168
static inline uint32_t
169
elf32_getSectionFlags(struct Elf32_Header *file, uint16_t s)
170
{
171
        return elf32_getSectionTable(file)[s].sh_flags;
172
}
173
 
174
char * elf32_getSectionName(struct Elf32_Header *file, int i);
175
uint32_t elf32_getSectionSize(struct Elf32_Header *file, int i);
176
uint32_t elf32_getSectionAddr(struct Elf32_Header *elfFile, int i);
177
void * elf32_getSection(struct Elf32_Header *file, int i);
178
void * elf32_getSectionNamed(struct Elf32_Header *file, char *str);
179
int elf32_getSegmentType (struct Elf32_Header *file, int segment);
180
void elf32_getSegmentInfo(struct Elf32_Header *file, 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
 
184
 
185
 
186
void elf32_fprintf(FILE *f, struct Elf32_Header *file, int size, const char *name, int flags);
187
uint32_t elf32_getEntryPoint (struct Elf32_Header *file);
188
 
189
/* Program header functions */
190
uint16_t elf32_getNumProgramHeaders(struct Elf32_Header *file);
191
 
192
static inline struct Elf32_Phdr *
193
elf32_getProgramHeaderTable(struct Elf32_Header *file)
194
{
195
        /* Cast heaven! */
196
        return (struct Elf32_Phdr*) (uintptr_t) (((uintptr_t) file) + file->e_phoff);
197
}
198
 
199
/* accessor functions */
200
static inline uint32_t
201
elf32_getProgramHeaderFlags(struct Elf32_Header *file, uint16_t ph)
202
{
203
        return elf32_getProgramHeaderTable(file)[ph].p_flags;
204
}
205
 
206
static inline uint32_t
207
elf32_getProgramHeaderType(struct Elf32_Header *file, uint16_t ph)
208
{
209
        return elf32_getProgramHeaderTable(file)[ph].p_type;
210
}
211
 
212
static inline uint32_t
213
elf32_getProgramHeaderFileSize(struct Elf32_Header *file, uint16_t ph)
214
{
215
        return elf32_getProgramHeaderTable(file)[ph].p_filesz;
216
}
217
 
218
static inline uint32_t
219
elf32_getProgramHeaderMemorySize(struct Elf32_Header *file, uint16_t ph)
220
{
221
        return elf32_getProgramHeaderTable(file)[ph].p_memsz;
222
}
223
 
224
static inline uint32_t
225
elf32_getProgramHeaderVaddr(struct Elf32_Header *file, uint16_t ph)
226
{
227
        return elf32_getProgramHeaderTable(file)[ph].p_vaddr;
228
}
229
 
230
static inline uint32_t
231
elf32_getProgramHeaderPaddr(struct Elf32_Header *file, uint16_t ph)
232
{
233
        return elf32_getProgramHeaderTable(file)[ph].p_paddr;
234
}
235
 
236
static inline uint32_t
237
elf32_getProgramHeaderOffset(struct Elf32_Header *file, uint16_t ph)
238
{
239
        return elf32_getProgramHeaderTable(file)[ph].p_offset;
240
}
241
 
242
#endif /* __ELF_ELF_32_H__ */

powered by: WebSVN 2.1.0

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