win-pvdrivers

view common/include/public/libelf.h @ 62:edd4a2ad5b44

Removed old inf files
author James Harper <james.harper@bendigoit.com.au>
date Wed Dec 19 10:22:50 2007 +1100 (2007-12-19)
parents 5712dede5a1b
children b474e898b409
line source
1 #ifndef __XC_LIBELF__
2 #define __XC_LIBELF__ 1
4 #if defined(__i386__) || defined(__x86_64) || defined(__ia64__)
5 #define XEN_ELF_LITTLE_ENDIAN
6 #elif defined(__powerpc__)
7 #define XEN_ELF_BIG_ENDIAN
8 #else
9 #error define architectural endianness
10 #endif
12 #undef ELFSIZE
13 #include "elfnote.h"
14 #include "elfstructs.h"
15 #include "features.h"
17 /* ------------------------------------------------------------------------ */
19 typedef union {
20 Elf32_Ehdr e32;
21 Elf64_Ehdr e64;
22 } elf_ehdr;
24 typedef union {
25 Elf32_Phdr e32;
26 Elf64_Phdr e64;
27 } elf_phdr;
29 typedef union {
30 Elf32_Shdr e32;
31 Elf64_Shdr e64;
32 } elf_shdr;
34 typedef union {
35 Elf32_Sym e32;
36 Elf64_Sym e64;
37 } elf_sym;
39 typedef union {
40 Elf32_Rel e32;
41 Elf64_Rel e64;
42 } elf_rel;
44 typedef union {
45 Elf32_Rela e32;
46 Elf64_Rela e64;
47 } elf_rela;
49 typedef union {
50 Elf32_Note e32;
51 Elf64_Note e64;
52 } elf_note;
54 struct elf_binary {
55 /* elf binary */
56 const char *image;
57 size_t size;
58 char class;
59 char data;
61 const elf_ehdr *ehdr;
62 const char *sec_strtab;
63 const elf_shdr *sym_tab;
64 const char *sym_strtab;
66 /* loaded to */
67 char *dest;
68 uint64_t pstart;
69 uint64_t pend;
70 uint64_t reloc_offset;
72 #ifndef __XEN__
73 /* misc */
74 FILE *log;
75 #endif
76 int verbose;
77 };
79 /* ------------------------------------------------------------------------ */
80 /* accessing elf header fields */
82 #ifdef XEN_ELF_BIG_ENDIAN
83 # define NATIVE_ELFDATA ELFDATA2MSB
84 #else
85 # define NATIVE_ELFDATA ELFDATA2LSB
86 #endif
88 #define elf_32bit(elf) (ELFCLASS32 == (elf)->class)
89 #define elf_64bit(elf) (ELFCLASS64 == (elf)->class)
90 #define elf_msb(elf) (ELFDATA2MSB == (elf)->data)
91 #define elf_lsb(elf) (ELFDATA2LSB == (elf)->data)
92 #define elf_swap(elf) (NATIVE_ELFDATA != (elf)->data)
94 #define elf_uval(elf, str, elem) \
95 ((ELFCLASS64 == (elf)->class) \
96 ? elf_access_unsigned((elf), (str), \
97 offsetof(typeof(*(str)),e64.elem), \
98 sizeof((str)->e64.elem)) \
99 : elf_access_unsigned((elf), (str), \
100 offsetof(typeof(*(str)),e32.elem), \
101 sizeof((str)->e32.elem)))
103 #define elf_sval(elf, str, elem) \
104 ((ELFCLASS64 == (elf)->class) \
105 ? elf_access_signed((elf), (str), \
106 offsetof(typeof(*(str)),e64.elem), \
107 sizeof((str)->e64.elem)) \
108 : elf_access_signed((elf), (str), \
109 offsetof(typeof(*(str)),e32.elem), \
110 sizeof((str)->e32.elem)))
112 #define elf_size(elf, str) \
113 ((ELFCLASS64 == (elf)->class) \
114 ? sizeof((str)->e64) \
115 : sizeof((str)->e32))
117 uint64_t elf_access_unsigned(struct elf_binary *elf, const void *ptr,
118 uint64_t offset, size_t size);
119 int64_t elf_access_signed(struct elf_binary *elf, const void *ptr,
120 uint64_t offset, size_t size);
122 uint64_t elf_round_up(struct elf_binary *elf, uint64_t addr);
124 /* ------------------------------------------------------------------------ */
125 /* xc_libelf_tools.c */
127 int elf_shdr_count(struct elf_binary *elf);
128 int elf_phdr_count(struct elf_binary *elf);
130 const elf_shdr *elf_shdr_by_name(struct elf_binary *elf, const char *name);
131 const elf_shdr *elf_shdr_by_index(struct elf_binary *elf, int index);
132 const elf_phdr *elf_phdr_by_index(struct elf_binary *elf, int index);
134 const char *elf_section_name(struct elf_binary *elf, const elf_shdr * shdr);
135 const void *elf_section_start(struct elf_binary *elf, const elf_shdr * shdr);
136 const void *elf_section_end(struct elf_binary *elf, const elf_shdr * shdr);
138 const void *elf_segment_start(struct elf_binary *elf, const elf_phdr * phdr);
139 const void *elf_segment_end(struct elf_binary *elf, const elf_phdr * phdr);
141 const elf_sym *elf_sym_by_name(struct elf_binary *elf, const char *symbol);
142 const elf_sym *elf_sym_by_index(struct elf_binary *elf, int index);
144 const char *elf_note_name(struct elf_binary *elf, const elf_note * note);
145 const void *elf_note_desc(struct elf_binary *elf, const elf_note * note);
146 uint64_t elf_note_numeric(struct elf_binary *elf, const elf_note * note);
147 const elf_note *elf_note_next(struct elf_binary *elf, const elf_note * note);
149 int elf_is_elfbinary(const void *image);
150 int elf_phdr_is_loadable(struct elf_binary *elf, const elf_phdr * phdr);
152 /* ------------------------------------------------------------------------ */
153 /* xc_libelf_loader.c */
155 int elf_init(struct elf_binary *elf, const char *image, size_t size);
156 #ifdef __XEN__
157 void elf_set_verbose(struct elf_binary *elf);
158 #else
159 void elf_set_logfile(struct elf_binary *elf, FILE * log, int verbose);
160 #endif
162 void elf_parse_binary(struct elf_binary *elf);
163 void elf_load_binary(struct elf_binary *elf);
165 void *elf_get_ptr(struct elf_binary *elf, unsigned long addr);
166 uint64_t elf_lookup_addr(struct elf_binary *elf, const char *symbol);
168 /* ------------------------------------------------------------------------ */
169 /* xc_libelf_relocate.c */
171 int elf_reloc(struct elf_binary *elf);
173 /* ------------------------------------------------------------------------ */
174 /* xc_libelf_dominfo.c */
176 #define UNSET_ADDR ((uint64_t)-1)
178 enum xen_elfnote_type {
179 XEN_ENT_NONE = 0,
180 XEN_ENT_LONG = 1,
181 XEN_ENT_STR = 2
182 };
184 struct xen_elfnote {
185 enum xen_elfnote_type type;
186 const char *name;
187 union {
188 const char *str;
189 uint64_t num;
190 } data;
191 };
193 struct elf_dom_parms {
194 /* raw */
195 const char *guest_info;
196 const void *elf_note_start;
197 const void *elf_note_end;
198 struct xen_elfnote elf_notes[XEN_ELFNOTE_MAX + 1];
200 /* parsed */
201 char guest_os[16];
202 char guest_ver[16];
203 char xen_ver[16];
204 char loader[16];
205 int pae;
206 int bsd_symtab;
207 uint64_t virt_base;
208 uint64_t virt_entry;
209 uint64_t virt_hypercall;
210 uint64_t virt_hv_start_low;
211 uint64_t elf_paddr_offset;
212 uint32_t f_supported[XENFEAT_NR_SUBMAPS];
213 uint32_t f_required[XENFEAT_NR_SUBMAPS];
215 /* calculated */
216 uint64_t virt_offset;
217 uint64_t virt_kstart;
218 uint64_t virt_kend;
219 };
221 static inline void elf_xen_feature_set(int nr, uint32_t * addr)
222 {
223 addr[nr >> 5] |= 1 << (nr & 31);
224 }
225 static inline int elf_xen_feature_get(int nr, uint32_t * addr)
226 {
227 return !!(addr[nr >> 5] & (1 << (nr & 31)));
228 }
230 int elf_xen_parse_features(const char *features,
231 uint32_t *supported,
232 uint32_t *required);
233 int elf_xen_parse_note(struct elf_binary *elf,
234 struct elf_dom_parms *parms,
235 const elf_note *note);
236 int elf_xen_parse_guest_info(struct elf_binary *elf,
237 struct elf_dom_parms *parms);
238 int elf_xen_parse(struct elf_binary *elf,
239 struct elf_dom_parms *parms);
241 #endif /* __XC_LIBELF__ */