1 // SPDX-License-Identifier: GPL-2.0
3 * dwarf-regs.c : Mapping of DWARF debug register numbers into register names.
5 * Written by: Masami Hiramatsu <mhiramat@kernel.org>
11 #include <dwarf-regs.h>
14 #include <linux/kernel.h>
16 /* Define const char * {arch}_register_tbl[] */
17 #define DEFINE_DWARF_REGSTR_TABLE
18 #include "../arch/x86/include/dwarf-regs-table.h"
19 #include "../arch/arm/include/dwarf-regs-table.h"
20 #include "../arch/arm64/include/dwarf-regs-table.h"
21 #include "../arch/sh/include/dwarf-regs-table.h"
22 #include "../arch/powerpc/include/dwarf-regs-table.h"
23 #include "../arch/riscv/include/dwarf-regs-table.h"
24 #include "../arch/s390/include/dwarf-regs-table.h"
25 #include "../arch/sparc/include/dwarf-regs-table.h"
26 #include "../arch/xtensa/include/dwarf-regs-table.h"
27 #include "../arch/mips/include/dwarf-regs-table.h"
28 #include "../arch/loongarch/include/dwarf-regs-table.h"
30 #define __get_dwarf_regstr(tbl, n) (((n) < ARRAY_SIZE(tbl)) ? (tbl)[(n)] : NULL)
32 /* Return architecture dependent register string (for kprobe-tracer) */
33 const char *get_dwarf_regstr(unsigned int n
, unsigned int machine
, unsigned int flags
)
35 if (machine
== EM_NONE
) {
36 /* Generic arch - use host arch */
41 return __get_dwarf_regstr(x86_32_regstr_tbl
, n
);
43 return __get_dwarf_regstr(x86_64_regstr_tbl
, n
);
45 return __get_dwarf_regstr(arm_regstr_tbl
, n
);
47 return __get_dwarf_regstr(aarch64_regstr_tbl
, n
);
49 return get_csky_regstr(n
, flags
);
51 return __get_dwarf_regstr(sh_regstr_tbl
, n
);
53 return __get_dwarf_regstr(s390_regstr_tbl
, n
);
56 return __get_dwarf_regstr(powerpc_regstr_tbl
, n
);
58 return __get_dwarf_regstr(riscv_regstr_tbl
, n
);
61 return __get_dwarf_regstr(sparc_regstr_tbl
, n
);
63 return __get_dwarf_regstr(xtensa_regstr_tbl
, n
);
65 return __get_dwarf_regstr(mips_regstr_tbl
, n
);
67 return __get_dwarf_regstr(loongarch_regstr_tbl
, n
);
69 pr_err("ELF MACHINE %x is not supported.\n", machine
);
74 #if EM_HOST != EM_X86_64 && EM_HOST != EM_386
75 __weak
int get_arch_regnum(const char *name __maybe_unused
)
81 /* Return DWARF register number from architecture register name */
82 int get_dwarf_regnum(const char *name
, unsigned int machine
, unsigned int flags __maybe_unused
)
84 char *regname
= strdup(name
);
91 /* For convenience, remove trailing characters */
92 p
= strpbrk(regname
, " ,)");
96 if (machine
== EM_NONE
) {
97 /* Generic arch - use host arch */
101 #if EM_HOST != EM_X86_64 && EM_HOST != EM_386
103 reg
= get_arch_regnum(regname
);
109 reg
= get_x86_regnum(regname
);
112 pr_err("ELF MACHINE %x is not supported.\n", machine
);