1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Mapping of DWARF debug register numbers into register names.
5 * Copyright (C) 2010 Ian Munsie, IBM Corporation.
11 #include <dwarf-regs.h>
12 #include <linux/ptrace.h>
13 #include <linux/kernel.h>
14 #include <linux/stringify.h>
17 struct pt_regs_dwarfnum
{
19 unsigned int dwarfnum
;
20 unsigned int ptregs_offset
;
23 #define REG_DWARFNUM_NAME(r, num) \
24 {.name = __stringify(%)__stringify(r), .dwarfnum = num, \
25 .ptregs_offset = offsetof(struct pt_regs, r)}
26 #define GPR_DWARFNUM_NAME(num) \
27 {.name = __stringify(%gpr##num), .dwarfnum = num, \
28 .ptregs_offset = offsetof(struct pt_regs, gpr[num])}
29 #define REG_DWARFNUM_END {.name = NULL, .dwarfnum = 0, .ptregs_offset = 0}
33 * http://refspecs.linuxfoundation.org/ELF/ppc64/PPC-elf64abi-1.9.html
35 static const struct pt_regs_dwarfnum regdwarfnum_table
[] = {
46 GPR_DWARFNUM_NAME(10),
47 GPR_DWARFNUM_NAME(11),
48 GPR_DWARFNUM_NAME(12),
49 GPR_DWARFNUM_NAME(13),
50 GPR_DWARFNUM_NAME(14),
51 GPR_DWARFNUM_NAME(15),
52 GPR_DWARFNUM_NAME(16),
53 GPR_DWARFNUM_NAME(17),
54 GPR_DWARFNUM_NAME(18),
55 GPR_DWARFNUM_NAME(19),
56 GPR_DWARFNUM_NAME(20),
57 GPR_DWARFNUM_NAME(21),
58 GPR_DWARFNUM_NAME(22),
59 GPR_DWARFNUM_NAME(23),
60 GPR_DWARFNUM_NAME(24),
61 GPR_DWARFNUM_NAME(25),
62 GPR_DWARFNUM_NAME(26),
63 GPR_DWARFNUM_NAME(27),
64 GPR_DWARFNUM_NAME(28),
65 GPR_DWARFNUM_NAME(29),
66 GPR_DWARFNUM_NAME(30),
67 GPR_DWARFNUM_NAME(31),
68 REG_DWARFNUM_NAME(msr
, 66),
69 REG_DWARFNUM_NAME(ctr
, 109),
70 REG_DWARFNUM_NAME(link
, 108),
71 REG_DWARFNUM_NAME(xer
, 101),
72 REG_DWARFNUM_NAME(dar
, 119),
73 REG_DWARFNUM_NAME(dsisr
, 118),
78 * get_arch_regstr() - lookup register name from it's DWARF register number
79 * @n: the DWARF register number
81 * get_arch_regstr() returns the name of the register in struct
82 * regdwarfnum_table from it's DWARF register number. If the register is not
83 * found in the table, this returns NULL;
85 const char *get_arch_regstr(unsigned int n
)
87 const struct pt_regs_dwarfnum
*roff
;
88 for (roff
= regdwarfnum_table
; roff
->name
!= NULL
; roff
++)
89 if (roff
->dwarfnum
== n
)
94 int regs_query_register_offset(const char *name
)
96 const struct pt_regs_dwarfnum
*roff
;
97 for (roff
= regdwarfnum_table
; roff
->name
!= NULL
; roff
++)
98 if (!strcmp(roff
->name
, name
))
99 return roff
->ptregs_offset
;