162306a36Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * dwarf-regs.c : Mapping of DWARF debug register numbers into register names. 462306a36Sopenharmony_ci * 562306a36Sopenharmony_ci * Written by: Masami Hiramatsu <mhiramat@kernel.org> 662306a36Sopenharmony_ci */ 762306a36Sopenharmony_ci 862306a36Sopenharmony_ci#include <debug.h> 962306a36Sopenharmony_ci#include <dwarf-regs.h> 1062306a36Sopenharmony_ci#include <elf.h> 1162306a36Sopenharmony_ci#include <linux/kernel.h> 1262306a36Sopenharmony_ci 1362306a36Sopenharmony_ci#ifndef EM_AARCH64 1462306a36Sopenharmony_ci#define EM_AARCH64 183 /* ARM 64 bit */ 1562306a36Sopenharmony_ci#endif 1662306a36Sopenharmony_ci 1762306a36Sopenharmony_ci#ifndef EM_LOONGARCH 1862306a36Sopenharmony_ci#define EM_LOONGARCH 258 /* LoongArch */ 1962306a36Sopenharmony_ci#endif 2062306a36Sopenharmony_ci 2162306a36Sopenharmony_ci/* Define const char * {arch}_register_tbl[] */ 2262306a36Sopenharmony_ci#define DEFINE_DWARF_REGSTR_TABLE 2362306a36Sopenharmony_ci#include "../arch/x86/include/dwarf-regs-table.h" 2462306a36Sopenharmony_ci#include "../arch/arm/include/dwarf-regs-table.h" 2562306a36Sopenharmony_ci#include "../arch/arm64/include/dwarf-regs-table.h" 2662306a36Sopenharmony_ci#include "../arch/sh/include/dwarf-regs-table.h" 2762306a36Sopenharmony_ci#include "../arch/powerpc/include/dwarf-regs-table.h" 2862306a36Sopenharmony_ci#include "../arch/s390/include/dwarf-regs-table.h" 2962306a36Sopenharmony_ci#include "../arch/sparc/include/dwarf-regs-table.h" 3062306a36Sopenharmony_ci#include "../arch/xtensa/include/dwarf-regs-table.h" 3162306a36Sopenharmony_ci#include "../arch/mips/include/dwarf-regs-table.h" 3262306a36Sopenharmony_ci#include "../arch/loongarch/include/dwarf-regs-table.h" 3362306a36Sopenharmony_ci 3462306a36Sopenharmony_ci#define __get_dwarf_regstr(tbl, n) (((n) < ARRAY_SIZE(tbl)) ? (tbl)[(n)] : NULL) 3562306a36Sopenharmony_ci 3662306a36Sopenharmony_ci/* Return architecture dependent register string (for kprobe-tracer) */ 3762306a36Sopenharmony_ciconst char *get_dwarf_regstr(unsigned int n, unsigned int machine) 3862306a36Sopenharmony_ci{ 3962306a36Sopenharmony_ci switch (machine) { 4062306a36Sopenharmony_ci case EM_NONE: /* Generic arch - use host arch */ 4162306a36Sopenharmony_ci return get_arch_regstr(n); 4262306a36Sopenharmony_ci case EM_386: 4362306a36Sopenharmony_ci return __get_dwarf_regstr(x86_32_regstr_tbl, n); 4462306a36Sopenharmony_ci case EM_X86_64: 4562306a36Sopenharmony_ci return __get_dwarf_regstr(x86_64_regstr_tbl, n); 4662306a36Sopenharmony_ci case EM_ARM: 4762306a36Sopenharmony_ci return __get_dwarf_regstr(arm_regstr_tbl, n); 4862306a36Sopenharmony_ci case EM_AARCH64: 4962306a36Sopenharmony_ci return __get_dwarf_regstr(aarch64_regstr_tbl, n); 5062306a36Sopenharmony_ci case EM_SH: 5162306a36Sopenharmony_ci return __get_dwarf_regstr(sh_regstr_tbl, n); 5262306a36Sopenharmony_ci case EM_S390: 5362306a36Sopenharmony_ci return __get_dwarf_regstr(s390_regstr_tbl, n); 5462306a36Sopenharmony_ci case EM_PPC: 5562306a36Sopenharmony_ci case EM_PPC64: 5662306a36Sopenharmony_ci return __get_dwarf_regstr(powerpc_regstr_tbl, n); 5762306a36Sopenharmony_ci case EM_SPARC: 5862306a36Sopenharmony_ci case EM_SPARCV9: 5962306a36Sopenharmony_ci return __get_dwarf_regstr(sparc_regstr_tbl, n); 6062306a36Sopenharmony_ci case EM_XTENSA: 6162306a36Sopenharmony_ci return __get_dwarf_regstr(xtensa_regstr_tbl, n); 6262306a36Sopenharmony_ci case EM_MIPS: 6362306a36Sopenharmony_ci return __get_dwarf_regstr(mips_regstr_tbl, n); 6462306a36Sopenharmony_ci case EM_LOONGARCH: 6562306a36Sopenharmony_ci return __get_dwarf_regstr(loongarch_regstr_tbl, n); 6662306a36Sopenharmony_ci default: 6762306a36Sopenharmony_ci pr_err("ELF MACHINE %x is not supported.\n", machine); 6862306a36Sopenharmony_ci } 6962306a36Sopenharmony_ci return NULL; 7062306a36Sopenharmony_ci} 71