Loading...
1// SPDX-License-Identifier: GPL-2.0
2#include <errno.h>
3#include "perf_regs.h"
4#include "event.h"
5
6const struct sample_reg __weak sample_reg_masks[] = {
7 SMPL_REG_END
8};
9
10int __weak arch_sdt_arg_parse_op(char *old_op __maybe_unused,
11 char **new_op __maybe_unused)
12{
13 return SDT_ARG_SKIP;
14}
15
16uint64_t __weak arch__intr_reg_mask(void)
17{
18 return PERF_REGS_MASK;
19}
20
21uint64_t __weak arch__user_reg_mask(void)
22{
23 return PERF_REGS_MASK;
24}
25
26#ifdef HAVE_PERF_REGS_SUPPORT
27int perf_reg_value(u64 *valp, struct regs_dump *regs, int id)
28{
29 int i, idx = 0;
30 u64 mask = regs->mask;
31
32 if (regs->cache_mask & (1ULL << id))
33 goto out;
34
35 if (!(mask & (1ULL << id)))
36 return -EINVAL;
37
38 for (i = 0; i < id; i++) {
39 if (mask & (1ULL << i))
40 idx++;
41 }
42
43 regs->cache_mask |= (1ULL << id);
44 regs->cache_regs[id] = regs->regs[idx];
45
46out:
47 *valp = regs->cache_regs[id];
48 return 0;
49}
50#endif
1// SPDX-License-Identifier: GPL-2.0
2#include <errno.h>
3#include <string.h>
4#include "perf_regs.h"
5#include "util/sample.h"
6#include "debug.h"
7
8int __weak arch_sdt_arg_parse_op(char *old_op __maybe_unused,
9 char **new_op __maybe_unused)
10{
11 return SDT_ARG_SKIP;
12}
13
14uint64_t __weak arch__intr_reg_mask(void)
15{
16 return 0;
17}
18
19uint64_t __weak arch__user_reg_mask(void)
20{
21 return 0;
22}
23
24#ifdef HAVE_PERF_REGS_SUPPORT
25
26const char *perf_reg_name(int id, const char *arch)
27{
28 const char *reg_name = NULL;
29
30 if (!strcmp(arch, "csky"))
31 reg_name = __perf_reg_name_csky(id);
32 else if (!strcmp(arch, "loongarch"))
33 reg_name = __perf_reg_name_loongarch(id);
34 else if (!strcmp(arch, "mips"))
35 reg_name = __perf_reg_name_mips(id);
36 else if (!strcmp(arch, "powerpc"))
37 reg_name = __perf_reg_name_powerpc(id);
38 else if (!strcmp(arch, "riscv"))
39 reg_name = __perf_reg_name_riscv(id);
40 else if (!strcmp(arch, "s390"))
41 reg_name = __perf_reg_name_s390(id);
42 else if (!strcmp(arch, "x86"))
43 reg_name = __perf_reg_name_x86(id);
44 else if (!strcmp(arch, "arm"))
45 reg_name = __perf_reg_name_arm(id);
46 else if (!strcmp(arch, "arm64"))
47 reg_name = __perf_reg_name_arm64(id);
48
49 return reg_name ?: "unknown";
50}
51
52int perf_reg_value(u64 *valp, struct regs_dump *regs, int id)
53{
54 int i, idx = 0;
55 u64 mask = regs->mask;
56
57 if ((u64)id >= PERF_SAMPLE_REGS_CACHE_SIZE)
58 return -EINVAL;
59
60 if (regs->cache_mask & (1ULL << id))
61 goto out;
62
63 if (!(mask & (1ULL << id)))
64 return -EINVAL;
65
66 for (i = 0; i < id; i++) {
67 if (mask & (1ULL << i))
68 idx++;
69 }
70
71 regs->cache_mask |= (1ULL << id);
72 regs->cache_regs[id] = regs->regs[idx];
73
74out:
75 *valp = regs->cache_regs[id];
76 return 0;
77}
78
79uint64_t perf_arch_reg_ip(const char *arch)
80{
81 if (!strcmp(arch, "arm"))
82 return __perf_reg_ip_arm();
83 else if (!strcmp(arch, "arm64"))
84 return __perf_reg_ip_arm64();
85 else if (!strcmp(arch, "csky"))
86 return __perf_reg_ip_csky();
87 else if (!strcmp(arch, "loongarch"))
88 return __perf_reg_ip_loongarch();
89 else if (!strcmp(arch, "mips"))
90 return __perf_reg_ip_mips();
91 else if (!strcmp(arch, "powerpc"))
92 return __perf_reg_ip_powerpc();
93 else if (!strcmp(arch, "riscv"))
94 return __perf_reg_ip_riscv();
95 else if (!strcmp(arch, "s390"))
96 return __perf_reg_ip_s390();
97 else if (!strcmp(arch, "x86"))
98 return __perf_reg_ip_x86();
99
100 pr_err("Fail to find IP register for arch %s, returns 0\n", arch);
101 return 0;
102}
103
104uint64_t perf_arch_reg_sp(const char *arch)
105{
106 if (!strcmp(arch, "arm"))
107 return __perf_reg_sp_arm();
108 else if (!strcmp(arch, "arm64"))
109 return __perf_reg_sp_arm64();
110 else if (!strcmp(arch, "csky"))
111 return __perf_reg_sp_csky();
112 else if (!strcmp(arch, "loongarch"))
113 return __perf_reg_sp_loongarch();
114 else if (!strcmp(arch, "mips"))
115 return __perf_reg_sp_mips();
116 else if (!strcmp(arch, "powerpc"))
117 return __perf_reg_sp_powerpc();
118 else if (!strcmp(arch, "riscv"))
119 return __perf_reg_sp_riscv();
120 else if (!strcmp(arch, "s390"))
121 return __perf_reg_sp_s390();
122 else if (!strcmp(arch, "x86"))
123 return __perf_reg_sp_x86();
124
125 pr_err("Fail to find SP register for arch %s, returns 0\n", arch);
126 return 0;
127}
128
129#endif