Line data Source code
1 : /* Fetch live process registers from TID.
2 : Copyright (C) 2013 Red Hat, Inc.
3 : This file is part of elfutils.
4 :
5 : This file is free software; you can redistribute it and/or modify
6 : it under the terms of either
7 :
8 : * the GNU Lesser General Public License as published by the Free
9 : Software Foundation; either version 3 of the License, or (at
10 : your option) any later version
11 :
12 : or
13 :
14 : * the GNU General Public License as published by the Free
15 : Software Foundation; either version 2 of the License, or (at
16 : your option) any later version
17 :
18 : or both in parallel, as here.
19 :
20 : elfutils is distributed in the hope that it will be useful, but
21 : WITHOUT ANY WARRANTY; without even the implied warranty of
22 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 : General Public License for more details.
24 :
25 : You should have received copies of the GNU General Public License and
26 : the GNU Lesser General Public License along with this program. If
27 : not, see <http://www.gnu.org/licenses/>. */
28 :
29 : #ifdef HAVE_CONFIG_H
30 : # include <config.h>
31 : #endif
32 :
33 : #include <stdlib.h>
34 : #if defined(__powerpc__) && defined(__linux__)
35 : # include <sys/ptrace.h>
36 : # include <sys/user.h>
37 : #endif
38 :
39 : #include "system.h"
40 :
41 : #define BACKEND ppc_
42 : #include "libebl_CPU.h"
43 :
44 : bool
45 1197 : ppc_dwarf_to_regno (Ebl *ebl __attribute__ ((unused)), unsigned *regno)
46 : {
47 1197 : switch (*regno)
48 : {
49 8 : case 108:
50 : // LR uses both 65 and 108 numbers, there is no consistency for it.
51 8 : *regno = 65;
52 8 : return true;
53 : case 0 ... 107:
54 : case 109 ... (114 - 1) -1:
55 : return true;
56 0 : case 1200 ... 1231:
57 0 : *regno = *regno - 1200 + (114 - 1);
58 0 : return true;
59 16 : default:
60 16 : return false;
61 : }
62 : abort ();
63 : }
64 :
65 : __typeof (ppc_dwarf_to_regno)
66 : ppc64_dwarf_to_regno
67 : __attribute__ ((alias ("ppc_dwarf_to_regno")));
68 :
69 : bool
70 0 : ppc_set_initial_registers_tid (pid_t tid __attribute__ ((unused)),
71 : ebl_tid_registers_t *setfunc __attribute__ ((unused)),
72 : void *arg __attribute__ ((unused)))
73 : {
74 : #if !defined(__powerpc__) || !defined(__linux__)
75 0 : return false;
76 : #else /* __powerpc__ */
77 : union
78 : {
79 : struct pt_regs r;
80 : long l[sizeof (struct pt_regs) / sizeof (long)];
81 : }
82 : user_regs;
83 : eu_static_assert (sizeof (struct pt_regs) % sizeof (long) == 0);
84 : /* PTRACE_GETREGS is EIO on kernel-2.6.18-308.el5.ppc64. */
85 : errno = 0;
86 : for (unsigned regno = 0; regno < sizeof (user_regs) / sizeof (long);
87 : regno++)
88 : {
89 : user_regs.l[regno] = ptrace (PTRACE_PEEKUSER, tid,
90 : (void *) (uintptr_t) (regno
91 : * sizeof (long)),
92 : NULL);
93 : if (errno != 0)
94 : return false;
95 : }
96 : #define GPRS (sizeof (user_regs.r.gpr) / sizeof (*user_regs.r.gpr))
97 : Dwarf_Word dwarf_regs[GPRS];
98 : for (unsigned gpr = 0; gpr < GPRS; gpr++)
99 : dwarf_regs[gpr] = user_regs.r.gpr[gpr];
100 : if (! setfunc (0, GPRS, dwarf_regs, arg))
101 : return false;
102 : dwarf_regs[0] = user_regs.r.link;
103 : // LR uses both 65 and 108 numbers, there is no consistency for it.
104 : if (! setfunc (65, 1, dwarf_regs, arg))
105 : return false;
106 : /* Registers like msr, ctr, xer, dar, dsisr etc. are probably irrelevant
107 : for CFI. */
108 : dwarf_regs[0] = user_regs.r.nip;
109 : return setfunc (-1, 1, dwarf_regs, arg);
110 : #endif /* __powerpc__ */
111 : }
112 :
113 : __typeof (ppc_set_initial_registers_tid)
114 : ppc64_set_initial_registers_tid
115 : __attribute__ ((alias ("ppc_set_initial_registers_tid")));
|