Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /*
0003  * dwarf-regs.c : Mapping of DWARF debug register numbers into register names.
0004  *
0005  * Written by: Masami Hiramatsu <mhiramat@kernel.org>
0006  */
0007 
0008 #include <debug.h>
0009 #include <dwarf-regs.h>
0010 #include <elf.h>
0011 #include <linux/kernel.h>
0012 
0013 #ifndef EM_AARCH64
0014 #define EM_AARCH64  183  /* ARM 64 bit */
0015 #endif
0016 
0017 /* Define const char * {arch}_register_tbl[] */
0018 #define DEFINE_DWARF_REGSTR_TABLE
0019 #include "../arch/x86/include/dwarf-regs-table.h"
0020 #include "../arch/arm/include/dwarf-regs-table.h"
0021 #include "../arch/arm64/include/dwarf-regs-table.h"
0022 #include "../arch/sh/include/dwarf-regs-table.h"
0023 #include "../arch/powerpc/include/dwarf-regs-table.h"
0024 #include "../arch/s390/include/dwarf-regs-table.h"
0025 #include "../arch/sparc/include/dwarf-regs-table.h"
0026 #include "../arch/xtensa/include/dwarf-regs-table.h"
0027 #include "../arch/mips/include/dwarf-regs-table.h"
0028 
0029 #define __get_dwarf_regstr(tbl, n) (((n) < ARRAY_SIZE(tbl)) ? (tbl)[(n)] : NULL)
0030 
0031 /* Return architecture dependent register string (for kprobe-tracer) */
0032 const char *get_dwarf_regstr(unsigned int n, unsigned int machine)
0033 {
0034     switch (machine) {
0035     case EM_NONE:   /* Generic arch - use host arch */
0036         return get_arch_regstr(n);
0037     case EM_386:
0038         return __get_dwarf_regstr(x86_32_regstr_tbl, n);
0039     case EM_X86_64:
0040         return __get_dwarf_regstr(x86_64_regstr_tbl, n);
0041     case EM_ARM:
0042         return __get_dwarf_regstr(arm_regstr_tbl, n);
0043     case EM_AARCH64:
0044         return __get_dwarf_regstr(aarch64_regstr_tbl, n);
0045     case EM_SH:
0046         return __get_dwarf_regstr(sh_regstr_tbl, n);
0047     case EM_S390:
0048         return __get_dwarf_regstr(s390_regstr_tbl, n);
0049     case EM_PPC:
0050     case EM_PPC64:
0051         return __get_dwarf_regstr(powerpc_regstr_tbl, n);
0052     case EM_SPARC:
0053     case EM_SPARCV9:
0054         return __get_dwarf_regstr(sparc_regstr_tbl, n);
0055     case EM_XTENSA:
0056         return __get_dwarf_regstr(xtensa_regstr_tbl, n);
0057     case EM_MIPS:
0058         return __get_dwarf_regstr(mips_regstr_tbl, n);
0059     default:
0060         pr_err("ELF MACHINE %x is not supported.\n", machine);
0061     }
0062     return NULL;
0063 }