dwarf-regs.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  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. #include <stddef.h>
  11. #include <linux/stringify.h>
  12. #include <dwarf-regs.h>
  13. struct pt_regs_dwarfnum {
  14. const char *name;
  15. unsigned int dwarfnum;
  16. };
  17. #define REG_DWARFNUM_NAME(r, num) {.name = r, .dwarfnum = num}
  18. #define GPR_DWARFNUM_NAME(num) \
  19. {.name = __stringify(%r##num), .dwarfnum = num}
  20. #define REG_DWARFNUM_END {.name = NULL, .dwarfnum = 0}
  21. /*
  22. * Reference:
  23. * http://infocenter.arm.com/help/topic/com.arm.doc.ihi0040a/IHI0040A_aadwarf.pdf
  24. */
  25. static const struct pt_regs_dwarfnum regdwarfnum_table[] = {
  26. GPR_DWARFNUM_NAME(0),
  27. GPR_DWARFNUM_NAME(1),
  28. GPR_DWARFNUM_NAME(2),
  29. GPR_DWARFNUM_NAME(3),
  30. GPR_DWARFNUM_NAME(4),
  31. GPR_DWARFNUM_NAME(5),
  32. GPR_DWARFNUM_NAME(6),
  33. GPR_DWARFNUM_NAME(7),
  34. GPR_DWARFNUM_NAME(8),
  35. GPR_DWARFNUM_NAME(9),
  36. GPR_DWARFNUM_NAME(10),
  37. REG_DWARFNUM_NAME("%fp", 11),
  38. REG_DWARFNUM_NAME("%ip", 12),
  39. REG_DWARFNUM_NAME("%sp", 13),
  40. REG_DWARFNUM_NAME("%lr", 14),
  41. REG_DWARFNUM_NAME("%pc", 15),
  42. REG_DWARFNUM_END,
  43. };
  44. /**
  45. * get_arch_regstr() - lookup register name from it's DWARF register number
  46. * @n: the DWARF register number
  47. *
  48. * get_arch_regstr() returns the name of the register in struct
  49. * regdwarfnum_table from it's DWARF register number. If the register is not
  50. * found in the table, this returns NULL;
  51. */
  52. const char *get_arch_regstr(unsigned int n)
  53. {
  54. const struct pt_regs_dwarfnum *roff;
  55. for (roff = regdwarfnum_table; roff->name != NULL; roff++)
  56. if (roff->dwarfnum == n)
  57. return roff->name;
  58. return NULL;
  59. }