1 // SPDX-License-Identifier: GPL-2.0 1 // SPDX-License-Identifier: GPL-2.0 2 /* 2 /* 3 * dwarf-regs.c : Mapping of DWARF debug regis 3 * dwarf-regs.c : Mapping of DWARF debug register numbers into register names. 4 * 4 * 5 * Written by: Masami Hiramatsu <mhiramat@kern 5 * Written by: Masami Hiramatsu <mhiramat@kernel.org> 6 */ 6 */ 7 7 8 #include <stdlib.h> !! 8 #include <util.h> 9 #include <string.h> << 10 #include <debug.h> 9 #include <debug.h> 11 #include <dwarf-regs.h> 10 #include <dwarf-regs.h> 12 #include <elf.h> 11 #include <elf.h> 13 #include <errno.h> << 14 #include <linux/kernel.h> 12 #include <linux/kernel.h> 15 13 16 #ifndef EM_AARCH64 14 #ifndef EM_AARCH64 17 #define EM_AARCH64 183 /* ARM 64 bit */ 15 #define EM_AARCH64 183 /* ARM 64 bit */ 18 #endif 16 #endif 19 17 20 #ifndef EM_LOONGARCH << 21 #define EM_LOONGARCH 258 /* LoongArch */ << 22 #endif << 23 << 24 /* Define const char * {arch}_register_tbl[] * 18 /* Define const char * {arch}_register_tbl[] */ 25 #define DEFINE_DWARF_REGSTR_TABLE 19 #define DEFINE_DWARF_REGSTR_TABLE 26 #include "../arch/x86/include/dwarf-regs-table 20 #include "../arch/x86/include/dwarf-regs-table.h" 27 #include "../arch/arm/include/dwarf-regs-table 21 #include "../arch/arm/include/dwarf-regs-table.h" 28 #include "../arch/arm64/include/dwarf-regs-tab 22 #include "../arch/arm64/include/dwarf-regs-table.h" 29 #include "../arch/sh/include/dwarf-regs-table. 23 #include "../arch/sh/include/dwarf-regs-table.h" 30 #include "../arch/powerpc/include/dwarf-regs-t 24 #include "../arch/powerpc/include/dwarf-regs-table.h" 31 #include "../arch/s390/include/dwarf-regs-tabl 25 #include "../arch/s390/include/dwarf-regs-table.h" 32 #include "../arch/sparc/include/dwarf-regs-tab 26 #include "../arch/sparc/include/dwarf-regs-table.h" 33 #include "../arch/xtensa/include/dwarf-regs-ta 27 #include "../arch/xtensa/include/dwarf-regs-table.h" 34 #include "../arch/mips/include/dwarf-regs-tabl << 35 #include "../arch/loongarch/include/dwarf-regs << 36 28 37 #define __get_dwarf_regstr(tbl, n) (((n) < ARR 29 #define __get_dwarf_regstr(tbl, n) (((n) < ARRAY_SIZE(tbl)) ? (tbl)[(n)] : NULL) 38 30 39 /* Return architecture dependent register stri 31 /* Return architecture dependent register string (for kprobe-tracer) */ 40 const char *get_dwarf_regstr(unsigned int n, u 32 const char *get_dwarf_regstr(unsigned int n, unsigned int machine) 41 { 33 { 42 switch (machine) { 34 switch (machine) { 43 case EM_NONE: /* Generic arch - use 35 case EM_NONE: /* Generic arch - use host arch */ 44 return get_arch_regstr(n); 36 return get_arch_regstr(n); 45 case EM_386: 37 case EM_386: 46 return __get_dwarf_regstr(x86_ 38 return __get_dwarf_regstr(x86_32_regstr_tbl, n); 47 case EM_X86_64: 39 case EM_X86_64: 48 return __get_dwarf_regstr(x86_ 40 return __get_dwarf_regstr(x86_64_regstr_tbl, n); 49 case EM_ARM: 41 case EM_ARM: 50 return __get_dwarf_regstr(arm_ 42 return __get_dwarf_regstr(arm_regstr_tbl, n); 51 case EM_AARCH64: 43 case EM_AARCH64: 52 return __get_dwarf_regstr(aarc 44 return __get_dwarf_regstr(aarch64_regstr_tbl, n); 53 case EM_SH: 45 case EM_SH: 54 return __get_dwarf_regstr(sh_r 46 return __get_dwarf_regstr(sh_regstr_tbl, n); 55 case EM_S390: 47 case EM_S390: 56 return __get_dwarf_regstr(s390 48 return __get_dwarf_regstr(s390_regstr_tbl, n); 57 case EM_PPC: 49 case EM_PPC: 58 case EM_PPC64: 50 case EM_PPC64: 59 return __get_dwarf_regstr(powe 51 return __get_dwarf_regstr(powerpc_regstr_tbl, n); 60 case EM_SPARC: 52 case EM_SPARC: 61 case EM_SPARCV9: 53 case EM_SPARCV9: 62 return __get_dwarf_regstr(spar 54 return __get_dwarf_regstr(sparc_regstr_tbl, n); 63 case EM_XTENSA: 55 case EM_XTENSA: 64 return __get_dwarf_regstr(xten 56 return __get_dwarf_regstr(xtensa_regstr_tbl, n); 65 case EM_MIPS: << 66 return __get_dwarf_regstr(mips << 67 case EM_LOONGARCH: << 68 return __get_dwarf_regstr(loon << 69 default: 57 default: 70 pr_err("ELF MACHINE %x is not 58 pr_err("ELF MACHINE %x is not supported.\n", machine); 71 } 59 } 72 return NULL; 60 return NULL; 73 } << 74 << 75 __weak int get_arch_regnum(const char *name __ << 76 { << 77 return -ENOTSUP; << 78 } << 79 << 80 /* Return DWARF register number from architect << 81 int get_dwarf_regnum(const char *name, unsigne << 82 { << 83 char *regname = strdup(name); << 84 int reg = -1; << 85 char *p; << 86 << 87 if (regname == NULL) << 88 return -EINVAL; << 89 << 90 /* For convenience, remove trailing ch << 91 p = strpbrk(regname, " ,)"); << 92 if (p) << 93 *p = '\0'; << 94 << 95 switch (machine) { << 96 case EM_NONE: /* Generic arch - use << 97 reg = get_arch_regnum(regname) << 98 break; << 99 default: << 100 pr_err("ELF MACHINE %x is not << 101 } << 102 free(regname); << 103 return reg; << 104 } 61 } 105 62
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.