18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * dwarf-regs.c : Mapping of DWARF debug register numbers into register names. 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Written by: Masami Hiramatsu <mhiramat@kernel.org> 68c2ecf20Sopenharmony_ci */ 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_ci#include <debug.h> 98c2ecf20Sopenharmony_ci#include <dwarf-regs.h> 108c2ecf20Sopenharmony_ci#include <elf.h> 118c2ecf20Sopenharmony_ci#include <linux/kernel.h> 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_ci#ifndef EM_AARCH64 148c2ecf20Sopenharmony_ci#define EM_AARCH64 183 /* ARM 64 bit */ 158c2ecf20Sopenharmony_ci#endif 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ci#ifndef EM_LOONGARCH 188c2ecf20Sopenharmony_ci#define EM_LOONGARCH 258 /* LoongArch */ 198c2ecf20Sopenharmony_ci#endif 208c2ecf20Sopenharmony_ci 218c2ecf20Sopenharmony_ci/* Define const char * {arch}_register_tbl[] */ 228c2ecf20Sopenharmony_ci#define DEFINE_DWARF_REGSTR_TABLE 238c2ecf20Sopenharmony_ci#include "../arch/x86/include/dwarf-regs-table.h" 248c2ecf20Sopenharmony_ci#include "../arch/arm/include/dwarf-regs-table.h" 258c2ecf20Sopenharmony_ci#include "../arch/arm64/include/dwarf-regs-table.h" 268c2ecf20Sopenharmony_ci#include "../arch/sh/include/dwarf-regs-table.h" 278c2ecf20Sopenharmony_ci#include "../arch/powerpc/include/dwarf-regs-table.h" 288c2ecf20Sopenharmony_ci#include "../arch/s390/include/dwarf-regs-table.h" 298c2ecf20Sopenharmony_ci#include "../arch/sparc/include/dwarf-regs-table.h" 308c2ecf20Sopenharmony_ci#include "../arch/xtensa/include/dwarf-regs-table.h" 318c2ecf20Sopenharmony_ci#include "../arch/loongarch/include/dwarf-regs-table.h" 328c2ecf20Sopenharmony_ci 338c2ecf20Sopenharmony_ci#define __get_dwarf_regstr(tbl, n) (((n) < ARRAY_SIZE(tbl)) ? (tbl)[(n)] : NULL) 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_ci/* Return architecture dependent register string (for kprobe-tracer) */ 368c2ecf20Sopenharmony_ciconst char *get_dwarf_regstr(unsigned int n, unsigned int machine) 378c2ecf20Sopenharmony_ci{ 388c2ecf20Sopenharmony_ci switch (machine) { 398c2ecf20Sopenharmony_ci case EM_NONE: /* Generic arch - use host arch */ 408c2ecf20Sopenharmony_ci return get_arch_regstr(n); 418c2ecf20Sopenharmony_ci case EM_386: 428c2ecf20Sopenharmony_ci return __get_dwarf_regstr(x86_32_regstr_tbl, n); 438c2ecf20Sopenharmony_ci case EM_X86_64: 448c2ecf20Sopenharmony_ci return __get_dwarf_regstr(x86_64_regstr_tbl, n); 458c2ecf20Sopenharmony_ci case EM_ARM: 468c2ecf20Sopenharmony_ci return __get_dwarf_regstr(arm_regstr_tbl, n); 478c2ecf20Sopenharmony_ci case EM_AARCH64: 488c2ecf20Sopenharmony_ci return __get_dwarf_regstr(aarch64_regstr_tbl, n); 498c2ecf20Sopenharmony_ci case EM_SH: 508c2ecf20Sopenharmony_ci return __get_dwarf_regstr(sh_regstr_tbl, n); 518c2ecf20Sopenharmony_ci case EM_S390: 528c2ecf20Sopenharmony_ci return __get_dwarf_regstr(s390_regstr_tbl, n); 538c2ecf20Sopenharmony_ci case EM_PPC: 548c2ecf20Sopenharmony_ci case EM_PPC64: 558c2ecf20Sopenharmony_ci return __get_dwarf_regstr(powerpc_regstr_tbl, n); 568c2ecf20Sopenharmony_ci case EM_SPARC: 578c2ecf20Sopenharmony_ci case EM_SPARCV9: 588c2ecf20Sopenharmony_ci return __get_dwarf_regstr(sparc_regstr_tbl, n); 598c2ecf20Sopenharmony_ci case EM_XTENSA: 608c2ecf20Sopenharmony_ci return __get_dwarf_regstr(xtensa_regstr_tbl, n); 618c2ecf20Sopenharmony_ci case EM_LOONGARCH: 628c2ecf20Sopenharmony_ci return __get_dwarf_regstr(loongarch_regstr_tbl, n); 638c2ecf20Sopenharmony_ci default: 648c2ecf20Sopenharmony_ci pr_err("ELF MACHINE %x is not supported.\n", machine); 658c2ecf20Sopenharmony_ci } 668c2ecf20Sopenharmony_ci return NULL; 678c2ecf20Sopenharmony_ci} 68