]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
perf dwarf-regs: Add csky perf to dwarf register number mapping functions
authorIan Rogers <irogers@google.com>
Sat, 17 Jan 2026 05:28:41 +0000 (21:28 -0800)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Tue, 20 Jan 2026 18:43:56 +0000 (15:43 -0300)
These functions allow the generic initial register state code in
unwind-libdw to be used.

Signed-off-by: Ian Rogers <irogers@google.com>
Cc: Aditya Bodkhe <aditya.b1@linux.ibm.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Albert Ou <aou@eecs.berkeley.edu>
Cc: Alexandre Ghiti <alex@ghiti.fr>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Athira Rajeev <atrajeev@linux.ibm.com>
Cc: Chun-Tse Shao <ctshao@google.com>
Cc: Dmitriy Vyukov <dvyukov@google.com>
Cc: Dr. David Alan Gilbert <linux@treblig.org>
Cc: Guo Ren <guoren@kernel.org>
Cc: Haibo Xu <haibo1.xu@intel.com>
Cc: Howard Chu <howardchu95@gmail.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: James Clark <james.clark@linaro.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: John Garry <john.g.garry@oracle.com>
Cc: Krzysztof Ɓopatowski <krzysztof.m.lopatowski@gmail.com>
Cc: Leo Yan <leo.yan@linux.dev>
Cc: Mark Wielaard <mark@klomp.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Palmer Dabbelt <palmer@dabbelt.com>
Cc: Paul Walmsley <pjw@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Sergei Trofimovich <slyich@gmail.com>
Cc: Shimin Guo <shimin.guo@skydio.com>
Cc: Stephen Brennan <stephen.s.brennan@oracle.com>
Cc: Thomas Falcon <thomas.falcon@intel.com>
Cc: Will Deacon <will@kernel.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/util/dwarf-regs-arch/dwarf-regs-csky.c
tools/perf/util/dwarf-regs.c
tools/perf/util/include/dwarf-regs.h
tools/perf/util/unwind-libdw-arch/Build
tools/perf/util/unwind-libdw-arch/unwind-libdw-csky.c [deleted file]
tools/perf/util/unwind-libdw.c
tools/perf/util/unwind-libdw.h

index 86394ed46397dffe8a930907ba938778d45012e7..cb44b774f8d90702e0792f0dcddc0cd19e2e7d40 100644 (file)
@@ -5,6 +5,10 @@
 #include <errno.h>
 #include <stddef.h>
 #include <dwarf-regs.h>
+// Ensure the V2 perf reg definitions are included.
+#undef __CSKYABIV2__
+#define __CSKYABIV2__ 1
+#include "../../../arch/csky/include/uapi/asm/perf_regs.h"
 
 #define CSKY_ABIV2_MAX_REGS 73
 static const char * const csky_dwarf_regs_table_abiv2[CSKY_ABIV2_MAX_REGS] = {
@@ -66,3 +70,57 @@ int __get_csky_regnum(const char *name, unsigned int flags)
 
        return __get_dwarf_regnum(csky_dwarf_regs_table_abiv1, CSKY_ABIV1_MAX_REGS, name);
 }
+
+int __get_dwarf_regnum_for_perf_regnum_csky(int perf_regnum, unsigned int flags)
+{
+       static const int dwarf_csky_regnums[][2] = {
+               [PERF_REG_CSKY_TLS] = {-ENOENT, 31},
+               [PERF_REG_CSKY_LR] = {15, 15},
+               [PERF_REG_CSKY_PC] = {-ENOENT, 32},
+               /* TODO: PERF_REG_CSKY_SR */
+               [PERF_REG_CSKY_SP] = {0, 14},
+               /* TODO: PERF_REG_CSKY_ORIG_A0 */
+               [PERF_REG_CSKY_A0] = {2, 0},
+               [PERF_REG_CSKY_A1] = {3, 1},
+               [PERF_REG_CSKY_A2] = {4, 2},
+               [PERF_REG_CSKY_A3] = {5, 3},
+               [PERF_REG_CSKY_REGS0] = {6, 4},
+               [PERF_REG_CSKY_REGS1] = {7, 5},
+               [PERF_REG_CSKY_REGS2] = {8, 6},
+               [PERF_REG_CSKY_REGS3] = {9, 7},
+               [PERF_REG_CSKY_REGS4] = {10, 8},
+               [PERF_REG_CSKY_REGS5] = {11, 9},
+               [PERF_REG_CSKY_REGS6] = {12, 10},
+               [PERF_REG_CSKY_REGS7] = {13, 11},
+               [PERF_REG_CSKY_REGS8] = {14, 12},
+               [PERF_REG_CSKY_REGS9] = {1, 13},
+               [PERF_REG_CSKY_EXREGS0] = {-ENOENT, 16},
+               [PERF_REG_CSKY_EXREGS1] = {-ENOENT, 17},
+               [PERF_REG_CSKY_EXREGS2] = {-ENOENT, 18},
+               [PERF_REG_CSKY_EXREGS3] = {-ENOENT, 19},
+               [PERF_REG_CSKY_EXREGS4] = {-ENOENT, 20},
+               [PERF_REG_CSKY_EXREGS5] = {-ENOENT, 21},
+               [PERF_REG_CSKY_EXREGS6] = {-ENOENT, 22},
+               [PERF_REG_CSKY_EXREGS7] = {-ENOENT, 23},
+               [PERF_REG_CSKY_EXREGS8] = {-ENOENT, 24},
+               [PERF_REG_CSKY_EXREGS9] = {-ENOENT, 25},
+               [PERF_REG_CSKY_EXREGS10] = {-ENOENT, 26},
+               [PERF_REG_CSKY_EXREGS11] = {-ENOENT, 27},
+               [PERF_REG_CSKY_EXREGS12] = {-ENOENT, 28},
+               [PERF_REG_CSKY_EXREGS13] = {-ENOENT, 29},
+               [PERF_REG_CSKY_EXREGS14] = {-ENOENT, 30},
+               /* TODO: PERF_REG_CSKY_HI */
+               /* TODO: PERF_REG_CSKY_LO */
+               /* TODO: PERF_REG_CSKY_DCSR */
+       };
+       int idx = 0;
+
+       if (flags & EF_CSKY_ABIV2)
+               idx++;
+
+       if (perf_regnum <  0 || perf_regnum > (int)ARRAY_SIZE(dwarf_csky_regnums) ||
+           dwarf_csky_regnums[perf_regnum][idx] == 0)
+               return -ENOENT;
+
+       return dwarf_csky_regnums[perf_regnum][idx];
+}
index c472ec5e4d1aa9f18a141a25ad2f475658f64b0f..7fa0930fd29873c4b48342ccde8b4bd6a8eed8e2 100644 (file)
@@ -202,6 +202,9 @@ int get_dwarf_regnum_for_perf_regnum(int perf_regnum, unsigned int machine,
        case EM_AARCH64:
                reg = __get_dwarf_regnum_for_perf_regnum_arm64(perf_regnum);
                break;
+       case EM_CSKY:
+               reg = __get_dwarf_regnum_for_perf_regnum_csky(perf_regnum, flags);
+               break;
        default:
                pr_err("ELF MACHINE %x is not supported.\n", machine);
                return -ENOENT;
index a52df8d1b138438b063d7c6b2a2691d05ab07a15..7780bc07e70e495daf6d2d7913395ea43727af97 100644 (file)
@@ -108,6 +108,8 @@ int __get_dwarf_regnum_for_perf_regnum_x86_64(int perf_regnum);
 int __get_dwarf_regnum_for_perf_regnum_arm(int perf_regnum);
 int __get_dwarf_regnum_for_perf_regnum_arm64(int perf_regnum);
 
+int __get_dwarf_regnum_for_perf_regnum_csky(int perf_regnum, unsigned int flags);
+
 /*
  * get_dwarf_regnum - Returns DWARF regnum from register name
  * name: architecture register name
index 79c3bbdc2dee9f3e4a2a3d4968dfd612043c2b82..5fa1754fca8d20094b4b4b10b9cc22b469ce04f1 100644 (file)
@@ -1,4 +1,3 @@
-perf-util-y += unwind-libdw-csky.o
 perf-util-y += unwind-libdw-loongarch.o
 perf-util-y += unwind-libdw-powerpc.o
 perf-util-y += unwind-libdw-riscv.o
diff --git a/tools/perf/util/unwind-libdw-arch/unwind-libdw-csky.c b/tools/perf/util/unwind-libdw-arch/unwind-libdw-csky.c
deleted file mode 100644 (file)
index 2556d03..0000000
+++ /dev/null
@@ -1,78 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-// Copyright (C) 2019 Hangzhou C-SKY Microsystems co.,ltd.
-
-#include <elfutils/libdwfl.h>
-#include "../arch/csky/include/uapi/asm/perf_regs.h"
-#include "util/unwind-libdw.h"
-#include "util/perf_regs.h"
-#include "util/sample.h"
-
-bool libdw_set_initial_registers_csky(Dwfl_Thread *thread, void *arg)
-{
-       struct unwind_info *ui = arg;
-       struct regs_dump *user_regs = perf_sample__user_regs(ui->sample);
-       Dwarf_Word dwarf_regs[PERF_REG_CSKY_MAX];
-
-#define REG(r) ({                                              \
-       Dwarf_Word val = 0;                                     \
-       perf_reg_value(&val, user_regs, PERF_REG_CSKY_##r);     \
-       val;                                                    \
-})
-
-#if defined(__CSKYABIV2__)
-       dwarf_regs[0]  = REG(A0);
-       dwarf_regs[1]  = REG(A1);
-       dwarf_regs[2]  = REG(A2);
-       dwarf_regs[3]  = REG(A3);
-       dwarf_regs[4]  = REG(REGS0);
-       dwarf_regs[5]  = REG(REGS1);
-       dwarf_regs[6]  = REG(REGS2);
-       dwarf_regs[7]  = REG(REGS3);
-       dwarf_regs[8]  = REG(REGS4);
-       dwarf_regs[9]  = REG(REGS5);
-       dwarf_regs[10] = REG(REGS6);
-       dwarf_regs[11] = REG(REGS7);
-       dwarf_regs[12] = REG(REGS8);
-       dwarf_regs[13] = REG(REGS9);
-       dwarf_regs[14] = REG(SP);
-       dwarf_regs[15] = REG(LR);
-       dwarf_regs[16] = REG(EXREGS0);
-       dwarf_regs[17] = REG(EXREGS1);
-       dwarf_regs[18] = REG(EXREGS2);
-       dwarf_regs[19] = REG(EXREGS3);
-       dwarf_regs[20] = REG(EXREGS4);
-       dwarf_regs[21] = REG(EXREGS5);
-       dwarf_regs[22] = REG(EXREGS6);
-       dwarf_regs[23] = REG(EXREGS7);
-       dwarf_regs[24] = REG(EXREGS8);
-       dwarf_regs[25] = REG(EXREGS9);
-       dwarf_regs[26] = REG(EXREGS10);
-       dwarf_regs[27] = REG(EXREGS11);
-       dwarf_regs[28] = REG(EXREGS12);
-       dwarf_regs[29] = REG(EXREGS13);
-       dwarf_regs[30] = REG(EXREGS14);
-       dwarf_regs[31] = REG(TLS);
-       dwarf_regs[32] = REG(PC);
-#else
-       dwarf_regs[0]  = REG(SP);
-       dwarf_regs[1]  = REG(REGS9);
-       dwarf_regs[2]  = REG(A0);
-       dwarf_regs[3]  = REG(A1);
-       dwarf_regs[4]  = REG(A2);
-       dwarf_regs[5]  = REG(A3);
-       dwarf_regs[6]  = REG(REGS0);
-       dwarf_regs[7]  = REG(REGS1);
-       dwarf_regs[8]  = REG(REGS2);
-       dwarf_regs[9]  = REG(REGS3);
-       dwarf_regs[10] = REG(REGS4);
-       dwarf_regs[11] = REG(REGS5);
-       dwarf_regs[12] = REG(REGS6);
-       dwarf_regs[13] = REG(REGS7);
-       dwarf_regs[14] = REG(REGS8);
-       dwarf_regs[15] = REG(LR);
-#endif
-       dwfl_thread_state_register_pc(thread, REG(PC));
-
-       return dwfl_thread_state_registers(thread, 0, PERF_REG_CSKY_MAX,
-                                          dwarf_regs);
-}
index 8f291f9f9469b2c62a4bb87e6d023371fdba381d..a193163da707851d59cd1917b5c76a499a5edae4 100644 (file)
@@ -292,7 +292,6 @@ static const Dwfl_Thread_Callbacks callbacks_generic = {
        .set_initial_registers = libdw_set_initial_registers_generic,
 };
 
-DEFINE_DWFL_THREAD_CALLBACKS(csky);
 DEFINE_DWFL_THREAD_CALLBACKS(loongarch);
 DEFINE_DWFL_THREAD_CALLBACKS(powerpc);
 DEFINE_DWFL_THREAD_CALLBACKS(riscv);
@@ -300,9 +299,7 @@ DEFINE_DWFL_THREAD_CALLBACKS(s390);
 
 static const Dwfl_Thread_Callbacks *get_thread_callbacks(const char *arch)
 {
-       if (!strcmp(arch, "csky"))
-               return &callbacks_csky;
-       else if (!strcmp(arch, "loongarch"))
+       if (!strcmp(arch, "loongarch"))
                return &callbacks_loongarch;
        else if (!strcmp(arch, "powerpc"))
                return &callbacks_powerpc;
index fe3ae2a768ada9890287561a5af011f275c7fa29..ee56f1e827e51d315d79e9487e9042febe1f46c2 100644 (file)
@@ -9,7 +9,6 @@ struct machine;
 struct perf_sample;
 struct thread;
 
-bool libdw_set_initial_registers_csky(Dwfl_Thread *thread, void *arg);
 bool libdw_set_initial_registers_loongarch(Dwfl_Thread *thread, void *arg);
 bool libdw_set_initial_registers_mips(Dwfl_Thread *thread, void *arg);
 bool libdw_set_initial_registers_powerpc(Dwfl_Thread *thread, void *arg);