microblaze-linux-tdep.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /* Target-dependent code for Xilinx MicroBlaze.
  2. Copyright (C) 2009-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 "frame.h"
  16. #include "inferior.h"
  17. #include "symtab.h"
  18. #include "target.h"
  19. #include "gdbcore.h"
  20. #include "gdbcmd.h"
  21. #include "symfile.h"
  22. #include "objfiles.h"
  23. #include "regcache.h"
  24. #include "value.h"
  25. #include "osabi.h"
  26. #include "regset.h"
  27. #include "solib-svr4.h"
  28. #include "microblaze-tdep.h"
  29. #include "trad-frame.h"
  30. #include "frame-unwind.h"
  31. #include "tramp-frame.h"
  32. #include "linux-tdep.h"
  33. static int
  34. microblaze_linux_memory_remove_breakpoint (struct gdbarch *gdbarch,
  35. struct bp_target_info *bp_tgt)
  36. {
  37. CORE_ADDR addr = bp_tgt->reqstd_address;
  38. const gdb_byte *bp;
  39. int val;
  40. int bplen;
  41. gdb_byte old_contents[BREAKPOINT_MAX];
  42. /* Determine appropriate breakpoint contents and size for this address. */
  43. bp = gdbarch_breakpoint_from_pc (gdbarch, &addr, &bplen);
  44. val = target_read_memory (addr, old_contents, bplen);
  45. /* If our breakpoint is no longer at the address, this means that the
  46. program modified the code on us, so it is wrong to put back the
  47. old value. */
  48. if (val == 0 && memcmp (bp, old_contents, bplen) == 0)
  49. val = target_write_raw_memory (addr, bp_tgt->shadow_contents, bplen);
  50. return val;
  51. }
  52. static void
  53. microblaze_linux_sigtramp_cache (struct frame_info *next_frame,
  54. struct trad_frame_cache *this_cache,
  55. CORE_ADDR func, LONGEST offset,
  56. int bias)
  57. {
  58. CORE_ADDR base;
  59. CORE_ADDR gpregs;
  60. int regnum;
  61. base = frame_unwind_register_unsigned (next_frame, MICROBLAZE_SP_REGNUM);
  62. if (bias > 0 && get_frame_address_in_block (next_frame) != func)
  63. /* See below, some signal trampolines increment the stack as their
  64. first instruction, need to compensate for that. */
  65. base -= bias;
  66. /* Find the address of the register buffer. */
  67. gpregs = base + offset;
  68. /* Registers saved on stack. */
  69. for (regnum = 0; regnum < MICROBLAZE_BTR_REGNUM; regnum++)
  70. trad_frame_set_reg_addr (this_cache, regnum,
  71. gpregs + regnum * MICROBLAZE_REGISTER_SIZE);
  72. trad_frame_set_id (this_cache, frame_id_build (base, func));
  73. }
  74. static void
  75. microblaze_linux_sighandler_cache_init (const struct tramp_frame *self,
  76. struct frame_info *next_frame,
  77. struct trad_frame_cache *this_cache,
  78. CORE_ADDR func)
  79. {
  80. microblaze_linux_sigtramp_cache (next_frame, this_cache, func,
  81. 0 /* Offset to ucontext_t. */
  82. + 24 /* Offset to .reg. */,
  83. 0);
  84. }
  85. static struct tramp_frame microblaze_linux_sighandler_tramp_frame =
  86. {
  87. SIGTRAMP_FRAME,
  88. 4,
  89. {
  90. { 0x31800077, ULONGEST_MAX }, /* addik R12,R0,119. */
  91. { 0xb9cc0008, ULONGEST_MAX }, /* brki R14,8. */
  92. { TRAMP_SENTINEL_INSN },
  93. },
  94. microblaze_linux_sighandler_cache_init
  95. };
  96. static void
  97. microblaze_linux_init_abi (struct gdbarch_info info,
  98. struct gdbarch *gdbarch)
  99. {
  100. linux_init_abi (info, gdbarch, 0);
  101. set_gdbarch_memory_remove_breakpoint (gdbarch,
  102. microblaze_linux_memory_remove_breakpoint);
  103. /* Shared library handling. */
  104. set_solib_svr4_fetch_link_map_offsets (gdbarch,
  105. linux_ilp32_fetch_link_map_offsets);
  106. /* Trampolines. */
  107. tramp_frame_prepend_unwinder (gdbarch,
  108. &microblaze_linux_sighandler_tramp_frame);
  109. }
  110. void _initialize_microblaze_linux_tdep ();
  111. void
  112. _initialize_microblaze_linux_tdep ()
  113. {
  114. gdbarch_register_osabi (bfd_arch_microblaze, 0, GDB_OSABI_LINUX,
  115. microblaze_linux_init_abi);
  116. }