win-pvdrivers

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