xtensa-linux-tdep.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /* Target-dependent code for GNU/Linux on Xtensa processors.
  2. Copyright (C) 2007-2022 Free Software Foundation, Inc.
  3. This file is part of GDB.
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  14. #include "defs.h"
  15. #include "xtensa-tdep.h"
  16. #include "osabi.h"
  17. #include "linux-tdep.h"
  18. #include "solib-svr4.h"
  19. #include "symtab.h"
  20. #include "gdbarch.h"
  21. /* This enum represents the signals' numbers on the Xtensa
  22. architecture. It just contains the signal definitions which are
  23. different from the generic implementation.
  24. It is derived from the file <arch/xtensa/include/uapi/asm/signal.h>,
  25. from the Linux kernel tree. */
  26. enum
  27. {
  28. XTENSA_LINUX_SIGRTMIN = 32,
  29. XTENSA_LINUX_SIGRTMAX = 63,
  30. };
  31. /* Implementation of `gdbarch_gdb_signal_from_target', as defined in
  32. gdbarch.h. */
  33. static enum gdb_signal
  34. xtensa_linux_gdb_signal_from_target (struct gdbarch *gdbarch,
  35. int signal)
  36. {
  37. if (signal >= XTENSA_LINUX_SIGRTMIN && signal <= XTENSA_LINUX_SIGRTMAX)
  38. {
  39. int offset = signal - XTENSA_LINUX_SIGRTMIN;
  40. if (offset == 0)
  41. return GDB_SIGNAL_REALTIME_32;
  42. else
  43. return (enum gdb_signal) (offset - 1
  44. + (int) GDB_SIGNAL_REALTIME_33);
  45. }
  46. else if (signal > XTENSA_LINUX_SIGRTMAX)
  47. return GDB_SIGNAL_UNKNOWN;
  48. return linux_gdb_signal_from_target (gdbarch, signal);
  49. }
  50. /* Implementation of `gdbarch_gdb_signal_to_target', as defined in
  51. gdbarch.h. */
  52. static int
  53. xtensa_linux_gdb_signal_to_target (struct gdbarch *gdbarch,
  54. enum gdb_signal signal)
  55. {
  56. switch (signal)
  57. {
  58. /* GDB_SIGNAL_REALTIME_32 is not continuous in <gdb/signals.def>,
  59. therefore we have to handle it here. */
  60. case GDB_SIGNAL_REALTIME_32:
  61. return XTENSA_LINUX_SIGRTMIN;
  62. /* GDB_SIGNAL_REALTIME_64 is not valid on Xtensa. */
  63. case GDB_SIGNAL_REALTIME_64:
  64. return -1;
  65. }
  66. /* GDB_SIGNAL_REALTIME_33 to _63 are continuous.
  67. Xtensa does not have _64. */
  68. if (signal >= GDB_SIGNAL_REALTIME_33
  69. && signal <= GDB_SIGNAL_REALTIME_63)
  70. {
  71. int offset = signal - GDB_SIGNAL_REALTIME_33;
  72. return XTENSA_LINUX_SIGRTMIN + 1 + offset;
  73. }
  74. return linux_gdb_signal_to_target (gdbarch, signal);
  75. }
  76. /* OS specific initialization of gdbarch. */
  77. static void
  78. xtensa_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
  79. {
  80. xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
  81. if (tdep->num_nopriv_regs < tdep->num_regs)
  82. {
  83. tdep->num_pseudo_regs += tdep->num_regs - tdep->num_nopriv_regs;
  84. tdep->num_regs = tdep->num_nopriv_regs;
  85. set_gdbarch_num_regs (gdbarch, tdep->num_regs);
  86. set_gdbarch_num_pseudo_regs (gdbarch, tdep->num_pseudo_regs);
  87. }
  88. linux_init_abi (info, gdbarch, 0);
  89. set_solib_svr4_fetch_link_map_offsets
  90. (gdbarch, linux_ilp32_fetch_link_map_offsets);
  91. set_gdbarch_gdb_signal_from_target (gdbarch,
  92. xtensa_linux_gdb_signal_from_target);
  93. set_gdbarch_gdb_signal_to_target (gdbarch,
  94. xtensa_linux_gdb_signal_to_target);
  95. /* Enable TLS support. */
  96. set_gdbarch_fetch_tls_load_module_address (gdbarch,
  97. svr4_fetch_objfile_link_map);
  98. }
  99. void _initialize_xtensa_linux_tdep ();
  100. void
  101. _initialize_xtensa_linux_tdep ()
  102. {
  103. gdbarch_register_osabi (bfd_arch_xtensa, bfd_mach_xtensa, GDB_OSABI_LINUX,
  104. xtensa_linux_init_abi);
  105. }