Skip to content

Commit f005302

Browse files
captain5050acmel
authored andcommitted
perf dwarf-regs: Add powerpc perf to DWARF register number mapping functions
These functions allow the generic initial register state code in unwind-libdw to be used. Note, the link register was being coped to DWARF register 65 that the SysV ABI spec claims is FPSCR. It is corrected here to 108, but this is unlikely to matter as FPSCR has little to no impact on unwinding. Signed-off-by: Ian Rogers <[email protected]> Cc: Aditya Bodkhe <[email protected]> Cc: Adrian Hunter <[email protected]> Cc: Albert Ou <[email protected]> Cc: Alexandre Ghiti <[email protected]> Cc: Andi Kleen <[email protected]> Cc: Athira Rajeev <[email protected]> Cc: Chun-Tse Shao <[email protected]> Cc: Dmitriy Vyukov <[email protected]> Cc: Dr. David Alan Gilbert <[email protected]> Cc: Guo Ren <[email protected]> Cc: Haibo Xu <[email protected]> Cc: Howard Chu <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: James Clark <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: John Garry <[email protected]> Cc: Krzysztof Łopatowski <[email protected]> Cc: Leo Yan <[email protected]> Cc: Mark Wielaard <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Palmer Dabbelt <[email protected]> Cc: Paul Walmsley <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Sergei Trofimovich <[email protected]> Cc: Shimin Guo <[email protected]> Cc: Stephen Brennan <[email protected]> Cc: Thomas Falcon <[email protected]> Cc: Will Deacon <[email protected]> Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 1f10d82 commit f005302

7 files changed

Lines changed: 82 additions & 83 deletions

File tree

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

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
*
55
* Copyright (C) 2010 Ian Munsie, IBM Corporation.
66
*/
7-
7+
#include <errno.h>
88
#include <dwarf-regs.h>
9+
#include "../../../arch/powerpc/include/uapi/asm/perf_regs.h"
910

1011
#define PPC_OP(op) (((op) >> 26) & 0x3F)
1112
#define PPC_RA(a) (((a) >> 16) & 0x1f)
@@ -59,3 +60,77 @@ void get_powerpc_regs(u32 raw_insn, int is_source,
5960
if ((op_loc->mem_ref) && (PPC_OP(raw_insn) != 31))
6061
op_loc->offset = get_offset_opcode(raw_insn);
6162
}
63+
64+
int __get_dwarf_regnum_for_perf_regnum_powerpc(int perf_regnum)
65+
{
66+
static const int dwarf_powerpc_regnums[] = {
67+
[PERF_REG_POWERPC_R0] = 0,
68+
[PERF_REG_POWERPC_R1] = 1,
69+
[PERF_REG_POWERPC_R2] = 2,
70+
[PERF_REG_POWERPC_R3] = 3,
71+
[PERF_REG_POWERPC_R4] = 4,
72+
[PERF_REG_POWERPC_R5] = 5,
73+
[PERF_REG_POWERPC_R6] = 6,
74+
[PERF_REG_POWERPC_R7] = 7,
75+
[PERF_REG_POWERPC_R8] = 8,
76+
[PERF_REG_POWERPC_R9] = 9,
77+
[PERF_REG_POWERPC_R10] = 10,
78+
[PERF_REG_POWERPC_R11] = 11,
79+
[PERF_REG_POWERPC_R12] = 12,
80+
[PERF_REG_POWERPC_R13] = 13,
81+
[PERF_REG_POWERPC_R14] = 14,
82+
[PERF_REG_POWERPC_R15] = 15,
83+
[PERF_REG_POWERPC_R16] = 16,
84+
[PERF_REG_POWERPC_R17] = 17,
85+
[PERF_REG_POWERPC_R18] = 18,
86+
[PERF_REG_POWERPC_R19] = 19,
87+
[PERF_REG_POWERPC_R20] = 20,
88+
[PERF_REG_POWERPC_R21] = 21,
89+
[PERF_REG_POWERPC_R22] = 22,
90+
[PERF_REG_POWERPC_R23] = 23,
91+
[PERF_REG_POWERPC_R24] = 24,
92+
[PERF_REG_POWERPC_R25] = 25,
93+
[PERF_REG_POWERPC_R26] = 26,
94+
[PERF_REG_POWERPC_R27] = 27,
95+
[PERF_REG_POWERPC_R28] = 28,
96+
[PERF_REG_POWERPC_R29] = 29,
97+
[PERF_REG_POWERPC_R30] = 30,
98+
[PERF_REG_POWERPC_R31] = 31,
99+
/* TODO: PERF_REG_POWERPC_NIP */
100+
[PERF_REG_POWERPC_MSR] = 66,
101+
/* TODO: PERF_REG_POWERPC_ORIG_R3 */
102+
[PERF_REG_POWERPC_CTR] = 109,
103+
[PERF_REG_POWERPC_LINK] = 108, /* Note, previously in perf encoded as 65? */
104+
[PERF_REG_POWERPC_XER] = 101,
105+
/* TODO: PERF_REG_POWERPC_CCR */
106+
/* TODO: PERF_REG_POWERPC_SOFTE */
107+
/* TODO: PERF_REG_POWERPC_TRAP */
108+
/* TODO: PERF_REG_POWERPC_DAR */
109+
/* TODO: PERF_REG_POWERPC_DSISR */
110+
/* TODO: PERF_REG_POWERPC_SIER */
111+
/* TODO: PERF_REG_POWERPC_MMCRA */
112+
/* TODO: PERF_REG_POWERPC_MMCR0 */
113+
/* TODO: PERF_REG_POWERPC_MMCR1 */
114+
/* TODO: PERF_REG_POWERPC_MMCR2 */
115+
/* TODO: PERF_REG_POWERPC_MMCR3 */
116+
/* TODO: PERF_REG_POWERPC_SIER2 */
117+
/* TODO: PERF_REG_POWERPC_SIER3 */
118+
/* TODO: PERF_REG_POWERPC_PMC1 */
119+
/* TODO: PERF_REG_POWERPC_PMC2 */
120+
/* TODO: PERF_REG_POWERPC_PMC3 */
121+
/* TODO: PERF_REG_POWERPC_PMC4 */
122+
/* TODO: PERF_REG_POWERPC_PMC5 */
123+
/* TODO: PERF_REG_POWERPC_PMC6 */
124+
/* TODO: PERF_REG_POWERPC_SDAR */
125+
/* TODO: PERF_REG_POWERPC_SIAR */
126+
};
127+
128+
if (perf_regnum == 0)
129+
return 0;
130+
131+
if (perf_regnum < 0 || perf_regnum > (int)ARRAY_SIZE(dwarf_powerpc_regnums) ||
132+
dwarf_powerpc_regnums[perf_regnum] == 0)
133+
return -ENOENT;
134+
135+
return dwarf_powerpc_regnums[perf_regnum];
136+
}

tools/perf/util/dwarf-regs.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,10 @@ int get_dwarf_regnum_for_perf_regnum(int perf_regnum, unsigned int machine,
205205
case EM_CSKY:
206206
reg = __get_dwarf_regnum_for_perf_regnum_csky(perf_regnum, flags);
207207
break;
208+
case EM_PPC:
209+
case EM_PPC64:
210+
reg = __get_dwarf_regnum_for_perf_regnum_powerpc(perf_regnum);
211+
break;
208212
case EM_LOONGARCH:
209213
reg = __get_dwarf_regnum_for_perf_regnum_loongarch(perf_regnum);
210214
break;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ int __get_dwarf_regnum_for_perf_regnum_arm64(int perf_regnum);
110110

111111
int __get_dwarf_regnum_for_perf_regnum_csky(int perf_regnum, unsigned int flags);
112112
int __get_dwarf_regnum_for_perf_regnum_loongarch(int perf_regnum);
113+
int __get_dwarf_regnum_for_perf_regnum_powerpc(int perf_regnum);
113114

114115
/*
115116
* get_dwarf_regnum - Returns DWARF regnum from register name
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
perf-util-y += unwind-libdw-powerpc.o
21
perf-util-y += unwind-libdw-riscv.o
32
perf-util-y += unwind-libdw-s390.o

tools/perf/util/unwind-libdw-arch/unwind-libdw-powerpc.c

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

tools/perf/util/unwind-libdw.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -292,15 +292,12 @@ static const Dwfl_Thread_Callbacks callbacks_generic = {
292292
.set_initial_registers = libdw_set_initial_registers_generic,
293293
};
294294

295-
DEFINE_DWFL_THREAD_CALLBACKS(powerpc);
296295
DEFINE_DWFL_THREAD_CALLBACKS(riscv);
297296
DEFINE_DWFL_THREAD_CALLBACKS(s390);
298297

299298
static const Dwfl_Thread_Callbacks *get_thread_callbacks(const char *arch)
300299
{
301-
if (!strcmp(arch, "powerpc"))
302-
return &callbacks_powerpc;
303-
else if (!strcmp(arch, "riscv"))
300+
if (!strcmp(arch, "riscv"))
304301
return &callbacks_riscv;
305302
else if (!strcmp(arch, "s390"))
306303
return &callbacks_s390;

tools/perf/util/unwind-libdw.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ struct perf_sample;
1010
struct thread;
1111

1212
bool libdw_set_initial_registers_mips(Dwfl_Thread *thread, void *arg);
13-
bool libdw_set_initial_registers_powerpc(Dwfl_Thread *thread, void *arg);
1413
bool libdw_set_initial_registers_riscv(Dwfl_Thread *thread, void *arg);
1514
bool libdw_set_initial_registers_s390(Dwfl_Thread *thread, void *arg);
1615

0 commit comments

Comments
 (0)