18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Mapping of DWARF debug register numbers into register names. 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright IBM Corp. 2010, 2017 68c2ecf20Sopenharmony_ci * Author(s): Heiko Carstens <heiko.carstens@de.ibm.com>, 78c2ecf20Sopenharmony_ci * Hendrik Brueckner <brueckner@linux.vnet.ibm.com> 88c2ecf20Sopenharmony_ci * 98c2ecf20Sopenharmony_ci */ 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_ci#include <errno.h> 128c2ecf20Sopenharmony_ci#include <stddef.h> 138c2ecf20Sopenharmony_ci#include <stdlib.h> 148c2ecf20Sopenharmony_ci#include <linux/kernel.h> 158c2ecf20Sopenharmony_ci#include <asm/ptrace.h> 168c2ecf20Sopenharmony_ci#include <string.h> 178c2ecf20Sopenharmony_ci#include <dwarf-regs.h> 188c2ecf20Sopenharmony_ci#include "dwarf-regs-table.h" 198c2ecf20Sopenharmony_ci 208c2ecf20Sopenharmony_ciconst char *get_arch_regstr(unsigned int n) 218c2ecf20Sopenharmony_ci{ 228c2ecf20Sopenharmony_ci return (n >= ARRAY_SIZE(s390_dwarf_regs)) ? NULL : s390_dwarf_regs[n]; 238c2ecf20Sopenharmony_ci} 248c2ecf20Sopenharmony_ci 258c2ecf20Sopenharmony_ci/* 268c2ecf20Sopenharmony_ci * Convert the register name into an offset to struct pt_regs (kernel). 278c2ecf20Sopenharmony_ci * This is required by the BPF prologue generator. The BPF 288c2ecf20Sopenharmony_ci * program is called in the BPF overflow handler in the perf 298c2ecf20Sopenharmony_ci * core. 308c2ecf20Sopenharmony_ci */ 318c2ecf20Sopenharmony_ciint regs_query_register_offset(const char *name) 328c2ecf20Sopenharmony_ci{ 338c2ecf20Sopenharmony_ci unsigned long gpr; 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_ci if (!name || strncmp(name, "%r", 2)) 368c2ecf20Sopenharmony_ci return -EINVAL; 378c2ecf20Sopenharmony_ci 388c2ecf20Sopenharmony_ci errno = 0; 398c2ecf20Sopenharmony_ci gpr = strtoul(name + 2, NULL, 10); 408c2ecf20Sopenharmony_ci if (errno || gpr >= 16) 418c2ecf20Sopenharmony_ci return -EINVAL; 428c2ecf20Sopenharmony_ci 438c2ecf20Sopenharmony_ci return offsetof(user_pt_regs, gprs) + 8 * gpr; 448c2ecf20Sopenharmony_ci} 45