blob: e8d5c551c69c08d4a17e89a370d0e4caedacb101 [file] [log] [blame]
Will Deaconeb668c62010-06-25 12:24:54 +01001/*
2 * Mapping of DWARF debug register numbers into register names.
3 *
4 * Copyright (C) 2010 Will Deacon, ARM Ltd.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
10
Florian Fainelli0ac8e582011-08-09 12:24:17 +010011#include <stdlib.h>
12#ifndef __UCLIBC__
Will Deaconeb668c62010-06-25 12:24:54 +010013#include <libio.h>
Florian Fainelli0ac8e582011-08-09 12:24:17 +010014#endif
Will Deaconeb668c62010-06-25 12:24:54 +010015#include <dwarf-regs.h>
16
17struct pt_regs_dwarfnum {
18 const char *name;
19 unsigned int dwarfnum;
20};
21
22#define STR(s) #s
23#define REG_DWARFNUM_NAME(r, num) {.name = r, .dwarfnum = num}
24#define GPR_DWARFNUM_NAME(num) \
25 {.name = STR(%r##num), .dwarfnum = num}
26#define REG_DWARFNUM_END {.name = NULL, .dwarfnum = 0}
27
28/*
29 * Reference:
30 * http://infocenter.arm.com/help/topic/com.arm.doc.ihi0040a/IHI0040A_aadwarf.pdf
31 */
32static const struct pt_regs_dwarfnum regdwarfnum_table[] = {
33 GPR_DWARFNUM_NAME(0),
34 GPR_DWARFNUM_NAME(1),
35 GPR_DWARFNUM_NAME(2),
36 GPR_DWARFNUM_NAME(3),
37 GPR_DWARFNUM_NAME(4),
38 GPR_DWARFNUM_NAME(5),
39 GPR_DWARFNUM_NAME(6),
40 GPR_DWARFNUM_NAME(7),
41 GPR_DWARFNUM_NAME(8),
42 GPR_DWARFNUM_NAME(9),
43 GPR_DWARFNUM_NAME(10),
44 REG_DWARFNUM_NAME("%fp", 11),
45 REG_DWARFNUM_NAME("%ip", 12),
46 REG_DWARFNUM_NAME("%sp", 13),
47 REG_DWARFNUM_NAME("%lr", 14),
48 REG_DWARFNUM_NAME("%pc", 15),
49 REG_DWARFNUM_END,
50};
51
52/**
53 * get_arch_regstr() - lookup register name from it's DWARF register number
54 * @n: the DWARF register number
55 *
56 * get_arch_regstr() returns the name of the register in struct
57 * regdwarfnum_table from it's DWARF register number. If the register is not
58 * found in the table, this returns NULL;
59 */
60const char *get_arch_regstr(unsigned int n)
61{
62 const struct pt_regs_dwarfnum *roff;
63 for (roff = regdwarfnum_table; roff->name != NULL; roff++)
64 if (roff->dwarfnum == n)
65 return roff->name;
66 return NULL;
67}