blob: daf6f3751454834fe83e47910c2d58c89514f20c [file] [log] [blame]
Mark Wielaard66637fa2014-04-09 11:48:23 +02001/* Fetch live process registers from TID.
Kyle McMartinc1e0fcb2014-06-09 21:06:26 +02002 Copyright (C) 2013, 2014 Red Hat, Inc.
Mark Wielaard66637fa2014-04-09 11:48:23 +02003 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 "system.h"
34#include <assert.h>
Ulf Hermann9c1509a2017-04-20 15:37:04 +020035#if defined(__aarch64__) && defined(__linux__)
Mark Wielaard66637fa2014-04-09 11:48:23 +020036# include <linux/uio.h>
37# include <sys/user.h>
38# include <sys/ptrace.h>
Kyle McMartinc1e0fcb2014-06-09 21:06:26 +020039/* Deal with old glibc defining user_pt_regs instead of user_regs_struct. */
40# ifndef HAVE_SYS_USER_REGS
41# define user_regs_struct user_pt_regs
42# define user_fpsimd_struct user_fpsimd_state
43# endif
Mark Wielaard66637fa2014-04-09 11:48:23 +020044#endif
45
46#define BACKEND aarch64_
47#include "libebl_CPU.h"
48
49bool
50aarch64_set_initial_registers_tid (pid_t tid __attribute__ ((unused)),
51 ebl_tid_registers_t *setfunc __attribute__ ((unused)),
52 void *arg __attribute__ ((unused)))
53{
Ulf Hermann9c1509a2017-04-20 15:37:04 +020054#if !defined(__aarch64__) || !defined(__linux__)
Mark Wielaard66637fa2014-04-09 11:48:23 +020055 return false;
56#else /* __aarch64__ */
57
58 /* General registers. */
Kyle McMartinc1e0fcb2014-06-09 21:06:26 +020059 struct user_regs_struct gregs;
Mark Wielaard66637fa2014-04-09 11:48:23 +020060 struct iovec iovec;
61 iovec.iov_base = &gregs;
62 iovec.iov_len = sizeof (gregs);
63 if (ptrace (PTRACE_GETREGSET, tid, NT_PRSTATUS, &iovec) != 0)
64 return false;
65
66 /* X0..X30 plus SP. */
67 if (! setfunc (0, 32, (Dwarf_Word *) &gregs.regs[0], arg))
68 return false;
69
70 /* PC. */
71 if (! setfunc (-1, 1, (Dwarf_Word *) &gregs.pc, arg))
72 return false;
73
74 /* ELR cannot be found. */
75
76 /* FP registers (only 64bits are used). */
Kyle McMartinc1e0fcb2014-06-09 21:06:26 +020077 struct user_fpsimd_struct fregs;
Mark Wielaard66637fa2014-04-09 11:48:23 +020078 iovec.iov_base = &fregs;
79 iovec.iov_len = sizeof (fregs);
80 if (ptrace (PTRACE_GETREGSET, tid, NT_FPREGSET, &iovec) != 0)
81 return false;
82
83 Dwarf_Word dwarf_fregs[32];
84 for (int r = 0; r < 32; r++)
85 dwarf_fregs[r] = fregs.vregs[r] & 0xFFFFFFFF;
86
87 if (! setfunc (64, 32, dwarf_fregs, arg))
88 return false;
89
90 return true;
91#endif /* __aarch64__ */
92}