xref: /openbmc/qemu/contrib/elf2dmp/qemu_elf.h (revision 58ea30f5145fc8c7ebb80ee0b0c812a3a958c762)
13fa2d384SViktor Prutyanov /*
23fa2d384SViktor Prutyanov  * Copyright (c) 2018 Virtuozzo International GmbH
33fa2d384SViktor Prutyanov  *
43fa2d384SViktor Prutyanov  * This work is licensed under the terms of the GNU GPL, version 2 or later.
53fa2d384SViktor Prutyanov  *
63fa2d384SViktor Prutyanov  */
73fa2d384SViktor Prutyanov 
8*58ea30f5SMarkus Armbruster #ifndef EMPF2DMP_QEMU_ELF_H
9*58ea30f5SMarkus Armbruster #define EMPF2DMP_QEMU_ELF_H
103fa2d384SViktor Prutyanov 
11e53f3466SViktor Prutyanov #include "elf.h"
123fa2d384SViktor Prutyanov 
133fa2d384SViktor Prutyanov typedef struct QEMUCPUSegment {
143fa2d384SViktor Prutyanov     uint32_t selector;
153fa2d384SViktor Prutyanov     uint32_t limit;
163fa2d384SViktor Prutyanov     uint32_t flags;
173fa2d384SViktor Prutyanov     uint32_t pad;
183fa2d384SViktor Prutyanov     uint64_t base;
193fa2d384SViktor Prutyanov } QEMUCPUSegment;
203fa2d384SViktor Prutyanov 
213fa2d384SViktor Prutyanov typedef struct QEMUCPUState {
223fa2d384SViktor Prutyanov     uint32_t version;
233fa2d384SViktor Prutyanov     uint32_t size;
243fa2d384SViktor Prutyanov     uint64_t rax, rbx, rcx, rdx, rsi, rdi, rsp, rbp;
253fa2d384SViktor Prutyanov     uint64_t r8, r9, r10, r11, r12, r13, r14, r15;
263fa2d384SViktor Prutyanov     uint64_t rip, rflags;
273fa2d384SViktor Prutyanov     QEMUCPUSegment cs, ds, es, fs, gs, ss;
283fa2d384SViktor Prutyanov     QEMUCPUSegment ldt, tr, gdt, idt;
293fa2d384SViktor Prutyanov     uint64_t cr[5];
303fa2d384SViktor Prutyanov     uint64_t kernel_gs_base;
313fa2d384SViktor Prutyanov } QEMUCPUState;
323fa2d384SViktor Prutyanov 
333fa2d384SViktor Prutyanov int is_system(QEMUCPUState *s);
343fa2d384SViktor Prutyanov 
353fa2d384SViktor Prutyanov typedef struct QEMU_Elf {
36bd4d0da7SViktor Prutyanov     GMappedFile *gmf;
373fa2d384SViktor Prutyanov     size_t size;
383fa2d384SViktor Prutyanov     void *map;
393fa2d384SViktor Prutyanov     QEMUCPUState **state;
403fa2d384SViktor Prutyanov     size_t state_nr;
413fa2d384SViktor Prutyanov     int has_kernel_gs_base;
423fa2d384SViktor Prutyanov } QEMU_Elf;
433fa2d384SViktor Prutyanov 
443fa2d384SViktor Prutyanov int QEMU_Elf_init(QEMU_Elf *qe, const char *filename);
453fa2d384SViktor Prutyanov void QEMU_Elf_exit(QEMU_Elf *qe);
463fa2d384SViktor Prutyanov 
473fa2d384SViktor Prutyanov Elf64_Phdr *elf64_getphdr(void *map);
483fa2d384SViktor Prutyanov Elf64_Half elf_getphdrnum(void *map);
493fa2d384SViktor Prutyanov 
50*58ea30f5SMarkus Armbruster #endif /* ELF2DMP_QEMU_ELF_H */
51