13
#include <xg_private.h>
14
#include <xc_dom.h> /* gunzip bits */
16
#include <xen/libelf/libelf.h>
18
static void print_string_note(const char *prefix, struct elf_binary *elf,
21
printf("%s: %s\n", prefix, (char*)elf_note_desc(elf, note));
24
static void print_numeric_note(const char *prefix, struct elf_binary *elf,
27
uint64_t value = elf_note_numeric(elf, note);
28
int descsz = elf_uval(elf, note, descsz);
30
printf("%s: %#*" PRIx64 " (%d bytes)\n",
31
prefix, 2+2*descsz, value, descsz);
34
static void print_l1_mfn_valid_note(const char *prefix, struct elf_binary *elf,
37
int descsz = elf_uval(elf, note, descsz);
38
const uint32_t *desc32 = elf_note_desc(elf, note);
39
const uint64_t *desc64 = elf_note_desc(elf, note);
41
/* XXX should be able to cope with a list of values. */
45
printf("%s: mask=%#"PRIx64" value=%#"PRIx64"\n", prefix,
46
desc64[0], desc64[1]);
49
printf("%s: mask=%#"PRIx32" value=%#"PRIx32"\n", prefix,
56
static int print_notes(struct elf_binary *elf, const elf_note *start, const elf_note *end)
61
for ( note = start; note < end; note = elf_note_next(elf, note) )
63
if (0 != strcmp(elf_note_name(elf, note), "Xen"))
68
switch(elf_uval(elf, note, type))
70
case XEN_ELFNOTE_INFO:
71
print_string_note("INFO", elf , note);
73
case XEN_ELFNOTE_ENTRY:
74
print_numeric_note("ENTRY", elf , note);
76
case XEN_ELFNOTE_HYPERCALL_PAGE:
77
print_numeric_note("HYPERCALL_PAGE", elf , note);
79
case XEN_ELFNOTE_VIRT_BASE:
80
print_numeric_note("VIRT_BASE", elf , note);
82
case XEN_ELFNOTE_PADDR_OFFSET:
83
print_numeric_note("PADDR_OFFSET", elf , note);
85
case XEN_ELFNOTE_XEN_VERSION:
86
print_string_note("XEN_VERSION", elf , note);
88
case XEN_ELFNOTE_GUEST_OS:
89
print_string_note("GUEST_OS", elf , note);
91
case XEN_ELFNOTE_GUEST_VERSION:
92
print_string_note("GUEST_VERSION", elf , note);
94
case XEN_ELFNOTE_LOADER:
95
print_string_note("LOADER", elf , note);
97
case XEN_ELFNOTE_PAE_MODE:
98
print_string_note("PAE_MODE", elf , note);
100
case XEN_ELFNOTE_FEATURES:
101
print_string_note("FEATURES", elf , note);
103
case XEN_ELFNOTE_HV_START_LOW:
104
print_numeric_note("HV_START_LOW", elf , note);
106
case XEN_ELFNOTE_SUSPEND_CANCEL:
107
print_numeric_note("SUSPEND_CANCEL", elf, note);
109
case XEN_ELFNOTE_L1_MFN_VALID:
110
print_l1_mfn_valid_note("L1_MFN_VALID", elf , note);
113
printf("unknown note type %#x\n",
114
(int)elf_uval(elf, note, type));
121
int main(int argc, char **argv)
124
int fd,h,size,usize,count;
127
struct elf_binary elf;
128
const elf_shdr *shdr;
133
fprintf(stderr, "Usage: readnotes <elfimage>\n");
138
fd = open(f, O_RDONLY);
141
fprintf(stderr, "Unable to open %s: %s\n", f, strerror(errno));
144
if (fstat(fd, &st) == -1)
146
fprintf(stderr, "Unable to determine size of %s: %s\n",
151
image = mmap(0, st.st_size, PROT_READ, MAP_SHARED, fd, 0);
152
if (image == MAP_FAILED)
154
fprintf(stderr, "Unable to map %s: %s\n", f, strerror(errno));
159
usize = xc_dom_check_gzip(image, st.st_size);
163
xc_dom_do_gunzip(image, st.st_size, tmp, usize);
168
if (0 != elf_init(&elf, image, size))
170
fprintf(stderr, "File %s is not an ELF image\n", f);
173
elf_set_logfile(&elf, stderr, 0);
175
count = elf_phdr_count(&elf);
176
for ( h=0; h < count; h++)
178
const elf_phdr *phdr;
179
phdr = elf_phdr_by_index(&elf, h);
180
if (elf_uval(&elf, phdr, p_type) != PT_NOTE)
183
/* Some versions of binutils do not correctly set
184
* p_offset for note segments.
186
if (elf_uval(&elf, phdr, p_offset) == 0)
189
notes_found = print_notes(&elf,
190
elf_segment_start(&elf, phdr),
191
elf_segment_end(&elf, phdr));
194
if ( notes_found == 0 )
196
count = elf_shdr_count(&elf);
197
for ( h=0; h < count; h++)
199
const elf_shdr *shdr;
200
shdr = elf_shdr_by_index(&elf, h);
201
if (elf_uval(&elf, shdr, sh_type) != SHT_NOTE)
203
notes_found = print_notes(&elf,
204
elf_section_start(&elf, shdr),
205
elf_section_end(&elf, shdr));
207
fprintf(stderr, "using notes from SHT_NOTE section\n");
212
shdr = elf_shdr_by_name(&elf, "__xen_guest");
214
printf("__xen_guest: %s\n", (char*)elf_section_start(&elf, shdr));