blob: 98ac87052a74c5cbdf2c954221d8ce4d3f9e9752 [file] [log] [blame]
Ian Munsiefead7962010-04-20 16:58:33 +10001/*
2 * Mapping of DWARF debug register numbers into register names.
3 *
4 * Copyright (C) 2010 Ian Munsie, IBM Corporation.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
10 */
11
Cody P Schafer861e10b2013-03-14 15:27:51 -070012#include <stddef.h>
Naveen N. Rao4679bcc2016-05-05 20:53:19 +053013#include <errno.h>
14#include <string.h>
Ian Munsiefead7962010-04-20 16:58:33 +100015#include <dwarf-regs.h>
Naveen N. Rao4679bcc2016-05-05 20:53:19 +053016#include <linux/ptrace.h>
17#include <linux/kernel.h>
Arnaldo Carvalho de Meloaa8cc2f2017-04-17 15:36:40 -030018#include <linux/stringify.h>
Naveen N. Rao4679bcc2016-05-05 20:53:19 +053019#include "util.h"
Ian Munsiefead7962010-04-20 16:58:33 +100020
21struct pt_regs_dwarfnum {
22 const char *name;
23 unsigned int dwarfnum;
Naveen N. Rao4679bcc2016-05-05 20:53:19 +053024 unsigned int ptregs_offset;
Ian Munsiefead7962010-04-20 16:58:33 +100025};
26
Naveen N. Rao4679bcc2016-05-05 20:53:19 +053027#define REG_DWARFNUM_NAME(r, num) \
Arnaldo Carvalho de Meloaa8cc2f2017-04-17 15:36:40 -030028 {.name = __stringify(%)__stringify(r), .dwarfnum = num, \
Naveen N. Rao4679bcc2016-05-05 20:53:19 +053029 .ptregs_offset = offsetof(struct pt_regs, r)}
30#define GPR_DWARFNUM_NAME(num) \
Arnaldo Carvalho de Meloaa8cc2f2017-04-17 15:36:40 -030031 {.name = __stringify(%gpr##num), .dwarfnum = num, \
Naveen N. Rao4679bcc2016-05-05 20:53:19 +053032 .ptregs_offset = offsetof(struct pt_regs, gpr[num])}
33#define REG_DWARFNUM_END {.name = NULL, .dwarfnum = 0, .ptregs_offset = 0}
Ian Munsiefead7962010-04-20 16:58:33 +100034
35/*
36 * Reference:
37 * http://refspecs.linuxfoundation.org/ELF/ppc64/PPC-elf64abi-1.9.html
38 */
39static const struct pt_regs_dwarfnum regdwarfnum_table[] = {
40 GPR_DWARFNUM_NAME(0),
41 GPR_DWARFNUM_NAME(1),
42 GPR_DWARFNUM_NAME(2),
43 GPR_DWARFNUM_NAME(3),
44 GPR_DWARFNUM_NAME(4),
45 GPR_DWARFNUM_NAME(5),
46 GPR_DWARFNUM_NAME(6),
47 GPR_DWARFNUM_NAME(7),
48 GPR_DWARFNUM_NAME(8),
49 GPR_DWARFNUM_NAME(9),
50 GPR_DWARFNUM_NAME(10),
51 GPR_DWARFNUM_NAME(11),
52 GPR_DWARFNUM_NAME(12),
53 GPR_DWARFNUM_NAME(13),
54 GPR_DWARFNUM_NAME(14),
55 GPR_DWARFNUM_NAME(15),
56 GPR_DWARFNUM_NAME(16),
57 GPR_DWARFNUM_NAME(17),
58 GPR_DWARFNUM_NAME(18),
59 GPR_DWARFNUM_NAME(19),
60 GPR_DWARFNUM_NAME(20),
61 GPR_DWARFNUM_NAME(21),
62 GPR_DWARFNUM_NAME(22),
63 GPR_DWARFNUM_NAME(23),
64 GPR_DWARFNUM_NAME(24),
65 GPR_DWARFNUM_NAME(25),
66 GPR_DWARFNUM_NAME(26),
67 GPR_DWARFNUM_NAME(27),
68 GPR_DWARFNUM_NAME(28),
69 GPR_DWARFNUM_NAME(29),
70 GPR_DWARFNUM_NAME(30),
71 GPR_DWARFNUM_NAME(31),
Naveen N. Rao4679bcc2016-05-05 20:53:19 +053072 REG_DWARFNUM_NAME(msr, 66),
73 REG_DWARFNUM_NAME(ctr, 109),
74 REG_DWARFNUM_NAME(link, 108),
75 REG_DWARFNUM_NAME(xer, 101),
76 REG_DWARFNUM_NAME(dar, 119),
77 REG_DWARFNUM_NAME(dsisr, 118),
Ian Munsiefead7962010-04-20 16:58:33 +100078 REG_DWARFNUM_END,
79};
80
81/**
82 * get_arch_regstr() - lookup register name from it's DWARF register number
83 * @n: the DWARF register number
84 *
85 * get_arch_regstr() returns the name of the register in struct
86 * regdwarfnum_table from it's DWARF register number. If the register is not
87 * found in the table, this returns NULL;
88 */
89const char *get_arch_regstr(unsigned int n)
90{
91 const struct pt_regs_dwarfnum *roff;
92 for (roff = regdwarfnum_table; roff->name != NULL; roff++)
93 if (roff->dwarfnum == n)
94 return roff->name;
95 return NULL;
96}
Naveen N. Rao4679bcc2016-05-05 20:53:19 +053097
98int regs_query_register_offset(const char *name)
99{
100 const struct pt_regs_dwarfnum *roff;
101 for (roff = regdwarfnum_table; roff->name != NULL; roff++)
102 if (!strcmp(roff->name, name))
103 return roff->ptregs_offset;
104 return -EINVAL;
105}