Ian Munsie | fead796 | 2010-04-20 16:58:33 +1000 | [diff] [blame] | 1 | /* |
| 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 Schafer | 861e10b | 2013-03-14 15:27:51 -0700 | [diff] [blame] | 12 | #include <stddef.h> |
Naveen N. Rao | 4679bcc | 2016-05-05 20:53:19 +0530 | [diff] [blame] | 13 | #include <errno.h> |
| 14 | #include <string.h> |
Ian Munsie | fead796 | 2010-04-20 16:58:33 +1000 | [diff] [blame] | 15 | #include <dwarf-regs.h> |
Naveen N. Rao | 4679bcc | 2016-05-05 20:53:19 +0530 | [diff] [blame] | 16 | #include <linux/ptrace.h> |
| 17 | #include <linux/kernel.h> |
Arnaldo Carvalho de Melo | aa8cc2f | 2017-04-17 15:36:40 -0300 | [diff] [blame] | 18 | #include <linux/stringify.h> |
Naveen N. Rao | 4679bcc | 2016-05-05 20:53:19 +0530 | [diff] [blame] | 19 | #include "util.h" |
Ian Munsie | fead796 | 2010-04-20 16:58:33 +1000 | [diff] [blame] | 20 | |
| 21 | struct pt_regs_dwarfnum { |
| 22 | const char *name; |
| 23 | unsigned int dwarfnum; |
Naveen N. Rao | 4679bcc | 2016-05-05 20:53:19 +0530 | [diff] [blame] | 24 | unsigned int ptregs_offset; |
Ian Munsie | fead796 | 2010-04-20 16:58:33 +1000 | [diff] [blame] | 25 | }; |
| 26 | |
Naveen N. Rao | 4679bcc | 2016-05-05 20:53:19 +0530 | [diff] [blame] | 27 | #define REG_DWARFNUM_NAME(r, num) \ |
Arnaldo Carvalho de Melo | aa8cc2f | 2017-04-17 15:36:40 -0300 | [diff] [blame] | 28 | {.name = __stringify(%)__stringify(r), .dwarfnum = num, \ |
Naveen N. Rao | 4679bcc | 2016-05-05 20:53:19 +0530 | [diff] [blame] | 29 | .ptregs_offset = offsetof(struct pt_regs, r)} |
| 30 | #define GPR_DWARFNUM_NAME(num) \ |
Arnaldo Carvalho de Melo | aa8cc2f | 2017-04-17 15:36:40 -0300 | [diff] [blame] | 31 | {.name = __stringify(%gpr##num), .dwarfnum = num, \ |
Naveen N. Rao | 4679bcc | 2016-05-05 20:53:19 +0530 | [diff] [blame] | 32 | .ptregs_offset = offsetof(struct pt_regs, gpr[num])} |
| 33 | #define REG_DWARFNUM_END {.name = NULL, .dwarfnum = 0, .ptregs_offset = 0} |
Ian Munsie | fead796 | 2010-04-20 16:58:33 +1000 | [diff] [blame] | 34 | |
| 35 | /* |
| 36 | * Reference: |
| 37 | * http://refspecs.linuxfoundation.org/ELF/ppc64/PPC-elf64abi-1.9.html |
| 38 | */ |
| 39 | static 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. Rao | 4679bcc | 2016-05-05 20:53:19 +0530 | [diff] [blame] | 72 | 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 Munsie | fead796 | 2010-04-20 16:58:33 +1000 | [diff] [blame] | 78 | 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 | */ |
| 89 | const 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. Rao | 4679bcc | 2016-05-05 20:53:19 +0530 | [diff] [blame] | 97 | |
| 98 | int 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 | } |