xref: /openbmc/qemu/contrib/elf2dmp/qemu_elf.h (revision 3fa2d384c245bcee3a9ecfa11f298b76ea4c9d57)
1*3fa2d384SViktor Prutyanov /*
2*3fa2d384SViktor Prutyanov  * Copyright (c) 2018 Virtuozzo International GmbH
3*3fa2d384SViktor Prutyanov  *
4*3fa2d384SViktor Prutyanov  * This work is licensed under the terms of the GNU GPL, version 2 or later.
5*3fa2d384SViktor Prutyanov  *
6*3fa2d384SViktor Prutyanov  */
7*3fa2d384SViktor Prutyanov 
8*3fa2d384SViktor Prutyanov #ifndef QEMU_ELF_H
9*3fa2d384SViktor Prutyanov #define QEMU_ELF_H
10*3fa2d384SViktor Prutyanov 
11*3fa2d384SViktor Prutyanov #include <stdint.h>
12*3fa2d384SViktor Prutyanov #include <elf.h>
13*3fa2d384SViktor Prutyanov 
14*3fa2d384SViktor Prutyanov typedef struct QEMUCPUSegment {
15*3fa2d384SViktor Prutyanov     uint32_t selector;
16*3fa2d384SViktor Prutyanov     uint32_t limit;
17*3fa2d384SViktor Prutyanov     uint32_t flags;
18*3fa2d384SViktor Prutyanov     uint32_t pad;
19*3fa2d384SViktor Prutyanov     uint64_t base;
20*3fa2d384SViktor Prutyanov } QEMUCPUSegment;
21*3fa2d384SViktor Prutyanov 
22*3fa2d384SViktor Prutyanov typedef struct QEMUCPUState {
23*3fa2d384SViktor Prutyanov     uint32_t version;
24*3fa2d384SViktor Prutyanov     uint32_t size;
25*3fa2d384SViktor Prutyanov     uint64_t rax, rbx, rcx, rdx, rsi, rdi, rsp, rbp;
26*3fa2d384SViktor Prutyanov     uint64_t r8, r9, r10, r11, r12, r13, r14, r15;
27*3fa2d384SViktor Prutyanov     uint64_t rip, rflags;
28*3fa2d384SViktor Prutyanov     QEMUCPUSegment cs, ds, es, fs, gs, ss;
29*3fa2d384SViktor Prutyanov     QEMUCPUSegment ldt, tr, gdt, idt;
30*3fa2d384SViktor Prutyanov     uint64_t cr[5];
31*3fa2d384SViktor Prutyanov     uint64_t kernel_gs_base;
32*3fa2d384SViktor Prutyanov } QEMUCPUState;
33*3fa2d384SViktor Prutyanov 
34*3fa2d384SViktor Prutyanov int is_system(QEMUCPUState *s);
35*3fa2d384SViktor Prutyanov 
36*3fa2d384SViktor Prutyanov typedef struct QEMU_Elf {
37*3fa2d384SViktor Prutyanov     int fd;
38*3fa2d384SViktor Prutyanov     size_t size;
39*3fa2d384SViktor Prutyanov     void *map;
40*3fa2d384SViktor Prutyanov     QEMUCPUState **state;
41*3fa2d384SViktor Prutyanov     size_t state_nr;
42*3fa2d384SViktor Prutyanov     int has_kernel_gs_base;
43*3fa2d384SViktor Prutyanov } QEMU_Elf;
44*3fa2d384SViktor Prutyanov 
45*3fa2d384SViktor Prutyanov int QEMU_Elf_init(QEMU_Elf *qe, const char *filename);
46*3fa2d384SViktor Prutyanov void QEMU_Elf_exit(QEMU_Elf *qe);
47*3fa2d384SViktor Prutyanov 
48*3fa2d384SViktor Prutyanov Elf64_Phdr *elf64_getphdr(void *map);
49*3fa2d384SViktor Prutyanov Elf64_Half elf_getphdrnum(void *map);
50*3fa2d384SViktor Prutyanov 
51*3fa2d384SViktor Prutyanov #endif /* QEMU_ELF_H */
52