1 /* Fetch live process registers from TID.
2 Copyright (C) 2013 Red Hat, Inc.
3 This file is part of elfutils.
5 This file is free software; you can redistribute it and/or modify
6 it under the terms of either
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
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
18 or both in parallel, as here.
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.
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/>. */
36 # include <sys/user.h>
37 # include <asm/ptrace.h>
38 # include <sys/ptrace.h>
42 #include "libebl_CPU.h"
45 s390_set_initial_registers_tid (pid_t tid __attribute__ ((unused)),
46 ebl_tid_registers_t *setfunc __attribute__ ((unused)),
47 void *arg __attribute__ ((unused)))
52 struct user user_regs;
54 parea.process_addr = (uintptr_t) &user_regs;
55 parea.kernel_addr = 0;
56 parea.len = sizeof (user_regs);
57 if (ptrace (PTRACE_PEEKUSR_AREA, tid, &parea, NULL) != 0)
59 /* If we run as s390x we get the 64-bit registers of tid.
60 But -m31 executable seems to use only the 32-bit parts of its
61 registers so we ignore the upper half. */
62 Dwarf_Word dwarf_regs[16];
63 for (unsigned u = 0; u < 16; u++)
64 dwarf_regs[u] = user_regs.regs.gprs[u];
65 if (! setfunc (0, 16, dwarf_regs, arg))
67 /* Avoid conversion double -> integer. */
68 eu_static_assert (sizeof user_regs.regs.fp_regs.fprs[0]
69 == sizeof dwarf_regs[0]);
70 for (unsigned u = 0; u < 16; u++)
72 // Store the double bits as is in the Dwarf_Word without conversion.
77 } fpr = { .d = user_regs.regs.fp_regs.fprs[u] };
78 dwarf_regs[u] = fpr.w;
81 if (! setfunc (16, 16, dwarf_regs, arg))
83 dwarf_regs[0] = user_regs.regs.psw.addr;
84 return setfunc (-1, 1, dwarf_regs, arg);
89 s390_normalize_pc (Ebl *ebl __attribute__ ((unused)), Dwarf_Addr *pc)
91 assert (ebl->class == ELFCLASS32);
93 /* Clear S390 bit 31. */
94 *pc &= (1U << 31) - 1;