1 /*
2 * dwarf-regs.c : Mapping of DWARF debug register numbers into register names.
3 *
4 * Written by: Masami Hiramatsu <mhiramat@kernel.org>
5 */
6
7 #include <util.h>
8 #include <debug.h>
9 #include <dwarf-regs.h>
10 #include <elf.h>
11
12 #ifndef EM_AARCH64
13 #define EM_AARCH64 183 /* ARM 64 bit */
14 #endif
15
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/s390/include/dwarf-regs-table.h"
24 #include "../arch/sparc/include/dwarf-regs-table.h"
25 #include "../arch/xtensa/include/dwarf-regs-table.h"
26
27 #define __get_dwarf_regstr(tbl, n) (((n) < ARRAY_SIZE(tbl)) ? (tbl)[(n)] : NULL)
28
29 /* Return architecture dependent register string (for kprobe-tracer) */
get_dwarf_regstr(unsigned int n,unsigned int machine)30 const char *get_dwarf_regstr(unsigned int n, unsigned int machine)
31 {
32 switch (machine) {
33 case EM_NONE: /* Generic arch - use host arch */
34 return get_arch_regstr(n);
35 case EM_386:
36 return __get_dwarf_regstr(x86_32_regstr_tbl, n);
37 case EM_X86_64:
38 return __get_dwarf_regstr(x86_64_regstr_tbl, n);
39 case EM_ARM:
40 return __get_dwarf_regstr(arm_regstr_tbl, n);
41 case EM_AARCH64:
42 return __get_dwarf_regstr(aarch64_regstr_tbl, n);
43 case EM_SH:
44 return __get_dwarf_regstr(sh_regstr_tbl, n);
45 case EM_S390:
46 return __get_dwarf_regstr(s390_regstr_tbl, n);
47 case EM_PPC:
48 case EM_PPC64:
49 return __get_dwarf_regstr(powerpc_regstr_tbl, n);
50 case EM_SPARC:
51 case EM_SPARCV9:
52 return __get_dwarf_regstr(sparc_regstr_tbl, n);
53 case EM_XTENSA:
54 return __get_dwarf_regstr(xtensa_regstr_tbl, n);
55 default:
56 pr_err("ELF MACHINE %x is not supported.\n", machine);
57 }
58 return NULL;
59 }
60