csky-linux-tdep.c 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. /* Target-dependent code for GNU/Linux on CSKY.
  2. Copyright (C) 2012-2022 Free Software Foundation, Inc.
  3. Contributed by C-SKY Microsystems and Mentor Graphics.
  4. This file is part of GDB.
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 3 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  15. #include "defs.h"
  16. #include "osabi.h"
  17. #include "glibc-tdep.h"
  18. #include "linux-tdep.h"
  19. #include "gdbarch.h"
  20. #include "solib-svr4.h"
  21. #include "regset.h"
  22. #include "trad-frame.h"
  23. #include "tramp-frame.h"
  24. #include "csky-tdep.h"
  25. /* Functions, definitions, and data structures for C-Sky core file debug. */
  26. /* General regset pc, r1, r0, psr, r2-r31 for CK810. */
  27. #define SIZEOF_CSKY_GREGSET 34*4
  28. /* Float regset fesr fsr fr0-fr31 for CK810. */
  29. #define SIZEOF_CSKY_FREGSET 34*4
  30. /* Offset mapping table from core_section to regcache of general
  31. registers for ck810. */
  32. static const int csky_gregset_offset[] =
  33. {
  34. 72, 1, 0, 89, 2, /* pc, r1, r0, psr, r2. */
  35. 3, 4, 5, 6, 7, /* r3 ~ r32. */
  36. 8, 9, 10, 11, 12,
  37. 13, 14, 15, 16, 17,
  38. 18, 19, 20, 21, 22,
  39. 23, 24, 25, 26, 27,
  40. 28, 29, 30, 31
  41. };
  42. /* Offset mapping table from core_section to regcache of float
  43. registers for ck810. */
  44. static const int csky_fregset_offset[] =
  45. {
  46. 122, 123, 40, 41, 42, /* fcr, fesr, fr0 ~ fr2. */
  47. 43, 44, 45, 46, 47, /* fr3 ~ fr15. */
  48. 48, 49, 50, 51, 52,
  49. 53, 54, 55
  50. };
  51. /* Implement the supply_regset hook for GP registers in core files. */
  52. static void
  53. csky_supply_gregset (const struct regset *regset,
  54. struct regcache *regcache, int regnum,
  55. const void *regs, size_t len)
  56. {
  57. int i, gregset_num;
  58. const gdb_byte *gregs = (const gdb_byte *) regs ;
  59. gdb_assert (len >= SIZEOF_CSKY_GREGSET);
  60. gregset_num = ARRAY_SIZE (csky_gregset_offset);
  61. for (i = 0; i < gregset_num; i++)
  62. {
  63. if ((regnum == csky_gregset_offset[i] || regnum == -1)
  64. && csky_gregset_offset[i] != -1)
  65. regcache->raw_supply (csky_gregset_offset[i], gregs + 4 * i);
  66. }
  67. }
  68. /* Implement the collect_regset hook for GP registers in core files. */
  69. static void
  70. csky_collect_gregset (const struct regset *regset,
  71. const struct regcache *regcache,
  72. int regnum, void *gregs_buf, size_t len)
  73. {
  74. int regno, gregset_num;
  75. gdb_byte *gregs = (gdb_byte *) gregs_buf ;
  76. gdb_assert (len >= SIZEOF_CSKY_GREGSET);
  77. gregset_num = ARRAY_SIZE (csky_gregset_offset);
  78. for (regno = 0; regno < gregset_num; regno++)
  79. {
  80. if ((regnum == csky_gregset_offset[regno] || regnum == -1)
  81. && csky_gregset_offset[regno] != -1)
  82. regcache->raw_collect (regno,
  83. gregs + 4 + csky_gregset_offset[regno]);
  84. }
  85. }
  86. /* Implement the supply_regset hook for FP registers in core files. */
  87. static void
  88. csky_supply_fregset (const struct regset *regset,
  89. struct regcache *regcache, int regnum,
  90. const void *regs, size_t len)
  91. {
  92. int i;
  93. int offset = 0;
  94. struct gdbarch *gdbarch = regcache->arch ();
  95. const gdb_byte *fregs = (const gdb_byte *) regs;
  96. int fregset_num = ARRAY_SIZE (csky_fregset_offset);
  97. gdb_assert (len >= SIZEOF_CSKY_FREGSET);
  98. for (i = 0; i < fregset_num; i++)
  99. {
  100. if ((regnum == csky_fregset_offset[i] || regnum == -1)
  101. && csky_fregset_offset[i] != -1)
  102. {
  103. int num = csky_fregset_offset[i];
  104. offset += register_size (gdbarch, num);
  105. regcache->raw_supply (csky_fregset_offset[i], fregs + offset);
  106. }
  107. }
  108. }
  109. /* Implement the collect_regset hook for FP registers in core files. */
  110. static void
  111. csky_collect_fregset (const struct regset *regset,
  112. const struct regcache *regcache,
  113. int regnum, void *fregs_buf, size_t len)
  114. {
  115. int regno;
  116. struct gdbarch *gdbarch = regcache->arch ();
  117. gdb_byte *fregs = (gdb_byte *) fregs_buf ;
  118. int fregset_num = ARRAY_SIZE (csky_fregset_offset);
  119. int offset = 0;
  120. gdb_assert (len >= SIZEOF_CSKY_FREGSET);
  121. for (regno = 0; regno < fregset_num; regno++)
  122. {
  123. if ((regnum == csky_fregset_offset[regno] || regnum == -1)
  124. && csky_fregset_offset[regno] != -1)
  125. {
  126. offset += register_size (gdbarch, csky_fregset_offset[regno]);
  127. regcache->raw_collect (regno, fregs + offset);
  128. }
  129. }
  130. }
  131. static const struct regset csky_regset_general =
  132. {
  133. NULL,
  134. csky_supply_gregset,
  135. csky_collect_gregset
  136. };
  137. static const struct regset csky_regset_float =
  138. {
  139. NULL,
  140. csky_supply_fregset,
  141. csky_collect_fregset
  142. };
  143. /* Iterate over core file register note sections. */
  144. static void
  145. csky_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
  146. iterate_over_regset_sections_cb *cb,
  147. void *cb_data,
  148. const struct regcache *regcache)
  149. {
  150. cb (".reg", sizeof (csky_gregset_offset), sizeof (csky_gregset_offset),
  151. &csky_regset_general, NULL, cb_data);
  152. cb (".reg2", sizeof (csky_fregset_offset), sizeof (csky_fregset_offset),
  153. &csky_regset_float, NULL, cb_data);
  154. }
  155. static void
  156. csky_linux_rt_sigreturn_init (const struct tramp_frame *self,
  157. struct frame_info *this_frame,
  158. struct trad_frame_cache *this_cache,
  159. CORE_ADDR func)
  160. {
  161. int i;
  162. CORE_ADDR sp = get_frame_register_unsigned (this_frame, 14);
  163. CORE_ADDR base = sp + CSKY_SIGINFO_OFFSET + CSKY_SIGINFO_SIZE
  164. + CSKY_UCONTEXT_SIGCONTEXT
  165. + CSKY_SIGCONTEXT_SC_USP
  166. + CSKY_SIGCONTEXT_SC_A0;
  167. /* Set addrs of R0 ~ R13. */
  168. for (i = 0; i < 14; i++)
  169. trad_frame_set_reg_addr (this_cache, i, base + i * 4);
  170. /* Set addrs of SP(R14) and R15. */
  171. trad_frame_set_reg_addr (this_cache, 14, base - 4);
  172. trad_frame_set_reg_addr (this_cache, 15, base + 4 * 14);
  173. /* Set addrs of R16 ~ R31. */
  174. for (i = 15; i < 31; i++)
  175. trad_frame_set_reg_addr (this_cache, i, base + i * 4);
  176. /* Set addrs of PSR and PC. */
  177. trad_frame_set_reg_addr (this_cache, 89, base + 4 * 33);
  178. trad_frame_set_reg_addr (this_cache, 72, base + 4 * 34);
  179. trad_frame_set_id (this_cache, frame_id_build (sp, func));
  180. }
  181. static struct tramp_frame
  182. csky_linux_rt_sigreturn_tramp_frame = {
  183. SIGTRAMP_FRAME,
  184. 4,
  185. {
  186. { CSKY_MOVI_R7_173, ULONGEST_MAX },
  187. { CSKY_TRAP_0, ULONGEST_MAX },
  188. { TRAMP_SENTINEL_INSN }
  189. },
  190. csky_linux_rt_sigreturn_init
  191. };
  192. /* Hook function for gdbarch_register_osabi. */
  193. static void
  194. csky_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
  195. {
  196. linux_init_abi (info, gdbarch, 0);
  197. /* Shared library handling. */
  198. set_gdbarch_skip_trampoline_code (gdbarch, find_solib_trampoline_target);
  199. set_gdbarch_skip_solib_resolver (gdbarch, glibc_skip_solib_resolver);
  200. set_solib_svr4_fetch_link_map_offsets (gdbarch,
  201. linux_ilp32_fetch_link_map_offsets);
  202. /* Enable TLS support. */
  203. set_gdbarch_fetch_tls_load_module_address (gdbarch,
  204. svr4_fetch_objfile_link_map);
  205. /* Core file support. */
  206. set_gdbarch_iterate_over_regset_sections (
  207. gdbarch, csky_linux_iterate_over_regset_sections);
  208. /* Append tramp frame unwinder for SIGNAL. */
  209. tramp_frame_prepend_unwinder (gdbarch,
  210. &csky_linux_rt_sigreturn_tramp_frame);
  211. }
  212. void _initialize_csky_linux_tdep ();
  213. void
  214. _initialize_csky_linux_tdep ()
  215. {
  216. gdbarch_register_osabi (bfd_arch_csky, 0, GDB_OSABI_LINUX,
  217. csky_linux_init_abi);
  218. }