xref: /linux/tools/perf/util/include/dwarf-regs.h (revision 7f71507851fc7764b36a3221839607d3a45c2025)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _PERF_DWARF_REGS_H_
3 #define _PERF_DWARF_REGS_H_
4 #include "annotate.h"
5 #include <elf.h>
6 
7 #ifndef EM_AARCH64
8 #define EM_AARCH64	183  /* ARM 64 bit */
9 #endif
10 
11 #ifndef EM_CSKY
12 #define EM_CSKY		252  /* C-SKY */
13 #endif
14 #ifndef EF_CSKY_ABIV1
15 #define EF_CSKY_ABIV1	0X10000000
16 #endif
17 #ifndef EF_CSKY_ABIV2
18 #define EF_CSKY_ABIV2	0X20000000
19 #endif
20 
21 #ifndef EM_LOONGARCH
22 #define EM_LOONGARCH	258 /* LoongArch */
23 #endif
24 
25 /* EM_HOST gives the ELF machine for host, EF_HOST gives additional flags. */
26 #if defined(__x86_64__)
27   #define EM_HOST EM_X86_64
28 #elif defined(__i386__)
29   #define EM_HOST EM_386
30 #elif defined(__aarch64__)
31   #define EM_HOST EM_AARCH64
32 #elif defined(__arm__)
33   #define EM_HOST EM_ARM
34 #elif defined(__alpha__)
35   #define EM_HOST EM_ALPHA
36 #elif defined(__arc__)
37   #define EM_HOST EM_ARC
38 #elif defined(__AVR__)
39   #define EM_HOST EM_AVR
40 #elif defined(__AVR32__)
41   #define EM_HOST EM_AVR32
42 #elif defined(__bfin__)
43   #define EM_HOST EM_BLACKFIN
44 #elif defined(__csky__)
45   #define EM_HOST EM_CSKY
46   #if defined(__CSKYABIV2__)
47     #define EF_HOST EF_CSKY_ABIV2
48   #else
49     #define EF_HOST EF_CSKY_ABIV1
50   #endif
51 #elif defined(__cris__)
52   #define EM_HOST EM_CRIS
53 #elif defined(__hppa__) // HP PA-RISC
54   #define EM_HOST EM_PARISC
55 #elif defined(__loongarch__)
56   #define EM_HOST EM_LOONGARCH
57 #elif defined(__mips__)
58   #define EM_HOST EM_MIPS
59 #elif defined(__m32r__)
60   #define EM_HOST EM_M32R
61 #elif defined(__microblaze__)
62   #define EM_HOST EM_MICROBLAZE
63 #elif defined(__MSP430__)
64   #define EM_HOST EM_MSP430
65 #elif defined(__powerpc64__)
66   #define EM_HOST EM_PPC64
67 #elif defined(__powerpc__)
68   #define EM_HOST EM_PPC
69 #elif defined(__riscv)
70   #define EM_HOST EM_RISCV
71 #elif defined(__s390x__)
72   #define EM_HOST EM_S390
73 #elif defined(__sh__)
74   #define EM_HOST EM_SH
75 #elif defined(__sparc64__) || defined(__sparc__)
76   #define EM_HOST EM_SPARC
77 #elif defined(__xtensa__)
78   #define EM_HOST EM_XTENSA
79 #else
80   /* Unknown host ELF machine type. */
81   #define EM_HOST EM_NONE
82 #endif
83 
84 #if !defined(EF_HOST)
85   #define EF_HOST 0
86 #endif
87 
88 #define DWARF_REG_PC  0xd3af9c /* random number */
89 #define DWARF_REG_FB  0xd3affb /* random number */
90 
91 #ifdef HAVE_LIBDW_SUPPORT
92 const char *get_csky_regstr(unsigned int n, unsigned int flags);
93 
94 /**
95  * get_dwarf_regstr() - Returns ftrace register string from DWARF regnum.
96  * @n: DWARF register number.
97  * @machine: ELF machine signature (EM_*).
98  * @flags: ELF flags for things like ABI differences.
99  */
100 const char *get_dwarf_regstr(unsigned int n, unsigned int machine, unsigned int flags);
101 
102 int get_x86_regnum(const char *name);
103 
104 #if !defined(__x86_64__) && !defined(__i386__)
105 int get_arch_regnum(const char *name);
106 #endif
107 
108 /*
109  * get_dwarf_regnum - Returns DWARF regnum from register name
110  * name: architecture register name
111  * machine: ELF machine signature (EM_*)
112  */
113 int get_dwarf_regnum(const char *name, unsigned int machine, unsigned int flags);
114 
115 void get_powerpc_regs(u32 raw_insn, int is_source, struct annotated_op_loc *op_loc);
116 
117 #else /* HAVE_LIBDW_SUPPORT */
118 
119 static inline int get_dwarf_regnum(const char *name __maybe_unused,
120 				   unsigned int machine __maybe_unused,
121 				   unsigned int flags __maybe_unused)
122 {
123 	return -1;
124 }
125 
126 static inline void get_powerpc_regs(u32 raw_insn __maybe_unused, int is_source __maybe_unused,
127 		struct annotated_op_loc *op_loc __maybe_unused)
128 {
129 	return;
130 }
131 #endif
132 
133 #endif
134