1 // SPDX-License-Identifier: GPL-2.0-only
3 * Mapping of DWARF debug register numbers into register names.
5 * Copyright (C) 2010 Will Deacon, ARM Ltd.
11 #include <dwarf-regs.h>
12 #include <linux/ptrace.h> /* for struct user_pt_regs */
13 #include <linux/stringify.h>
16 struct pt_regs_dwarfnum
{
18 unsigned int dwarfnum
;
21 #define REG_DWARFNUM_NAME(r, num) {.name = r, .dwarfnum = num}
22 #define GPR_DWARFNUM_NAME(num) \
23 {.name = __stringify(%x##num), .dwarfnum = num}
24 #define REG_DWARFNUM_END {.name = NULL, .dwarfnum = 0}
25 #define DWARFNUM2OFFSET(index) \
26 (index * sizeof((struct user_pt_regs *)0)->regs[0])
30 * http://infocenter.arm.com/help/topic/com.arm.doc.ihi0057b/IHI0057B_aadwarf64.pdf
32 static const struct pt_regs_dwarfnum regdwarfnum_table
[] = {
43 GPR_DWARFNUM_NAME(10),
44 GPR_DWARFNUM_NAME(11),
45 GPR_DWARFNUM_NAME(12),
46 GPR_DWARFNUM_NAME(13),
47 GPR_DWARFNUM_NAME(14),
48 GPR_DWARFNUM_NAME(15),
49 GPR_DWARFNUM_NAME(16),
50 GPR_DWARFNUM_NAME(17),
51 GPR_DWARFNUM_NAME(18),
52 GPR_DWARFNUM_NAME(19),
53 GPR_DWARFNUM_NAME(20),
54 GPR_DWARFNUM_NAME(21),
55 GPR_DWARFNUM_NAME(22),
56 GPR_DWARFNUM_NAME(23),
57 GPR_DWARFNUM_NAME(24),
58 GPR_DWARFNUM_NAME(25),
59 GPR_DWARFNUM_NAME(26),
60 GPR_DWARFNUM_NAME(27),
61 GPR_DWARFNUM_NAME(28),
62 GPR_DWARFNUM_NAME(29),
63 REG_DWARFNUM_NAME("%lr", 30),
64 REG_DWARFNUM_NAME("%sp", 31),
69 * get_arch_regstr() - lookup register name from it's DWARF register number
70 * @n: the DWARF register number
72 * get_arch_regstr() returns the name of the register in struct
73 * regdwarfnum_table from it's DWARF register number. If the register is not
74 * found in the table, this returns NULL;
76 const char *get_arch_regstr(unsigned int n
)
78 const struct pt_regs_dwarfnum
*roff
;
79 for (roff
= regdwarfnum_table
; roff
->name
!= NULL
; roff
++)
80 if (roff
->dwarfnum
== n
)
85 int regs_query_register_offset(const char *name
)
87 const struct pt_regs_dwarfnum
*roff
;
89 for (roff
= regdwarfnum_table
; roff
->name
!= NULL
; roff
++)
90 if (!strcmp(roff
->name
, name
))
91 return DWARFNUM2OFFSET(roff
->dwarfnum
);