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