1 /* Fetch live process registers from TID. 2 Copyright (C) 2014 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 #if defined __arm__ 34 # include <sys/types.h> 35 # include <sys/user.h> 36 # include <sys/ptrace.h> 37 #endif 38 39 #ifdef __aarch64__ 40 # include <linux/uio.h> 41 # include <sys/user.h> 42 # include <sys/ptrace.h> 43 /* Deal with old glibc defining user_pt_regs instead of user_regs_struct. */ 44 # ifndef HAVE_SYS_USER_REGS 45 # define user_regs_struct user_pt_regs 46 # endif 47 #endif 48 49 #define BACKEND arm_ 50 #include "libebl_CPU.h" 51 52 bool 53 arm_set_initial_registers_tid (pid_t tid __attribute__ ((unused)), 54 ebl_tid_registers_t *setfunc __attribute__ ((unused)), 55 void *arg __attribute__ ((unused))) 56 { 57 #if !defined __arm__ && !defined __aarch64__ 58 return false; 59 #else /* __arm__ || __aarch64__ */ 60 #if defined __arm__ 61 struct user_regs user_regs; 62 if (ptrace (PTRACE_GETREGS, tid, NULL, &user_regs) != 0) 63 return false; 64 65 Dwarf_Word dwarf_regs[16]; 66 /* R0..R12 SP LR PC */ 67 for (int i = 0; i < 16; i++) 68 dwarf_regs[i] = user_regs.uregs[i]; 69 70 return setfunc (0, 16, dwarf_regs, arg); 71 #elif defined __aarch64__ 72 /* Compat mode: arm compatible code running on aarch64 */ 73 int i; 74 struct user_regs_struct gregs; 75 struct iovec iovec; 76 iovec.iov_base = &gregs; 77 iovec.iov_len = sizeof (gregs); 78 if (ptrace (PTRACE_GETREGSET, tid, NT_PRSTATUS, &iovec) != 0) 79 return false; 80 81 Dwarf_Word dwarf_regs[16]; 82 /* R0..R12 SP LR PC, encoded as 32 bit quantities */ 83 uint32_t *u32_ptr = (uint32_t *) &gregs.regs[0]; 84 for (i = 0; i < 16; i++) 85 dwarf_regs[i] = u32_ptr[i]; 86 87 return setfunc (0, 16, dwarf_regs, arg); 88 #else 89 # error "source file error, it cannot happen" 90 #endif 91 #endif 92 } 93