1 // SPDX-License-Identifier: GPL-2.0 2 /* 3 * dwarf-regs.c : Mapping of DWARF debug register numbers into register names. 4 * 5 * Written by: Masami Hiramatsu <mhiramat@kernel.org> 6 */ 7 8 #include <debug.h> 9 #include <dwarf-regs.h> 10 #include <elf.h> 11 #include <linux/kernel.h> 12 13 #ifndef EM_AARCH64 14 #define EM_AARCH64 183 /* ARM 64 bit */ 15 #endif 16 17 #ifndef EM_LOONGARCH 18 #define EM_LOONGARCH 258 /* LoongArch */ 19 #endif 20 21 /* Define const char * {arch}_register_tbl[] */ 22 #define DEFINE_DWARF_REGSTR_TABLE 23 #include "../arch/x86/include/dwarf-regs-table.h" 24 #include "../arch/arm/include/dwarf-regs-table.h" 25 #include "../arch/arm64/include/dwarf-regs-table.h" 26 #include "../arch/sh/include/dwarf-regs-table.h" 27 #include "../arch/powerpc/include/dwarf-regs-table.h" 28 #include "../arch/s390/include/dwarf-regs-table.h" 29 #include "../arch/sparc/include/dwarf-regs-table.h" 30 #include "../arch/xtensa/include/dwarf-regs-table.h" 31 #include "../arch/mips/include/dwarf-regs-table.h" 32 #include "../arch/loongarch/include/dwarf-regs-table.h" 33 34 #define __get_dwarf_regstr(tbl, n) (((n) < ARRAY_SIZE(tbl)) ? (tbl)[(n)] : NULL) 35 36 /* Return architecture dependent register string (for kprobe-tracer) */ 37 const char *get_dwarf_regstr(unsigned int n, unsigned int machine) 38 { 39 switch (machine) { 40 case EM_NONE: /* Generic arch - use host arch */ 41 return get_arch_regstr(n); 42 case EM_386: 43 return __get_dwarf_regstr(x86_32_regstr_tbl, n); 44 case EM_X86_64: 45 return __get_dwarf_regstr(x86_64_regstr_tbl, n); 46 case EM_ARM: 47 return __get_dwarf_regstr(arm_regstr_tbl, n); 48 case EM_AARCH64: 49 return __get_dwarf_regstr(aarch64_regstr_tbl, n); 50 case EM_SH: 51 return __get_dwarf_regstr(sh_regstr_tbl, n); 52 case EM_S390: 53 return __get_dwarf_regstr(s390_regstr_tbl, n); 54 case EM_PPC: 55 case EM_PPC64: 56 return __get_dwarf_regstr(powerpc_regstr_tbl, n); 57 case EM_SPARC: 58 case EM_SPARCV9: 59 return __get_dwarf_regstr(sparc_regstr_tbl, n); 60 case EM_XTENSA: 61 return __get_dwarf_regstr(xtensa_regstr_tbl, n); 62 case EM_MIPS: 63 return __get_dwarf_regstr(mips_regstr_tbl, n); 64 case EM_LOONGARCH: 65 return __get_dwarf_regstr(loongarch_regstr_tbl, n); 66 default: 67 pr_err("ELF MACHINE %x is not supported.\n", machine); 68 } 69 return NULL; 70 } 71