or1k-linux-tdep.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /* Target-dependent code for GNU/Linux on OpenRISC processors.
  2. Copyright (C) 2018-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 "or1k-tdep.h"
  16. #include "osabi.h"
  17. #include "glibc-tdep.h"
  18. #include "linux-tdep.h"
  19. #include "solib-svr4.h"
  20. #include "regset.h"
  21. #include "tramp-frame.h"
  22. #include "trad-frame.h"
  23. #include "gdbarch.h"
  24. #include "features/or1k-linux.c"
  25. /* Define the general register mapping. The kernel and GDB put registers
  26. r1 to r31 in the same place. The NPC register is stored at index 32 in
  27. linux and 33 in GDB, in GDB 32 is for PPC which is not popupated from linux.
  28. Register r0 is always 0 and can be ignored. */
  29. static const struct regcache_map_entry or1k_linux_gregmap[] =
  30. {
  31. { 32, OR1K_ZERO_REGNUM, 4 }, /* r0 to r31 */
  32. { 1, OR1K_NPC_REGNUM, 4 },
  33. { 0 }
  34. };
  35. /* Define the general register regset. */
  36. static const struct regset or1k_linux_gregset =
  37. {
  38. or1k_linux_gregmap, regcache_supply_regset, regcache_collect_regset
  39. };
  40. /* Define hook for core file support. */
  41. static void
  42. or1k_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
  43. iterate_over_regset_sections_cb *cb,
  44. void *cb_data,
  45. const struct regcache *regcache)
  46. {
  47. cb (".reg", (33 * 4), (33 * 4), &or1k_linux_gregset, NULL, cb_data);
  48. }
  49. /* Signal trampoline support. */
  50. static void or1k_linux_sigframe_init (const struct tramp_frame *self,
  51. struct frame_info *this_frame,
  52. struct trad_frame_cache *this_cache,
  53. CORE_ADDR func);
  54. #define OR1K_RT_SIGRETURN 139
  55. #define OR1K_INST_L_ORI_R11_R0_IMM 0xa9600000
  56. #define OR1K_INST_L_SYS_1 0x20000001
  57. #define OR1K_INST_L_NOP 0x15000000
  58. static const struct tramp_frame or1k_linux_sigframe = {
  59. SIGTRAMP_FRAME,
  60. 4,
  61. {
  62. { OR1K_INST_L_ORI_R11_R0_IMM | OR1K_RT_SIGRETURN, ULONGEST_MAX },
  63. { OR1K_INST_L_SYS_1, ULONGEST_MAX },
  64. { OR1K_INST_L_NOP, ULONGEST_MAX },
  65. { TRAMP_SENTINEL_INSN }
  66. },
  67. or1k_linux_sigframe_init,
  68. NULL
  69. };
  70. /* Runtime signal frames look like this:
  71. struct rt_sigframe {
  72. struct siginfo info;
  73. struct ucontext uc;
  74. unsigned char retcode[16];
  75. };
  76. struct ucontext {
  77. unsigned long uc_flags; - 4
  78. struct ucontext *uc_link; - 4
  79. stack_t uc_stack; - 4 * 3
  80. struct sigcontext uc_mcontext;
  81. sigset_t uc_sigmask;
  82. };
  83. struct sigcontext {
  84. struct user_regs_struct regs;
  85. unsigned long oldmask;
  86. };
  87. struct user_regs_struct {
  88. unsigned long gpr[32];
  89. unsigned long pc;
  90. unsigned long sr;
  91. }; */
  92. #define SIGFRAME_SIGINFO_SIZE 128
  93. #define UCONTEXT_MCONTEXT_OFFSET 20
  94. static void
  95. or1k_linux_sigframe_init (const struct tramp_frame *self,
  96. struct frame_info *this_frame,
  97. struct trad_frame_cache *this_cache,
  98. CORE_ADDR func)
  99. {
  100. CORE_ADDR frame_sp = get_frame_sp (this_frame);
  101. CORE_ADDR mcontext_base;
  102. CORE_ADDR regs_base;
  103. mcontext_base = frame_sp + SIGFRAME_SIGINFO_SIZE + UCONTEXT_MCONTEXT_OFFSET;
  104. /* Handle the general registers 0-31 followed by the PC. */
  105. regs_base = mcontext_base;
  106. for (int i = 0; i < 32; i++)
  107. trad_frame_set_reg_addr (this_cache, OR1K_ZERO_REGNUM + i,
  108. regs_base + (i * 4));
  109. trad_frame_set_reg_addr (this_cache, OR1K_NPC_REGNUM, regs_base + (32 * 4));
  110. trad_frame_set_reg_addr (this_cache, OR1K_SR_REGNUM, regs_base + (33 * 4));
  111. /* Choice of the bottom of the sigframe is somewhat arbitrary. */
  112. trad_frame_set_id (this_cache, frame_id_build (frame_sp, func));
  113. }
  114. /* Initialize OpenRISC Linux ABI info. */
  115. static void
  116. or1k_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
  117. {
  118. linux_init_abi (info, gdbarch, 0);
  119. set_solib_svr4_fetch_link_map_offsets (gdbarch,
  120. linux_ilp32_fetch_link_map_offsets);
  121. /* GNU/Linux uses SVR4-style shared libraries. */
  122. set_gdbarch_skip_trampoline_code (gdbarch, find_solib_trampoline_target);
  123. /* GNU/Linux uses the dynamic linker included in the GNU C Library. */
  124. set_gdbarch_skip_solib_resolver (gdbarch, glibc_skip_solib_resolver);
  125. set_gdbarch_software_single_step (gdbarch, or1k_software_single_step);
  126. /* Enable TLS support. */
  127. set_gdbarch_fetch_tls_load_module_address (gdbarch,
  128. svr4_fetch_objfile_link_map);
  129. set_gdbarch_iterate_over_regset_sections
  130. (gdbarch, or1k_linux_iterate_over_regset_sections);
  131. tramp_frame_prepend_unwinder (gdbarch, &or1k_linux_sigframe);
  132. }
  133. /* Initialize OpenRISC Linux target support. */
  134. void _initialize_or1k_linux_tdep ();
  135. void
  136. _initialize_or1k_linux_tdep ()
  137. {
  138. gdbarch_register_osabi (bfd_arch_or1k, 0, GDB_OSABI_LINUX,
  139. or1k_linux_init_abi);
  140. /* Initialize the standard target descriptions. */
  141. initialize_tdesc_or1k_linux ();
  142. }