1 | /*
|
---|
2 | * Copyright (c) 2011 Jiri Svoboda
|
---|
3 | * All rights reserved.
|
---|
4 | *
|
---|
5 | * Redistribution and use in source and binary forms, with or without
|
---|
6 | * modification, are permitted provided that the following conditions
|
---|
7 | * are met:
|
---|
8 | *
|
---|
9 | * - Redistributions of source code must retain the above copyright
|
---|
10 | * notice, this list of conditions and the following disclaimer.
|
---|
11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
12 | * notice, this list of conditions and the following disclaimer in the
|
---|
13 | * documentation and/or other materials provided with the distribution.
|
---|
14 | * - The name of the author may not be used to endorse or promote products
|
---|
15 | * derived from this software without specific prior written permission.
|
---|
16 | *
|
---|
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
27 | */
|
---|
28 |
|
---|
29 | /** @addtogroup libcamd64
|
---|
30 | * @{
|
---|
31 | */
|
---|
32 | /** @file Definitions needed to write core files in Linux-ELF format.
|
---|
33 | */
|
---|
34 |
|
---|
35 | #ifndef LIBC_amd64_ELF_LINUX_H_
|
---|
36 | #define LBIC_amd64_ELF_LINUX_H_
|
---|
37 |
|
---|
38 | #include <libarch/istate.h>
|
---|
39 | #include <sys/types.h>
|
---|
40 |
|
---|
41 | /** Linux kernel struct pt_regs structure.
|
---|
42 | *
|
---|
43 | * We need this to save register state to a core file in Linux format
|
---|
44 | * (readable by GDB configured for Linux target).
|
---|
45 | */
|
---|
46 | typedef struct {
|
---|
47 | uint64_t r15;
|
---|
48 | uint64_t r14;
|
---|
49 | uint64_t r13;
|
---|
50 | uint64_t r12;
|
---|
51 | uint64_t rbp;
|
---|
52 | uint64_t rbx;
|
---|
53 | uint64_t r11;
|
---|
54 | uint64_t r10;
|
---|
55 | uint64_t r9;
|
---|
56 | uint64_t r8;
|
---|
57 | uint64_t rax;
|
---|
58 | uint64_t rcx;
|
---|
59 | uint64_t rdx;
|
---|
60 | uint64_t rsi;
|
---|
61 | uint64_t rdi;
|
---|
62 | uint64_t old_rax;
|
---|
63 | uint64_t rip;
|
---|
64 | uint64_t cs;
|
---|
65 | uint64_t rflags;
|
---|
66 | uint64_t rsp;
|
---|
67 | uint64_t ss;
|
---|
68 |
|
---|
69 | /*
|
---|
70 | * The following registers need to be part of elf_regs_t.
|
---|
71 | * Unfortunately, we don't have any information about them in our
|
---|
72 | * istate_t.
|
---|
73 | */
|
---|
74 | uint64_t unused_fs_base;
|
---|
75 | uint64_t unused_gs_base;
|
---|
76 | uint64_t unused_ds;
|
---|
77 | uint64_t unused_es;
|
---|
78 | uint64_t unused_fs;
|
---|
79 | uint64_t unused_gs;
|
---|
80 | } elf_regs_t;
|
---|
81 |
|
---|
82 | /** Convert istate_t to elf_regs_t. */
|
---|
83 | static inline void istate_to_elf_regs(istate_t *istate, elf_regs_t *elf_regs)
|
---|
84 | {
|
---|
85 | elf_regs->r15 = istate->r15;
|
---|
86 | elf_regs->r14 = istate->r14;
|
---|
87 | elf_regs->r13 = istate->r13;
|
---|
88 | elf_regs->r12 = istate->r12;
|
---|
89 | elf_regs->rbp = istate->rbp;
|
---|
90 | elf_regs->rbx = istate->rbx;
|
---|
91 | elf_regs->r11 = istate->r11;
|
---|
92 | elf_regs->r10 = istate->r10;
|
---|
93 | elf_regs->r9 = istate->r9;
|
---|
94 | elf_regs->r8 = istate->r8;
|
---|
95 | elf_regs->rax = istate->rax;
|
---|
96 | elf_regs->rcx = istate->rcx;
|
---|
97 | elf_regs->rdx = istate->rdx;
|
---|
98 | elf_regs->rsi = istate->rsi;
|
---|
99 | elf_regs->rdi = istate->rdi;
|
---|
100 | elf_regs->rip = istate->rip;
|
---|
101 | elf_regs->cs = istate->cs;
|
---|
102 | elf_regs->rflags = istate->rflags;
|
---|
103 | elf_regs->rsp = istate->rsp;
|
---|
104 | elf_regs->ss = istate->ss;
|
---|
105 |
|
---|
106 | /*
|
---|
107 | * Reset the registers for which there is not enough info in istate_t.
|
---|
108 | */
|
---|
109 | elf_regs->unused_fs_base = 0;
|
---|
110 | elf_regs->unused_gs_base = 0;
|
---|
111 | elf_regs->unused_ds = 0;
|
---|
112 | elf_regs->unused_es = 0;
|
---|
113 | elf_regs->unused_fs = 0;
|
---|
114 | elf_regs->unused_gs = 0;
|
---|
115 | }
|
---|
116 |
|
---|
117 | #endif
|
---|
118 |
|
---|
119 | /** @}
|
---|
120 | */
|
---|