Skip to content

Commit 285b523

Browse files
captain5050namhyung
authored andcommitted
perf dwarf-regs: Move powerpc dwarf-regs out of arch
Move arch/powerpc/util/dwarf-regs.c to util/dwarf-regs-powerpc.c and compile in unconditionally. get_arch_regstr is redundant when EM_NONE is treated as EM_HOST so remove and update dwarf-regs.c conditions. Make get_powerpc_regs unconditionally available whwn libdw is. Reviewed-by: Masami Hiramatsu (Google) <[email protected]> Signed-off-by: Ian Rogers <[email protected]> Cc: Anup Patel <[email protected]> Cc: Yang Jihong <[email protected]> Cc: Palmer Dabbelt <[email protected]> Cc: David S. Miller <[email protected]> Cc: Albert Ou <[email protected]> Cc: Shenlin Liang <[email protected]> Cc: Nick Terrell <[email protected]> Cc: Guilherme Amadio <[email protected]> Cc: Steinar H. Gunderson <[email protected]> Cc: Changbin Du <[email protected]> Cc: Alexander Lobakin <[email protected]> Cc: Przemek Kitszel <[email protected]> Cc: Huacai Chen <[email protected]> Cc: Guo Ren <[email protected]> Cc: Masahiro Yamada <[email protected]> Cc: Will Deacon <[email protected]> Cc: James Clark <[email protected]> Cc: Mike Leach <[email protected]> Cc: Chen Pei <[email protected]> Cc: Leo Yan <[email protected]> Cc: Oliver Upton <[email protected]> Cc: Aditya Gupta <[email protected]> Cc: Kajol Jain <[email protected]> Cc: Athira Rajeev <[email protected]> Cc: [email protected] Cc: [email protected] Cc: Bibo Mao <[email protected]> Cc: John Garry <[email protected]> Cc: Atish Patra <[email protected]> Cc: Dima Kogan <[email protected]> Cc: Paul Walmsley <[email protected]> Cc: Dr. David Alan Gilbert <[email protected]> Cc: [email protected] Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Namhyung Kim <[email protected]>
1 parent 8a768a2 commit 285b523

File tree

6 files changed

+70
-149
lines changed

6 files changed

+70
-149
lines changed

tools/perf/arch/powerpc/util/Build

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ perf-util-y += sym-handling.o
77
perf-util-y += evsel.o
88
perf-util-y += event.o
99

10-
perf-util-$(CONFIG_LIBDW) += dwarf-regs.o
1110
perf-util-$(CONFIG_LIBDW) += skip-callchain-idx.o
1211

1312
perf-util-$(CONFIG_LIBUNWIND) += unwind-libunwind.o

tools/perf/arch/powerpc/util/dwarf-regs.c

Lines changed: 0 additions & 141 deletions
This file was deleted.

tools/perf/util/Build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ perf-util-$(CONFIG_LIBDW) += probe-finder.o
205205
perf-util-$(CONFIG_LIBDW) += dwarf-aux.o
206206
perf-util-$(CONFIG_LIBDW) += dwarf-regs.o
207207
perf-util-$(CONFIG_LIBDW) += dwarf-regs-csky.o
208+
perf-util-$(CONFIG_LIBDW) += dwarf-regs-powerpc.o
208209
perf-util-$(CONFIG_LIBDW) += dwarf-regs-x86.o
209210
perf-util-$(CONFIG_LIBDW) += debuginfo.o
210211
perf-util-$(CONFIG_LIBDW) += annotate-data.o

tools/perf/util/dwarf-regs-powerpc.c

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// SPDX-License-Identifier: GPL-2.0-or-later
2+
/*
3+
* Mapping of DWARF debug register numbers into register names.
4+
*
5+
* Copyright (C) 2010 Ian Munsie, IBM Corporation.
6+
*/
7+
8+
#include <dwarf-regs.h>
9+
10+
#define PPC_OP(op) (((op) >> 26) & 0x3F)
11+
#define PPC_RA(a) (((a) >> 16) & 0x1f)
12+
#define PPC_RT(t) (((t) >> 21) & 0x1f)
13+
#define PPC_RB(b) (((b) >> 11) & 0x1f)
14+
#define PPC_D(D) ((D) & 0xfffe)
15+
#define PPC_DS(DS) ((DS) & 0xfffc)
16+
#define OP_LD 58
17+
#define OP_STD 62
18+
19+
static int get_source_reg(u32 raw_insn)
20+
{
21+
return PPC_RA(raw_insn);
22+
}
23+
24+
static int get_target_reg(u32 raw_insn)
25+
{
26+
return PPC_RT(raw_insn);
27+
}
28+
29+
static int get_offset_opcode(u32 raw_insn)
30+
{
31+
int opcode = PPC_OP(raw_insn);
32+
33+
/* DS- form */
34+
if ((opcode == OP_LD) || (opcode == OP_STD))
35+
return PPC_DS(raw_insn);
36+
else
37+
return PPC_D(raw_insn);
38+
}
39+
40+
/*
41+
* Fills the required fields for op_loc depending on if it
42+
* is a source or target.
43+
* D form: ins RT,D(RA) -> src_reg1 = RA, offset = D, dst_reg1 = RT
44+
* DS form: ins RT,DS(RA) -> src_reg1 = RA, offset = DS, dst_reg1 = RT
45+
* X form: ins RT,RA,RB -> src_reg1 = RA, src_reg2 = RB, dst_reg1 = RT
46+
*/
47+
void get_powerpc_regs(u32 raw_insn, int is_source,
48+
struct annotated_op_loc *op_loc)
49+
{
50+
if (is_source)
51+
op_loc->reg1 = get_source_reg(raw_insn);
52+
else
53+
op_loc->reg1 = get_target_reg(raw_insn);
54+
55+
if (op_loc->multi_regs)
56+
op_loc->reg2 = PPC_RB(raw_insn);
57+
58+
/* TODO: Implement offset handling for X Form */
59+
if ((op_loc->mem_ref) && (PPC_OP(raw_insn) != 31))
60+
op_loc->offset = get_offset_opcode(raw_insn);
61+
}

tools/perf/util/dwarf-regs.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,17 @@
3232
const char *get_dwarf_regstr(unsigned int n, unsigned int machine, unsigned int flags)
3333
{
3434
#if EM_HOST == EM_X86_64 || EM_HOST == EM_386 || EM_HOST == EM_AARCH64 || EM_HOST == EM_ARM \
35-
|| EM_HOST == EM_CSKY || EM_HOST == EM_LOONGARCH || EM_HOST == EM_MIPS
35+
|| EM_HOST == EM_CSKY || EM_HOST == EM_LOONGARCH || EM_HOST == EM_MIPS || EM_HOST == EM_PPC \
36+
|| EM_HOST == EM_PPC64
3637
if (machine == EM_NONE) {
3738
/* Generic arch - use host arch */
3839
machine = EM_HOST;
3940
}
4041
#endif
4142
switch (machine) {
4243
#if EM_HOST != EM_X86_64 && EM_HOST != EM_386 && EM_HOST != EM_AARCH64 && EM_HOST != EM_ARM \
43-
&& EM_HOST != EM_CSKY && EM_HOST != EM_LOONGARCH && EM_HOST != EM_MIPS
44+
&& EM_HOST != EM_CSKY && EM_HOST != EM_LOONGARCH && EM_HOST != EM_MIPS && EM_HOST != EM_PPC \
45+
&& EM_HOST != EM_PPC64
4446
case EM_NONE: /* Generic arch - use host arch */
4547
return get_arch_regstr(n);
4648
#endif

tools/perf/util/include/dwarf-regs.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@
9090

9191
#ifdef HAVE_LIBDW_SUPPORT
9292
#if !defined(__x86_64__) && !defined(__i386__) && !defined(__aarch64__) && !defined(__arm__) \
93-
&& !defined(__loongarch__) && !defined(__mips__)
93+
&& !defined(__loongarch__) && !defined(__mips__) && !defined(__powerpc__) \
94+
&& !defined(__powerpc64__)
9495
const char *get_arch_regstr(unsigned int n);
9596
#endif
9697

@@ -117,6 +118,8 @@ int get_arch_regnum(const char *name);
117118
*/
118119
int get_dwarf_regnum(const char *name, unsigned int machine, unsigned int flags);
119120

121+
void get_powerpc_regs(u32 raw_insn, int is_source, struct annotated_op_loc *op_loc);
122+
120123
#else /* HAVE_LIBDW_SUPPORT */
121124

122125
static inline int get_dwarf_regnum(const char *name __maybe_unused,
@@ -125,16 +128,12 @@ static inline int get_dwarf_regnum(const char *name __maybe_unused,
125128
{
126129
return -1;
127130
}
128-
#endif
129131

130-
#if !defined(__powerpc__) || !defined(HAVE_LIBDW_SUPPORT)
131132
static inline void get_powerpc_regs(u32 raw_insn __maybe_unused, int is_source __maybe_unused,
132133
struct annotated_op_loc *op_loc __maybe_unused)
133134
{
134135
return;
135136
}
136-
#else
137-
void get_powerpc_regs(u32 raw_insn, int is_source, struct annotated_op_loc *op_loc);
138137
#endif
139138

140139
#endif

0 commit comments

Comments
 (0)