linux-sh-low.cc 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. /* GNU/Linux/SH specific low level interface, for the remote server for GDB.
  2. Copyright (C) 1995-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 "server.h"
  15. #include "linux-low.h"
  16. /* Linux target op definitions for the SH architecture. */
  17. class sh_target : public linux_process_target
  18. {
  19. public:
  20. const regs_info *get_regs_info () override;
  21. const gdb_byte *sw_breakpoint_from_kind (int kind, int *size) override;
  22. protected:
  23. void low_arch_setup () override;
  24. bool low_cannot_fetch_register (int regno) override;
  25. bool low_cannot_store_register (int regno) override;
  26. bool low_supports_breakpoints () override;
  27. CORE_ADDR low_get_pc (regcache *regcache) override;
  28. void low_set_pc (regcache *regcache, CORE_ADDR newpc) override;
  29. bool low_breakpoint_at (CORE_ADDR pc) override;
  30. };
  31. /* The singleton target ops object. */
  32. static sh_target the_sh_target;
  33. bool
  34. sh_target::low_supports_breakpoints ()
  35. {
  36. return true;
  37. }
  38. CORE_ADDR
  39. sh_target::low_get_pc (regcache *regcache)
  40. {
  41. return linux_get_pc_32bit (regcache);
  42. }
  43. void
  44. sh_target::low_set_pc (regcache *regcache, CORE_ADDR pc)
  45. {
  46. linux_set_pc_32bit (regcache, pc);
  47. }
  48. /* Defined in auto-generated file reg-sh.c. */
  49. void init_registers_sh (void);
  50. extern const struct target_desc *tdesc_sh;
  51. #ifdef HAVE_SYS_REG_H
  52. #include <sys/reg.h>
  53. #endif
  54. #include <asm/ptrace.h>
  55. #define sh_num_regs 41
  56. /* Currently, don't check/send MQ. */
  57. static int sh_regmap[] = {
  58. 0, 4, 8, 12, 16, 20, 24, 28,
  59. 32, 36, 40, 44, 48, 52, 56, 60,
  60. REG_PC*4, REG_PR*4, REG_GBR*4, -1,
  61. REG_MACH*4, REG_MACL*4, REG_SR*4,
  62. REG_FPUL*4, REG_FPSCR*4,
  63. REG_FPREG0*4+0, REG_FPREG0*4+4, REG_FPREG0*4+8, REG_FPREG0*4+12,
  64. REG_FPREG0*4+16, REG_FPREG0*4+20, REG_FPREG0*4+24, REG_FPREG0*4+28,
  65. REG_FPREG0*4+32, REG_FPREG0*4+36, REG_FPREG0*4+40, REG_FPREG0*4+44,
  66. REG_FPREG0*4+48, REG_FPREG0*4+52, REG_FPREG0*4+56, REG_FPREG0*4+60,
  67. };
  68. bool
  69. sh_target::low_cannot_store_register (int regno)
  70. {
  71. return false;
  72. }
  73. bool
  74. sh_target::low_cannot_fetch_register (int regno)
  75. {
  76. return false;
  77. }
  78. /* Correct in either endianness, obviously. */
  79. static const unsigned short sh_breakpoint = 0xc3c3;
  80. #define sh_breakpoint_len 2
  81. /* Implementation of target ops method "sw_breakpoint_from_kind". */
  82. const gdb_byte *
  83. sh_target::sw_breakpoint_from_kind (int kind, int *size)
  84. {
  85. *size = sh_breakpoint_len;
  86. return (const gdb_byte *) &sh_breakpoint;
  87. }
  88. bool
  89. sh_target::low_breakpoint_at (CORE_ADDR where)
  90. {
  91. unsigned short insn;
  92. read_memory (where, (unsigned char *) &insn, 2);
  93. if (insn == sh_breakpoint)
  94. return true;
  95. /* If necessary, recognize more trap instructions here. GDB only uses the
  96. one. */
  97. return false;
  98. }
  99. /* Provide only a fill function for the general register set. ps_lgetregs
  100. will use this for NPTL support. */
  101. static void sh_fill_gregset (struct regcache *regcache, void *buf)
  102. {
  103. int i;
  104. for (i = 0; i < 23; i++)
  105. if (sh_regmap[i] != -1)
  106. collect_register (regcache, i, (char *) buf + sh_regmap[i]);
  107. }
  108. static struct regset_info sh_regsets[] = {
  109. { 0, 0, 0, 0, GENERAL_REGS, sh_fill_gregset, NULL },
  110. NULL_REGSET
  111. };
  112. static struct regsets_info sh_regsets_info =
  113. {
  114. sh_regsets, /* regsets */
  115. 0, /* num_regsets */
  116. NULL, /* disabled_regsets */
  117. };
  118. static struct usrregs_info sh_usrregs_info =
  119. {
  120. sh_num_regs,
  121. sh_regmap,
  122. };
  123. static struct regs_info myregs_info =
  124. {
  125. NULL, /* regset_bitmap */
  126. &sh_usrregs_info,
  127. &sh_regsets_info
  128. };
  129. const regs_info *
  130. sh_target::get_regs_info ()
  131. {
  132. return &myregs_info;
  133. }
  134. void
  135. sh_target::low_arch_setup ()
  136. {
  137. current_process ()->tdesc = tdesc_sh;
  138. }
  139. /* The linux target ops object. */
  140. linux_process_target *the_linux_target = &the_sh_target;
  141. void
  142. initialize_low_arch (void)
  143. {
  144. init_registers_sh ();
  145. initialize_regsets_info (&sh_regsets_info);
  146. }